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