एपीआई:मुखपृष्ठ
| This page is part of the MediaWiki action API documentation. |
MediaWiki action API
- Introduction and quick start
- FAQ
- Tutorial
- Formats
- Error reporting
- Restricting usage
- Cross-site requests
- Authentication
- Queries
- Searching (by title, content, coordinates...)
- Parsing wikitext and expanding templates
- Purging pages' caches
- Parameter information
- Changing wiki content
- Create and edit pages
- Move pages
- Merge pages
- Rollback
- Delete pages
- Restore deleted revisions
- (Un)protect pages
- (Un)block users
- (Un)watch pages
- Mark revisions of watched pages as visited
- Send email
- Patrol changes
- Import pages
- Change user group membership
- Upload files
- User options
- Tokens
- Page language
- Watchlist feed
- Wikidata
- Extensions
- Using the API in MediaWiki and extensions
- Miscellaneous
- Implementation
- Client code
- Asserting
- यह एपीआई द्वारा कार्य का अवलोकन है। दायें ओर में दिये मेनू को इसके उपविषय और एपीआई से जुड़े जानकारी हेतु देखें।
मीडियाविकि एपीआई एक वेब सेवा है, जो आपको विकि के विशेषता, डाटा, आदि को एचटीटीपी या यूआरएल द्वारा जो मुखतः api.php होता है।
कोई भी विशेष कार्य हेतु क्रिया दे सकता है। जो मुख्यतः action=query होता है, यह जानकारी प्राप्त करने के लिए उपयोग किया जाता है। यह पहले एक मीडियाविकि एपीआई के रूप में जाना जाता था। लेकिन अब वेब एपीआई भी उपलब्ध हो गया है, जो रेस्टबेस और विकिडाटा कुएरी सेवा नाम से जाना जाता है।
Contents
प्रस्तावना[edit]
Note: यदि आप "आंतरिक एपीआई" या "पीएचपी एपीआई" का उपयोग करना चाहते हैं, तो extension interface देखें, जो आपको पीएचपी के कई कार्यों और मीडियाविकि के स्थापन के बारे में बताता है।
मीडियाविकि का एपीआई आप मीडियाविकि के स्थापन की देख रेख में भी कर सकते हैं, या आप कोई बॉट का निर्माण कर स्वतः इसकी देख रेख कर सकते हैं। यह सीधे ही उच्च-स्तर में डाटा पर नियंत्रण स्थापित करने देता है। ग्राहक कार्यक्रम द्वारा वे विकि पर प्रवेश कर डाटा ले सकते हैं और बदलाव भेज सकते हैं। यह स्वतः ही एचटीटीपी द्वारा होता है। Supported clients include bots, thin web-based JavaScript clients such as Navigation popups and LiveRC, end-user applications such as Vandal Fighter, and other web sites (Tool Labs' utilities).
नए मीडियाविकि के स्थापन में वेब सेवा मूल रूप से सक्रिय होती है। लेकिन प्रबन्धक चाहे तो इसे निष्क्रिय कर सकता है।
मीडियाविकि दो अलग रूपों में भी उपलब्ध है:
- Special:Export पृष्ठ आपको एक साथ कई विकि सामग्री को एक्सएमएल प्रारूप में डालने कि सुविधा प्रदान करता है। आप और जानकारी के लिए मेटा पर निर्यात करने में सहायता देखें।
- मानक वेब आधारित रूप (आप जो अभी इस पृष्ठ को देख रहे हैं, वही है यह रूप)। वेब आधारित उपयोग हेतु Manual:Parameters to index.php को पढ़ें।
एक सरल उदाहरण[edit]
यह पता आपको अंग्रेज़ी विकिपीडिया के वेब सेवा एपीआई के बारे में सामग्री पृष्ठ पर ले जाएगा।
आप कोई भी भाषा का उपयोग कर एचटीटीपी का गेट अनुरोध कर सकते हैं। इसके लिए आप कोई भी ब्राउज़र का भी उपयोग कर सकते हैं। इसके बाद आपको जेसन के रूप में पृष्ठ मिलेगा। आप इसका प्रारूप jsonfm से कोई एचटीएमएल प्रारूप में भी बदल सकते हैं, जो जाँच करते समय बहुत अच्छा होता है, क्योंकि वह कोई भी त्रुटि होने पर बहुत जानकारी दे देता है।
यहाँ jsonfm यूआरएल है, आसानी से पढ़ने और क्लिक करने वाली कड़ी।
कृपया इसमें से यूआरएल लेकर देखें, कि यह कैसे कार्य करता है।
अन्तिम बिन्दु =[edit]
https://en.wikipedia.org/w/api.php
यह अन्तिम बिन्दु है। यह मीडियाविकि वेब के एपीआई का मुखपृष्ठ के समान ही है। यह यूआरएल अंग्रेज़ी विकिपीडिया के एपीआई का आधार यूआरएल है। यह केवल https://en.wikipedia.org/wiki/ ही है।
यदि आप कोई कार्यक्रम अंग्रेज़ी विकिपीडिया में उपयोग करने के लिए लिख रहे हैं, तो उसका हर पता इस आधार यूआरएल पर आधारित होना चाहिए। If you're using a different MediaWiki installation, you'll need to find its endpoint and use that instead. All Wikimedia wikis have endpoints that follow this pattern:
https://www.mediawiki.org/w/api.php # MediaWiki API
https://en.wikipedia.org/w/api.php # अंग्रेज़ी विकिपीडिया एपीआई
https://nl.wikipedia.org/w/api.php # डच विकिपीडिया एपीआई
https://commons.wikimedia.org/w/api.php # विकिमीडिया कॉमन एपीआई
| MediaWiki version: | ≥ 1.17 |
Since r75621, we have RSD discovery for the endpoint: look for the link rel="EditURI" in the HTML source of any page and extract the api.php URL; the actual link contains additional info. उदाहरण के लिए यह देखें।
<link rel="EditURI" type="application/rsd+xml" href="//www.mediawiki.org/w/api.php?action=rsd" />
अन्यथा, ऐसा कोई भी तरीका नहीं है किसी भी विकि के अन्तिम बिन्दु को देखने का। If you're lucky, either the full path to index.php will not be hidden under strange rewrite rules so that you'll only have to take the "edit" (or history) link and replace index.php (etc.) with api.php, or you'll be able to use the default script path (like w/api.php).
Now let's move on to the parameters in the query string of the URL.
प्रारूप[edit]
format=json यह एपीआई को बताता है कि आप डाटा को जेसन प्रारूप में प्राप्त करना चाहते हैं। आप शायद यह भी उपयोग करना चाहे format=jsonfm जिससे आप इसका एचटीएमएल संस्करण प्राप्त कर सकते हो। यह परीक्षण के दौरान त्रुटि जाँच करने में सहायक होता है। The API supports other output formats such as XML and native PHP, but there are plans to remove less popular formats (phab:T95715), so you might not want to use them.
प्रतिक्रिया[edit]
action=query
The MediaWiki web service API implements dozens of actions and extensions implement many more; the dynamically generated API help documents all available actions on a wiki. इस मामले में हम "query" का उपयोग कुछ जानकारी हासिल करने में करते हैं।
इसमें से "query" सबसे अधिक उपयोगी और महत्वपूर्ण एपीआई है, जिसमें Special:MyLanguage/API:Query भी है।
यह उदाहरण केवल छोटी सी व्याख्या करता है।
Action-specific parameters[edit]
titles=Main%20Page
The rest of the example URL contains parameters used by the "query" action. Here, we're telling the web service API that we want information about the Wiki page called "Main Page". (The %20 comes from percent-encoding a space.) If you need to query multiple pages, put them all in one request to optimize network and server resources: titles=PageA|PageB|PageC. See the query documentation for details.
prop=revisions
You can request many kinds of information, or properties, about a page. This parameter tells the web service API that we want information about a particular revision of the page. Since we're not specifying any revision information, the API will give us information about the latest revision — the main page of Wikipedia as it stands right now.
rvprop=content
Finally, this parameter tells the web service API that we want the content of the latest revision of the page. If we passed in rvprop=content|user instead, we'd get the latest page content and the name of the user who made the most recent revision.
यह केवल एक उदाहरण है। Queries are explained in more detail here, and the API reference lists all the possible actions, all the possible values for rvprop, and so on.
चलो शुरू करें[edit]
मीडियाविकि वेब एपीआई सेवा शुरू करने से पहले कृपया इन लेखों को भी देख लें।
- सामान्य प्रश्नोत्तर
- इनपुट और आउटपुट प्रारूप के बारे में जानकारी
- त्रुटि और चेतावनी के बारे में जानकारी
- कोई भी नियम जो आपके विकि पर लागू होती है। जैसे विकिमीडिया संस्थान के विकि उपयोग के नियम और चिन्ह नियम, जो आपके द्वारा एपीआई का उपयोग करने पर लागू हो जाते हैं। ठीक उसी प्रकार जब आप अपना ब्राउज़र का उपयोग करते हैं।
इसके अलावा आपको जो जानकारी चाहिए वह दायें ओर दिये गए मेनू पर दिया हुआ है। इसके साथ ही कार्य से जुड़ा और दिशा निर्देश से जुड़े लेख नीचे में दिये गए हैं।
Identifying your client[edit]
When you make HTTP requests to the MediaWiki web service API, be sure to specify a User-Agent header that properly identifies your client. Don't use the default User-Agent provided by your client library, but make up a custom header that identifies your script or service and provides some type of means of contacting you (e.g., an e-mail address).
An example User-Agent string might look like:
MyCoolTool/1.1 (https://example.org/MyCoolTool/; [email protected]) BasedOnSuperLib/1.4
On Wikimedia wikis, if you don't supply a User-Agent header, or you supply an empty or generic one, your request will fail with an HTTP 403 error (cf. m:User-Agent policy). Other MediaWiki installations may have similar policies.
If you are calling the API from browser-based JavaScript, you won't be able to influence the User-Agent header: the browser will use its own. To work around this, use the Api-User-Agent header:
// Using XMLHttpRequest
xhr.setRequestHeader( 'Api-User-Agent', 'Example/1.0' );
// Using jQuery
$.ajax( {
url: remoteUrlWithOrigin,
data: queryData,
dataType: 'json',
type: 'POST',
headers: { 'Api-User-Agent': 'Example/1.0' },
success: function(data) {
// do something with data
}
} );
// Using mw.Api, specify it when creating the mw.Api object
var api = new mw.Api( {
ajax: {
headers: { 'Api-User-Agent': 'Example/1.0' }
}
} );
api.get( {...} ).done(function(data) {
// do something with data
});
In PHP, you can identify your user-agent with code such as this:
ini_set('user_agent', 'MyCoolTool/1.1 (https://example.org/MyCoolTool/; [email protected]) BasedOnSuperLib/1.4');
Or if you use cURL:
curl_setopt($curl, CURLOPT_USERAGENT, 'MyCoolTool/1.1 (https://example.org/MyCoolTool/; [email protected]) BasedOnSuperLib/1.4');
Logging in[edit]
Your client will probably need to log in to MediaWiki, possibly via its own user account. See the login manual page for details.
API etiquette[edit]
Please also read: API:Etiquette
If your requests obtain data that can be cached for a while, you should take steps to cache it, so you don't request the same data over and over again. More information about rate-limiting, concurrency, and general API etiquette can be found at API:Etiquette. Some clients may be able to cache data themselves, but for others (particularly JavaScript clients), this is not possible.
Per the HTTP specification, POST requests cannot be cached. Therefore, whenever you're reading data from the web service API, you should use GET requests, not POST.
Also note that a request cannot be served from cache unless the URL is exactly the same. If you make a request for api.php?....titles=Foo|Bar|Hello, and cache the result, then a request for api.php?....titles=Hello|Bar|Hello|Foo will not go through the cache — even though MediaWiki returns the same data!
You should take care to normalize the URLs you send to the MediaWiki web service, so that slightly different user input won't cause you to waste time on unnecessary HTTP requests. You can normalize a list of page titles by removing duplicates and sorting the titles alphabetically. Similar techniques will work for other kinds of data.
उपयोगी कड़ी[edit]
The menu bar on the right side of this page links to more detailed, task-specific documentation. Here are some links having to do with the API as a whole:
- The API sandbox available on all Wikimedia wikis makes it easy to try out different actions interactively.
- The API reference contains automatically-generated descriptions of all actions and parameters.
- Hook into Wikipedia information using PHP and the MediaWiki API (IBM developerWorks article, 17 May 2011)
- Hook into Wikipedia using Java and the MediaWiki API (6 April 2012)
- The API tutorial leads you through hands-on exercises and includes a training video.
- Mailing list for notifications and questions: API mailing list
- Low-traffic mailing list for announcements only (all posts to this list are posted to mediawiki-api as well): mediawiki-api-announce
- View and report API bugs in the MediaWiki-API Phabricator project (When reporting new bugs, don't forget to add MediaWiki-API to Projects)
- एपीआई का स्रोत देखें
- Manual:Database layout — The current MediaWiki database schema
- Browse the current database schema in git