MediaWiki
REL1_19
|
00001 <?php 00030 class SpecialBlock extends FormSpecialPage { 00033 const HIDEUSER_CONTRIBLIMIT = 1000; 00034 00037 protected $target; 00038 00040 protected $type; 00041 00043 protected $previousTarget; 00044 00046 protected $requestedHideUser; 00047 00049 protected $alreadyBlocked; 00050 00052 protected $preErrors = array(); 00053 00054 public function __construct() { 00055 parent::__construct( 'Block', 'block' ); 00056 } 00057 00064 protected function checkExecutePermissions( User $user ) { 00065 parent::checkExecutePermissions( $user ); 00066 00067 # bug 15810: blocked admins should have limited access here 00068 $status = self::checkUnblockSelf( $this->target, $user ); 00069 if ( $status !== true ) { 00070 throw new ErrorPageError( 'badaccess', $status ); 00071 } 00072 } 00073 00079 protected function setParameter( $par ) { 00080 # Extract variables from the request. Try not to get into a situation where we 00081 # need to extract *every* variable from the form just for processing here, but 00082 # there are legitimate uses for some variables 00083 $request = $this->getRequest(); 00084 list( $this->target, $this->type ) = self::getTargetAndType( $par, $request ); 00085 if ( $this->target instanceof User ) { 00086 # Set the 'relevant user' in the skin, so it displays links like Contributions, 00087 # User logs, UserRights, etc. 00088 $this->getSkin()->setRelevantUser( $this->target ); 00089 } 00090 00091 list( $this->previousTarget, /*...*/ ) = Block::parseTarget( $request->getVal( 'wpPreviousTarget' ) ); 00092 $this->requestedHideUser = $request->getBool( 'wpHideUser' ); 00093 } 00094 00100 protected function alterForm( HTMLForm $form ) { 00101 $form->setWrapperLegendMsg( 'blockip-legend' ); 00102 $form->setHeaderText( '' ); 00103 $form->setSubmitCallback( array( __CLASS__, 'processUIForm' ) ); 00104 00105 $msg = $this->alreadyBlocked ? 'ipb-change-block' : 'ipbsubmit'; 00106 $form->setSubmitTextMsg( $msg ); 00107 00108 # Don't need to do anything if the form has been posted 00109 if( !$this->getRequest()->wasPosted() && $this->preErrors ){ 00110 $s = HTMLForm::formatErrors( $this->preErrors ); 00111 if( $s ){ 00112 $form->addHeaderText( Html::rawElement( 00113 'div', 00114 array( 'class' => 'error' ), 00115 $s 00116 ) ); 00117 } 00118 } 00119 } 00120 00125 protected function getFormFields(){ 00126 global $wgBlockAllowsUTEdit; 00127 00128 $user = $this->getUser(); 00129 00130 $a = array( 00131 'Target' => array( 00132 'type' => 'text', 00133 'label-message' => 'ipadressorusername', 00134 'tabindex' => '1', 00135 'id' => 'mw-bi-target', 00136 'size' => '45', 00137 'required' => true, 00138 'validation-callback' => array( __CLASS__, 'validateTargetField' ), 00139 ), 00140 'Expiry' => array( 00141 'type' => !count( self::getSuggestedDurations() ) ? 'text' : 'selectorother', 00142 'label-message' => 'ipbexpiry', 00143 'required' => true, 00144 'tabindex' => '2', 00145 'options' => self::getSuggestedDurations(), 00146 'other' => $this->msg( 'ipbother' )->text(), 00147 ), 00148 'Reason' => array( 00149 'type' => 'selectandother', 00150 'label-message' => 'ipbreason', 00151 'options-message' => 'ipbreason-dropdown', 00152 ), 00153 'CreateAccount' => array( 00154 'type' => 'check', 00155 'label-message' => 'ipbcreateaccount', 00156 'default' => true, 00157 ), 00158 ); 00159 00160 if( self::canBlockEmail( $user ) ) { 00161 $a['DisableEmail'] = array( 00162 'type' => 'check', 00163 'label-message' => 'ipbemailban', 00164 ); 00165 } 00166 00167 if( $wgBlockAllowsUTEdit ){ 00168 $a['DisableUTEdit'] = array( 00169 'type' => 'check', 00170 'label-message' => 'ipb-disableusertalk', 00171 'default' => false, 00172 ); 00173 } 00174 00175 $a['AutoBlock'] = array( 00176 'type' => 'check', 00177 'label-message' => 'ipbenableautoblock', 00178 'default' => true, 00179 ); 00180 00181 # Allow some users to hide name from block log, blocklist and listusers 00182 if( $user->isAllowed( 'hideuser' ) ) { 00183 $a['HideUser'] = array( 00184 'type' => 'check', 00185 'label-message' => 'ipbhidename', 00186 'cssclass' => 'mw-block-hideuser', 00187 ); 00188 } 00189 00190 # Watchlist their user page? (Only if user is logged in) 00191 if( $user->isLoggedIn() ) { 00192 $a['Watch'] = array( 00193 'type' => 'check', 00194 'label-message' => 'ipbwatchuser', 00195 ); 00196 } 00197 00198 $a['HardBlock'] = array( 00199 'type' => 'check', 00200 'label-message' => 'ipb-hardblock', 00201 'default' => false, 00202 ); 00203 00204 # This is basically a copy of the Target field, but the user can't change it, so we 00205 # can see if the warnings we maybe showed to the user before still apply 00206 $a['PreviousTarget'] = array( 00207 'type' => 'hidden', 00208 'default' => false, 00209 ); 00210 00211 # We'll turn this into a checkbox if we need to 00212 $a['Confirm'] = array( 00213 'type' => 'hidden', 00214 'default' => '', 00215 'label-message' => 'ipb-confirm', 00216 ); 00217 00218 $this->maybeAlterFormDefaults( $a ); 00219 00220 return $a; 00221 } 00222 00230 protected function maybeAlterFormDefaults( &$fields ){ 00231 # This will be overwritten by request data 00232 $fields['Target']['default'] = (string)$this->target; 00233 00234 # This won't be 00235 $fields['PreviousTarget']['default'] = (string)$this->target; 00236 00237 $block = Block::newFromTarget( $this->target ); 00238 00239 if( $block instanceof Block && !$block->mAuto # The block exists and isn't an autoblock 00240 && ( $this->type != Block::TYPE_RANGE # The block isn't a rangeblock 00241 || $block->getTarget() == $this->target ) # or if it is, the range is what we're about to block 00242 ) 00243 { 00244 $fields['HardBlock']['default'] = $block->isHardblock(); 00245 $fields['CreateAccount']['default'] = $block->prevents( 'createaccount' ); 00246 $fields['AutoBlock']['default'] = $block->isAutoblocking(); 00247 00248 if( isset( $fields['DisableEmail'] ) ){ 00249 $fields['DisableEmail']['default'] = $block->prevents( 'sendemail' ); 00250 } 00251 00252 if( isset( $fields['HideUser'] ) ){ 00253 $fields['HideUser']['default'] = $block->mHideName; 00254 } 00255 00256 if( isset( $fields['DisableUTEdit'] ) ){ 00257 $fields['DisableUTEdit']['default'] = $block->prevents( 'editownusertalk' ); 00258 } 00259 00260 // If the username was hidden (ipb_deleted == 1), don't show the reason 00261 // unless this user also has rights to hideuser: Bug 35839 00262 if ( !$block->mHideName || $this->getUser()->isAllowed( 'hideuser' ) ) { 00263 $fields['Reason']['default'] = $block->mReason; 00264 } else { 00265 $fields['Reason']['default'] = ''; 00266 } 00267 00268 if( $this->getRequest()->wasPosted() ){ 00269 # Ok, so we got a POST submission asking us to reblock a user. So show the 00270 # confirm checkbox; the user will only see it if they haven't previously 00271 $fields['Confirm']['type'] = 'check'; 00272 } else { 00273 # We got a target, but it wasn't a POST request, so the user must have gone 00274 # to a link like [[Special:Block/User]]. We don't need to show the checkbox 00275 # as long as they go ahead and block *that* user 00276 $fields['Confirm']['default'] = 1; 00277 } 00278 00279 if( $block->mExpiry == 'infinity' ) { 00280 $fields['Expiry']['default'] = 'indefinite'; 00281 } else { 00282 $fields['Expiry']['default'] = wfTimestamp( TS_RFC2822, $block->mExpiry ); 00283 } 00284 00285 $this->alreadyBlocked = true; 00286 $this->preErrors[] = array( 'ipb-needreblock', (string)$block->getTarget() ); 00287 } 00288 00289 # We always need confirmation to do HideUser 00290 if( $this->requestedHideUser ){ 00291 $fields['Confirm']['type'] = 'check'; 00292 unset( $fields['Confirm']['default'] ); 00293 $this->preErrors[] = 'ipb-confirmhideuser'; 00294 } 00295 00296 # Or if the user is trying to block themselves 00297 if( (string)$this->target === $this->getUser()->getName() ){ 00298 $fields['Confirm']['type'] = 'check'; 00299 unset( $fields['Confirm']['default'] ); 00300 $this->preErrors[] = 'ipb-blockingself'; 00301 } 00302 } 00303 00307 protected function preText(){ 00308 $text = $this->msg( 'blockiptext' )->parse(); 00309 00310 $otherBlockMessages = array(); 00311 if( $this->target !== null ) { 00312 # Get other blocks, i.e. from GlobalBlocking or TorBlock extension 00313 wfRunHooks( 'OtherBlockLogLink', array( &$otherBlockMessages, $this->target ) ); 00314 00315 if( count( $otherBlockMessages ) ) { 00316 $s = Html::rawElement( 00317 'h2', 00318 array(), 00319 $this->msg( 'ipb-otherblocks-header', count( $otherBlockMessages ) )->parse() 00320 ) . "\n"; 00321 00322 $list = ''; 00323 00324 foreach( $otherBlockMessages as $link ) { 00325 $list .= Html::rawElement( 'li', array(), $link ) . "\n"; 00326 } 00327 00328 $s .= Html::rawElement( 00329 'ul', 00330 array( 'class' => 'mw-blockip-alreadyblocked' ), 00331 $list 00332 ) . "\n"; 00333 00334 $text .= $s; 00335 } 00336 } 00337 00338 return $text; 00339 } 00340 00345 protected function postText(){ 00346 # Link to the user's contributions, if applicable 00347 if( $this->target instanceof User ){ 00348 $contribsPage = SpecialPage::getTitleFor( 'Contributions', $this->target->getName() ); 00349 $links[] = Linker::link( 00350 $contribsPage, 00351 $this->msg( 'ipb-blocklist-contribs', $this->target->getName() )->escaped() 00352 ); 00353 } 00354 00355 # Link to unblock the specified user, or to a blank unblock form 00356 if( $this->target instanceof User ) { 00357 $message = $this->msg( 'ipb-unblock-addr', $this->target->getName() )->parse(); 00358 $list = SpecialPage::getTitleFor( 'Unblock', $this->target->getName() ); 00359 } else { 00360 $message = $this->msg( 'ipb-unblock' )->parse(); 00361 $list = SpecialPage::getTitleFor( 'Unblock' ); 00362 } 00363 $links[] = Linker::linkKnown( $list, $message, array() ); 00364 00365 # Link to the block list 00366 $links[] = Linker::linkKnown( 00367 SpecialPage::getTitleFor( 'BlockList' ), 00368 $this->msg( 'ipb-blocklist' )->escaped() 00369 ); 00370 00371 $user = $this->getUser(); 00372 00373 # Link to edit the block dropdown reasons, if applicable 00374 if ( $user->isAllowed( 'editinterface' ) ) { 00375 $links[] = Linker::link( 00376 Title::makeTitle( NS_MEDIAWIKI, 'Ipbreason-dropdown' ), 00377 $this->msg( 'ipb-edit-dropdown' )->escaped(), 00378 array(), 00379 array( 'action' => 'edit' ) 00380 ); 00381 } 00382 00383 $text = Html::rawElement( 00384 'p', 00385 array( 'class' => 'mw-ipb-conveniencelinks' ), 00386 $this->getLanguage()->pipeList( $links ) 00387 ); 00388 00389 if( $this->target instanceof User ){ 00390 # Get relevant extracts from the block and suppression logs, if possible 00391 $userpage = $this->target->getUserPage(); 00392 $out = ''; 00393 00394 LogEventsList::showLogExtract( 00395 $out, 00396 'block', 00397 $userpage, 00398 '', 00399 array( 00400 'lim' => 10, 00401 'msgKey' => array( 'blocklog-showlog', $userpage->getText() ), 00402 'showIfEmpty' => false 00403 ) 00404 ); 00405 $text .= $out; 00406 00407 # Add suppression block entries if allowed 00408 if( $user->isAllowed( 'suppressionlog' ) ) { 00409 LogEventsList::showLogExtract( 00410 $out, 00411 'suppress', 00412 $userpage, 00413 '', 00414 array( 00415 'lim' => 10, 00416 'conds' => array( 'log_action' => array( 'block', 'reblock', 'unblock' ) ), 00417 'msgKey' => array( 'blocklog-showsuppresslog', $userpage->getText() ), 00418 'showIfEmpty' => false 00419 ) 00420 ); 00421 00422 $text .= $out; 00423 } 00424 } 00425 00426 return $text; 00427 } 00428 00437 public static function getTargetAndType( $par, WebRequest $request = null ){ 00438 $i = 0; 00439 $target = null; 00440 00441 while( true ){ 00442 switch( $i++ ){ 00443 case 0: 00444 # The HTMLForm will check wpTarget first and only if it doesn't get 00445 # a value use the default, which will be generated from the options 00446 # below; so this has to have a higher precedence here than $par, or 00447 # we could end up with different values in $this->target and the HTMLForm! 00448 if( $request instanceof WebRequest ){ 00449 $target = $request->getText( 'wpTarget', null ); 00450 } 00451 break; 00452 case 1: 00453 $target = $par; 00454 break; 00455 case 2: 00456 if( $request instanceof WebRequest ){ 00457 $target = $request->getText( 'ip', null ); 00458 } 00459 break; 00460 case 3: 00461 # B/C @since 1.18 00462 if( $request instanceof WebRequest ){ 00463 $target = $request->getText( 'wpBlockAddress', null ); 00464 } 00465 break; 00466 case 4: 00467 break 2; 00468 } 00469 00470 list( $target, $type ) = Block::parseTarget( $target ); 00471 00472 if( $type !== null ){ 00473 return array( $target, $type ); 00474 } 00475 } 00476 00477 return array( null, null ); 00478 } 00479 00488 public static function validateTargetField( $value, $alldata, $form ) { 00489 global $wgBlockCIDRLimit; 00490 00491 list( $target, $type ) = self::getTargetAndType( $value ); 00492 00493 if( $type == Block::TYPE_USER ){ 00494 # TODO: why do we not have a User->exists() method? 00495 if( !$target->getId() ){ 00496 return $form->msg( 'nosuchusershort', 00497 wfEscapeWikiText( $target->getName() ) ); 00498 } 00499 00500 $status = self::checkUnblockSelf( $target, $form->getUser() ); 00501 if ( $status !== true ) { 00502 return $form->msg( 'badaccess', $status ); 00503 } 00504 00505 } elseif( $type == Block::TYPE_RANGE ){ 00506 list( $ip, $range ) = explode( '/', $target, 2 ); 00507 00508 if( ( IP::isIPv4( $ip ) && $wgBlockCIDRLimit['IPv4'] == 32 ) 00509 || ( IP::isIPv6( $ip ) && $wgBlockCIDRLimit['IPv6'] == 128 ) ) 00510 { 00511 # Range block effectively disabled 00512 return $form->msg( 'range_block_disabled' ); 00513 } 00514 00515 if( ( IP::isIPv4( $ip ) && $range > 32 ) 00516 || ( IP::isIPv6( $ip ) && $range > 128 ) ) 00517 { 00518 # Dodgy range 00519 return $form->msg( 'ip_range_invalid' ); 00520 } 00521 00522 if( IP::isIPv4( $ip ) && $range < $wgBlockCIDRLimit['IPv4'] ) { 00523 return $form->msg( 'ip_range_toolarge', $wgBlockCIDRLimit['IPv4'] ); 00524 } 00525 00526 if( IP::isIPv6( $ip ) && $range < $wgBlockCIDRLimit['IPv6'] ) { 00527 return $form->msg( 'ip_range_toolarge', $wgBlockCIDRLimit['IPv6'] ); 00528 } 00529 } elseif( $type == Block::TYPE_IP ){ 00530 # All is well 00531 } else { 00532 return $form->msg( 'badipaddress' ); 00533 } 00534 00535 return true; 00536 } 00537 00544 public static function processUIForm( array $data, HTMLForm $form ) { 00545 return self::processForm( $data, $form->getContext() ); 00546 } 00547 00554 public static function processForm( array $data, IContextSource $context ){ 00555 global $wgBlockAllowsUTEdit; 00556 00557 $performer = $context->getUser(); 00558 00559 // Handled by field validator callback 00560 // self::validateTargetField( $data['Target'] ); 00561 00562 # This might have been a hidden field or a checkbox, so interesting data 00563 # can come from it 00564 $data['Confirm'] = !in_array( $data['Confirm'], array( '', '0', null, false ), true ); 00565 00566 list( $target, $type ) = self::getTargetAndType( $data['Target'] ); 00567 if( $type == Block::TYPE_USER ){ 00568 $user = $target; 00569 $target = $user->getName(); 00570 $userId = $user->getId(); 00571 00572 # Give admins a heads-up before they go and block themselves. Much messier 00573 # to do this for IPs, but it's pretty unlikely they'd ever get the 'block' 00574 # permission anyway, although the code does allow for it. 00575 # Note: Important to use $target instead of $data['Target'] 00576 # since both $data['PreviousTarget'] and $target are normalized 00577 # but $data['target'] gets overriden by (non-normalized) request variable 00578 # from previous request. 00579 if( $target === $performer->getName() && 00580 ( $data['PreviousTarget'] !== $target || !$data['Confirm'] ) ) 00581 { 00582 return array( 'ipb-blockingself' ); 00583 } 00584 } elseif( $type == Block::TYPE_RANGE ){ 00585 $userId = 0; 00586 } elseif( $type == Block::TYPE_IP ){ 00587 $target = $target->getName(); 00588 $userId = 0; 00589 } else { 00590 # This should have been caught in the form field validation 00591 return array( 'badipaddress' ); 00592 } 00593 00594 if( ( strlen( $data['Expiry'] ) == 0) || ( strlen( $data['Expiry'] ) > 50 ) 00595 || !self::parseExpiryInput( $data['Expiry'] ) ) 00596 { 00597 return array( 'ipb_expiry_invalid' ); 00598 } 00599 00600 if( !isset( $data['DisableEmail'] ) ){ 00601 $data['DisableEmail'] = false; 00602 } 00603 00604 # If the user has done the form 'properly', they won't even have been given the 00605 # option to suppress-block unless they have the 'hideuser' permission 00606 if( !isset( $data['HideUser'] ) ){ 00607 $data['HideUser'] = false; 00608 } 00609 00610 if( $data['HideUser'] ) { 00611 if( !$performer->isAllowed('hideuser') ){ 00612 # this codepath is unreachable except by a malicious user spoofing forms, 00613 # or by race conditions (user has oversight and sysop, loads block form, 00614 # and is de-oversighted before submission); so need to fail completely 00615 # rather than just silently disable hiding 00616 return array( 'badaccess-group0' ); 00617 } 00618 00619 # Recheck params here... 00620 if( $type != Block::TYPE_USER ) { 00621 $data['HideUser'] = false; # IP users should not be hidden 00622 } elseif( !in_array( $data['Expiry'], array( 'infinite', 'infinity', 'indefinite' ) ) ) { 00623 # Bad expiry. 00624 return array( 'ipb_expiry_temp' ); 00625 } elseif( $user->getEditCount() > self::HIDEUSER_CONTRIBLIMIT ) { 00626 # Typically, the user should have a handful of edits. 00627 # Disallow hiding users with many edits for performance. 00628 return array( 'ipb_hide_invalid' ); 00629 } elseif( !$data['Confirm'] ){ 00630 return array( 'ipb-confirmhideuser' ); 00631 } 00632 } 00633 00634 # Create block object. 00635 $block = new Block(); 00636 $block->setTarget( $target ); 00637 $block->setBlocker( $performer ); 00638 $block->mReason = $data['Reason'][0]; 00639 $block->mExpiry = self::parseExpiryInput( $data['Expiry'] ); 00640 $block->prevents( 'createaccount', $data['CreateAccount'] ); 00641 $block->prevents( 'editownusertalk', ( !$wgBlockAllowsUTEdit || $data['DisableUTEdit'] ) ); 00642 $block->prevents( 'sendemail', $data['DisableEmail'] ); 00643 $block->isHardblock( $data['HardBlock'] ); 00644 $block->isAutoblocking( $data['AutoBlock'] ); 00645 $block->mHideName = $data['HideUser']; 00646 00647 if( !wfRunHooks( 'BlockIp', array( &$block, &$performer ) ) ) { 00648 return array( 'hookaborted' ); 00649 } 00650 00651 # Try to insert block. Is there a conflicting block? 00652 $status = $block->insert(); 00653 if( !$status ) { 00654 # Show form unless the user is already aware of this... 00655 if( !$data['Confirm'] || ( array_key_exists( 'PreviousTarget', $data ) 00656 && $data['PreviousTarget'] !== $target ) ) 00657 { 00658 return array( array( 'ipb_already_blocked', $block->getTarget() ) ); 00659 # Otherwise, try to update the block... 00660 } else { 00661 # This returns direct blocks before autoblocks/rangeblocks, since we should 00662 # be sure the user is blocked by now it should work for our purposes 00663 $currentBlock = Block::newFromTarget( $target ); 00664 00665 if( $block->equals( $currentBlock ) ) { 00666 return array( array( 'ipb_already_blocked', $block->getTarget() ) ); 00667 } 00668 00669 # If the name was hidden and the blocking user cannot hide 00670 # names, then don't allow any block changes... 00671 if( $currentBlock->mHideName && !$performer->isAllowed( 'hideuser' ) ) { 00672 return array( 'cant-see-hidden-user' ); 00673 } 00674 00675 $currentBlock->delete(); 00676 $status = $block->insert(); 00677 $logaction = 'reblock'; 00678 00679 # Unset _deleted fields if requested 00680 if( $currentBlock->mHideName && !$data['HideUser'] ) { 00681 RevisionDeleteUser::unsuppressUserName( $target, $userId ); 00682 } 00683 00684 # If hiding/unhiding a name, this should go in the private logs 00685 if( (bool)$currentBlock->mHideName ){ 00686 $data['HideUser'] = true; 00687 } 00688 } 00689 } else { 00690 $logaction = 'block'; 00691 } 00692 00693 wfRunHooks( 'BlockIpComplete', array( $block, $performer ) ); 00694 00695 # Set *_deleted fields if requested 00696 if( $data['HideUser'] ) { 00697 RevisionDeleteUser::suppressUserName( $target, $userId ); 00698 } 00699 00700 # Can't watch a rangeblock 00701 if( $type != Block::TYPE_RANGE && $data['Watch'] ) { 00702 $performer->addWatch( Title::makeTitle( NS_USER, $target ) ); 00703 } 00704 00705 # Block constructor sanitizes certain block options on insert 00706 $data['BlockEmail'] = $block->prevents( 'sendemail' ); 00707 $data['AutoBlock'] = $block->isAutoblocking(); 00708 00709 # Prepare log parameters 00710 $logParams = array(); 00711 $logParams[] = $data['Expiry']; 00712 $logParams[] = self::blockLogFlags( $data, $type ); 00713 00714 # Make log entry, if the name is hidden, put it in the oversight log 00715 $log_type = $data['HideUser'] ? 'suppress' : 'block'; 00716 $log = new LogPage( $log_type ); 00717 $log_id = $log->addEntry( 00718 $logaction, 00719 Title::makeTitle( NS_USER, $target ), 00720 $data['Reason'][0], 00721 $logParams 00722 ); 00723 # Relate log ID to block IDs (bug 25763) 00724 $blockIds = array_merge( array( $status['id'] ), $status['autoIds'] ); 00725 $log->addRelations( 'ipb_id', $blockIds, $log_id ); 00726 00727 # Report to the user 00728 return true; 00729 } 00730 00739 public static function getSuggestedDurations( $lang = null ){ 00740 $a = array(); 00741 $msg = $lang === null 00742 ? wfMessage( 'ipboptions' )->inContentLanguage()->text() 00743 : wfMessage( 'ipboptions' )->inLanguage( $lang )->text(); 00744 00745 if( $msg == '-' ){ 00746 return array(); 00747 } 00748 00749 foreach( explode( ',', $msg ) as $option ) { 00750 if( strpos( $option, ':' ) === false ){ 00751 $option = "$option:$option"; 00752 } 00753 00754 list( $show, $value ) = explode( ':', $option ); 00755 $a[htmlspecialchars( $show )] = htmlspecialchars( $value ); 00756 } 00757 00758 return $a; 00759 } 00760 00767 public static function parseExpiryInput( $expiry ) { 00768 static $infinity; 00769 if( $infinity == null ){ 00770 $infinity = wfGetDB( DB_SLAVE )->getInfinity(); 00771 } 00772 00773 if ( $expiry == 'infinite' || $expiry == 'indefinite' ) { 00774 $expiry = $infinity; 00775 } else { 00776 $expiry = strtotime( $expiry ); 00777 00778 if ( $expiry < 0 || $expiry === false ) { 00779 return false; 00780 } 00781 00782 $expiry = wfTimestamp( TS_MW, $expiry ); 00783 } 00784 00785 return $expiry; 00786 } 00787 00793 public static function canBlockEmail( $user ) { 00794 global $wgEnableUserEmail, $wgSysopEmailBans; 00795 00796 return ( $wgEnableUserEmail && $wgSysopEmailBans && $user->isAllowed( 'blockemail' ) ); 00797 } 00798 00807 public static function checkUnblockSelf( $user, User $performer ) { 00808 if ( is_int( $user ) ) { 00809 $user = User::newFromId( $user ); 00810 } elseif ( is_string( $user ) ) { 00811 $user = User::newFromName( $user ); 00812 } 00813 00814 if( $performer->isBlocked() ){ 00815 if( $user instanceof User && $user->getId() == $performer->getId() ) { 00816 # User is trying to unblock themselves 00817 if ( $performer->isAllowed( 'unblockself' ) ) { 00818 return true; 00819 # User blocked themselves and is now trying to reverse it 00820 } elseif ( $performer->blockedBy() === $performer->getName() ) { 00821 return true; 00822 } else { 00823 return 'ipbnounblockself'; 00824 } 00825 } else { 00826 # User is trying to block/unblock someone else 00827 return 'ipbblocked'; 00828 } 00829 } else { 00830 return true; 00831 } 00832 } 00833 00841 protected static function blockLogFlags( array $data, $type ) { 00842 global $wgBlockAllowsUTEdit; 00843 $flags = array(); 00844 00845 # when blocking a user the option 'anononly' is not available/has no effect -> do not write this into log 00846 if( !$data['HardBlock'] && $type != Block::TYPE_USER ){ 00847 // For grepping: message block-log-flags-anononly 00848 $flags[] = 'anononly'; 00849 } 00850 00851 if( $data['CreateAccount'] ){ 00852 // For grepping: message block-log-flags-nocreate 00853 $flags[] = 'nocreate'; 00854 } 00855 00856 # Same as anononly, this is not displayed when blocking an IP address 00857 if( !$data['AutoBlock'] && $type == Block::TYPE_USER ){ 00858 // For grepping: message block-log-flags-noautoblock 00859 $flags[] = 'noautoblock'; 00860 } 00861 00862 if( $data['DisableEmail'] ){ 00863 // For grepping: message block-log-flags-noemail 00864 $flags[] = 'noemail'; 00865 } 00866 00867 if( $wgBlockAllowsUTEdit && $data['DisableUTEdit'] ){ 00868 // For grepping: message block-log-flags-nousertalk 00869 $flags[] = 'nousertalk'; 00870 } 00871 00872 if( $data['HideUser'] ){ 00873 // For grepping: message block-log-flags-hiddenname 00874 $flags[] = 'hiddenname'; 00875 } 00876 00877 return implode( ',', $flags ); 00878 } 00879 00885 public function onSubmit( array $data ) { 00886 // This isn't used since we need that HTMLForm that's passed in the 00887 // second parameter. See alterForm for the real function 00888 } 00889 00894 public function onSuccess() { 00895 $out = $this->getOutput(); 00896 $out->setPageTitle( $this->msg( 'blockipsuccesssub' ) ); 00897 $out->addWikiMsg( 'blockipsuccesstext', $this->target ); 00898 } 00899 } 00900 00901 # BC @since 1.18 00902 class IPBlockForm extends SpecialBlock {}