*/
use MediaWiki\MediaWikiServices;
-use MediaWiki\Storage\RevisionStore;
/**
* @ingroup API
*/
class ApiTag extends ApiBase {
- /** @var RevisionStore */
+ use ApiBlockInfoTrait;
+
+ /** @var \MediaWiki\Revision\RevisionStore */
private $revisionStore;
public function execute() {
// make sure the user is allowed
$this->checkUserRightsAny( 'changetags' );
- if ( $user->isBlocked() ) {
- $this->dieBlocked( $user->getBlock() );
+ // Fail early if the user is sitewide blocked.
+ $block = $user->getBlock();
+ if ( $block && $block->isSitewide() ) {
+ $this->dieBlocked( $block );
}
// Check if user can add tags
}
protected function processIndividual( $type, $params, $id ) {
+ $user = $this->getUser();
$idResult = [ $type => $id ];
// validate the ID
switch ( $type ) {
case 'rcid':
$valid = RecentChange::newFromId( $id );
+ if ( $valid && $this->getPermissionManager()->isBlockedFrom( $user, $valid->getTitle() ) ) {
+ $idResult['status'] = 'error';
+ $idResult += $this->getErrorFormatter()->formatMessage( ApiMessage::create(
+ 'apierror-blocked',
+ 'blocked',
+ [ 'blockinfo' => $this->getBlockDetails( $user->getBlock() ) ]
+ ) );
+ return $idResult;
+ }
break;
case 'revid':
$valid = $this->revisionStore->getRevisionById( $id );
+ if (
+ $valid &&
+ $this->getPermissionManager()->isBlockedFrom( $user, $valid->getPageAsLinkTarget() )
+ ) {
+ $idResult['status'] = 'error';
+ $idResult += $this->getErrorFormatter()->formatMessage( ApiMessage::create(
+ 'apierror-blocked',
+ 'blocked',
+ [ 'blockinfo' => $this->getBlockDetails( $user->getBlock() ) ]
+ ) );
+ return $idResult;
+ }
break;
case 'logid':
$valid = self::validateLogId( $id );