API:שאילתא
![]() | דף זה הוא חלק מהתיעוד של ה־action API של מדיה־ויקי |
action=query
מאפשר לקבל מידע אודות אתר הוויקי ואת הנתונים ששמורים בו, כגון טקסט ויקי של דף ספציפי, קישורים וקטגוריות במקבץ של דפים או האסימון שמאפשר שינוי תוכן באתר .
תיעוד API
action=query(main | query)
Fetch data from and about MediaWiki. All data modifications will first have to use query to acquire a token to prevent abuse from malicious sites. Parameters:
Examples:
|
מודולים עבור שאילתות
מודול השאילתא כולל שלושה סוגים של תת־מודולים (נקראים גם מודולי שאילתא):
- מטא־נתונים אודות אתר הוויקי והמשתמש המחובר.
- מאפיינים של עמודים, כולל גרסאות עמודים ותוכן.
- רשימות של דפים שתואמים קריטריון מסוים.
דוגמאות
דוגמה 1: ציון דפים
בשונה ממודולי ה־meta וה־list במודול השאילתא, כל מודולי השיאלתא שמתייחסים למאפיינים עובדים עם מקבץ של דפים שניתן לציין אותם באחת מהדרכים הבאות:
- לפי שם תוך שימוש בפרמטר
titles
, לדוגמהtitles=Foo|Bar|Main_Page
. - לפי מזהה הדף (ID) תוך שימוש בפרמטר
pageids
, לדוגמהpageids=123|456|75915
. - לפי מזהה גרסה תוך שימוש בפרמטר
revids
, למשלrevids=478198|54872|54894545
. רוב מודולי השאילתא יהפכו את מזהה הגרבה למזהה הדף המתאים. רק prop=revisions משתמש בפועל במזהה הגרסה. - שימוש בגנרטור.
בקשת GET
תשובה
{
"batchcomplete": true,
"query": {
"pages": [
{
"pageid": 1130,
"ns": 0,
"title": "Avicenna"
},
{
"pageid": 17412,
"ns": 0,
"title": "Klein bottle"
},
{
"pageid": 33642,
"ns": 0,
"title": "Warrant"
}
]
}
}
Example 2: Title normalization
Title normalization converts page titles to their canonical form.
This means capitalizing the first character, replacing underscores with spaces, and changing namespace to the localized form defined for that wiki.
בקשת GET
תשובה
{
"batchcomplete": true,
"query": {
"normalized": [
{
"fromencoded": false,
"from": "Project:articleA",
"to": "Wikipedia:ArticleA"
},
{
"fromencoded": false,
"from": "article_B",
"to": "Article B"
}
],
"pages": [
{
"ns": 0,
"title": "Article B",
"missing": true
},
{
"ns": 4,
"title": "Wikipedia:ArticleA",
"missing": true
}
]
}
}
דוגמה 3: כותרות שגויות או חסרות
כותרות שאינן קיימות או שהן בלתי־תקינות יכללו מאפיין missing
או invalid
בתשובה.
In output formats that support numeric array keys, missing and invalid titles will have negative page IDs.
In some cases, a title can be viewed by a user but cannot be accessed by the API, such as pages that mirror content from another wiki.
These titles will have a known
attribute set in the response.
בקשת GET
תשובה
{
"batchcomplete": true,
"query": {
"pages": [
{
"ns": 0,
"title": "Doesntexist",
"missing": true
},
{
"title": "Talk:",
"invalidreason": "The requested page title is empty or contains only the name of a namespace.",
"invalid": true
},
{
"pageid": 15580374,
"ns": 0,
"title": "Main Page"
}
]
}
}
דוגמה 4: שאילתות נוספות
כאשר כל הנתונים לא מוחזרים בתשובה של השאילתא, לעיתים יתווסף המאפיין continue
על מנת להודיע שיש נתונים נוספים.
בקשת GET
תשובה
{
"continue": {
"accontinue": "List_of_largest_companies_in_Sri_Lanka",
"continue": "-||"
},
"query": {
"allcategories": [
{
"category": "List of BioWare characters"
},
{
"category": "List of Harlequin Romance novels"
},
{
"category": "List of MPs elected in UK elections templates"
},
{
"category": "List of Metamorphoses characters"
},
{
"category": "List of Rockstar Games characters"
},
{
"category": "List of Star Trek awards and nominations"
},
{
"category": "List of Swedish films of the 2020s"
},
{
"category": "List of association football clubs in the Republic of Ireland templates"
},
{
"category": "List of awards and nominations received by Aleksej Pechkuroy"
},
{
"category": "List of cabinet templates"
}
]
}
}
כדי לקבל נתונים נוספים, יש להוסיף את הערכים שלהם לבקשה הראשונה.
GET request
Response
{
"batchcomplete": true,
"query": {
"allcategories": [
{
"category": "List of largest companies in Sri Lanka"
},
{
"category": "List of longest beaches of the world"
},
{
"category": "List of ministers by ministry of Bangladesh"
},
{
"category": "List of people from Palm Beach, Florida"
},
{
"category": "List of video game characters"
}
]
}
}
דוגמה 5: אחזור שהסתיים (Batchcomplete)
ה־API מחזיר אלמנט batchcomplete
כדי לציין שכל הנתונים של האחזור הנוכחי הוחזרו.
MW 1.25+
בתשובה של השאילתא להלן, batchcomplete
הוכלל כדי לציין שכל הנתונים של כל אחת משלושת התמונות הוחזרו.
ההמשך הבא יתחיל בהחזרת 3 התמונות הבאות.
בקשת GET
תשובה
{
"batchcomplete": true,
"continue": {
"aicontinue": "20020822143445|Do_You_Want_to_Know_a_Secret_(Beatles_song_-_sample).ogg",
"continue": "-||"
},
"query": {
"allimages": [
{
"name": "Simon_and_Garfunkel_-_Mrs_Robinson.ogg",
"timestamp": "2002-08-04T19:55:17Z",
"url": "https://upload.wikimedia.org/wikipedia/en/6/64/Simon_and_Garfunkel_-_Mrs_Robinson.ogg",
"descriptionurl": "https://en.wikipedia.org/wiki/File:Simon_and_Garfunkel_-_Mrs_Robinson.ogg",
"descriptionshorturl": "https://en.wikipedia.org/w/index.php?curid=67723",
"ns": 6,
"title": "File:Simon and Garfunkel - Mrs Robinson.ogg"
},
{
"name": "Simon_and_Garfunkel_-_Scarborough_Fair.ogg",
"timestamp": "2002-08-04T20:01:36Z",
"url": "https://upload.wikimedia.org/wikipedia/en/c/c1/Simon_and_Garfunkel_-_Scarborough_Fair.ogg",
"descriptionurl": "https://en.wikipedia.org/wiki/File:Simon_and_Garfunkel_-_Scarborough_Fair.ogg",
"descriptionshorturl": "https://en.wikipedia.org/w/index.php?curid=67779",
"ns": 6,
"title": "File:Simon and Garfunkel - Scarborough Fair.ogg"
},
{
"name": "Beatles_please_me.ogg",
"timestamp": "2002-08-22T14:34:00Z",
"url": "https://upload.wikimedia.org/wikipedia/en/e/ee/Beatles_please_me.ogg",
"descriptionurl": "https://en.wikipedia.org/wiki/File:Beatles_please_me.ogg",
"descriptionshorturl": "https://en.wikipedia.org/w/index.php?curid=74826",
"ns": 6,
"title": "File:Beatles please me.ogg"
}
]
}
}
דוגמה 6: גנרטורים
Use generators if you want to get data about a set of pages.
For example, to get data about pages in a certain category, instead of querying list=categorymembers
and then querying again with pageids
set to all the returned pages, combine the two API calls into one by using generator=categorymembers
.
When using a list module as a generator, you don't need to specify the pages.
However, for a property module, you should specify the pages which the generator will work on.
For example, to load all pages that are linked to from the main page, use generator=links&titles=Main%20Page
.
Parameters passed to a generator must be prefixed with a g
. For instance, when using generator=backlinks
, use gbllimit
instead of bllimit
.
The sample query below gets links and categories for the first three pages in the main namespace starting with "Ba".
בקשת GET
תשובה
{
"continue": {
"plcontinue": "14977970|0|Kirkwall_Ba_game",
"continue": "||categories"
},
"query": {
"pages": [
{
"pageid": 98178,
"ns": 0,
"title": "Ba",
"links": [
{
"ns": 0,
"title": "BA"
},
{
"ns": 4,
"title": "Wikipedia:Mainspace"
},
{
"ns": 4,
"title": "Wikipedia:Naming conventions (capitalization)"
},
{
"ns": 4,
"title": "Wikipedia:Protection policy"
},
{
"ns": 4,
"title": "Wikipedia:Redirect"
},
{
"ns": 10,
"title": "Template:R from miscapitalisation"
},
{
"ns": 10,
"title": "Template:R from modification"
},
{
"ns": 10,
"title": "Template:R to disambiguation page"
},
{
"ns": 14,
"title": "Category:Redirects from ambiguous terms"
},
{
"ns": 14,
"title": "Category:Redirects from other capitalisations"
}
],
"categories": [
{
"ns": 14,
"title": "Category:Redirects from ambiguous terms"
},
{
"ns": 14,
"title": "Category:Redirects from other capitalisations"
},
{
"ns": 14,
"title": "Category:Unprintworthy redirects"
}
]
},
{
"pageid": 14977970,
"ns": 0,
"title": "Ba'"
},
{
"pageid": 33351890,
"ns": 0,
"title": "Ba'Al Shem Tov"
}
]
}
}
אזהרות אפשריות
הודעת האזהרה | סיבה |
---|---|
כרגע אין תמיכה עבור דפים מיוחדים. | Thrown if a title in the Special: or Media: namespace is given. The pages in these namespaces cannot be queried. |
פתרון הפניות לא יכול לשמש יחד עם הפרמטר revids. הפניות ש־revids מצביע אליהן לא נפתרו. | Thrown if the redirect parameter is used in a query that specifies pages using revids .
|
Parameter history
- v1.21: Introduced
continue
- v1.24: Introduced
rawcontinue
(note raw continuation was the default behavior until v1.26)
הערות נוספות
- ציון כותרות באמצעות
titles
אוpageids
מוגבל ל־50 כותרות עבור כל שאילתא, או 500 עבור משתמשים שמחזיקים בהרשאהapihighlimits
. - ניתן להשתמש במספר מודולי שאילתא ביחד על מנת לקבל את מה שאתם צריכים תוך ביצוע שאילתא אחת, לדוגמה
prop=info|revisions&list=backlinks|embeddedin|allimages&meta=userinfo
. - Generators always pass page titles to the query module. Unlike lists (which may include additional data by default), generators should not output any information themselves, unless when explicitly requested via the generator module's query parameters.
Resolving redirects
Redirects can be resolved automatically, so that the target of a redirect is returned instead of the given title.
When present, they will always contain from
and to
attributes and may contain a tofragment
attribute for those redirects that point to specific sections.
Both normalization and redirection may take place.
In the case of multiple redirects, all redirects will be resolved, and in case of a circular redirect, there might not be a page in the 'pages' section (see also below).
Redirect resolution cannot be used in combination with the revids=
parameter or with a generator generating revids; doing that will produce a warning and will not resolve redirects for the specified revids.
The examples below show how the redirects
parameter works.
Using "redirects" parameter. "Main page" is a redirect to "Main Page"
Result |
---|
{
"batchcomplete": true,
"query": {
"redirects": [
{
"from": "Main page",
"to": "Main Page"
}
],
"pages": [
{
"pageid": 15580374,
"ns": 0,
"title": "Main Page"
}
]
}
}
|
Same request but without the "redirects" parameter.
Result |
---|
{
"batchcomplete": true,
"query": {
"pages": [
{
"pageid": 217225,
"ns": 0,
"title": "Main page"
}
]
}
}
|
Without "redirects" you may want to use prop=info to obtain redirect status.
Result |
---|
{
"batchcomplete": true,
"query": {
"pages": [
{
"pageid": 217225,
"ns": 0,
"title": "Main page",
"contentmodel": "wikitext",
"pagelanguage": "en",
"pagelanguagehtmlcode": "en",
"pagelanguagedir": "ltr",
"touched": "2017-12-17T02:02:05Z",
"lastrevid": 777924062,
"length": 170,
"redirect": true
}
]
}
}
|
Request with a section link. "Wikipedia:!--" is a redirect to "Wikipedia:Manual of Style#Invisible comments"
Result |
---|
{
"batchcomplete": true,
"query": {
"redirects": [
{
"from": "Wikipedia:!--",
"to": "Wikipedia:Manual of Style",
"tofragment": "Invisible comments"
}
],
"pages": [
{
"pageid": 33697,
"ns": 4,
"title": "Wikipedia:Manual of Style"
}
]
}
}
|
Here is a case of a circular redirect: Page1 → Page2 → Page3 → Page1. Also, in this example a non-normalized name 'page1' is used.
Result |
---|
{
"batchcomplete": true,
"query": {
"normalized": [
{
"fromencoded": false,
"from": "page1",
"to": "Page1"
}
],
"redirects": [
{
"from": "Page1",
"to": "Page2"
},
{
"from": "Page2",
"to": "Page3"
},
{
"from": "Page3",
"to": "Page1"
}
],
"pages": [
{
"ns": 0,
"title": "Page1",
"missing": true
}
]
}
}
|
ראו גם
- API:עמוד ראשי - מדריך ההתחלה המהירה.
- API:Raw query continue - מכיל מידע אודות אופן השימוש בפרמטר
rawcontinue
.
![]() | הדף או המיזם הזה מתוחזק על ידי Core Platform Team .
קבלת עזרה:
|