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