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