MediaWiki
REL1_24
|
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_IP: 00067 $out->addWikiMsg( 'unblocked-ip', wfEscapeWikiText( $this->target ) ); 00068 break; 00069 case Block::TYPE_USER: 00070 $out->addWikiMsg( 'unblocked', wfEscapeWikiText( $this->target ) ); 00071 break; 00072 case Block::TYPE_RANGE: 00073 $out->addWikiMsg( 'unblocked-range', wfEscapeWikiText( $this->target ) ); 00074 break; 00075 case Block::TYPE_ID: 00076 case Block::TYPE_AUTO: 00077 $out->addWikiMsg( 'unblocked-id', wfEscapeWikiText( $this->target ) ); 00078 break; 00079 } 00080 } 00081 } 00082 00083 protected function getFields() { 00084 $fields = array( 00085 'Target' => array( 00086 'type' => 'text', 00087 'label-message' => 'ipaddressorusername', 00088 'autofocus' => true, 00089 'size' => '45', 00090 'required' => true, 00091 ), 00092 'Name' => array( 00093 'type' => 'info', 00094 'label-message' => 'ipaddressorusername', 00095 ), 00096 'Reason' => array( 00097 'type' => 'text', 00098 'label-message' => 'ipbreason', 00099 ) 00100 ); 00101 00102 if ( $this->block instanceof Block ) { 00103 list( $target, $type ) = $this->block->getTargetAndType(); 00104 00105 # Autoblocks are logged as "autoblock #123 because the IP was recently used by 00106 # User:Foo, and we've just got any block, auto or not, that applies to a target 00107 # the user has specified. Someone could be fishing to connect IPs to autoblocks, 00108 # so don't show any distinction between unblocked IPs and autoblocked IPs 00109 if ( $type == Block::TYPE_AUTO && $this->type == Block::TYPE_IP ) { 00110 $fields['Target']['default'] = $this->target; 00111 unset( $fields['Name'] ); 00112 } else { 00113 $fields['Target']['default'] = $target; 00114 $fields['Target']['type'] = 'hidden'; 00115 switch ( $type ) { 00116 case Block::TYPE_IP: 00117 $fields['Name']['default'] = Linker::linkKnown( 00118 SpecialPage::getTitleFor( 'Contributions', $target->getName() ), 00119 $target->getName() 00120 ); 00121 $fields['Name']['raw'] = true; 00122 break; 00123 case Block::TYPE_USER: 00124 $fields['Name']['default'] = Linker::link( 00125 $target->getUserPage(), 00126 $target->getName() 00127 ); 00128 $fields['Name']['raw'] = true; 00129 break; 00130 00131 case Block::TYPE_RANGE: 00132 $fields['Name']['default'] = $target; 00133 break; 00134 00135 case Block::TYPE_AUTO: 00136 $fields['Name']['default'] = $this->block->getRedactedName(); 00137 $fields['Name']['raw'] = true; 00138 # Don't expose the real target of the autoblock 00139 $fields['Target']['default'] = "#{$this->target}"; 00140 break; 00141 } 00142 // target is hidden, so the reason is the first element 00143 $fields['Target']['autofocus'] = false; 00144 $fields['Reason']['autofocus'] = true; 00145 } 00146 } else { 00147 $fields['Target']['default'] = $this->target; 00148 unset( $fields['Name'] ); 00149 } 00150 00151 return $fields; 00152 } 00153 00160 public static function processUIUnblock( array $data, HTMLForm $form ) { 00161 return self::processUnblock( $data, $form->getContext() ); 00162 } 00163 00172 public static function processUnblock( array $data, IContextSource $context ) { 00173 $performer = $context->getUser(); 00174 $target = $data['Target']; 00175 $block = Block::newFromTarget( $data['Target'] ); 00176 00177 if ( !$block instanceof Block ) { 00178 return array( array( 'ipb_cant_unblock', $target ) ); 00179 } 00180 00181 # bug 15810: blocked admins should have limited access here. This 00182 # won't allow sysops to remove autoblocks on themselves, but they 00183 # should have ipblock-exempt anyway 00184 $status = SpecialBlock::checkUnblockSelf( $target, $performer ); 00185 if ( $status !== true ) { 00186 throw new ErrorPageError( 'badaccess', $status ); 00187 } 00188 00189 # If the specified IP is a single address, and the block is a range block, don't 00190 # unblock the whole range. 00191 list( $target, $type ) = SpecialBlock::getTargetAndType( $target ); 00192 if ( $block->getType() == Block::TYPE_RANGE && $type == Block::TYPE_IP ) { 00193 $range = $block->getTarget(); 00194 00195 return array( array( 'ipb_blocked_as_range', $target, $range ) ); 00196 } 00197 00198 # If the name was hidden and the blocking user cannot hide 00199 # names, then don't allow any block removals... 00200 if ( !$performer->isAllowed( 'hideuser' ) && $block->mHideName ) { 00201 return array( 'unblock-hideuser' ); 00202 } 00203 00204 # Delete block 00205 if ( !$block->delete() ) { 00206 return array( 'ipb_cant_unblock', htmlspecialchars( $block->getTarget() ) ); 00207 } 00208 00209 # Unset _deleted fields as needed 00210 if ( $block->mHideName ) { 00211 # Something is deeply FUBAR if this is not a User object, but who knows? 00212 $id = $block->getTarget() instanceof User 00213 ? $block->getTarget()->getID() 00214 : User::idFromName( $block->getTarget() ); 00215 00216 RevisionDeleteUser::unsuppressUserName( $block->getTarget(), $id ); 00217 } 00218 00219 # Redact the name (IP address) for autoblocks 00220 if ( $block->getType() == Block::TYPE_AUTO ) { 00221 $page = Title::makeTitle( NS_USER, '#' . $block->getId() ); 00222 } else { 00223 $page = $block->getTarget() instanceof User 00224 ? $block->getTarget()->getUserpage() 00225 : Title::makeTitle( NS_USER, $block->getTarget() ); 00226 } 00227 00228 # Make log entry 00229 $log = new LogPage( 'block' ); 00230 $log->addEntry( 'unblock', $page, $data['Reason'], array(), $performer ); 00231 00232 return true; 00233 } 00234 00235 protected function getGroupName() { 00236 return 'users'; 00237 } 00238 }