Merge "(bug 42787) Make import robust against corrupt content."
[lhc/web/wiklou.git] / includes / specials / SpecialUnblock.php
index 8974c5d..853a805 100644 (file)
@@ -1,5 +1,7 @@
 <?php
 /**
+ * Implements Special:Unblock
+ *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
@@ -35,50 +37,37 @@ class SpecialUnblock extends SpecialPage {
        }
 
        public function execute( $par ){
-               global $wgUser, $wgOut, $wgRequest;
+               $this->checkPermissions();
+               $this->checkReadOnly();
 
-               # Check permissions
-               if( !$wgUser->isAllowed( 'block' ) ) {
-                       $wgOut->permissionRequired( 'block' );
-                       return;
-               }
-               # Check for database lock
-               if( wfReadOnly() ) {
-                       $wgOut->readOnlyPage();
-                       return;
-               }
-
-               list( $this->target, $this->type ) = SpecialBlock::getTargetAndType( $par, $wgRequest );
+               list( $this->target, $this->type ) = SpecialBlock::getTargetAndType( $par, $this->getRequest() );
                $this->block = Block::newFromTarget( $this->target );
 
-               # bug 15810: blocked admins should have limited access here.  This won't allow sysops
-               # to remove autoblocks on themselves, but they should have ipblock-exempt anyway
-               $status = SpecialBlock::checkUnblockSelf( $this->target );
-               if ( $status !== true ) {
-                       throw new ErrorPageError( 'badaccess', $status );
-               }
+               $this->setHeaders();
+               $this->outputHeader();
 
-               $wgOut->setPageTitle( wfMsg( 'unblockip' ) );
-               $wgOut->addModules( 'mediawiki.special' );
+               $out = $this->getOutput();
+               $out->setPageTitle( $this->msg( 'unblockip' ) );
+               $out->addModules( 'mediawiki.special' );
 
                $form = new HTMLForm( $this->getFields(), $this->getContext() );
-               $form->setWrapperLegend( wfMsg( 'unblockip' ) );
-               $form->setSubmitCallback( array( __CLASS__, 'processUnblock' ) );
-               $form->setSubmitText( wfMsg( 'ipusubmit' ) );
-               $form->addPreText( wfMsgExt( 'unblockiptext', 'parse' ) );
+               $form->setWrapperLegendMsg( 'unblockip' );
+               $form->setSubmitCallback( array( __CLASS__, 'processUIUnblock' ) );
+               $form->setSubmitTextMsg( 'ipusubmit' );
+               $form->addPreText( $this->msg( 'unblockiptext' )->parseAsBlock() );
 
                if( $form->show() ){
                        switch( $this->type ){
                                case Block::TYPE_USER:
                                case Block::TYPE_IP:
-                                       $wgOut->addWikiMsg( 'unblocked',  $this->target );
+                                       $out->addWikiMsg( 'unblocked', wfEscapeWikiText( $this->target ) );
                                        break;
                                case Block::TYPE_RANGE:
-                                       $wgOut->addWikiMsg( 'unblocked-range', $this->target );
+                                       $out->addWikiMsg( 'unblocked-range', wfEscapeWikiText( $this->target ) );
                                        break;
                                case Block::TYPE_ID:
                                case Block::TYPE_AUTO:
-                                       $wgOut->addWikiMsg( 'unblocked-id', $this->target );
+                                       $out->addWikiMsg( 'unblocked-id', wfEscapeWikiText( $this->target ) );
                                        break;
                        }
                }
@@ -120,8 +109,7 @@ class SpecialUnblock extends SpecialPage {
                                switch( $type ){
                                        case Block::TYPE_USER:
                                        case Block::TYPE_IP:
-                                               $skin = $this->getSkin();
-                                               $fields['Name']['default'] = $skin->link(
+                                               $fields['Name']['default'] = Linker::link(
                                                        $target->getUserPage(),
                                                        $target->getName()
                                                );
@@ -148,13 +136,24 @@ class SpecialUnblock extends SpecialPage {
                return $fields;
        }
 
+       /**
+        * Submit callback for an HTMLForm object
+        * @return Array( Array(message key, parameters)
+        */
+       public static function processUIUnblock( array $data, HTMLForm $form ) {
+               return self::processUnblock( $data, $form->getContext() );
+       }
+
        /**
         * Process the form
+        *
+        * @param $data Array
+        * @param $context IContextSource
+        * @throws ErrorPageError
         * @return Array( Array(message key, parameters) ) on failure, True on success
         */
-       public static function processUnblock( array $data ){
-               global $wgUser;
-
+       public static function processUnblock( array $data, IContextSource $context ){
+               $performer = $context->getUser();
                $target = $data['Target'];
                $block = Block::newFromTarget( $data['Target'] );
 
@@ -162,6 +161,14 @@ class SpecialUnblock extends SpecialPage {
                        return array( array( 'ipb_cant_unblock', $target ) );
                }
 
+               # bug 15810: blocked admins should have limited access here.  This
+               # won't allow sysops to remove autoblocks on themselves, but they
+               # should have ipblock-exempt anyway
+               $status = SpecialBlock::checkUnblockSelf( $target, $performer );
+               if ( $status !== true ) {
+                       throw new ErrorPageError( 'badaccess', $status );
+               }
+
                # 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 );
@@ -172,7 +179,7 @@ class SpecialUnblock extends SpecialPage {
 
                # If the name was hidden and the blocking user cannot hide
                # names, then don't allow any block removals...
-               if( !$wgUser->isAllowed( 'hideuser' ) && $block->mHideName ) {
+               if( !$performer->isAllowed( 'hideuser' ) && $block->mHideName ) {
                        return array( 'unblock-hideuser' );
                }
 
@@ -191,11 +198,17 @@ class SpecialUnblock extends SpecialPage {
                        RevisionDeleteUser::unsuppressUserName( $block->getTarget(), $id );
                }
 
+               # Redact the name (IP address) for autoblocks
+               if ( $block->getType() == Block::TYPE_AUTO ) {
+                       $page = Title::makeTitle( NS_USER, '#' . $block->getId() );
+               } else {
+                       $page = $block->getTarget() instanceof User
+                               ? $block->getTarget()->getUserpage()
+                               : Title::makeTitle( NS_USER, $block->getTarget() );
+               }
+
                # Make log entry
                $log = new LogPage( 'block' );
-               $page = $block->getTarget() instanceof User
-                       ? $block->getTarget()->getUserpage()
-                       : Title::makeTitle( NS_USER, $block->getTarget() );
                $log->addEntry( 'unblock', $page, $data['Reason'] );
 
                return true;