| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
, |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
namespace MediaWiki\Api; |
| 26 |
|
| 27 |
use ChangeTags; |
| 28 |
use MediaWiki\Revision\RevisionStore; |
| 29 |
use RecentChange; |
| 30 |
use Wikimedia\ParamValidator\ParamValidator; |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
class ApiPatrol extends ApiBase { |
| 37 |
private RevisionStore $revisionStore; |
| 38 |
|
| 39 |
public function __construct( |
| 40 |
ApiMain $main, |
| 41 |
string $action, |
| 42 |
RevisionStore $revisionStore |
| 43 |
) { |
| 44 |
parent::__construct( $main, $action ); |
| 45 |
$this->revisionStore = $revisionStore; |
| 46 |
} |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
public function execute() { |
| 52 |
$params = $this->extractRequestParams(); |
| 53 |
$this->requireOnlyOneParameter( $params, 'rcid', 'revid' ); |
| 54 |
|
| 55 |
if ( isset( $params['rcid'] ) ) { |
| 56 |
$rc = RecentChange::newFromId( $params['rcid'] ); |
| 57 |
if ( !$rc ) { |
| 58 |
$this->dieWithError( [ 'apierror-nosuchrcid', $params['rcid'] ] ); |
| 59 |
} |
| 60 |
} else { |
| 61 |
$rev = $this->revisionStore->getRevisionById( $params['revid'] ); |
| 62 |
if ( !$rev ) { |
| 63 |
$this->dieWithError( [ 'apierror-nosuchrevid', $params['revid'] ] ); |
| 64 |
} |
| 65 |
$rc = $this->revisionStore->getRecentChange( $rev ); |
| 66 |
if ( !$rc ) { |
| 67 |
$this->dieWithError( [ 'apierror-notpatrollable', $params['revid'] ] ); |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
$user = $this->getUser(); |
| 72 |
$tags = $params['tags']; |
| 73 |
|
| 74 |
|
| 75 |
if ( $tags !== null ) { |
| 76 |
$ableToTag = ChangeTags::canAddTagsAccompanyingChange( $tags, $this->getAuthority() ); |
| 77 |
if ( !$ableToTag->isOK() ) { |
| 78 |
$this->dieStatus( $ableToTag ); |
| 79 |
} |
| 80 |
} |
| 81 |
|
| 82 |
$status = $rc->markPatrolled( $user, $tags ); |
| 83 |
|
| 84 |
if ( !$status->isGood() ) { |
| 85 |
$this->dieStatus( $status ); |
| 86 |
} |
| 87 |
|
| 88 |
$result = [ 'rcid' => (int)$rc->getAttribute( 'rc_id' ) ]; |
| 89 |
ApiQueryBase::addTitleInfo( $result, $rc->getTitle() ); |
| 90 |
$this->getResult()->addValue( null, $this->getModuleName(), $result ); |
| 91 |
} |
| 92 |
|
| 93 |
public function mustBePosted() { |
| 94 |
return true; |
| 95 |
} |
| 96 |
|
| 97 |
public function isWriteMode() { |
| 98 |
return true; |
| 99 |
} |
| 100 |
|
| 101 |
public function getAllowedParams() { |
| 102 |
return [ |
| 103 |
'rcid' => [ |
| 104 |
ParamValidator::PARAM_TYPE => 'integer' |
| 105 |
], |
| 106 |
'revid' => [ |
| 107 |
ParamValidator::PARAM_TYPE => 'integer' |
| 108 |
], |
| 109 |
'tags' => [ |
| 110 |
ParamValidator::PARAM_TYPE => 'tags', |
| 111 |
ParamValidator::PARAM_ISMULTI => true, |
| 112 |
], |
| 113 |
]; |
| 114 |
} |
| 115 |
|
| 116 |
public function needsToken() { |
| 117 |
return 'patrol'; |
| 118 |
} |
| 119 |
|
| 120 |
protected function getExamplesMessages() { |
| 121 |
return [ |
| 122 |
'action=patrol&token=123ABC&rcid=230672766' |
| 123 |
=> 'apihelp-patrol-example-rcid', |
| 124 |
'action=patrol&token=123ABC&revid=230672766' |
| 125 |
=> 'apihelp-patrol-example-revid', |
| 126 |
]; |
| 127 |
} |
| 128 |
|
| 129 |
public function getHelpUrls() { |
| 130 |
return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Patrol'; |
| 131 |
} |
| 132 |
} |
| 133 |
|
| 134 |
|
| 135 |
class_alias( ApiPatrol::class, 'ApiPatrol' ); |