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