MediaWiki REL1_31
ApiPatrol.php
Go to the documentation of this file.
1<?php
29class ApiPatrol extends ApiBase {
30
34 public function execute() {
36 $this->requireOnlyOneParameter( $params, 'rcid', 'revid' );
37
38 if ( isset( $params['rcid'] ) ) {
39 $rc = RecentChange::newFromId( $params['rcid'] );
40 if ( !$rc ) {
41 $this->dieWithError( [ 'apierror-nosuchrcid', $params['rcid'] ] );
42 }
43 } else {
44 $rev = Revision::newFromId( $params['revid'] );
45 if ( !$rev ) {
46 $this->dieWithError( [ 'apierror-nosuchrevid', $params['revid'] ] );
47 }
48 $rc = $rev->getRecentChange();
49 if ( !$rc ) {
50 $this->dieWithError( [ 'apierror-notpatrollable', $params['revid'] ] );
51 }
52 }
53
54 $user = $this->getUser();
55 $tags = $params['tags'];
56
57 // Check if user can add tags
58 if ( !is_null( $tags ) ) {
59 $ableToTag = ChangeTags::canAddTagsAccompanyingChange( $tags, $user );
60 if ( !$ableToTag->isOK() ) {
61 $this->dieStatus( $ableToTag );
62 }
63 }
64
65 $retval = $rc->doMarkPatrolled( $user, false, $tags );
66
67 if ( $retval ) {
68 $this->dieStatus( $this->errorArrayToStatus( $retval, $user ) );
69 }
70
71 $result = [ 'rcid' => intval( $rc->getAttribute( 'rc_id' ) ) ];
72 ApiQueryBase::addTitleInfo( $result, $rc->getTitle() );
73 $this->getResult()->addValue( null, $this->getModuleName(), $result );
74 }
75
76 public function mustBePosted() {
77 return true;
78 }
79
80 public function isWriteMode() {
81 return true;
82 }
83
84 public function getAllowedParams() {
85 return [
86 'rcid' => [
87 ApiBase::PARAM_TYPE => 'integer'
88 ],
89 'revid' => [
90 ApiBase::PARAM_TYPE => 'integer'
91 ],
92 'tags' => [
93 ApiBase::PARAM_TYPE => 'tags',
95 ],
96 ];
97 }
98
99 public function needsToken() {
100 return 'patrol';
101 }
102
103 protected function getExamplesMessages() {
104 return [
105 'action=patrol&token=123ABC&rcid=230672766'
106 => 'apihelp-patrol-example-rcid',
107 'action=patrol&token=123ABC&revid=230672766'
108 => 'apihelp-patrol-example-revid',
109 ];
110 }
111
112 public function getHelpUrls() {
113 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Patrol';
114 }
115}
This abstract class implements many basic API functions, and is the base of all API classes.
Definition ApiBase.php:37
dieWithError( $msg, $code=null, $data=null, $httpCode=null)
Abort execution with an error.
Definition ApiBase.php:1895
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below.
Definition ApiBase.php:87
errorArrayToStatus(array $errors, User $user=null)
Turn an array of message keys or key+param arrays into a Status.
Definition ApiBase.php:1766
extractRequestParams( $parseLimit=true)
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition ApiBase.php:749
getResult()
Get the result object.
Definition ApiBase.php:641
getModuleName()
Get the name of the module being executed by this instance.
Definition ApiBase.php:521
dieStatus(StatusValue $status)
Throw an ApiUsageException based on the Status object.
Definition ApiBase.php:1960
requireOnlyOneParameter( $params, $required)
Die if none or more than one of a certain set of parameters is set and not false.
Definition ApiBase.php:785
const PARAM_ISMULTI
(boolean) Accept multiple pipe-separated values for this parameter (e.g.
Definition ApiBase.php:51
Allows user to patrol pages.
Definition ApiPatrol.php:29
isWriteMode()
Indicates whether this module requires write mode.
Definition ApiPatrol.php:80
execute()
Patrols the article or provides the reason the patrol failed.
Definition ApiPatrol.php:34
needsToken()
Returns the token type this module requires in order to execute.
Definition ApiPatrol.php:99
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
Definition ApiPatrol.php:84
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:76
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...
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:1777
$params