$user = $this->getUser();
$this->checkUserRightsAny( RevisionDeleter::getRestriction( $params['type'] ) );
- // @TODO Use PermissionManager::isBlockedFrom() instead.
- $block = $user->getBlock();
- if ( $block ) {
- $this->dieBlocked( $block );
- }
-
if ( !$params['ids'] ) {
$this->dieWithError( [ 'apierror-paramempty', 'ids' ], 'paramempty_ids' );
}
$this->dieWithError( [ 'apierror-revdel-needtarget' ], 'needtarget' );
}
+ if ( $this->getPermissionManager()->isBlockedFrom( $user, $targetObj ) ) {
+ $this->dieBlocked( $user->getBlock() );
+ }
+
$list = RevisionDeleter::createList(
$params['type'], $this->getContext(), $targetObj, $params['ids']
);
'NewSection' => \SpecialNewSection::class,
'PermanentLink' => \SpecialPermanentLink::class,
'Redirect' => \SpecialRedirect::class,
- 'Revisiondelete' => \SpecialRevisionDelete::class,
+ 'Revisiondelete' => [
+ 'class' => \SpecialRevisionDelete::class,
+ 'services' => [
+ 'PermissionManager',
+ ],
+ ],
'RunJobs' => \SpecialRunJobs::class,
'Specialpages' => \SpecialSpecialpages::class,
'PageData' => \SpecialPageData::class,
*/
private $existingPropNames = null;
+ /**
+ * @var string|null
+ */
+ private $ns;
+
/**
* @var bool
*/
'label-message' => 'pageswithprop-prop',
'required' => true,
],
+ 'namespace' => [
+ 'type' => 'namespaceselect',
+ 'name' => 'namespace',
+ 'label-message' => 'namespace',
+ 'all' => null,
+ 'default' => null,
+ ],
'reverse' => [
'type' => 'check',
'name' => 'reverse',
public function onSubmit( $data, $form ) {
$this->propName = $data['propname'];
+ $this->ns = $data['namespace'];
parent::execute( $data['propname'] );
}
}
public function getQueryInfo() {
- return [
+ $query = [
'tables' => [ 'page_props', 'page' ],
'fields' => [
'page_id' => 'pp_page',
],
'options' => []
];
+
+ if ( $this->ns && isset( $this->ns ) ) {
+ $query['conds']['page_namespace'] = $this->ns;
+ }
+
+ return $query;
}
function getOrderFields() {
*/
use MediaWiki\Storage\RevisionRecord;
+use MediaWiki\Permissions\PermissionManager;
/**
* Special page allowing users with the appropriate permissions to view
/** @var string */
private $otherReason;
+ /** @var PermissionManager */
+ private $permissionManager;
+
/**
* UI labels for each type.
*/
],
];
- public function __construct() {
+ /**
+ * @inheritDoc
+ *
+ * @param PermissionManager $permissionManager
+ */
+ public function __construct( PermissionManager $permissionManager ) {
parent::__construct( 'Revisiondelete', 'deleterevision' );
+
+ $this->permissionManager = $permissionManager;
}
public function doesWrites() {
$output = $this->getOutput();
$user = $this->getUser();
- // Check blocks
- // @TODO Use PermissionManager::isBlockedFrom() instead.
- $block = $user->getBlock();
- if ( $block ) {
- throw new UserBlockedError( $block );
- }
-
$this->setHeaders();
$this->outputHeader();
$request = $this->getRequest();
return;
}
+ // Check blocks
+ if ( $this->permissionManager->isBlockedFrom( $user, $this->targetObj ) ) {
+ throw new UserBlockedError( $user->getBlock() );
+ }
+
$this->typeLabels = self::$UILabels[$this->typeName];
$list = $this->getList();
$list->reset();
}
// Validate request parameters
- $optional = [ 'maxjobs' => 0, 'maxtime' => 30, 'type' => false, 'async' => true ];
+ $optional = [ 'maxjobs' => 0, 'maxtime' => 30, 'type' => false,
+ 'async' => true, 'stats' => false ];
$required = array_flip( [ 'title', 'tasks', 'signature', 'sigexpiry' ] );
$params = array_intersect_key( $this->getRequest()->getValues(), $required + $optional );
$missing = array_diff_key( $required, $params );
DeferredUpdates::POSTSEND
);
} else {
- $this->doRun( $params );
- print "Done\n";
+ $stats = $this->doRun( $params );
+
+ if ( $params['stats'] ) {
+ $this->getRequest()->response()->header( 'Content-Type: application/json' );
+ print FormatJson::encode( $stats );
+ } else {
+ print "Done\n";
+ }
}
}
protected function doRun( array $params ) {
$runner = new JobRunner( LoggerFactory::getInstance( 'runJobs' ) );
- $runner->run( [
+ return $runner->run( [
'type' => $params['type'],
'maxJobs' => $params['maxjobs'] ?: 1,
'maxTime' => $params['maxtime'] ?: 30
<?php
+use MediaWiki\Block\DatabaseBlock;
+use MediaWiki\Block\Restriction\PageRestriction;
+
/**
* Tests for action=revisiondelete
* @covers APIRevisionDelete
$this->assertTrue( $item['texthidden'], 'texthidden' );
$this->assertEquals( $item['id'], $revid );
}
+
+ public function testPartiallyBlockedPage() {
+ $this->setExpectedApiException( 'apierror-blocked-partial' );
+
+ $user = static::getTestSysop()->getUser();
+
+ $block = new DatabaseBlock( [
+ 'address' => $user,
+ 'by' => static::getTestSysop()->getUser()->getId(),
+ 'sitewide' => false,
+ ] );
+
+ $block->setRestrictions( [
+ new PageRestriction( 0, Title::newFromText( self::$page )->getArticleID() )
+ ] );
+ $block->insert();
+
+ $revid = array_shift( $this->revs );
+
+ $this->doApiRequest( [
+ 'action' => 'revisiondelete',
+ 'type' => 'revision',
+ 'target' => self::$page,
+ 'ids' => $revid,
+ 'hide' => 'content|user|comment',
+ 'token' => $user->getEditToken(),
+ ] );
+ }
}