MediaWiki REL1_30
ApiPatrol.php
Go to the documentation of this file.
1<?php
31class ApiPatrol extends ApiBase {
32
36 public function execute() {
38 $this->requireOnlyOneParameter( $params, 'rcid', 'revid' );
39
40 if ( isset( $params['rcid'] ) ) {
41 $rc = RecentChange::newFromId( $params['rcid'] );
42 if ( !$rc ) {
43 $this->dieWithError( [ 'apierror-nosuchrcid', $params['rcid'] ] );
44 }
45 } else {
46 $rev = Revision::newFromId( $params['revid'] );
47 if ( !$rev ) {
48 $this->dieWithError( [ 'apierror-nosuchrevid', $params['revid'] ] );
49 }
50 $rc = $rev->getRecentChange();
51 if ( !$rc ) {
52 $this->dieWithError( [ 'apierror-notpatrollable', $params['revid'] ] );
53 }
54 }
55
56 $user = $this->getUser();
57 $tags = $params['tags'];
58
59 // Check if user can add tags
60 if ( !is_null( $tags ) ) {
61 $ableToTag = ChangeTags::canAddTagsAccompanyingChange( $tags, $user );
62 if ( !$ableToTag->isOK() ) {
63 $this->dieStatus( $ableToTag );
64 }
65 }
66
67 $retval = $rc->doMarkPatrolled( $user, false, $tags );
68
69 if ( $retval ) {
70 $this->dieStatus( $this->errorArrayToStatus( $retval, $user ) );
71 }
72
73 $result = [ 'rcid' => intval( $rc->getAttribute( 'rc_id' ) ) ];
74 ApiQueryBase::addTitleInfo( $result, $rc->getTitle() );
75 $this->getResult()->addValue( null, $this->getModuleName(), $result );
76 }
77
78 public function mustBePosted() {
79 return true;
80 }
81
82 public function isWriteMode() {
83 return true;
84 }
85
86 public function getAllowedParams() {
87 return [
88 'rcid' => [
89 ApiBase::PARAM_TYPE => 'integer'
90 ],
91 'revid' => [
92 ApiBase::PARAM_TYPE => 'integer'
93 ],
94 'tags' => [
95 ApiBase::PARAM_TYPE => 'tags',
97 ],
98 ];
99 }
100
101 public function needsToken() {
102 return 'patrol';
103 }
104
105 protected function getExamplesMessages() {
106 return [
107 'action=patrol&token=123ABC&rcid=230672766'
108 => 'apihelp-patrol-example-rcid',
109 'action=patrol&token=123ABC&revid=230672766'
110 => 'apihelp-patrol-example-revid',
111 ];
112 }
113
114 public function getHelpUrls() {
115 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Patrol';
116 }
117}
This abstract class implements many basic API functions, and is the base of all API classes.
Definition ApiBase.php:41
dieWithError( $msg, $code=null, $data=null, $httpCode=null)
Abort execution with an error.
Definition ApiBase.php:1855
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below.
Definition ApiBase.php:91
errorArrayToStatus(array $errors, User $user=null)
Turn an array of message keys or key+param arrays into a Status.
Definition ApiBase.php:1726
extractRequestParams( $parseLimit=true)
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition ApiBase.php:740
getResult()
Get the result object.
Definition ApiBase.php:632
getModuleName()
Get the name of the module being executed by this instance.
Definition ApiBase.php:512
dieStatus(StatusValue $status)
Throw an ApiUsageException based on the Status object.
Definition ApiBase.php:1920
requireOnlyOneParameter( $params, $required)
Die if none or more than one of a certain set of parameters is set and not false.
Definition ApiBase.php:776
const PARAM_ISMULTI
(boolean) Accept multiple pipe-separated values for this parameter (e.g.
Definition ApiBase.php:55
Allows user to patrol pages.
Definition ApiPatrol.php:31
isWriteMode()
Indicates whether this module requires write mode.
Definition ApiPatrol.php:82
execute()
Patrols the article or provides the reason the patrol failed.
Definition ApiPatrol.php:36
needsToken()
Returns the token type this module requires in order to execute.
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
Definition ApiPatrol.php:86
getHelpUrls()
Return links to more detailed help pages about the module.
getExamplesMessages()
Returns usage examples for this module.
mustBePosted()
Indicates whether this module must be called with a POST request.
Definition ApiPatrol.php:78
static addTitleInfo(&$arr, $title, $prefix='')
Add information (title and namespace) about a Title object to a result array.
static canAddTagsAccompanyingChange(array $tags, User $user=null)
Is it OK to allow the user to apply all the specified tags at the same time as they edit/make the cha...
getUser()
Get the User object.
static newFromId( $rcid)
Obtain the recent change with a given rc_id value.
static newFromId( $id, $flags=0)
Load a page revision from a given revision ID number.
Definition Revision.php:116
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account incomplete not yet checked for validity & $retval
Definition hooks.txt:266
presenting them properly to the user as errors is done by the caller return true use this to change the list i e etc $rev
Definition hooks.txt:1760
$params