API:Main module/pl
Ta strona jest częścią dokumentacji API akcji MediaWiki. |
The main module includes parameters that can be used for any API request.
Dokumentacja API
Przykład
Żądanie GET
Get help for the main module.
Odpowiedź
...
</head>
<body class="mediawiki ltr sitedir-ltr mw-hide-empty-elt ns--1 ns-special mw-special-ApiHelp page-Special_ApiHelp rootpage-Special_ApiHelp skin-apioutput action-view">
<div class="mw-body" role="main">
<h1 class="firstHeading">MediaWiki API help</h1>
<div class="mw-body-content">
<div id="mw-content-text"><p>This is an auto-generated MediaWiki API documentation page.
</p><p>Documentation and examples: <a class="external free" href="https://www.mediawiki.org/wiki/API">https://www.mediawiki.org/wiki/API</a>
</p><h2 class="apihelp-header" id="main">Main module</h2>
<div class="apihelp-block apihelp-flags"><ul><li><span class="apihelp-source">Source: <span dir="ltr" lang="en">MediaWiki</span></span></li><li><span class="apihelp-license">License: <a href="/wiki/Special:Version/License/MediaWiki" title="Special:Version/License/MediaWiki"><span dir="ltr" lang="en">GPL-2.0-or-later</span></a></span></li></ul></div>
<div class="hlist plainlinks api-main-links">
<ul><li><a href="https://www.mediawiki.org/wiki/Special:MyLanguage/API:Main_page" class="extiw" title="mw:Special:MyLanguage/API:Main page">Documentation</a></li>
<li><a href="https://www.mediawiki.org/wiki/Special:MyLanguage/API:FAQ" class="extiw" title="mw:Special:MyLanguage/API:FAQ">FAQ</a></li>
<li><a class="external text" href="https://lists.wikimedia.org/mailman/listinfo/mediawiki-api">Mailing list</a></li>
<li><a class="external text" href="https://lists.wikimedia.org/mailman/listinfo/mediawiki-api-announce">API Announcements</a></li>
<li><a class="external text" href="https://phabricator.wikimedia.org/maniphest/query/GebfyV4uCaLd/#R">Bugs & requests</a></li></ul></div>
<p><strong>Status:</strong> The MediaWiki API is a mature and stable interface that is actively supported and improved. While we try to avoid it, we may occasionally need to make breaking changes; subscribe to <a class="external text" href="https://lists.wikimedia.org/pipermail/mediawiki-api-announce/">the mediawiki-api-announce mailing list</a> for notice of updates.
</p><p><strong>Erroneous requests:</strong> When erroneous requests are sent to the API, an HTTP header will be sent with the key "MediaWiki-API-Error" and then both the value of the header and the error code sent back will be set to the same value. For more information see <a href="https://www.mediawiki.org/wiki/Special:MyLanguage/API:Errors_and_warnings" class="extiw" title="mw:Special:MyLanguage/API:Errors and warnings">API: Errors and warnings</a>.
</p>
...
Przykładowy kod
Python
#!/usr/bin/python3
"""
main_module.py
MediaWiki API Demos
Demo of `Main module` module: Get help for the main module.
MIT License
"""
import requests
S = requests.Session()
URL = "https://en.wikipedia.org/w/api.php"
PARAMS = {
"action": "help",
"format": "json"
}
R = S.get(url=URL, params=PARAMS)
DATA = R.json()
print(DATA)
PHP
<?php
/*
main_module.php
MediaWiki API Demos
Demo of `Main module` module: Get help for the main module.
MIT License
*/
$endPoint = "https://en.wikipedia.org/w/api.php";
$params = [
"action" => "help",
"format" => "json"
];
$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 );
var_dump( $result );
JavaScript
/*
main_module.js
MediaWiki API Demos
Demo of `Main module` module: Get help for the main module.
MIT License
*/
var url = "https://en.wikipedia.org/w/api.php";
var params = {
action: "help",
format: "json"
};
url = url + "?origin=*";
Object.keys(params).forEach(function(key){url += "&" + key + "=" + params[key];});
fetch(url)
.then(function(response){return response.json();})
.then(function(response) {console.log(response);})
.catch(function(error){console.log(error);});
MediaWiki JS
/*
main_module.js
MediaWiki API Demos
Demo of `Main module` module: Get help for the main module.
MIT License
*/
var params = {
action: 'help',
format: 'json'
},
api = new mw.Api();
api.get( params ).done( function ( data ) {
console.log( data );
} );
Możliwe błędy
Kod | Info |
---|---|
unknownaction | The action specified, action, is not recognized. |
unknownformat | Nierozpoznany format „format”. |
missingparam | Parametr $1 musi być podany. |
maxlag | Waiting for host: lag seconds lagged. |
maxlag | Oczekiwania na serwer bazy danych: opóźnienie lag sekund. |
readapidenied | You need read permission to use this module. |
noapiwrite | Edytowanie przez API jest wyłączone na tej wiki. |
writeapidenied | You're not allowed to edit this wiki through the API. |
promised-nonwrite-api | The Promise-Non-Write-API-Action HTTP header cannot be sent to write-mode API modules.
|
readonly_lag | Baza danych została automatycznie zablokowana na czas potrzebny do wykonania synchronizacji zmian między serwerem głównym i serwerami pośredniczącymi. |
assertanonfailed | You are no longer logged out, so the action could not be completed. |
assertuserfailed | Nie jesteś już zalogowany, więc akcja nie mogła zostać zakończona. |
assertbotfailed | You do not have the bot right, so the action could not be completed.
|
assertnameduserfailed | You are no longer logged in as "assertUser", so the action could not be completed. |
invalidmethod | Invalid HTTP method. Consider using GET or POST. |
mustbeposted | The $1 module requires a POST request. |
Parameter history
- v1.17: Wprowadzono
servedby
- v1.14: Wprowadzono
requestid
Zobacz też
- Podręcznik:Parametry dla index.php - A partial list of the parameters to index.php , the main script of the MediaWiki software.