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