MediaWiki
REL1_21
|
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 'autofocus' => true, 00138 'required' => true, 00139 'validation-callback' => array( __CLASS__, 'validateTargetField' ), 00140 ), 00141 'Expiry' => array( 00142 'type' => !count( self::getSuggestedDurations() ) ? 'text' : 'selectorother', 00143 'label-message' => 'ipbexpiry', 00144 'required' => true, 00145 'tabindex' => '2', 00146 'options' => self::getSuggestedDurations(), 00147 'other' => $this->msg( 'ipbother' )->text(), 00148 'default' => $this->msg( 'ipb-default-expiry' )->inContentLanguage()->text(), 00149 ), 00150 'Reason' => array( 00151 'type' => 'selectandother', 00152 'label-message' => 'ipbreason', 00153 'options-message' => 'ipbreason-dropdown', 00154 ), 00155 'CreateAccount' => array( 00156 'type' => 'check', 00157 'label-message' => 'ipbcreateaccount', 00158 'default' => true, 00159 ), 00160 ); 00161 00162 if ( self::canBlockEmail( $user ) ) { 00163 $a['DisableEmail'] = array( 00164 'type' => 'check', 00165 'label-message' => 'ipbemailban', 00166 ); 00167 } 00168 00169 if ( $wgBlockAllowsUTEdit ) { 00170 $a['DisableUTEdit'] = array( 00171 'type' => 'check', 00172 'label-message' => 'ipb-disableusertalk', 00173 'default' => false, 00174 ); 00175 } 00176 00177 $a['AutoBlock'] = array( 00178 'type' => 'check', 00179 'label-message' => 'ipbenableautoblock', 00180 'default' => true, 00181 ); 00182 00183 # Allow some users to hide name from block log, blocklist and listusers 00184 if ( $user->isAllowed( 'hideuser' ) ) { 00185 $a['HideUser'] = array( 00186 'type' => 'check', 00187 'label-message' => 'ipbhidename', 00188 'cssclass' => 'mw-block-hideuser', 00189 ); 00190 } 00191 00192 # Watchlist their user page? (Only if user is logged in) 00193 if ( $user->isLoggedIn() ) { 00194 $a['Watch'] = array( 00195 'type' => 'check', 00196 'label-message' => 'ipbwatchuser', 00197 ); 00198 } 00199 00200 $a['HardBlock'] = array( 00201 'type' => 'check', 00202 'label-message' => 'ipb-hardblock', 00203 'default' => false, 00204 ); 00205 00206 # This is basically a copy of the Target field, but the user can't change it, so we 00207 # can see if the warnings we maybe showed to the user before still apply 00208 $a['PreviousTarget'] = array( 00209 'type' => 'hidden', 00210 'default' => false, 00211 ); 00212 00213 # We'll turn this into a checkbox if we need to 00214 $a['Confirm'] = array( 00215 'type' => 'hidden', 00216 'default' => '', 00217 'label-message' => 'ipb-confirm', 00218 ); 00219 00220 $this->maybeAlterFormDefaults( $a ); 00221 00222 return $a; 00223 } 00224 00232 protected function maybeAlterFormDefaults( &$fields ) { 00233 # This will be overwritten by request data 00234 $fields['Target']['default'] = (string)$this->target; 00235 00236 # This won't be 00237 $fields['PreviousTarget']['default'] = (string)$this->target; 00238 00239 $block = Block::newFromTarget( $this->target ); 00240 00241 if ( $block instanceof Block && !$block->mAuto # The block exists and isn't an autoblock 00242 && ( $this->type != Block::TYPE_RANGE # The block isn't a rangeblock 00243 || $block->getTarget() == $this->target ) # or if it is, the range is what we're about to block 00244 ) 00245 { 00246 $fields['HardBlock']['default'] = $block->isHardblock(); 00247 $fields['CreateAccount']['default'] = $block->prevents( 'createaccount' ); 00248 $fields['AutoBlock']['default'] = $block->isAutoblocking(); 00249 00250 if ( isset( $fields['DisableEmail'] ) ) { 00251 $fields['DisableEmail']['default'] = $block->prevents( 'sendemail' ); 00252 } 00253 00254 if ( isset( $fields['HideUser'] ) ) { 00255 $fields['HideUser']['default'] = $block->mHideName; 00256 } 00257 00258 if ( isset( $fields['DisableUTEdit'] ) ) { 00259 $fields['DisableUTEdit']['default'] = $block->prevents( 'editownusertalk' ); 00260 } 00261 00262 // If the username was hidden (ipb_deleted == 1), don't show the reason 00263 // unless this user also has rights to hideuser: Bug 35839 00264 if ( !$block->mHideName || $this->getUser()->isAllowed( 'hideuser' ) ) { 00265 $fields['Reason']['default'] = $block->mReason; 00266 } else { 00267 $fields['Reason']['default'] = ''; 00268 } 00269 00270 if ( $this->getRequest()->wasPosted() ) { 00271 # Ok, so we got a POST submission asking us to reblock a user. So show the 00272 # confirm checkbox; the user will only see it if they haven't previously 00273 $fields['Confirm']['type'] = 'check'; 00274 } else { 00275 # We got a target, but it wasn't a POST request, so the user must have gone 00276 # to a link like [[Special:Block/User]]. We don't need to show the checkbox 00277 # as long as they go ahead and block *that* user 00278 $fields['Confirm']['default'] = 1; 00279 } 00280 00281 if ( $block->mExpiry == 'infinity' ) { 00282 $fields['Expiry']['default'] = 'infinite'; 00283 } else { 00284 $fields['Expiry']['default'] = wfTimestamp( TS_RFC2822, $block->mExpiry ); 00285 } 00286 00287 $this->alreadyBlocked = true; 00288 $this->preErrors[] = array( 'ipb-needreblock', wfEscapeWikiText( (string)$block->getTarget() ) ); 00289 } 00290 00291 # We always need confirmation to do HideUser 00292 if ( $this->requestedHideUser ) { 00293 $fields['Confirm']['type'] = 'check'; 00294 unset( $fields['Confirm']['default'] ); 00295 $this->preErrors[] = 'ipb-confirmhideuser'; 00296 } 00297 00298 # Or if the user is trying to block themselves 00299 if ( (string)$this->target === $this->getUser()->getName() ) { 00300 $fields['Confirm']['type'] = 'check'; 00301 unset( $fields['Confirm']['default'] ); 00302 $this->preErrors[] = 'ipb-blockingself'; 00303 } 00304 } 00305 00310 protected function preText() { 00311 $this->getOutput()->addModules( 'mediawiki.special.block' ); 00312 00313 $text = $this->msg( 'blockiptext' )->parse(); 00314 00315 $otherBlockMessages = array(); 00316 if ( $this->target !== null ) { 00317 # Get other blocks, i.e. from GlobalBlocking or TorBlock extension 00318 wfRunHooks( 'OtherBlockLogLink', array( &$otherBlockMessages, $this->target ) ); 00319 00320 if ( count( $otherBlockMessages ) ) { 00321 $s = Html::rawElement( 00322 'h2', 00323 array(), 00324 $this->msg( 'ipb-otherblocks-header', count( $otherBlockMessages ) )->parse() 00325 ) . "\n"; 00326 00327 $list = ''; 00328 00329 foreach ( $otherBlockMessages as $link ) { 00330 $list .= Html::rawElement( 'li', array(), $link ) . "\n"; 00331 } 00332 00333 $s .= Html::rawElement( 00334 'ul', 00335 array( 'class' => 'mw-blockip-alreadyblocked' ), 00336 $list 00337 ) . "\n"; 00338 00339 $text .= $s; 00340 } 00341 } 00342 00343 return $text; 00344 } 00345 00350 protected function postText() { 00351 $links = array(); 00352 00353 # Link to the user's contributions, if applicable 00354 if ( $this->target instanceof User ) { 00355 $contribsPage = SpecialPage::getTitleFor( 'Contributions', $this->target->getName() ); 00356 $links[] = Linker::link( 00357 $contribsPage, 00358 $this->msg( 'ipb-blocklist-contribs', $this->target->getName() )->escaped() 00359 ); 00360 } 00361 00362 # Link to unblock the specified user, or to a blank unblock form 00363 if ( $this->target instanceof User ) { 00364 $message = $this->msg( 'ipb-unblock-addr', wfEscapeWikiText( $this->target->getName() ) )->parse(); 00365 $list = SpecialPage::getTitleFor( 'Unblock', $this->target->getName() ); 00366 } else { 00367 $message = $this->msg( 'ipb-unblock' )->parse(); 00368 $list = SpecialPage::getTitleFor( 'Unblock' ); 00369 } 00370 $links[] = Linker::linkKnown( $list, $message, array() ); 00371 00372 # Link to the block list 00373 $links[] = Linker::linkKnown( 00374 SpecialPage::getTitleFor( 'BlockList' ), 00375 $this->msg( 'ipb-blocklist' )->escaped() 00376 ); 00377 00378 $user = $this->getUser(); 00379 00380 # Link to edit the block dropdown reasons, if applicable 00381 if ( $user->isAllowed( 'editinterface' ) ) { 00382 $links[] = Linker::link( 00383 Title::makeTitle( NS_MEDIAWIKI, 'Ipbreason-dropdown' ), 00384 $this->msg( 'ipb-edit-dropdown' )->escaped(), 00385 array(), 00386 array( 'action' => 'edit' ) 00387 ); 00388 } 00389 00390 $text = Html::rawElement( 00391 'p', 00392 array( 'class' => 'mw-ipb-conveniencelinks' ), 00393 $this->getLanguage()->pipeList( $links ) 00394 ); 00395 00396 $userTitle = self::getTargetUserTitle( $this->target ); 00397 if ( $userTitle ) { 00398 # Get relevant extracts from the block and suppression logs, if possible 00399 $out = ''; 00400 00401 LogEventsList::showLogExtract( 00402 $out, 00403 'block', 00404 $userTitle, 00405 '', 00406 array( 00407 'lim' => 10, 00408 'msgKey' => array( 'blocklog-showlog', $userTitle->getText() ), 00409 'showIfEmpty' => false 00410 ) 00411 ); 00412 $text .= $out; 00413 00414 # Add suppression block entries if allowed 00415 if ( $user->isAllowed( 'suppressionlog' ) ) { 00416 LogEventsList::showLogExtract( 00417 $out, 00418 'suppress', 00419 $userTitle, 00420 '', 00421 array( 00422 'lim' => 10, 00423 'conds' => array( 'log_action' => array( 'block', 'reblock', 'unblock' ) ), 00424 'msgKey' => array( 'blocklog-showsuppresslog', $userTitle->getText() ), 00425 'showIfEmpty' => false 00426 ) 00427 ); 00428 00429 $text .= $out; 00430 } 00431 } 00432 00433 return $text; 00434 } 00435 00442 protected static function getTargetUserTitle( $target ) { 00443 if ( $target instanceof User ) { 00444 return $target->getUserPage(); 00445 } elseif ( IP::isIPAddress( $target ) ) { 00446 return Title::makeTitleSafe( NS_USER, $target ); 00447 } 00448 return null; 00449 } 00450 00459 public static function getTargetAndType( $par, WebRequest $request = null ) { 00460 $i = 0; 00461 $target = null; 00462 00463 while( true ) { 00464 switch( $i++ ) { 00465 case 0: 00466 # The HTMLForm will check wpTarget first and only if it doesn't get 00467 # a value use the default, which will be generated from the options 00468 # below; so this has to have a higher precedence here than $par, or 00469 # we could end up with different values in $this->target and the HTMLForm! 00470 if ( $request instanceof WebRequest ) { 00471 $target = $request->getText( 'wpTarget', null ); 00472 } 00473 break; 00474 case 1: 00475 $target = $par; 00476 break; 00477 case 2: 00478 if ( $request instanceof WebRequest ) { 00479 $target = $request->getText( 'ip', null ); 00480 } 00481 break; 00482 case 3: 00483 # B/C @since 1.18 00484 if ( $request instanceof WebRequest ) { 00485 $target = $request->getText( 'wpBlockAddress', null ); 00486 } 00487 break; 00488 case 4: 00489 break 2; 00490 } 00491 00492 list( $target, $type ) = Block::parseTarget( $target ); 00493 00494 if ( $type !== null ) { 00495 return array( $target, $type ); 00496 } 00497 } 00498 00499 return array( null, null ); 00500 } 00501 00510 public static function validateTargetField( $value, $alldata, $form ) { 00511 $status = self::validateTarget( $value, $form->getUser() ); 00512 if ( !$status->isOK() ) { 00513 $errors = $status->getErrorsArray(); 00514 return call_user_func_array( array( $form, 'msg' ), $errors[0] ); 00515 } else { 00516 return true; 00517 } 00518 } 00519 00528 public static function validateTarget( $value, User $user ) { 00529 global $wgBlockCIDRLimit; 00530 00531 list( $target, $type ) = self::getTargetAndType( $value ); 00532 $status = Status::newGood( $target ); 00533 00534 if ( $type == Block::TYPE_USER ) { 00535 if ( $target->isAnon() ) { 00536 $status->fatal( 00537 'nosuchusershort', 00538 wfEscapeWikiText( $target->getName() ) 00539 ); 00540 } 00541 00542 $unblockStatus = self::checkUnblockSelf( $target, $user ); 00543 if ( $unblockStatus !== true ) { 00544 $status->fatal( 'badaccess', $unblockStatus ); 00545 } 00546 } elseif ( $type == Block::TYPE_RANGE ) { 00547 list( $ip, $range ) = explode( '/', $target, 2 ); 00548 00549 if ( 00550 ( IP::isIPv4( $ip ) && $wgBlockCIDRLimit['IPv4'] == 32 ) || 00551 ( IP::isIPv6( $ip ) && $wgBlockCIDRLimit['IPv6'] == 128 ) 00552 ) { 00553 // Range block effectively disabled 00554 $status->fatal( 'range_block_disabled' ); 00555 } 00556 00557 if ( 00558 ( IP::isIPv4( $ip ) && $range > 32 ) || 00559 ( IP::isIPv6( $ip ) && $range > 128 ) 00560 ) { 00561 // Dodgy range 00562 $status->fatal( 'ip_range_invalid' ); 00563 } 00564 00565 if ( IP::isIPv4( $ip ) && $range < $wgBlockCIDRLimit['IPv4'] ) { 00566 $status->fatal( 'ip_range_toolarge', $wgBlockCIDRLimit['IPv4'] ); 00567 } 00568 00569 if ( IP::isIPv6( $ip ) && $range < $wgBlockCIDRLimit['IPv6'] ) { 00570 $status->fatal( 'ip_range_toolarge', $wgBlockCIDRLimit['IPv6'] ); 00571 } 00572 } elseif ( $type == Block::TYPE_IP ) { 00573 # All is well 00574 } else { 00575 $status->fatal( 'badipaddress' ); 00576 } 00577 00578 return $status; 00579 } 00580 00587 public static function processUIForm( array $data, HTMLForm $form ) { 00588 return self::processForm( $data, $form->getContext() ); 00589 } 00590 00597 public static function processForm( array $data, IContextSource $context ) { 00598 global $wgBlockAllowsUTEdit; 00599 00600 $performer = $context->getUser(); 00601 00602 // Handled by field validator callback 00603 // self::validateTargetField( $data['Target'] ); 00604 00605 # This might have been a hidden field or a checkbox, so interesting data 00606 # can come from it 00607 $data['Confirm'] = !in_array( $data['Confirm'], array( '', '0', null, false ), true ); 00608 00609 list( $target, $type ) = self::getTargetAndType( $data['Target'] ); 00610 if ( $type == Block::TYPE_USER ) { 00611 $user = $target; 00612 $target = $user->getName(); 00613 $userId = $user->getId(); 00614 00615 # Give admins a heads-up before they go and block themselves. Much messier 00616 # to do this for IPs, but it's pretty unlikely they'd ever get the 'block' 00617 # permission anyway, although the code does allow for it. 00618 # Note: Important to use $target instead of $data['Target'] 00619 # since both $data['PreviousTarget'] and $target are normalized 00620 # but $data['target'] gets overriden by (non-normalized) request variable 00621 # from previous request. 00622 if ( $target === $performer->getName() && 00623 ( $data['PreviousTarget'] !== $target || !$data['Confirm'] ) ) 00624 { 00625 return array( 'ipb-blockingself' ); 00626 } 00627 } elseif ( $type == Block::TYPE_RANGE ) { 00628 $userId = 0; 00629 } elseif ( $type == Block::TYPE_IP ) { 00630 $target = $target->getName(); 00631 $userId = 0; 00632 } else { 00633 # This should have been caught in the form field validation 00634 return array( 'badipaddress' ); 00635 } 00636 00637 if ( ( strlen( $data['Expiry'] ) == 0) || ( strlen( $data['Expiry'] ) > 50 ) 00638 || !self::parseExpiryInput( $data['Expiry'] ) ) 00639 { 00640 return array( 'ipb_expiry_invalid' ); 00641 } 00642 00643 if ( !isset( $data['DisableEmail'] ) ) { 00644 $data['DisableEmail'] = false; 00645 } 00646 00647 # If the user has done the form 'properly', they won't even have been given the 00648 # option to suppress-block unless they have the 'hideuser' permission 00649 if ( !isset( $data['HideUser'] ) ) { 00650 $data['HideUser'] = false; 00651 } 00652 00653 if ( $data['HideUser'] ) { 00654 if ( !$performer->isAllowed( 'hideuser' ) ) { 00655 # this codepath is unreachable except by a malicious user spoofing forms, 00656 # or by race conditions (user has oversight and sysop, loads block form, 00657 # and is de-oversighted before submission); so need to fail completely 00658 # rather than just silently disable hiding 00659 return array( 'badaccess-group0' ); 00660 } 00661 00662 # Recheck params here... 00663 if ( $type != Block::TYPE_USER ) { 00664 $data['HideUser'] = false; # IP users should not be hidden 00665 } elseif ( !in_array( $data['Expiry'], array( 'infinite', 'infinity', 'indefinite' ) ) ) { 00666 # Bad expiry. 00667 return array( 'ipb_expiry_temp' ); 00668 } elseif ( $user->getEditCount() > self::HIDEUSER_CONTRIBLIMIT ) { 00669 # Typically, the user should have a handful of edits. 00670 # Disallow hiding users with many edits for performance. 00671 return array( 'ipb_hide_invalid' ); 00672 } elseif ( !$data['Confirm'] ) { 00673 return array( 'ipb-confirmhideuser' ); 00674 } 00675 } 00676 00677 # Create block object. 00678 $block = new Block(); 00679 $block->setTarget( $target ); 00680 $block->setBlocker( $performer ); 00681 $block->mReason = $data['Reason'][0]; 00682 $block->mExpiry = self::parseExpiryInput( $data['Expiry'] ); 00683 $block->prevents( 'createaccount', $data['CreateAccount'] ); 00684 $block->prevents( 'editownusertalk', ( !$wgBlockAllowsUTEdit || $data['DisableUTEdit'] ) ); 00685 $block->prevents( 'sendemail', $data['DisableEmail'] ); 00686 $block->isHardblock( $data['HardBlock'] ); 00687 $block->isAutoblocking( $data['AutoBlock'] ); 00688 $block->mHideName = $data['HideUser']; 00689 00690 if ( !wfRunHooks( 'BlockIp', array( &$block, &$performer ) ) ) { 00691 return array( 'hookaborted' ); 00692 } 00693 00694 # Try to insert block. Is there a conflicting block? 00695 $status = $block->insert(); 00696 if ( !$status ) { 00697 # Indicates whether the user is confirming the block and is aware of 00698 # the conflict (did not change the block target in the meantime) 00699 $blockNotConfirmed = !$data['Confirm'] || ( array_key_exists( 'PreviousTarget', $data ) 00700 && $data['PreviousTarget'] !== $target ); 00701 00702 # Special case for API - bug 32434 00703 $reblockNotAllowed = ( array_key_exists( 'Reblock', $data ) && !$data['Reblock'] ); 00704 00705 # Show form unless the user is already aware of this... 00706 if( $blockNotConfirmed || $reblockNotAllowed ) { 00707 return array( array( 'ipb_already_blocked', $block->getTarget() ) ); 00708 # Otherwise, try to update the block... 00709 } else { 00710 # This returns direct blocks before autoblocks/rangeblocks, since we should 00711 # be sure the user is blocked by now it should work for our purposes 00712 $currentBlock = Block::newFromTarget( $target ); 00713 00714 if ( $block->equals( $currentBlock ) ) { 00715 return array( array( 'ipb_already_blocked', $block->getTarget() ) ); 00716 } 00717 00718 # If the name was hidden and the blocking user cannot hide 00719 # names, then don't allow any block changes... 00720 if ( $currentBlock->mHideName && !$performer->isAllowed( 'hideuser' ) ) { 00721 return array( 'cant-see-hidden-user' ); 00722 } 00723 00724 $currentBlock->delete(); 00725 $status = $block->insert(); 00726 $logaction = 'reblock'; 00727 00728 # Unset _deleted fields if requested 00729 if ( $currentBlock->mHideName && !$data['HideUser'] ) { 00730 RevisionDeleteUser::unsuppressUserName( $target, $userId ); 00731 } 00732 00733 # If hiding/unhiding a name, this should go in the private logs 00734 if ( (bool)$currentBlock->mHideName ) { 00735 $data['HideUser'] = true; 00736 } 00737 } 00738 } else { 00739 $logaction = 'block'; 00740 } 00741 00742 wfRunHooks( 'BlockIpComplete', array( $block, $performer ) ); 00743 00744 # Set *_deleted fields if requested 00745 if ( $data['HideUser'] ) { 00746 RevisionDeleteUser::suppressUserName( $target, $userId ); 00747 } 00748 00749 # Can't watch a rangeblock 00750 if ( $type != Block::TYPE_RANGE && $data['Watch'] ) { 00751 $performer->addWatch( Title::makeTitle( NS_USER, $target ) ); 00752 } 00753 00754 # Block constructor sanitizes certain block options on insert 00755 $data['BlockEmail'] = $block->prevents( 'sendemail' ); 00756 $data['AutoBlock'] = $block->isAutoblocking(); 00757 00758 # Prepare log parameters 00759 $logParams = array(); 00760 $logParams[] = $data['Expiry']; 00761 $logParams[] = self::blockLogFlags( $data, $type ); 00762 00763 # Make log entry, if the name is hidden, put it in the oversight log 00764 $log_type = $data['HideUser'] ? 'suppress' : 'block'; 00765 $log = new LogPage( $log_type ); 00766 $log_id = $log->addEntry( 00767 $logaction, 00768 Title::makeTitle( NS_USER, $target ), 00769 $data['Reason'][0], 00770 $logParams 00771 ); 00772 # Relate log ID to block IDs (bug 25763) 00773 $blockIds = array_merge( array( $status['id'] ), $status['autoIds'] ); 00774 $log->addRelations( 'ipb_id', $blockIds, $log_id ); 00775 00776 # Report to the user 00777 return true; 00778 } 00779 00788 public static function getSuggestedDurations( $lang = null ) { 00789 $a = array(); 00790 $msg = $lang === null 00791 ? wfMessage( 'ipboptions' )->inContentLanguage()->text() 00792 : wfMessage( 'ipboptions' )->inLanguage( $lang )->text(); 00793 00794 if ( $msg == '-' ) { 00795 return array(); 00796 } 00797 00798 foreach ( explode( ',', $msg ) as $option ) { 00799 if ( strpos( $option, ':' ) === false ) { 00800 $option = "$option:$option"; 00801 } 00802 00803 list( $show, $value ) = explode( ':', $option ); 00804 $a[htmlspecialchars( $show )] = htmlspecialchars( $value ); 00805 } 00806 00807 return $a; 00808 } 00809 00816 public static function parseExpiryInput( $expiry ) { 00817 static $infinity; 00818 if ( $infinity == null ) { 00819 $infinity = wfGetDB( DB_SLAVE )->getInfinity(); 00820 } 00821 00822 if ( $expiry == 'infinite' || $expiry == 'indefinite' ) { 00823 $expiry = $infinity; 00824 } else { 00825 $expiry = strtotime( $expiry ); 00826 00827 if ( $expiry < 0 || $expiry === false ) { 00828 return false; 00829 } 00830 00831 $expiry = wfTimestamp( TS_MW, $expiry ); 00832 } 00833 00834 return $expiry; 00835 } 00836 00842 public static function canBlockEmail( $user ) { 00843 global $wgEnableUserEmail, $wgSysopEmailBans; 00844 00845 return ( $wgEnableUserEmail && $wgSysopEmailBans && $user->isAllowed( 'blockemail' ) ); 00846 } 00847 00856 public static function checkUnblockSelf( $user, User $performer ) { 00857 if ( is_int( $user ) ) { 00858 $user = User::newFromId( $user ); 00859 } elseif ( is_string( $user ) ) { 00860 $user = User::newFromName( $user ); 00861 } 00862 00863 if ( $performer->isBlocked() ) { 00864 if ( $user instanceof User && $user->getId() == $performer->getId() ) { 00865 # User is trying to unblock themselves 00866 if ( $performer->isAllowed( 'unblockself' ) ) { 00867 return true; 00868 # User blocked themselves and is now trying to reverse it 00869 } elseif ( $performer->blockedBy() === $performer->getName() ) { 00870 return true; 00871 } else { 00872 return 'ipbnounblockself'; 00873 } 00874 } else { 00875 # User is trying to block/unblock someone else 00876 return 'ipbblocked'; 00877 } 00878 } else { 00879 return true; 00880 } 00881 } 00882 00890 protected static function blockLogFlags( array $data, $type ) { 00891 global $wgBlockAllowsUTEdit; 00892 $flags = array(); 00893 00894 # when blocking a user the option 'anononly' is not available/has no effect 00895 # -> do not write this into log 00896 if ( !$data['HardBlock'] && $type != Block::TYPE_USER ) { 00897 // For grepping: message block-log-flags-anononly 00898 $flags[] = 'anononly'; 00899 } 00900 00901 if ( $data['CreateAccount'] ) { 00902 // For grepping: message block-log-flags-nocreate 00903 $flags[] = 'nocreate'; 00904 } 00905 00906 # Same as anononly, this is not displayed when blocking an IP address 00907 if ( !$data['AutoBlock'] && $type == Block::TYPE_USER ) { 00908 // For grepping: message block-log-flags-noautoblock 00909 $flags[] = 'noautoblock'; 00910 } 00911 00912 if ( $data['DisableEmail'] ) { 00913 // For grepping: message block-log-flags-noemail 00914 $flags[] = 'noemail'; 00915 } 00916 00917 if ( $wgBlockAllowsUTEdit && $data['DisableUTEdit'] ) { 00918 // For grepping: message block-log-flags-nousertalk 00919 $flags[] = 'nousertalk'; 00920 } 00921 00922 if ( $data['HideUser'] ) { 00923 // For grepping: message block-log-flags-hiddenname 00924 $flags[] = 'hiddenname'; 00925 } 00926 00927 return implode( ',', $flags ); 00928 } 00929 00935 public function onSubmit( array $data ) { 00936 // This isn't used since we need that HTMLForm that's passed in the 00937 // second parameter. See alterForm for the real function 00938 } 00939 00944 public function onSuccess() { 00945 $out = $this->getOutput(); 00946 $out->setPageTitle( $this->msg( 'blockipsuccesssub' ) ); 00947 $out->addWikiMsg( 'blockipsuccesstext', wfEscapeWikiText( $this->target ) ); 00948 } 00949 00950 protected function getGroupName() { 00951 return 'users'; 00952 } 00953 } 00954 00955 # BC @since 1.18 00956 class IPBlockForm extends SpecialBlock {}