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