MediaWiki  REL1_19
SpecialUnblock.php
Go to the documentation of this file.
00001 <?php
00027 class SpecialUnblock extends SpecialPage {
00028 
00029         protected $target;
00030         protected $type;
00031         protected $block;
00032 
00033         public function __construct(){
00034                 parent::__construct( 'Unblock', 'block' );
00035         }
00036 
00037         public function execute( $par ){
00038                 $this->checkPermissions();
00039                 $this->checkReadOnly();
00040 
00041                 list( $this->target, $this->type ) = SpecialBlock::getTargetAndType( $par, $this->getRequest() );
00042                 $this->block = Block::newFromTarget( $this->target );
00043 
00044                 $this->setHeaders();
00045                 $this->outputHeader();
00046 
00047                 $out = $this->getOutput();
00048                 $out->setPageTitle( $this->msg( 'unblockip' ) );
00049                 $out->addModules( 'mediawiki.special' );
00050 
00051                 $form = new HTMLForm( $this->getFields(), $this->getContext() );
00052                 $form->setWrapperLegend( wfMsg( 'unblockip' ) );
00053                 $form->setSubmitCallback( array( __CLASS__, 'processUIUnblock' ) );
00054                 $form->setSubmitText( wfMsg( 'ipusubmit' ) );
00055                 $form->addPreText( wfMsgExt( 'unblockiptext', 'parse' ) );
00056 
00057                 if( $form->show() ){
00058                         switch( $this->type ){
00059                                 case Block::TYPE_USER:
00060                                 case Block::TYPE_IP:
00061                                         $out->addWikiMsg( 'unblocked',  $this->target );
00062                                         break;
00063                                 case Block::TYPE_RANGE:
00064                                         $out->addWikiMsg( 'unblocked-range', $this->target );
00065                                         break;
00066                                 case Block::TYPE_ID:
00067                                 case Block::TYPE_AUTO:
00068                                         $out->addWikiMsg( 'unblocked-id', $this->target );
00069                                         break;
00070                         }
00071                 }
00072         }
00073 
00074         protected function getFields(){
00075                 $fields = array(
00076                         'Target' => array(
00077                                 'type' => 'text',
00078                                 'label-message' => 'ipadressorusername',
00079                                 'tabindex' => '1',
00080                                 'size' => '45',
00081                                 'required' => true,
00082                         ),
00083                         'Name' => array(
00084                                 'type' => 'info',
00085                                 'label-message' => 'ipadressorusername',
00086                         ),
00087                         'Reason' => array(
00088                                 'type' => 'text',
00089                                 'label-message' => 'ipbreason',
00090                         )
00091                 );
00092 
00093                 if( $this->block instanceof Block ){
00094                         list( $target, $type ) = $this->block->getTargetAndType();
00095 
00096                         # Autoblocks are logged as "autoblock #123 because the IP was recently used by
00097                         # User:Foo, and we've just got any block, auto or not, that applies to a target
00098                         # the user has specified.  Someone could be fishing to connect IPs to autoblocks,
00099                         # so don't show any distinction between unblocked IPs and autoblocked IPs
00100                         if( $type == Block::TYPE_AUTO && $this->type == Block::TYPE_IP ){
00101                                 $fields['Target']['default'] = $this->target;
00102                                 unset( $fields['Name'] );
00103 
00104                         } else {
00105                                 $fields['Target']['default'] = $target;
00106                                 $fields['Target']['type'] = 'hidden';
00107                                 switch( $type ){
00108                                         case Block::TYPE_USER:
00109                                         case Block::TYPE_IP:
00110                                                 $fields['Name']['default'] = Linker::link(
00111                                                         $target->getUserPage(),
00112                                                         $target->getName()
00113                                                 );
00114                                                 $fields['Name']['raw'] = true;
00115                                                 break;
00116 
00117                                         case Block::TYPE_RANGE:
00118                                                 $fields['Name']['default'] = $target;
00119                                                 break;
00120 
00121                                         case Block::TYPE_AUTO:
00122                                                 $fields['Name']['default'] = $this->block->getRedactedName();
00123                                                 $fields['Name']['raw'] = true;
00124                                                 # Don't expose the real target of the autoblock
00125                                                 $fields['Target']['default'] = "#{$this->target}";
00126                                                 break;
00127                                 }
00128                         }
00129 
00130                 } else {
00131                         $fields['Target']['default'] = $this->target;
00132                         unset( $fields['Name'] );
00133                 }
00134                 return $fields;
00135         }
00136 
00140         public static function processUIUnblock( array $data, HTMLForm $form ) {
00141                 return self::processUnblock( $data, $form->getContext() );
00142         }
00143 
00151         public static function processUnblock( array $data, IContextSource $context ){
00152                 $performer = $context->getUser();
00153                 $target = $data['Target'];
00154                 $block = Block::newFromTarget( $data['Target'] );
00155 
00156                 if( !$block instanceof Block ){
00157                         return array( array( 'ipb_cant_unblock', $target ) );
00158                 }
00159 
00160                 # bug 15810: blocked admins should have limited access here.  This
00161                 # won't allow sysops to remove autoblocks on themselves, but they
00162                 # should have ipblock-exempt anyway
00163                 $status = SpecialBlock::checkUnblockSelf( $target, $performer );
00164                 if ( $status !== true ) {
00165                         throw new ErrorPageError( 'badaccess', $status );
00166                 }
00167 
00168                 # If the specified IP is a single address, and the block is a range block, don't
00169                 # unblock the whole range.
00170                 list( $target, $type ) = SpecialBlock::getTargetAndType( $target );
00171                 if( $block->getType() == Block::TYPE_RANGE && $type == Block::TYPE_IP ) {
00172                          $range = $block->getTarget();
00173                          return array( array( 'ipb_blocked_as_range', $target, $range ) );
00174                 }
00175 
00176                 # If the name was hidden and the blocking user cannot hide
00177                 # names, then don't allow any block removals...
00178                 if( !$performer->isAllowed( 'hideuser' ) && $block->mHideName ) {
00179                         return array( 'unblock-hideuser' );
00180                 }
00181 
00182                 # Delete block
00183                 if ( !$block->delete() ) {
00184                         return array( 'ipb_cant_unblock', htmlspecialchars( $block->getTarget() ) );
00185                 }
00186 
00187                 # Unset _deleted fields as needed
00188                 if( $block->mHideName ) {
00189                         # Something is deeply FUBAR if this is not a User object, but who knows?
00190                         $id = $block->getTarget() instanceof User
00191                                 ? $block->getTarget()->getID()
00192                                 : User::idFromName( $block->getTarget() );
00193 
00194                         RevisionDeleteUser::unsuppressUserName( $block->getTarget(), $id );
00195                 }
00196 
00197                 # Redact the name (IP address) for autoblocks
00198                 if ( $block->getType() == Block::TYPE_AUTO ) {
00199                         $page = Title::makeTitle( NS_USER, '#' . $block->getId() );
00200                 } else {
00201                         $page = $block->getTarget() instanceof User
00202                                 ? $block->getTarget()->getUserpage()
00203                                 : Title::makeTitle( NS_USER, $block->getTarget() );
00204                 }
00205 
00206                 # Make log entry
00207                 $log = new LogPage( 'block' );
00208                 $log->addEntry( 'unblock', $page, $data['Reason'] );
00209 
00210                 return true;
00211         }
00212 }