Movatterモバイル変換


[0]ホーム

URL:


Jump to content
MediaWiki
Search

API:Patrol

From mediawiki.org
Translate this page
Languages:
This page is part of theMediaWiki Action API documentation.
MediaWiki Action API
Basics
Authentication
Accounts and Users
Page Operations
Search
Developer Utilities
Tutorials
v · d · e
MediaWiki version:
1.14

POST request to patrol a page or a revision.

API documentation

[edit]
The following documentation is the output ofSpecial:ApiHelp/patrol, automatically generated by the pre-release version of MediaWiki that is running on this site (MediaWiki.org).

action=patrol

(main |patrol)
  • This module requires read rights.
  • This module requires write rights.
  • This module only accepts POST requests.
  • Source:MediaWiki
  • License:GPL-2.0-or-later

Patrol a page or revision.

Specific parameters:
Other general parameters are available.
rcid

Recentchanges ID to patrol.

Type: integer
revid

Revision ID to patrol.

Type: integer
tags

Change tags to apply to the entry in the patrol log.

Values (separate with| oralternative): AWB, convenient-discussions
token

A "patrol" token retrieved fromaction=query&meta=tokens

This parameter is required.

Example

[edit]

Patrolling a request is a multi-step process:

  1. Log in, via one of the methods described onAPI:Login.
  2. GET apatrol token. This token is the same for all pages, but changes at every login.
  3. Send a POST request, with the patrol token, to patrol a request.

The sample code below covers the final step in detail.

POST request

[edit]
Patrolling a recent change ofrcid 437659.
api.php?action=patrol&format=json&rcid=437659&token=123ABC [try in ApiSandbox]

Response

[edit]
{"patrol":{"rcid":437659,"ns":0,"title":"Sandbox"}}

Sample code

[edit]

Python

[edit]
#!/usr/bin/python3"""    patrol.py    MediaWiki API Demos    Demo of `Patrol` module: Patrol a recent change    MIT license"""importrequestsS=requests.Session()URL="https://test.wikipedia.org/w/api.php"# Step 1: Retrieve a login tokenPARAMS_1={"action":"query","meta":"tokens","type":"login","format":"json"}R=S.get(url=URL,params=PARAMS_1)DATA=R.json()LOGIN_TOKEN=DATA['query']['tokens']['logintoken']# Step 2: Send a POST request to log in. For this login# method, obtain bot credentials by first visiting# https://www.test.wikipedia.org/wiki/Manual:Bot_passwords# See https://www.mediawiki.org/wiki/API:Login for more# information on log in methods.PARAMS_2={"action":"login","lgname":"username","lgpassword":"password","format":"json","lgtoken":LOGIN_TOKEN}R=S.post(URL,data=PARAMS_2)DATA=R.json()# Step 3: While logged in, retrieve a patrol tokenPARAMS_3={"action":"query","meta":"tokens","type":"patrol","format":"json"}R=S.get(url=URL,params=PARAMS_3)DATA=R.json()PATROL_TOKEN=DATA["query"]["tokens"]["patroltoken"]# Step 4: Send a POST request to patrol a recent changePARAMS_4={"action":"patrol","format":"json","rcid":"437659","token":PATROL_TOKEN}R=S.post(url=URL,data=PARAMS_4)DATA=R.json()print(DATA)

PHP

[edit]
<?php/*    patrol.php    MediaWiki API DemosDemo of `Patrol` module: Patrol a recent change    MIT license*/$endPoint="https://test.wikipedia.org/w/api.php";$login_Token=getLoginToken();// Step 1loginRequest($login_Token);// Step 2$patrol_Token=getPatrolToken();// Step 3patrol($patrol_Token);// Step 4// Step 1: GET request to fetch login tokenfunctiongetLoginToken(){global$endPoint;$params1=["action"=>"query","meta"=>"tokens","type"=>"login","format"=>"json"];$url=$endPoint."?".http_build_query($params1);$ch=curl_init($url);curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);curl_setopt($ch,CURLOPT_COOKIEJAR,"cookie.txt");curl_setopt($ch,CURLOPT_COOKIEFILE,"cookie.txt");$output=curl_exec($ch);curl_close($ch);$result=json_decode($output,true);return$result["query"]["tokens"]["logintoken"];}// Step 2: POST request to log in. Use of main account for login is not// supported. Obtain credentials via Special:BotPasswords// (https://www.mediawiki.org/wiki/Special:BotPasswords) for lgname & lgpasswordfunctionloginRequest($logintoken){global$endPoint;$params2=["action"=>"login","lgname"=>"bot_user_name","lgpassword"=>"bot_password","lgtoken"=>$logintoken,"format"=>"json"];$ch=curl_init();curl_setopt($ch,CURLOPT_URL,$endPoint);curl_setopt($ch,CURLOPT_POST,true);curl_setopt($ch,CURLOPT_POSTFIELDS,http_build_query($params2));curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);curl_setopt($ch,CURLOPT_COOKIEJAR,"cookie.txt");curl_setopt($ch,CURLOPT_COOKIEFILE,"cookie.txt");$output=curl_exec($ch);curl_close($ch);}// Step 3: GET request to fetch Patrol tokenfunctiongetPatrolToken(){global$endPoint;$params3=["action"=>"query","meta"=>"tokens","type"=>"patrol","format"=>"json"];$url=$endPoint."?".http_build_query($params3);$ch=curl_init($url);curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);curl_setopt($ch,CURLOPT_COOKIEJAR,"cookie.txt");curl_setopt($ch,CURLOPT_COOKIEFILE,"cookie.txt");$output=curl_exec($ch);curl_close($ch);$result=json_decode($output,true);return$result["query"]["tokens"]["patroltoken"];}// Step 4: POST request to patrol a recent changefunctionpatrol($patroltoken){global$endPoint;$params4=["action"=>"patrol","rcid"=>"91","token"=>$patroltoken,"format"=>"json"];$ch=curl_init();curl_setopt($ch,CURLOPT_URL,$endPoint);curl_setopt($ch,CURLOPT_POST,true);curl_setopt($ch,CURLOPT_POSTFIELDS,http_build_query($params4));curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);curl_setopt($ch,CURLOPT_COOKIEJAR,"cookie.txt");curl_setopt($ch,CURLOPT_COOKIEFILE,"cookie.txt");$output=curl_exec($ch);curl_close($ch);echo($output);}

JavaScript

[edit]
/*    patrol.js    MediaWiki API Demos    Demo of `Patrol` module: Patrol a recent change    MIT license*/varrequest=require('request').defaults({jar:true}),url="http://dev.wiki.local.wmftest.net:8080/w/api.php";// Step 1: GET request to fetch login tokenfunctiongetLoginToken(){varparams_0={action:"query",meta:"tokens",type:"login",format:"json"};request.get({url:url,qs:params_0},function(error,res,body){if(error){return;}vardata=JSON.parse(body);loginRequest(data.query.tokens.logintoken);});}// Step 2: POST request to log in.// Use of main account for login is not// supported. Obtain credentials via Special:BotPasswords// (https://www.mediawiki.org/wiki/Special:BotPasswords) for lgname & lgpasswordfunctionloginRequest(login_token){varparams_1={action:"login",lgname:"bot_username",lgpassword:"bot_password",lgtoken:login_token,format:"json"};request.post({url:url,form:params_1},function(error,res,body){if(error){return;}getPatrolToken();});}// Step 3: GET request to fetch Patrol tokenfunctiongetPatrolToken(){varparams_2={action:"query",meta:"tokens",type:"patrol",format:"json"};request.get({url:url,qs:params_2},function(error,res,body){if(error){return;}vardata=JSON.parse(body);patrol(data.query.tokens.patroltoken);});}// Step 4: POST request to patrol a recent changefunctionpatrol(patrol_token){varparams_3={action:"patrol",rcid:"104",token:patrol_token,format:"json"};request.post({url:url,form:params_3},function(error,res,body){if(error){return;}console.log(body);});}// Start From Step 1getLoginToken();

MediaWiki JS

[edit]
/*patrol.jsMediaWiki API DemosDemo of `Patrol` module: Patrol a recent changeMIT License*/varparams={action:'patrol',revid:'77',format:'json'},api=newmw.Api();api.postWithToken('patrol',params).done(function(data){console.log(data);});

Possible errors

[edit]

In addition tothe standard error messages:

CodeInfo
patroldisabledPatrolling is disabled on this wiki
noautopatrolYou are not allowed to mark your own changes as patrolled.
Only users with theautopatrol right can do this
notpatrollableThe revision rid can't be patrolled as it's too old.
nosuchrcidThere is no recent change with IDrcid.
nosuchrevidThere is no revision with IDrevid.

Parameter history

[edit]
  • v1.27: Introducedtags
  • v1.22: Introducedrevid

Additional notes

[edit]
  • For MediaWiki versions earlier than 1.17, the patrol token is the same the edit token.
  • autopatrol rights are required in order to use this module.
  • revid andrcid may be obtained throughAPI:Recentchanges.
Retrieved from "https://www.mediawiki.org/w/index.php?title=API:Patrol&oldid=7670218"
Category:

[8]ページ先頭

©2009-2026 Movatter.jp