Merge "Declare dynamic properties"
[lhc/web/wiklou.git] / includes / specials / SpecialRevisionDelete.php
index 682bceb..698e590 100644 (file)
  * @ingroup SpecialPage
  */
 
+use MediaWiki\MediaWikiServices;
+use MediaWiki\Storage\RevisionRecord;
+use MediaWiki\Permissions\PermissionManager;
+
 /**
  * Special page allowing users with the appropriate permissions to view
  * and hide revisions. Log items can also be hidden.
@@ -64,6 +68,9 @@ class SpecialRevisionDelete extends UnlistedSpecialPage {
        /** @var string */
        private $otherReason;
 
+       /** @var PermissionManager */
+       private $permissionManager;
+
        /**
         * UI labels for each type.
         */
@@ -105,8 +112,15 @@ class SpecialRevisionDelete extends UnlistedSpecialPage {
                ],
        ];
 
-       public function __construct() {
+       /**
+        * @inheritDoc
+        *
+        * @param PermissionManager $permissionManager
+        */
+       public function __construct( PermissionManager $permissionManager ) {
                parent::__construct( 'Revisiondelete', 'deleterevision' );
+
+               $this->permissionManager = $permissionManager;
        }
 
        public function doesWrites() {
@@ -122,13 +136,6 @@ class SpecialRevisionDelete extends UnlistedSpecialPage {
                $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();
@@ -178,12 +185,19 @@ class SpecialRevisionDelete extends UnlistedSpecialPage {
                        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();
-               $this->mIsAllowed = $user->isAllowed( RevisionDeleter::getRestriction( $this->typeName ) );
-               $canViewSuppressedOnly = $this->getUser()->isAllowed( 'viewsuppressed' ) &&
-                       !$this->getUser()->isAllowed( 'suppressrevision' );
+               $permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
+               $this->mIsAllowed = $permissionManager->userHasRight( $user,
+                       RevisionDeleter::getRestriction( $this->typeName ) );
+               $canViewSuppressedOnly = $permissionManager->userHasRight( $user, 'viewsuppressed' ) &&
+                       !$permissionManager->userHasRight( $user, 'suppressrevision' );
                $pageIsSuppressed = $list->areAnySuppressed();
                $this->mIsAllowed = $this->mIsAllowed && !( $canViewSuppressedOnly && $pageIsSuppressed );
 
@@ -197,12 +211,12 @@ class SpecialRevisionDelete extends UnlistedSpecialPage {
                        [ $this->typeLabels['check-label'], 'wpHidePrimary',
                                RevisionDeleter::getRevdelConstant( $this->typeName )
                        ],
-                       [ 'revdelete-hide-comment', 'wpHideComment', Revision::DELETED_COMMENT ],
-                       [ 'revdelete-hide-user', 'wpHideUser', Revision::DELETED_USER ]
+                       [ 'revdelete-hide-comment', 'wpHideComment', RevisionRecord::DELETED_COMMENT ],
+                       [ 'revdelete-hide-user', 'wpHideUser', RevisionRecord::DELETED_USER ]
                ];
-               if ( $user->isAllowed( 'suppressrevision' ) ) {
+               if ( $permissionManager->userHasRight( $user, 'suppressrevision' ) ) {
                        $this->checks[] = [ 'revdelete-hide-restricted',
-                               'wpHideRestricted', Revision::DELETED_RESTRICTED ];
+                               'wpHideRestricted', RevisionRecord::DELETED_RESTRICTED ];
                }
 
                # Either submit or create our form
@@ -212,7 +226,7 @@ class SpecialRevisionDelete extends UnlistedSpecialPage {
                        $this->showForm();
                }
 
-               if ( $user->isAllowed( 'deletedhistory' ) ) {
+               if ( $permissionManager->userHasRight( $user, 'deletedhistory' ) ) {
                        $qc = $this->getLogQueryCond();
                        # Show relevant lines from the deletion log
                        $deleteLogPage = new LogPage( 'delete' );
@@ -226,7 +240,7 @@ class SpecialRevisionDelete extends UnlistedSpecialPage {
                        );
                }
                # Show relevant lines from the suppression log
-               if ( $user->isAllowed( 'suppressionlog' ) ) {
+               if ( $permissionManager->userHasRight( $user, 'suppressionlog' ) ) {
                        $suppressLogPage = new LogPage( 'suppress' );
                        $output->addHTML( "<h2>" . $suppressLogPage->getName()->escaped() . "</h2>\n" );
                        LogEventsList::showLogExtract(
@@ -265,7 +279,10 @@ class SpecialRevisionDelete extends UnlistedSpecialPage {
                                        [ 'action' => 'history' ]
                                );
                                # Link to deleted edits
-                               if ( $this->getUser()->isAllowed( 'undelete' ) ) {
+                               if ( MediaWikiServices::getInstance()
+                                               ->getPermissionManager()
+                                               ->userHasRight( $this->getUser(), 'undelete' )
+                               ) {
                                        $undelete = SpecialPage::getTitleFor( 'Undelete' );
                                        $links[] = $linkRenderer->makeKnownLink(
                                                $undelete,
@@ -469,7 +486,10 @@ class SpecialRevisionDelete extends UnlistedSpecialPage {
                                Xml::closeElement( 'fieldset' ) . "\n" .
                                Xml::closeElement( 'form' ) . "\n";
                        // Show link to edit the dropdown reasons
-                       if ( $this->getUser()->isAllowed( 'editinterface' ) ) {
+                       if ( MediaWikiServices::getInstance()
+                                       ->getPermissionManager()
+                                       ->userHasRight( $this->getUser(), 'editinterface' )
+                       ) {
                                $link = $this->getLinkRenderer()->makeKnownLink(
                                        $this->msg( 'revdelete-reason-dropdown' )->inContentLanguage()->getTitle(),
                                        $this->msg( 'revdelete-edit-reasonlist' )->text(),
@@ -495,7 +515,10 @@ class SpecialRevisionDelete extends UnlistedSpecialPage {
                        'revdelete-text-others'
                );
 
-               if ( $this->getUser()->isAllowed( 'suppressrevision' ) ) {
+               if ( MediaWikiServices::getInstance()
+                               ->getPermissionManager()
+                               ->userHasRight( $this->getUser(), 'suppressrevision' )
+               ) {
                        $this->getOutput()->addWikiMsg( 'revdelete-suppress-text' );
                }
 
@@ -530,7 +553,7 @@ class SpecialRevisionDelete extends UnlistedSpecialPage {
                                        $bitfield & $field
                                );
 
-                               if ( $field == Revision::DELETED_RESTRICTED ) {
+                               if ( $field == RevisionRecord::DELETED_RESTRICTED ) {
                                        $innerHTML = "<b>$innerHTML</b>";
                                }
 
@@ -561,7 +584,7 @@ class SpecialRevisionDelete extends UnlistedSpecialPage {
                                $line .= '<td class="mw-revdel-checkbox">' . Xml::radio( $name, 0, $selected == 0 ) . '</td>';
                                $line .= '<td class="mw-revdel-checkbox">' . Xml::radio( $name, 1, $selected == 1 ) . '</td>';
                                $label = $this->msg( $message )->escaped();
-                               if ( $field == Revision::DELETED_RESTRICTED ) {
+                               if ( $field == RevisionRecord::DELETED_RESTRICTED ) {
                                        $label = "<b>$label</b>";
                                }
                                $line .= "<td>$label</td>";
@@ -599,8 +622,10 @@ class SpecialRevisionDelete extends UnlistedSpecialPage {
                                . $this->otherReason;
                }
                # Can the user set this field?
-               if ( $bitParams[Revision::DELETED_RESTRICTED] == 1
-                       && !$this->getUser()->isAllowed( 'suppressrevision' )
+               if ( $bitParams[RevisionRecord::DELETED_RESTRICTED] == 1
+                       && !MediaWikiServices::getInstance()
+                               ->getPermissionManager()
+                               ->userHasRight( $this->getUser(), 'suppressrevision' )
                ) {
                        throw new PermissionsError( 'suppressrevision' );
                }
@@ -662,8 +687,8 @@ class SpecialRevisionDelete extends UnlistedSpecialPage {
                        }
                        $bitfield[$field] = $val;
                }
-               if ( !isset( $bitfield[Revision::DELETED_RESTRICTED] ) ) {
-                       $bitfield[Revision::DELETED_RESTRICTED] = 0;
+               if ( !isset( $bitfield[RevisionRecord::DELETED_RESTRICTED] ) ) {
+                       $bitfield[RevisionRecord::DELETED_RESTRICTED] = 0;
                }
 
                return $bitfield;