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