Replace usages of deprecated User::isAllowed. Step 2.
[lhc/web/wiklou.git] / includes / specials / SpecialUnblock.php
index 632415c..931b179 100644 (file)
@@ -21,6 +21,9 @@
  * @ingroup SpecialPage
  */
 
+use MediaWiki\Block\DatabaseBlock;
+use MediaWiki\MediaWikiServices;
+
 /**
  * A special page for unblocking users
  *
@@ -45,7 +48,7 @@ class SpecialUnblock extends SpecialPage {
                $this->checkReadOnly();
 
                list( $this->target, $this->type ) = SpecialBlock::getTargetAndType( $par, $this->getRequest() );
-               $this->block = Block::newFromTarget( $this->target );
+               $this->block = DatabaseBlock::newFromTarget( $this->target );
                if ( $this->target instanceof User ) {
                        # Set the 'relevant user' in the skin, so it displays links like Contributions,
                        # User logs, UserRights, etc.
@@ -54,6 +57,7 @@ class SpecialUnblock extends SpecialPage {
 
                $this->setHeaders();
                $this->outputHeader();
+               $this->addHelpLink( 'Help:Blocking users' );
 
                $out = $this->getOutput();
                $out->setPageTitle( $this->msg( 'unblockip' ) );
@@ -67,17 +71,17 @@ class SpecialUnblock extends SpecialPage {
 
                if ( $form->show() ) {
                        switch ( $this->type ) {
-                               case Block::TYPE_IP:
+                               case DatabaseBlock::TYPE_IP:
                                        $out->addWikiMsg( 'unblocked-ip', wfEscapeWikiText( $this->target ) );
                                        break;
-                               case Block::TYPE_USER:
+                               case DatabaseBlock::TYPE_USER:
                                        $out->addWikiMsg( 'unblocked', wfEscapeWikiText( $this->target ) );
                                        break;
-                               case Block::TYPE_RANGE:
+                               case DatabaseBlock::TYPE_RANGE:
                                        $out->addWikiMsg( 'unblocked-range', wfEscapeWikiText( $this->target ) );
                                        break;
-                               case Block::TYPE_ID:
-                               case Block::TYPE_AUTO:
+                               case DatabaseBlock::TYPE_ID:
+                               case DatabaseBlock::TYPE_AUTO:
                                        $out->addWikiMsg( 'unblocked-id', wfEscapeWikiText( $this->target ) );
                                        break;
                        }
@@ -104,28 +108,28 @@ class SpecialUnblock extends SpecialPage {
                        ]
                ];
 
-               if ( $this->block instanceof Block ) {
+               if ( $this->block instanceof DatabaseBlock ) {
                        list( $target, $type ) = $this->block->getTargetAndType();
 
                        # Autoblocks are logged as "autoblock #123 because the IP was recently used by
                        # User:Foo, and we've just got any block, auto or not, that applies to a target
                        # the user has specified.  Someone could be fishing to connect IPs to autoblocks,
                        # so don't show any distinction between unblocked IPs and autoblocked IPs
-                       if ( $type == Block::TYPE_AUTO && $this->type == Block::TYPE_IP ) {
+                       if ( $type == DatabaseBlock::TYPE_AUTO && $this->type == DatabaseBlock::TYPE_IP ) {
                                $fields['Target']['default'] = $this->target;
                                unset( $fields['Name'] );
                        } else {
                                $fields['Target']['default'] = $target;
                                $fields['Target']['type'] = 'hidden';
                                switch ( $type ) {
-                                       case Block::TYPE_IP:
+                                       case DatabaseBlock::TYPE_IP:
                                                $fields['Name']['default'] = $this->getLinkRenderer()->makeKnownLink(
                                                        SpecialPage::getTitleFor( 'Contributions', $target->getName() ),
                                                        $target->getName()
                                                );
                                                $fields['Name']['raw'] = true;
                                                break;
-                                       case Block::TYPE_USER:
+                                       case DatabaseBlock::TYPE_USER:
                                                $fields['Name']['default'] = $this->getLinkRenderer()->makeLink(
                                                        $target->getUserPage(),
                                                        $target->getName()
@@ -133,11 +137,11 @@ class SpecialUnblock extends SpecialPage {
                                                $fields['Name']['raw'] = true;
                                                break;
 
-                                       case Block::TYPE_RANGE:
+                                       case DatabaseBlock::TYPE_RANGE:
                                                $fields['Name']['default'] = $target;
                                                break;
 
-                                       case Block::TYPE_AUTO:
+                                       case DatabaseBlock::TYPE_AUTO:
                                                $fields['Name']['default'] = $this->block->getRedactedName();
                                                $fields['Name']['raw'] = true;
                                                # Don't expose the real target of the autoblock
@@ -160,7 +164,7 @@ class SpecialUnblock extends SpecialPage {
         * Submit callback for an HTMLForm object
         * @param array $data
         * @param HTMLForm $form
-        * @return array|bool Array(message key, parameters)
+        * @return array|bool [ message key, parameters ]
         */
        public static function processUIUnblock( array $data, HTMLForm $form ) {
                return self::processUnblock( $data, $form->getContext() );
@@ -175,14 +179,14 @@ class SpecialUnblock extends SpecialPage {
         * @param array $data
         * @param IContextSource $context
         * @throws ErrorPageError
-        * @return array|bool Array( Array( message key, parameters ) ) on failure, True on success
+        * @return array|bool [ [ message key, parameters ] ] on failure, True on success
         */
        public static function processUnblock( array $data, IContextSource $context ) {
                $performer = $context->getUser();
                $target = $data['Target'];
-               $block = Block::newFromTarget( $data['Target'] );
+               $block = DatabaseBlock::newFromTarget( $data['Target'] );
 
-               if ( !$block instanceof Block ) {
+               if ( !$block instanceof DatabaseBlock ) {
                        return [ [ 'ipb_cant_unblock', $target ] ];
                }
 
@@ -197,7 +201,7 @@ class SpecialUnblock extends SpecialPage {
                # If the specified IP is a single address, and the block is a range block, don't
                # unblock the whole range.
                list( $target, $type ) = SpecialBlock::getTargetAndType( $target );
-               if ( $block->getType() == Block::TYPE_RANGE && $type == Block::TYPE_IP ) {
+               if ( $block->getType() == DatabaseBlock::TYPE_RANGE && $type == DatabaseBlock::TYPE_IP ) {
                        $range = $block->getTarget();
 
                        return [ [ 'ipb_blocked_as_range', $target, $range ] ];
@@ -205,7 +209,10 @@ class SpecialUnblock extends SpecialPage {
 
                # If the name was hidden and the blocking user cannot hide
                # names, then don't allow any block removals...
-               if ( !$performer->isAllowed( 'hideuser' ) && $block->mHideName ) {
+               if ( !MediaWikiServices::getInstance()
+                               ->getPermissionManager()
+                               ->userHasRight( $performer, 'hideuser' ) && $block->getHideName()
+               ) {
                        return [ 'unblock-hideuser' ];
                }
 
@@ -222,7 +229,7 @@ class SpecialUnblock extends SpecialPage {
                Hooks::run( 'UnblockUserComplete', [ $block, $performer ] );
 
                # Unset _deleted fields as needed
-               if ( $block->mHideName ) {
+               if ( $block->getHideName() ) {
                        # Something is deeply FUBAR if this is not a User object, but who knows?
                        $id = $block->getTarget() instanceof User
                                ? $block->getTarget()->getId()
@@ -232,7 +239,7 @@ class SpecialUnblock extends SpecialPage {
                }
 
                # Redact the name (IP address) for autoblocks
-               if ( $block->getType() == Block::TYPE_AUTO ) {
+               if ( $block->getType() == DatabaseBlock::TYPE_AUTO ) {
                        $page = Title::makeTitle( NS_USER, '#' . $block->getId() );
                } else {
                        $page = $block->getTarget() instanceof User
@@ -246,7 +253,7 @@ class SpecialUnblock extends SpecialPage {
                $logEntry->setComment( $data['Reason'] );
                $logEntry->setPerformer( $performer );
                if ( isset( $data['Tags'] ) ) {
-                       $logEntry->setTags( $data['Tags'] );
+                       $logEntry->addTags( $data['Tags'] );
                }
                $logEntry->setRelations( [ 'ipb_id' => $block->getId() ] );
                $logId = $logEntry->insert();