MediaWiki
REL1_21
|
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 00155 public static function processUnblock( array $data, IContextSource $context ) { 00156 $performer = $context->getUser(); 00157 $target = $data['Target']; 00158 $block = Block::newFromTarget( $data['Target'] ); 00159 00160 if( !$block instanceof Block ) { 00161 return array( array( 'ipb_cant_unblock', $target ) ); 00162 } 00163 00164 # bug 15810: blocked admins should have limited access here. This 00165 # won't allow sysops to remove autoblocks on themselves, but they 00166 # should have ipblock-exempt anyway 00167 $status = SpecialBlock::checkUnblockSelf( $target, $performer ); 00168 if ( $status !== true ) { 00169 throw new ErrorPageError( 'badaccess', $status ); 00170 } 00171 00172 # If the specified IP is a single address, and the block is a range block, don't 00173 # unblock the whole range. 00174 list( $target, $type ) = SpecialBlock::getTargetAndType( $target ); 00175 if( $block->getType() == Block::TYPE_RANGE && $type == Block::TYPE_IP ) { 00176 $range = $block->getTarget(); 00177 return array( array( 'ipb_blocked_as_range', $target, $range ) ); 00178 } 00179 00180 # If the name was hidden and the blocking user cannot hide 00181 # names, then don't allow any block removals... 00182 if( !$performer->isAllowed( 'hideuser' ) && $block->mHideName ) { 00183 return array( 'unblock-hideuser' ); 00184 } 00185 00186 # Delete block 00187 if ( !$block->delete() ) { 00188 return array( 'ipb_cant_unblock', htmlspecialchars( $block->getTarget() ) ); 00189 } 00190 00191 # Unset _deleted fields as needed 00192 if( $block->mHideName ) { 00193 # Something is deeply FUBAR if this is not a User object, but who knows? 00194 $id = $block->getTarget() instanceof User 00195 ? $block->getTarget()->getID() 00196 : User::idFromName( $block->getTarget() ); 00197 00198 RevisionDeleteUser::unsuppressUserName( $block->getTarget(), $id ); 00199 } 00200 00201 # Redact the name (IP address) for autoblocks 00202 if ( $block->getType() == Block::TYPE_AUTO ) { 00203 $page = Title::makeTitle( NS_USER, '#' . $block->getId() ); 00204 } else { 00205 $page = $block->getTarget() instanceof User 00206 ? $block->getTarget()->getUserpage() 00207 : Title::makeTitle( NS_USER, $block->getTarget() ); 00208 } 00209 00210 # Make log entry 00211 $log = new LogPage( 'block' ); 00212 $log->addEntry( 'unblock', $page, $data['Reason'] ); 00213 00214 return true; 00215 } 00216 00217 protected function getGroupName() { 00218 return 'users'; 00219 } 00220 }