Trợ giúp về API MediaWiki

This is an auto-generated MediaWiki Action API documentation page.

General information

Status: 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 the mediawiki-api-announce mailing list for notice of updates.

Erroneous requests: 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 API: Errors and warnings.

Request methods

Action API requests may use GET and POST methods. Prefer using the GET method, which allows requests to be routed to faster replica servers and responses to be cached, unless the length of the URL with parameters would exceed its length limit (commonly 8000 bytes), or a module only accepts POST requests.

Parameters for POST requests may be sent in the query part of the request URL (like in GET requests) and in the POST request body, and mixing both ways in one request is allowed. Certain parameters such as passwords must be sent in the request body. If the same parameter is sent as part of the URL and also in the request body, it must have the same value in both places.

Data types

Input to MediaWiki should be NFC-normalized UTF-8. MediaWiki may attempt to convert other input, but this may cause some operations (such as edits with MD5 checks) to fail.

Parameters that take multiple values are normally submitted with the values separated using the pipe character, e.g. param=value1|value2 or param=value1%7Cvalue2. If a value must contain the pipe character, use U+001F (Unit Separator) as the separator and prefix the value with U+001F, e.g. param=%1Fvalue1%1Fvalue2.

Some parameter types in API requests need further explanation:

boolean

Boolean parameters work like HTML checkboxes: if the parameter is specified, regardless of value, it is considered true. For a false value, omit the parameter entirely.

expiry

Expiry values may be relative (e.g. 5 months or 2 weeks) or absolute (e.g. 2014-09-18T12:34:56Z). For no expiry, use infinite, indefinite, infinity or never.

timestamp

Timestamps may be specified in several formats, see the Timestamp library input formats documented on mediawiki.org for details. ISO 8601 date and time is recommended: 2001-01-15T14:56:00Z. The string now may be used to specify the current time.

Limits

Most API modules can accept up to 50 inputs in multivalue parameters, and can return up to 500 results per query (50 results for slow queries).

For users with the apihighlimits right (Bot và Bảo quản viên), the limits are increased to 500 inputs and 5.000 results (500 results for slow queries).

Templated parameters

Templated parameters support cases where an API module needs a value for each value of some other parameter. For example, if there were an API module to request fruit, it might have a parameter fruits to specify which fruits are being requested and a templated parameter {fruit}-quantity to specify how many of each fruit to request. An API client that wants 1 apple, 5 bananas, and 20 strawberries could then make a request like fruits=apples|bananas|strawberries&apples-quantity=1&bananas-quantity=5&strawberries-quantity=20.

Mô đun chính

Specify the action to perform, the format of the response, and options that apply to all API modules.

Các tham số:
action

Tác vụ nào để thực hiện. Tham số này nên được gửi như một phần của URL yêu cầu (không phải thân POST) để dễ dàng sử dụng trong việc gỡ lỗi, phân tích và định tuyến hoặc lọc yêu cầu.

acquiretempusername
Nếu tính năng tạo tài khoản tạm thời được kích hoạt và thành viên hiện tại đã đăng xuất, hàm sẽ lấy tên người dùng thành viên tạm thời và lưu trữ nó trong phiên hiện tại. Nếu một tên đã được lưu trữ sẵn, hàm sẽ trả về chính tên đó.
antispoof
Kiểm tra xem tên người dùng qua quá trình kiểm tra tiêu chuẩn của AntiSpoof.
block
Cấm người dùng.
centralauthtoken
Fetch a centralauthtoken for making an authenticated request to an attached wiki.
changeauthenticationdata
Change authentication data for the current user.
changecontentmodel
Change the content model of a page
checktoken
Check the validity of a token from action=query&meta=tokens.
clearhasmsg
Xóa cờ hasmsg cho người dùng hiện tại.
clientlogin
Log in to the wiki using the interactive flow.
compare
Get the difference between two pages.
createaccount
Mở tài khoản mới.
createlocalaccount
Forcibly create a local account. The central account must exist.
delete
Xóa trang.
deleteglobalaccount
Delete a global user.
echocreateevent
Manually trigger a notification to a user
echomarkread
Mark notifications as read for the current user.
echomarkseen
Mark notifications as seen for the current user.
echomute
Mute or unmute notifications from certain users or pages.
edit
Tạo và sửa trang.
emailuser
Gửi thư cho người dùng.
embedvideo
Get generated video embed code for given parameters.
expandtemplates
Bung tất cả bản mẫu trong mã wiki.
feedcontributions
Trả về nguồn cấp đóng góp người dùng.
feedrecentchanges
Trả về nguồn cấp thay đổi gần đây.
feedwatchlist
Trả về nguồn cấp danh sách theo dõi.
filerevert
Phục hồi một tập tin sang một phiên bản cũ.
globaluserrights
Add/remove a user to/from global groups.
help
Hiển thị trợ giúp cho các mô-đun xác định.
imagerotate
Xoay một hoặc nhiều hình ảnh.
import
Import a page from another wiki, or from an XML file.
jsonconfig
Allows direct access to JsonConfig subsystem.
languagesearch
Tìm kiếm tên ngôn ngữ trong bất kỳ tập lệnh nào.
linkaccount
Link an account from a third-party provider to the current user.
login
Log in and get authentication cookies.
logout
Thoát ra và xóa dữ liệu phiên làm việc.
managetags
Perform management tasks relating to change tags.
mergehistory
Hợp nhất lịch sử trang.
move
Di chuyển trang.
opensearch
Tìm kiếm trong wiki qua giao thức OpenSearch.
options
Change preferences of the current user.
paraminfo
Lấy thông tin về các module API.
parse
Parses content and returns parser output.
patrol
Patrol a page or revision.
protect
Change the protection level of a page.
purge
Purge the cache for the given titles.
query
Fetch data from and about MediaWiki.
removeauthenticationdata
Remove authentication data for the current user.
resetpassword
Send a password reset email to a user.
revisiondelete
Delete and undelete revisions.
rollback
Lùi lại sửa đổi gần đây nhất trên trang này.
rsd
Export an RSD (Really Simple Discovery) schema.
setglobalaccountstatus
Hide or lock (or unhide or unlock) a global user account.
setnotificationtimestamp
Update the notification timestamp for watched pages.
setpagelanguage
Change the language of a page.
spamblacklist
Validate one or more URLs against the spam block list.
tag
Add or remove change tags from individual revisions or log entries.
templatedata
Trích xuất dữ liệu được lưu bởi phần mở rộng TemplateData.
thank
Gửi thông báo cảm ơn đến một biên tập viên.
titleblacklist
Validate a page title, filename, or username against the TitleBlacklist.
torblock
Check if an IP address is blocked as a Tor exit node.
unblock
Unblock a user.
undelete
Undelete revisions of a deleted page.
unlinkaccount
Remove a linked third-party account from the current user.
upload
Upload a file, or get the status of pending uploads.
userrights
Change a user's group membership.
validatepassword
Validate a password against the wiki's password policies.
watch
Add or remove pages from the current user's watchlist.
categorytree
Internal. Internal module for the CategoryTree extension.
cirrus-check-sanity
Internal. Reports on the correctness of a range of page ids in the search index
cirrus-config-dump
Internal. Dump of CirrusSearch configuration.
cirrus-profiles-dump
Internal. Dump of CirrusSearch profiles for this wiki.
cirrus-schema-dump
Internal. Dump of CirrusSearch schema (settings and mappings) for this wiki.
codemirror-validate
Internal. Kiểm tra lỗi trong nội dung đã cho
cspreport
Internal. Used by browsers to report violations of the Content Security Policy. This module should never be used, except when used automatically by a CSP compliant web browser.
jsondata
Internal. Retrieve localized JSON data.
scribunto-console
Internal. Mô đun nội bộ để phản hồi các yêu cầu XHR từ console Scribunto.
stashedit
Internal. Prepare an edit in shared cache.
Một trong các giá trị: acquiretempusername, antispoof, block, centralauthtoken, changeauthenticationdata, changecontentmodel, checktoken, clearhasmsg, clientlogin, compare, createaccount, createlocalaccount, delete, deleteglobalaccount, echocreateevent, echomarkread, echomarkseen, echomute, edit, emailuser, embedvideo, expandtemplates, feedcontributions, feedrecentchanges, feedwatchlist, filerevert, globaluserrights, help, imagerotate, import, jsonconfig, languagesearch, linkaccount, login, logout, managetags, mergehistory, move, opensearch, options, paraminfo, parse, patrol, protect, purge, query, removeauthenticationdata, resetpassword, revisiondelete, rollback, rsd, setglobalaccountstatus, setnotificationtimestamp, setpagelanguage, spamblacklist, tag, templatedata, thank, titleblacklist, torblock, unblock, undelete, unlinkaccount, upload, userrights, validatepassword, watch, categorytree, cirrus-check-sanity, cirrus-config-dump, cirrus-profiles-dump, cirrus-schema-dump, codemirror-validate, cspreport, jsondata, scribunto-console, stashedit
Default: help
format

Định dạng của dữ liệu được cho ra.

json
Cho ra dữ liệu dưới dạng JSON.
jsonfm
Cho ra dữ liệu dưới dạng JSON (định dạng bằng HTML).
none
Không cho ra gì.
php
Output data in serialized PHP format.
phpfm
Output data in serialized PHP format (pretty-print in HTML).
rawfm
Cho ra dữ liệu bao gồm các phần tử gỡ lỗi dưới dạng JSON (định dạng bằng HTML).
xml
Cho ra dữ liệu dưới dạng XML.
xmlfm
Cho ra dữ liệu dưới dạng XML (định dạng bằng HTML).
Một trong các giá trị: json, jsonfm, none, php, phpfm, rawfm, xml, xmlfm
Default: jsonfm
maxlag

Độ trễ tối đa có thể được sử dụng khi MediaWiki được cài đặt trên một cụm cơ sở dữ liệu được sao chép. Để tránh các thao tác gây ra độ trễ sao chép trang web quá mức, tham số này có thể làm khiến máy khách chờ cho đến khi độ trễ sao chép nhỏ hơn giá trị được chỉ định. Trong trường hợp độ trễ quá mức, mã lỗi maxlag sẽ được trả về kèm theo một thông báo như Đang chờ $host: trễ $lag giây.
Xem Manual: Maxlag parameter để biết thêm thông tin.

Type: integer
smaxage

Chỉnh đầu đề điều khiển bộ nhớ đệm HTTP s-maxage thành số giây nhiều như thế này. Lỗi sẽ không bao giờ được lưu vào bộ nhớ đệm.

Type: integer
The value must be no less than 0.
Default: 0
maxage

Chỉnh đầu đề điều khiển bộ nhớ đệm HTTP max-age thành số giây nhiều như thế này. Lỗi sẽ không bao giờ được lưu vào bộ nhớ đệm.

Type: integer
The value must be no less than 0.
Default: 0
assert

Xác minh rằng thành viên đã đăng nhập (kể cả có thể là thành viên tạm thời) nếu được chỉnh thành user, not đã đăng nhập nếu được chỉnh thành anon, hoặc có quyền thành viên bot nếu bot.

Một trong các giá trị: anon, bot, user
assertuser

Xác minh rằng thành viên hiện tại là thành viên có tên.

Kiểu: người dùng, bằng một giá trị bất kỳ trong tên người dùng và Người dùng tạm thời
requestid

Bất kỳ giá trị nào được cung cấp ở đây sẽ được bao gồm trong phản hồi. Có thể được sử dụng để phân biệt các yêu cầu.

servedby

Bao gồm tên máy chủ đã xử lý yêu cầu trong kết quả.

Type: boolean (details)
curtimestamp

Bao gồm dấu thời gian hiện tại trong kết quả.

Type: boolean (details)
responselanginfo

Bao gồm các ngôn ngữ được sử dụng cho uselang và errorlang trong kết quả.

Type: boolean (details)
origin

Khi truy cập API bằng yêu cầu AJAX liên tên miền (CORS), hãy đặt tham số này thành tên miền gốc. Giá trị này phải được bao gồm trong bất kỳ yêu cầu pre-flight nào, và do đó phải là một phần của URL yêu cầu (không phải thân POST). Đối với các yêu cầu đã xác thực, giá trị này phải khớp chính xác với một trong các nguồn gốc trong tiêu đề Origin, vì vậy nó cần được đặt thành một địa chỉ dạng như https://en.wikipedia.org hoặc https://meta.wikimedia.org. Nếu tham số này không khớp với tiêu đề Origin, phản hồi 403 sẽ được trả về. Nếu tham số này khớp với tiêu đề Origin và nguồn gốc đó được cho phép, các tiêu đề Access-Control-Allow-Origin và Access-Control-Allow-Credentials sẽ được thiết lập. Đối với các yêu cầu chưa xác thực, hãy chỉ định giá trị *. Điều này sẽ làm cho tiêu đề Access-Control-Allow-Origin được thiết lập, nhưng Access-Control-Allow-Credentials sẽ là false và tất cả dữ liệu riêng của người dùng sẽ bị hạn chế.

crossorigin

Khi truy cập API bằng yêu cầu AJAX liên miền (CORS) và sử dụng nhà cung cấp phiên an toàn trước các cuộc tấn công giả mạo yêu cầu liên trang web (CSRF) (chẳng hạn như OAuth), hãy sử dụng tùy chọn này thay vì origin=* để yêu cầu được xác thực (tức là không bị đăng xuất). Tùy chọn này phải được đưa vào bất kỳ yêu cầu pre-flight nào, và do đó phải là một phần của URL yêu cầu (chứ không phải phần thân POST).

Lưu ý rằng hầu hết các nhà cung cấp phiên, bao gồm cả các phiên dựa trên cookie tiêu chuẩn, không hỗ trợ CORS được xác thực và không thể sử dụng với tham số này.

Type: boolean (details)
uselang

Ngôn ngữ để sử dụng cho các bản dịch thông điệp. action=query&meta=siteinfo&siprop=languages trả về một danh sách các mã ngôn ngữ. Bạn có thể định rõ user để sử dụng ngôn ngữ của người dùng hiện tại hoặc content để sử dụng ngôn ngữ nội dung của wiki này.

Default: user
variant

Biến thể của ngôn ngữ. Chỉ hoạt động nếu ngôn ngữ gốc hỗ trợ chuyển đổi biến thể.

errorformat

Định dạng để sử dụng cho văn bản cảnh báo và lỗi đầu ra

plaintext
Mã Wiki có thẻ HTML đã bị xóa và các thực thể đã được thay thế.
wikitext
Mã wiki chưa được phân tích.
html
HTML
raw
Khóa và tham số của thông báo.
none
Không có văn bản nào được hiển thị, chỉ có mã lỗi.
bc
Định dạng được sử dụng trước MediaWiki 1.29. errorlang và errorsuselocal bị bỏ qua.
Một trong các giá trị: bc, html, none, plaintext, raw, wikitext
Default: bc
errorlang

Ngôn ngữ để sử dụng cho cảnh báo và lỗi. action=query&meta=site info&siprop=languages trả về một danh sách mã ngôn ngữ. Hãy chỉ định content để sử dụng ngôn ngữ nội dung của wiki này hoặc uselang để sử dụng giá trị tương tự với tham số uselang.

Default: uselang
errorsuselocal

Nếu được cung cấp, văn bản lỗi sẽ sử dụng thông báo được tùy chỉnh cục bộ từ không gian tên MediaWiki.

Type: boolean (details)
centralauthtoken

When accessing the API using a cross-domain AJAX request (CORS), use this to authenticate as the current SUL user. Use action=centralauthtoken on this wiki to retrieve the token, before making the CORS request. Each token may only be used once, and expires after 60 seconds. This should be included in any pre-flight request, and therefore should be included in the request URI (not the POST body).

Các ví dụ:
Trợ giúp cho các mô-đun chính.
api.php?action=help [open in sandbox]
Tất cả trợ giúp trong một trang
api.php?action=help&recursivesubmodules=1&toc [open in sandbox]

Ghi công

API developers:

  • Yuri Astrakhan (creator, lead developer Sep 2006–Sep 2007)
  • Roan Kattouw (lead developer Sep 2007–2009)
  • Victor Vasiliev
  • Bryan Tong Minh
  • Sam Reed
  • Brad Jorsch (lead developer 2013–2020)

Please send your comments, suggestions and questions to mediawiki-api@lists.wikimedia.org or file a bug report at https://phabricator.wikimedia.org/.