MediaWiki REL1_37
ApiPatrol.php
Go to the documentation of this file.
1<?php
26
31class ApiPatrol extends ApiBase {
34
40 public function __construct(
41 ApiMain $main,
42 $action,
44 ) {
45 parent::__construct( $main, $action );
46 $this->revisionStore = $revisionStore;
47 }
48
52 public function execute() {
53 $params = $this->extractRequestParams();
54 $this->requireOnlyOneParameter( $params, 'rcid', 'revid' );
55
56 if ( isset( $params['rcid'] ) ) {
57 $rc = RecentChange::newFromId( $params['rcid'] );
58 if ( !$rc ) {
59 $this->dieWithError( [ 'apierror-nosuchrcid', $params['rcid'] ] );
60 }
61 } else {
62 $rev = $this->revisionStore->getRevisionById( $params['revid'] );
63 if ( !$rev ) {
64 $this->dieWithError( [ 'apierror-nosuchrevid', $params['revid'] ] );
65 }
66 $rc = $this->revisionStore->getRecentChange( $rev );
67 if ( !$rc ) {
68 $this->dieWithError( [ 'apierror-notpatrollable', $params['revid'] ] );
69 }
70 }
71
72 $user = $this->getUser();
73 $tags = $params['tags'];
74
75 // Check if user can add tags
76 if ( $tags !== null ) {
77 $ableToTag = ChangeTags::canAddTagsAccompanyingChange( $tags, $this->getAuthority() );
78 if ( !$ableToTag->isOK() ) {
79 $this->dieStatus( $ableToTag );
80 }
81 }
82
83 $retval = $rc->doMarkPatrolled( $user, false, $tags );
84
85 if ( $retval ) {
86 $this->dieStatus( $this->errorArrayToStatus( $retval, $user ) );
87 }
88
89 $result = [ 'rcid' => (int)$rc->getAttribute( 'rc_id' ) ];
90 ApiQueryBase::addTitleInfo( $result, $rc->getTitle() );
91 $this->getResult()->addValue( null, $this->getModuleName(), $result );
92 }
93
94 public function mustBePosted() {
95 return true;
96 }
97
98 public function isWriteMode() {
99 return true;
100 }
101
102 public function getAllowedParams() {
103 return [
104 'rcid' => [
105 ApiBase::PARAM_TYPE => 'integer'
106 ],
107 'revid' => [
108 ApiBase::PARAM_TYPE => 'integer'
109 ],
110 'tags' => [
111 ApiBase::PARAM_TYPE => 'tags',
113 ],
114 ];
115 }
116
117 public function needsToken() {
118 return 'patrol';
119 }
120
121 protected function getExamplesMessages() {
122 return [
123 'action=patrol&token=123ABC&rcid=230672766'
124 => 'apihelp-patrol-example-rcid',
125 'action=patrol&token=123ABC&revid=230672766'
126 => 'apihelp-patrol-example-revid',
127 ];
128 }
129
130 public function getHelpUrls() {
131 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Patrol';
132 }
133}
This abstract class implements many basic API functions, and is the base of all API classes.
Definition ApiBase.php:55
dieWithError( $msg, $code=null, $data=null, $httpCode=0)
Abort execution with an error.
Definition ApiBase.php:1436
const PARAM_TYPE
Definition ApiBase.php:81
errorArrayToStatus(array $errors, User $user=null)
Turn an array of message keys or key+param arrays into a Status.
Definition ApiBase.php:1241
requireOnlyOneParameter( $params,... $required)
Die if none or more than one of a certain set of parameters is set and not false.
Definition ApiBase.php:901
getResult()
Get the result object.
Definition ApiBase.php:628
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition ApiBase.php:764
getModuleName()
Get the name of the module being executed by this instance.
Definition ApiBase.php:497
dieStatus(StatusValue $status)
Throw an ApiUsageException based on the Status object.
Definition ApiBase.php:1495
const PARAM_ISMULTI
Definition ApiBase.php:77
This is the main API class, used for both external and internal processing.
Definition ApiMain.php:49
Allows user to patrol pages.
Definition ApiPatrol.php:31
RevisionStore $revisionStore
Definition ApiPatrol.php:33
isWriteMode()
Indicates whether this module requires write mode.
Definition ApiPatrol.php:98
execute()
Patrols the article or provides the reason the patrol failed.
Definition ApiPatrol.php:52
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...
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:94
__construct(ApiMain $main, $action, RevisionStore $revisionStore)
Definition ApiPatrol.php:40
static canAddTagsAccompanyingChange(array $tags, Authority $performer=null)
Is it OK to allow the user to apply all the specified tags at the same time as they edit/make the cha...
Service for looking up page revisions.