Jump to content
MediaWiki

API:Random/pl

From mediawiki.org
This page is a translated version of the page API:Random and the translation is 43% complete.
Ta strona jest częścią dokumentacji API akcji MediaWiki.
API akcji MediaWiki
Podstawy
Uwierzytelnianie
Konta i użytkownicy
Operacje na stronach
Wyszukiwanie
Narzędzia dla programistów
Samouczki
p · o · e
Wersja MediaWiki:
≥ 1.12

GET request to view a list of random pages.

This module can be used as a generator .

Dokumentacja API

Poniższa dokumentacja jest rezultatem Special:ApiHelp/query+random, automatycznie wygenerowanym przez przedwczesną wersję MediaWiki, na której działa ta witryna (MediaWiki.org).

list=random (rn)

(main | query | random)
  • This module requires read rights.
  • This module can be used as a generator.
  • Source: MediaWiki
  • License: GPL-2.0-or-later

Get a set of random pages.

Pages are listed in a fixed sequence, only the starting point is random. This means that if, for example, Main Page is the first random page in the list, List of fictional monkeys will always be second, List of people on stamps of Vanuatu third, etc.

Specific parameters:
Other general parameters are available.
rnnamespace

Return pages in these namespaces only.

Values (separate with | or alternative): 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 90, 91, 92, 93, 100, 101, 102, 103, 104, 105, 106, 107, 710, 711, 828, 829, 1198, 1199, 1728, 1729, 2600, 5500, 5501
To specify all values, use *.
rnfilterredir

How to filter for redirects.

One of the following values: all, nonredirects, redirects
Default: nonredirects
rnminsize

Limit to pages with at least this many bytes.

Type: integer
rnmaxsize

Limit to pages with at most this many bytes.

Type: integer
rncontentmodel

Filter pages that have the specified content model.

One of the following values: GadgetDefinition, Graph.JsonConfig, Json.JsonConfig, JsonSchema, MassMessageListContent, NewsletterContent, Scribunto, SecurePoll, css, flow-board, javascript, json, sanitized-css, text, translate-messagebundle, unknown, vue, wikitext
rnredirect
Deprecated.

Use rnfilterredir=redirects instead.

Type: boolean (details)
rnlimit

Limit how many random pages will be returned.

Type: integer or max
The value must be between 1 and 500.
Default: 1
rncontinue

When more results are available, use this to continue. More detailed information on how to continue queries can be found on mediawiki.org.

Examples:
Return two random pages from the main namespace.
api.php?action=query&list=random&rnnamespace=0&rnlimit=2 [open in sandbox]
Return page info about two random pages from the main namespace.
api.php?action=query&generator=random&grnnamespace=0&grnlimit=2&prop=info [open in sandbox]
Return page info about one random page from the main namespace that has at least 500 bytes of text.
api.php?action=query&list=random&rnnamespace=0&rnlimit=1&minsize=500 [open in sandbox]

Przykład

Żądanie GET

List 5 random pages

Odpowiedź

{
"batchcomplete":"",
"continue":{
"rncontinue":"0.559881820010|0.559881954661|47659388|0",
"continue":"-||"
},
"query":{
"random":[
{
"id":32381675,
"ns":0,
"title":"Mallabhum Institute of Technology"
},
{
"id":25126452,
"ns":3,
"title":"User talk:96.232.132.176"
},
{
"id":1440028,
"ns":0,
"title":"Hyundai Epsilon engine"
},
{
"id":35446805,
"ns":15,
"title":"Category talk:Ukrainian card games"
},
{
"id":12613,
"ns":0,
"title":"Grue"
}
]
}
}

Przykładowy kod

Python

#!/usr/bin/python3
"""
 get_random.py
 MediaWiki API Demos
 Demo of `Random` module: Get request to list 5 random pages.
 MIT License
"""
importrequests
S = requests.Session()
URL = "https://en.wikipedia.org/w/api.php"
PARAMS = {
 "action": "query",
 "format": "json",
 "list": "random",
 "rnlimit": "5"
}
R = S.get(url=URL, params=PARAMS)
DATA = R.json()
RANDOMS = DATA["query"]["random"]
for r in RANDOMS:
 print(r["title"])

PHP

<?php
/*
 get_random.php
 MediaWiki API Demos
 Demo of Random module: Get request to list 5 random pages.
 MIT License
*/
$endPoint = "https://en.wikipedia.org/w/api.php";
$params = [
 "action" => "query",
 "format" => "json",
 "list" => "random",
 "rnlimit" => "5"
];
$url = $endPoint . "?" . http_build_query( $params );
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
$output = curl_exec( $ch );
curl_close( $ch );
$result = json_decode( $output, true );
foreach( $result["query"]["random"] as $k => $v ) {
 echo( $v["title"] . "\n" );
}

JavaScript

/*
 get_random.js
 MediaWiki API Demos
 Demo of `Random` module: Get request to list 5 random pages.
 MIT License
*/
varurl="https://en.wikipedia.org/w/api.php";
varparams={
action:"query",
format:"json",
list:"random",
rnlimit:"5"
};
url=url+"?origin=*";
Object.keys(params).forEach(function(key){url+="&"+key+"="+params[key];});
fetch(url)
.then(function(response){returnresponse.json();})
.then(function(response){
varrandoms=response.query.random;
for(varrinrandoms){
console.log(randoms[r].title);
}
})
.catch(function(error){console.log(error);});

MediaWiki JS

/*
	get_random.js
	MediaWiki API Demos
	Demo of `Random` module: Get request to list 5 random pages.
	MIT License
*/
varparams={
action:'query',
format:'json',
list:'random',
rnlimit:'5'
},
api=newmw.Api();
api.get(params).done(function(data){
varrandoms=data.query.random,
r;
for(rinrandoms){
console.log(randoms[r].title);
}
});

Historia parametrów

  • v1.26: Previous limit of 10/20 on rnlimit was increased to standard 500/5000 limits.
  • v1.26: Deprecated rnredirect
  • v1.26: Wprowadzono rnfilterredir
  • v1.14: Wprowadzono rnredirect

Dodatkowe informacje

  • Unlike most modules in the Action API , the default number of pages returned is 1, not 10.
  • Pages are returned in a fixed sequence; only the starting point is actually random.
  • The default behavior is to pick pages from across the entire wiki, including talk pages, user pages, and so on. If you are looking for similar functionality as Special:Random, i.e. pick random articles, restrict rnnamespace to 0.
  • If the number of pages is fewer than rnlimit, the request will simply return all available pages. It will not repeat pages to pad out the response up to the limit.

Zobacz też

AltStyle によって変換されたページ (->オリジナル) /