00001 <?php
00012 function wfSpecialBlockip( $par ) {
00013 global $wgUser, $wgOut, $wgRequest;
00014
00015 # Can't block when the database is locked
00016 if( wfReadOnly() ) {
00017 $wgOut->readOnlyPage();
00018 return;
00019 }
00020 # Permission check
00021 if( !$wgUser->isAllowed( 'block' ) ) {
00022 $wgOut->permissionRequired( 'block' );
00023 return;
00024 }
00025
00026 $ipb = new IPBlockForm( $par );
00027
00028 $action = $wgRequest->getVal( 'action' );
00029 if( 'success' == $action ) {
00030 $ipb->showSuccess();
00031 } elseif( $wgRequest->wasPosted() && 'submit' == $action &&
00032 $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
00033 $ipb->doSubmit();
00034 } else {
00035 $ipb->showForm( '' );
00036 }
00037 }
00038
00044 class IPBlockForm {
00045 var $BlockAddress, $BlockExpiry, $BlockReason;
00046
00047 const HIDEUSER_CONTRIBLIMIT = 1000;
00048
00049 public function __construct( $par ) {
00050 global $wgRequest, $wgUser, $wgBlockAllowsUTEdit;
00051
00052 $this->BlockAddress = $wgRequest->getVal( 'wpBlockAddress', $wgRequest->getVal( 'ip', $par ) );
00053 $this->BlockAddress = strtr( $this->BlockAddress, '_', ' ' );
00054 $this->BlockReason = $wgRequest->getText( 'wpBlockReason' );
00055 $this->BlockReasonList = $wgRequest->getText( 'wpBlockReasonList' );
00056 $this->BlockExpiry = $wgRequest->getVal( 'wpBlockExpiry', wfMsg( 'ipbotheroption' ) );
00057 $this->BlockOther = $wgRequest->getVal( 'wpBlockOther', '' );
00058
00059 # Unchecked checkboxes are not included in the form data at all, so having one
00060 # that is true by default is a bit tricky
00061 $byDefault = !$wgRequest->wasPosted();
00062 $this->BlockAnonOnly = $wgRequest->getBool( 'wpAnonOnly', $byDefault );
00063 $this->BlockCreateAccount = $wgRequest->getBool( 'wpCreateAccount', $byDefault );
00064 $this->BlockEnableAutoblock = $wgRequest->getBool( 'wpEnableAutoblock', $byDefault );
00065 $this->BlockEmail = false;
00066 if( self::canBlockEmail( $wgUser ) ) {
00067 $this->BlockEmail = $wgRequest->getBool( 'wpEmailBan', false );
00068 }
00069 $this->BlockWatchUser = $wgRequest->getBool( 'wpWatchUser', false ) && $wgUser->isLoggedIn();
00070 # Re-check user's rights to hide names, very serious, defaults to null
00071 if( $wgUser->isAllowed( 'hideuser' ) ) {
00072 $this->BlockHideName = $wgRequest->getBool( 'wpHideName', null );
00073 } else {
00074 $this->BlockHideName = false;
00075 }
00076 $this->BlockAllowUsertalk = ( $wgRequest->getBool( 'wpAllowUsertalk', $byDefault ) && $wgBlockAllowsUTEdit );
00077 $this->BlockReblock = $wgRequest->getBool( 'wpChangeBlock', false );
00078
00079 $this->wasPosted = $wgRequest->wasPosted();
00080 }
00081
00082 public function showForm( $err ) {
00083 global $wgOut, $wgUser, $wgSysopUserBans;
00084
00085 $wgOut->setPageTitle( wfMsg( 'blockip-title' ) );
00086 $wgOut->addWikiMsg( 'blockiptext' );
00087
00088 if( $wgSysopUserBans ) {
00089 $mIpaddress = Xml::label( wfMsg( 'ipadressorusername' ), 'mw-bi-target' );
00090 } else {
00091 $mIpaddress = Xml::label( wfMsg( 'ipaddress' ), 'mw-bi-target' );
00092 }
00093 $mIpbexpiry = Xml::label( wfMsg( 'ipbexpiry' ), 'wpBlockExpiry' );
00094 $mIpbother = Xml::label( wfMsg( 'ipbother' ), 'mw-bi-other' );
00095 $mIpbreasonother = Xml::label( wfMsg( 'ipbreason' ), 'wpBlockReasonList' );
00096 $mIpbreason = Xml::label( wfMsg( 'ipbotherreason' ), 'mw-bi-reason' );
00097
00098 $titleObj = SpecialPage::getTitleFor( 'Blockip' );
00099 $user = User::newFromName( $this->BlockAddress );
00100
00101 $alreadyBlocked = false;
00102 $otherBlockedMsgs = array();
00103 if( $err && $err[0] != 'ipb_already_blocked' ) {
00104 $key = array_shift( $err );
00105 $msg = wfMsgReal( $key, $err );
00106 $wgOut->setSubtitle( wfMsgHtml( 'formerror' ) );
00107 $wgOut->addHTML( Xml::tags( 'p', array( 'class' => 'error' ), $msg ) );
00108 } elseif( $this->BlockAddress ) {
00109 # Get other blocks, i.e. from GlobalBlocking or TorBlock extension
00110 wfRunHooks( 'OtherBlockLogLink', array( &$otherBlockedMsgs, $this->BlockAddress ) );
00111
00112 $userId = is_object( $user ) ? $user->getId() : 0;
00113 $currentBlock = Block::newFromDB( $this->BlockAddress, $userId );
00114 if( !is_null( $currentBlock ) && !$currentBlock->mAuto && # The block exists and isn't an autoblock
00115 ( $currentBlock->mRangeStart == $currentBlock->mRangeEnd || # The block isn't a rangeblock
00116 # or if it is, the range is what we're about to block
00117 ( $currentBlock->mAddress == $this->BlockAddress ) )
00118 ) {
00119 $alreadyBlocked = true;
00120 # Set the block form settings to the existing block
00121 if( !$this->wasPosted ) {
00122 $this->BlockAnonOnly = $currentBlock->mAnonOnly;
00123 $this->BlockCreateAccount = $currentBlock->mCreateAccount;
00124 $this->BlockEnableAutoblock = $currentBlock->mEnableAutoblock;
00125 $this->BlockEmail = $currentBlock->mBlockEmail;
00126 $this->BlockHideName = $currentBlock->mHideName;
00127 $this->BlockAllowUsertalk = $currentBlock->mAllowUsertalk;
00128 if( $currentBlock->mExpiry == 'infinity' ) {
00129 $this->BlockOther = 'indefinite';
00130 } else {
00131 $this->BlockOther = wfTimestamp( TS_ISO_8601, $currentBlock->mExpiry );
00132 }
00133 $this->BlockReason = $currentBlock->mReason;
00134 }
00135 }
00136 }
00137
00138 # Show other blocks from extensions, i.e. GlockBlocking and TorBlock
00139 if( count( $otherBlockedMsgs ) ) {
00140 $wgOut->addHTML(
00141 Html::rawElement( 'h2', array(), wfMsgExt( 'ipb-otherblocks-header', 'parseinline', count( $otherBlockedMsgs ) ) ) . "\n"
00142 );
00143 $list = '';
00144 foreach( $otherBlockedMsgs as $link ) {
00145 $list .= Html::rawElement( 'li', array(), $link ) . "\n";
00146 }
00147 $wgOut->addHTML( Html::rawElement( 'ul', array( 'class' => 'mw-blockip-alreadyblocked' ), $list ) . "\n" );
00148 }
00149
00150 # Username/IP is blocked already locally
00151 if( $alreadyBlocked ) {
00152 $wgOut->addWikiMsg( 'ipb-needreblock', $this->BlockAddress );
00153 }
00154
00155 $scBlockExpiryOptions = wfMsgForContent( 'ipboptions' );
00156
00157 $showblockoptions = $scBlockExpiryOptions != '-';
00158 if( !$showblockoptions ) $mIpbother = $mIpbexpiry;
00159
00160 $blockExpiryFormOptions = Xml::option( wfMsg( 'ipbotheroption' ), 'other' );
00161 foreach( explode( ',', $scBlockExpiryOptions ) as $option ) {
00162 if( strpos( $option, ':' ) === false ) $option = "$option:$option";
00163 list( $show, $value ) = explode( ':', $option );
00164 $show = htmlspecialchars( $show );
00165 $value = htmlspecialchars( $value );
00166 $blockExpiryFormOptions .= Xml::option( $show, $value, $this->BlockExpiry === $value ? true : false ) . "\n";
00167 }
00168
00169 $reasonDropDown = Xml::listDropDown( 'wpBlockReasonList',
00170 wfMsgForContent( 'ipbreason-dropdown' ),
00171 wfMsgForContent( 'ipbreasonotherlist' ), $this->BlockReasonList, 'wpBlockDropDown', 4 );
00172
00173 global $wgStylePath, $wgStyleVersion;
00174 $wgOut->addHTML(
00175 Xml::tags( 'script', array( 'type' => 'text/javascript', 'src' => "$wgStylePath/common/block.js?$wgStyleVersion" ), '' ) .
00176 Xml::openElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalURL( 'action=submit' ), 'id' => 'blockip' ) ) .
00177 Xml::openElement( 'fieldset' ) .
00178 Xml::element( 'legend', null, wfMsg( 'blockip-legend' ) ) .
00179 Xml::openElement( 'table', array( 'border' => '0', 'id' => 'mw-blockip-table' ) ) .
00180 "<tr>
00181 <td class='mw-label'>
00182 {$mIpaddress}
00183 </td>
00184 <td class='mw-input'>" .
00185 Html::input( 'wpBlockAddress', $this->BlockAddress, 'text', array(
00186 'tabindex' => '1',
00187 'id' => 'mw-bi-target',
00188 'onchange' => 'updateBlockOptions()',
00189 'size' => '45',
00190 'required' => ''
00191 ) + ( $this->BlockAddress ? array() : array( 'autofocus' ) ) ). "
00192 </td>
00193 </tr>
00194 <tr>"
00195 );
00196 if( $showblockoptions ) {
00197 $wgOut->addHTML("
00198 <td class='mw-label'>
00199 {$mIpbexpiry}
00200 </td>
00201 <td class='mw-input'>" .
00202 Xml::tags( 'select',
00203 array(
00204 'id' => 'wpBlockExpiry',
00205 'name' => 'wpBlockExpiry',
00206 'onchange' => 'considerChangingExpiryFocus()',
00207 'tabindex' => '2' ),
00208 $blockExpiryFormOptions ) .
00209 "</td>"
00210 );
00211 }
00212 $wgOut->addHTML("
00213 </tr>
00214 <tr id='wpBlockOther'>
00215 <td class='mw-label'>
00216 {$mIpbother}
00217 </td>
00218 <td class='mw-input'>" .
00219 Xml::input( 'wpBlockOther', 45, $this->BlockOther,
00220 array( 'tabindex' => '3', 'id' => 'mw-bi-other' ) ) . "
00221 </td>
00222 </tr>
00223 <tr>
00224 <td class='mw-label'>
00225 {$mIpbreasonother}
00226 </td>
00227 <td class='mw-input'>
00228 {$reasonDropDown}
00229 </td>
00230 </tr>
00231 <tr id=\"wpBlockReason\">
00232 <td class='mw-label'>
00233 {$mIpbreason}
00234 </td>
00235 <td class='mw-input'>" .
00236 Html::input( 'wpBlockReason', $this->BlockReason, 'text', array(
00237 'tabindex' => '5',
00238 'id' => 'mw-bi-reason',
00239 'maxlength' => '200',
00240 'size' => '45'
00241 ) + ( $this->BlockAddress ? array( 'autofocus' ) : array() ) ) . "
00242 </td>
00243 </tr>
00244 <tr id='wpAnonOnlyRow'>
00245 <td> </td>
00246 <td class='mw-input'>" .
00247 Xml::checkLabel( wfMsg( 'ipbanononly' ),
00248 'wpAnonOnly', 'wpAnonOnly', $this->BlockAnonOnly,
00249 array( 'tabindex' => '6' ) ) . "
00250 </td>
00251 </tr>
00252 <tr id='wpCreateAccountRow'>
00253 <td> </td>
00254 <td class='mw-input'>" .
00255 Xml::checkLabel( wfMsg( 'ipbcreateaccount' ),
00256 'wpCreateAccount', 'wpCreateAccount', $this->BlockCreateAccount,
00257 array( 'tabindex' => '7' ) ) . "
00258 </td>
00259 </tr>
00260 <tr id='wpEnableAutoblockRow'>
00261 <td> </td>
00262 <td class='mw-input'>" .
00263 Xml::checkLabel( wfMsg( 'ipbenableautoblock' ),
00264 'wpEnableAutoblock', 'wpEnableAutoblock', $this->BlockEnableAutoblock,
00265 array( 'tabindex' => '8' ) ) . "
00266 </td>
00267 </tr>"
00268 );
00269
00270 if( self::canBlockEmail( $wgUser ) ) {
00271 $wgOut->addHTML("
00272 <tr id='wpEnableEmailBan'>
00273 <td> </td>
00274 <td class='mw-input'>" .
00275 Xml::checkLabel( wfMsg( 'ipbemailban' ),
00276 'wpEmailBan', 'wpEmailBan', $this->BlockEmail,
00277 array( 'tabindex' => '9' ) ) . "
00278 </td>
00279 </tr>"
00280 );
00281 }
00282
00283 // Allow some users to hide name from block log, blocklist and listusers
00284 if( $wgUser->isAllowed( 'hideuser' ) ) {
00285 $wgOut->addHTML("
00286 <tr id='wpEnableHideUser'>
00287 <td> </td>
00288 <td class='mw-input'><strong>" .
00289 Xml::checkLabel( wfMsg( 'ipbhidename' ),
00290 'wpHideName', 'wpHideName', $this->BlockHideName,
00291 array( 'tabindex' => '10' )
00292 ) . "
00293 </strong></td>
00294 </tr>"
00295 );
00296 }
00297
00298 # Watchlist their user page? (Only if user is logged in)
00299 if( $wgUser->isLoggedIn() ) {
00300 $wgOut->addHTML("
00301 <tr id='wpEnableWatchUser'>
00302 <td> </td>
00303 <td class='mw-input'>" .
00304 Xml::checkLabel( wfMsg( 'ipbwatchuser' ),
00305 'wpWatchUser', 'wpWatchUser', $this->BlockWatchUser,
00306 array( 'tabindex' => '11' ) ) . "
00307 </td>
00308 </tr>"
00309 );
00310 }
00311
00312 # Can we explicitly disallow the use of user_talk?
00313 global $wgBlockAllowsUTEdit;
00314 if( $wgBlockAllowsUTEdit ){
00315 $wgOut->addHTML("
00316 <tr id='wpAllowUsertalkRow'>
00317 <td> </td>
00318 <td class='mw-input'>" .
00319 Xml::checkLabel( wfMsg( 'ipballowusertalk' ),
00320 'wpAllowUsertalk', 'wpAllowUsertalk', $this->BlockAllowUsertalk,
00321 array( 'tabindex' => '12' ) ) . "
00322 </td>
00323 </tr>"
00324 );
00325 }
00326
00327 $wgOut->addHTML("
00328 <tr>
00329 <td style='padding-top: 1em'> </td>
00330 <td class='mw-submit' style='padding-top: 1em'>" .
00331 Xml::submitButton( wfMsg( $alreadyBlocked ? 'ipb-change-block' : 'ipbsubmit' ),
00332 array( 'name' => 'wpBlock', 'tabindex' => '13', 'accesskey' => 's' ) ) . "
00333 </td>
00334 </tr>" .
00335 Xml::closeElement( 'table' ) .
00336 Xml::hidden( 'wpEditToken', $wgUser->editToken() ) .
00337 ( $alreadyBlocked ? Xml::hidden( 'wpChangeBlock', 1 ) : "" ) .
00338 Xml::closeElement( 'fieldset' ) .
00339 Xml::closeElement( 'form' ) .
00340 Xml::tags( 'script', array( 'type' => 'text/javascript' ), 'updateBlockOptions()' ) . "\n"
00341 );
00342
00343 $wgOut->addHTML( $this->getConvenienceLinks() );
00344
00345 if( is_object( $user ) ) {
00346 $this->showLogFragment( $wgOut, $user->getUserPage() );
00347 } elseif( preg_match( '/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/', $this->BlockAddress ) ) {
00348 $this->showLogFragment( $wgOut, Title::makeTitle( NS_USER, $this->BlockAddress ) );
00349 } elseif( preg_match( '/^\w{1,4}:\w{1,4}:\w{1,4}:\w{1,4}:\w{1,4}:\w{1,4}:\w{1,4}:\w{1,4}/', $this->BlockAddress ) ) {
00350 $this->showLogFragment( $wgOut, Title::makeTitle( NS_USER, $this->BlockAddress ) );
00351 }
00352 }
00353
00359 public static function canBlockEmail( $user ) {
00360 global $wgEnableUserEmail, $wgSysopEmailBans;
00361 return ( $wgEnableUserEmail && $wgSysopEmailBans && $user->isAllowed( 'blockemail' ) );
00362 }
00363
00369 function doBlock( &$userId = null, &$expiry = null ) {
00370 global $wgUser, $wgSysopUserBans, $wgSysopRangeBans, $wgBlockAllowsUTEdit, $wgBlockCIDRLimit;
00371
00372 $userId = 0;
00373 # Expand valid IPv6 addresses, usernames are left as is
00374 $this->BlockAddress = IP::sanitizeIP( $this->BlockAddress );
00375 # isIPv4() and IPv6() are used for final validation
00376 $rxIP4 = '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}';
00377 $rxIP6 = '\w{1,4}:\w{1,4}:\w{1,4}:\w{1,4}:\w{1,4}:\w{1,4}:\w{1,4}:\w{1,4}';
00378 $rxIP = "($rxIP4|$rxIP6)";
00379
00380 # Check for invalid specifications
00381 if( !preg_match( "/^$rxIP$/", $this->BlockAddress ) ) {
00382 $matches = array();
00383 if( preg_match( "/^($rxIP4)\\/(\\d{1,2})$/", $this->BlockAddress, $matches ) ) {
00384 # IPv4
00385 if( $wgSysopRangeBans ) {
00386 if( !IP::isIPv4( $this->BlockAddress ) || $matches[2] > 32 ) {
00387 return array( 'ip_range_invalid' );
00388 } elseif ( $matches[2] < $wgBlockCIDRLimit['IPv4'] ) {
00389 return array( 'ip_range_toolarge', $wgBlockCIDRLimit['IPv4'] );
00390 }
00391 $this->BlockAddress = Block::normaliseRange( $this->BlockAddress );
00392 } else {
00393 # Range block illegal
00394 return array( 'range_block_disabled' );
00395 }
00396 } elseif( preg_match( "/^($rxIP6)\\/(\\d{1,3})$/", $this->BlockAddress, $matches ) ) {
00397 # IPv6
00398 if( $wgSysopRangeBans ) {
00399 if( !IP::isIPv6( $this->BlockAddress ) || $matches[2] > 128 ) {
00400 return array( 'ip_range_invalid' );
00401 } elseif( $matches[2] < $wgBlockCIDRLimit['IPv6'] ) {
00402 return array( 'ip_range_toolarge', $wgBlockCIDRLimit['IPv6'] );
00403 }
00404 $this->BlockAddress = Block::normaliseRange( $this->BlockAddress );
00405 } else {
00406 # Range block illegal
00407 return array('range_block_disabled');
00408 }
00409 } else {
00410 # Username block
00411 if( $wgSysopUserBans ) {
00412 $user = User::newFromName( $this->BlockAddress );
00413 if( !is_null( $user ) && $user->getId() ) {
00414 # Use canonical name
00415 $userId = $user->getId();
00416 $this->BlockAddress = $user->getName();
00417 } else {
00418 return array( 'nosuchusershort', htmlspecialchars( $user ? $user->getName() : $this->BlockAddress ) );
00419 }
00420 } else {
00421 return array( 'badipaddress' );
00422 }
00423 }
00424 }
00425
00426 if( $wgUser->isBlocked() && ( $wgUser->getId() !== $userId ) ) {
00427 return array( 'cant-block-while-blocked' );
00428 }
00429
00430 $reasonstr = $this->BlockReasonList;
00431 if( $reasonstr != 'other' && $this->BlockReason != '' ) {
00432 // Entry from drop down menu + additional comment
00433 $reasonstr .= wfMsgForContent( 'colon-separator' ) . $this->BlockReason;
00434 } elseif( $reasonstr == 'other' ) {
00435 $reasonstr = $this->BlockReason;
00436 }
00437
00438 $expirestr = $this->BlockExpiry;
00439 if( $expirestr == 'other' )
00440 $expirestr = $this->BlockOther;
00441
00442 if( ( strlen( $expirestr ) == 0) || ( strlen( $expirestr ) > 50 ) ) {
00443 return array( 'ipb_expiry_invalid' );
00444 }
00445
00446 if( false === ( $expiry = Block::parseExpiryInput( $expirestr ) ) ) {
00447 // Bad expiry.
00448 return array( 'ipb_expiry_invalid' );
00449 }
00450
00451 if( $this->BlockHideName ) {
00452 // Recheck params here...
00453 if( !$userId || !$wgUser->isAllowed('hideuser') ) {
00454 $this->BlockHideName = false; // IP users should not be hidden
00455 } elseif( $expiry !== 'infinity' ) {
00456 // Bad expiry.
00457 return array( 'ipb_expiry_temp' );
00458 } elseif( User::edits( $userId ) > self::HIDEUSER_CONTRIBLIMIT ) {
00459 // Typically, the user should have a handful of edits.
00460 // Disallow hiding users with many edits for performance.
00461 return array( 'ipb_hide_invalid' );
00462 }
00463 }
00464
00465 # Create block object
00466 # Note: for a user block, ipb_address is only for display purposes
00467 $block = new Block( $this->BlockAddress, $userId, $wgUser->getId(),
00468 $reasonstr, wfTimestampNow(), 0, $expiry, $this->BlockAnonOnly,
00469 $this->BlockCreateAccount, $this->BlockEnableAutoblock, $this->BlockHideName,
00470 $this->BlockEmail,
00471 isset( $this->BlockAllowUsertalk ) ? $this->BlockAllowUsertalk : $wgBlockAllowsUTEdit
00472 );
00473
00474 # Should this be privately logged?
00475 $suppressLog = (bool)$this->BlockHideName;
00476 if( wfRunHooks( 'BlockIp', array( &$block, &$wgUser ) ) ) {
00477 # Try to insert block. Is there a conflicting block?
00478 if( !$block->insert() ) {
00479 # Show form unless the user is already aware of this...
00480 if( !$this->BlockReblock ) {
00481 return array( 'ipb_already_blocked' );
00482 # Otherwise, try to update the block...
00483 } else {
00484 # This returns direct blocks before autoblocks/rangeblocks, since we should
00485 # be sure the user is blocked by now it should work for our purposes
00486 $currentBlock = Block::newFromDB( $this->BlockAddress, $userId );
00487 if( $block->equals( $currentBlock ) ) {
00488 return array( 'ipb_already_blocked' );
00489 }
00490 # If the name was hidden and the blocking user cannot hide
00491 # names, then don't allow any block changes...
00492 if( $currentBlock->mHideName && !$wgUser->isAllowed( 'hideuser' ) ) {
00493 return array( 'cant-see-hidden-user' );
00494 }
00495 $currentBlock->delete();
00496 $block->insert();
00497 # If hiding/unhiding a name, this should go in the private logs
00498 $suppressLog = $suppressLog || (bool)$currentBlock->mHideName;
00499 $log_action = 'reblock';
00500 # Unset _deleted fields if requested
00501 if( $currentBlock->mHideName && !$this->BlockHideName ) {
00502 self::unsuppressUserName( $this->BlockAddress, $userId );
00503 }
00504 }
00505 } else {
00506 $log_action = 'block';
00507 }
00508 wfRunHooks( 'BlockIpComplete', array( $block, $wgUser ) );
00509
00510 # Set *_deleted fields if requested
00511 if( $this->BlockHideName ) {
00512 self::suppressUserName( $this->BlockAddress, $userId );
00513 }
00514
00515 # Only show watch link when this is no range block
00516 if( $this->BlockWatchUser && $block->mRangeStart == $block->mRangeEnd ) {
00517 $wgUser->addWatch( Title::makeTitle( NS_USER, $this->BlockAddress ) );
00518 }
00519
00520 # Block constructor sanitizes certain block options on insert
00521 $this->BlockEmail = $block->mBlockEmail;
00522 $this->BlockEnableAutoblock = $block->mEnableAutoblock;
00523
00524 # Prepare log parameters
00525 $logParams = array();
00526 $logParams[] = $expirestr;
00527 $logParams[] = $this->blockLogFlags();
00528
00529 # Make log entry, if the name is hidden, put it in the oversight log
00530 $log_type = $suppressLog ? 'suppress' : 'block';
00531 $log = new LogPage( $log_type );
00532 $log->addEntry( $log_action, Title::makeTitle( NS_USER, $this->BlockAddress ),
00533 $reasonstr, $logParams );
00534
00535 # Report to the user
00536 return array();
00537 } else {
00538 return array( 'hookaborted' );
00539 }
00540 }
00541
00542 public static function suppressUserName( $name, $userId, $dbw = null ) {
00543 $op = '|';
00544 return self::setUsernameBitfields( $name, $userId, $op, $dbw );
00545 }
00546
00547 public static function unsuppressUserName( $name, $userId, $dbw = null ) {
00548 $op = '&';
00549 return self::setUsernameBitfields( $name, $userId, $op, $dbw );
00550 }
00551
00552 private static function setUsernameBitfields( $name, $userId, $op, $dbw ) {
00553 if( $op !== '|' && $op !== '&' ) return false;
00554 if( !$dbw )
00555 $dbw = wfGetDB( DB_MASTER );
00556 $delUser = Revision::DELETED_USER | Revision::DELETED_RESTRICTED;
00557 $delAction = LogPage::DELETED_ACTION | Revision::DELETED_RESTRICTED;
00558 # Normalize user name
00559 $userTitle = Title::makeTitleSafe( NS_USER, $name );
00560 $userDbKey = $userTitle->getDBkey();
00561 # To suppress, we OR the current bitfields with Revision::DELETED_USER
00562 # to put a 1 in the username *_deleted bit. To unsuppress we AND the
00563 # current bitfields with the inverse of Revision::DELETED_USER. The
00564 # username bit is made to 0 (x & 0 = 0), while others are unchanged (x & 1 = x).
00565 # The same goes for the sysop-restricted *_deleted bit.
00566 if( $op == '&' ) {
00567 $delUser = "~{$delUser}";
00568 $delAction = "~{$delAction}";
00569 }
00570 # Hide name from live edits
00571 $dbw->update( 'revision', array( "rev_deleted = rev_deleted $op $delUser" ),
00572 array( 'rev_user' => $userId ), __METHOD__ );
00573 # Hide name from deleted edits
00574 $dbw->update( 'archive', array( "ar_deleted = ar_deleted $op $delUser" ),
00575 array( 'ar_user_text' => $name ), __METHOD__ );
00576 # Hide name from logs
00577 $dbw->update( 'logging', array( "log_deleted = log_deleted $op $delUser" ),
00578 array( 'log_user' => $userId, "log_type != 'suppress'" ), __METHOD__ );
00579 $dbw->update( 'logging', array( "log_deleted = log_deleted $op $delAction" ),
00580 array( 'log_namespace' => NS_USER, 'log_title' => $userDbKey,
00581 "log_type != 'suppress'" ), __METHOD__ );
00582 # Hide name from RC
00583 $dbw->update( 'recentchanges', array( "rc_deleted = rc_deleted $op $delUser" ),
00584 array( 'rc_user_text' => $name ), __METHOD__ );
00585 $dbw->update( 'recentchanges', array( "rc_deleted = rc_deleted $op $delAction" ),
00586 array( 'rc_namespace' => NS_USER, 'rc_title' => $userDbKey, 'rc_logid > 0' ), __METHOD__ );
00587 # Hide name from live images
00588 $dbw->update( 'oldimage', array( "oi_deleted = oi_deleted $op $delUser" ),
00589 array( 'oi_user_text' => $name ), __METHOD__ );
00590 # Hide name from deleted images
00591 # WMF - schema change pending
00592 # $dbw->update( 'filearchive', array( "fa_deleted = fa_deleted $op $delUser" ),
00593 # array( 'fa_user_text' => $name ), __METHOD__ );
00594 # Done!
00595 return true;
00596 }
00597
00602 public function doSubmit() {
00603 global $wgOut;
00604 $retval = $this->doBlock();
00605 if( empty( $retval ) ) {
00606 $titleObj = SpecialPage::getTitleFor( 'Blockip' );
00607 $wgOut->redirect( $titleObj->getFullURL( 'action=success&ip=' .
00608 urlencode( $this->BlockAddress ) ) );
00609 return;
00610 }
00611 $this->showForm( $retval );
00612 }
00613
00614 public function showSuccess() {
00615 global $wgOut;
00616
00617 $wgOut->setPageTitle( wfMsg( 'blockip-title' ) );
00618 $wgOut->setSubtitle( wfMsg( 'blockipsuccesssub' ) );
00619 $text = wfMsgExt( 'blockipsuccesstext', array( 'parse' ), $this->BlockAddress );
00620 $wgOut->addHTML( $text );
00621 }
00622
00623 private function showLogFragment( $out, $title ) {
00624 global $wgUser;
00625
00626
00627 $userBlocked = $title->getText();
00628
00629 LogEventsList::showLogExtract(
00630 $out,
00631 'block',
00632 $title->getPrefixedText(),
00633 '',
00634 array(
00635 'lim' => 10,
00636 'msgKey' => array(
00637 'blocklog-showlog',
00638 $userBlocked
00639 ),
00640 'showIfEmpty' => false
00641 )
00642 );
00643
00644
00645 if( $wgUser->isAllowed( 'hideuser' ) ) {
00646 LogEventsList::showLogExtract( $out, 'suppress', $title->getPrefixedText(), '',
00647 array(
00648 'lim' => 10,
00649 'conds' => array(
00650 'log_action' => array(
00651 'block',
00652 'reblock',
00653 'unblock'
00654 )
00655 ),
00656 'msgKey' => array(
00657 'blocklog-showsuppresslog',
00658 $userBlocked
00659 ),
00660 'showIfEmpty' => false
00661 )
00662 );
00663 }
00664 }
00665
00672 private function blockLogFlags() {
00673 global $wgBlockAllowsUTEdit;
00674 $flags = array();
00675 if( $this->BlockAnonOnly && IP::isIPAddress( $this->BlockAddress ) )
00676
00677 $flags[] = 'anononly';
00678 if( $this->BlockCreateAccount )
00679 $flags[] = 'nocreate';
00680 if( !$this->BlockEnableAutoblock && !IP::isIPAddress( $this->BlockAddress ) )
00681
00682 $flags[] = 'noautoblock';
00683 if( $this->BlockEmail )
00684 $flags[] = 'noemail';
00685 if( !$this->BlockAllowUsertalk && $wgBlockAllowsUTEdit )
00686 $flags[] = 'nousertalk';
00687 if( $this->BlockHideName )
00688 $flags[] = 'hiddenname';
00689 return implode( ',', $flags );
00690 }
00691
00697 private function getConvenienceLinks() {
00698 global $wgUser, $wgLang;
00699 $skin = $wgUser->getSkin();
00700 if( $this->BlockAddress )
00701 $links[] = $this->getContribsLink( $skin );
00702 $links[] = $this->getUnblockLink( $skin );
00703 $links[] = $this->getBlockListLink( $skin );
00704 if ( $wgUser->isAllowed( 'editinterface' ) ) {
00705 $title = Title::makeTitle( NS_MEDIAWIKI, 'Ipbreason-dropdown' );
00706 $links[] = $skin->link(
00707 $title,
00708 wfMsgHtml( 'ipb-edit-dropdown' ),
00709 array(),
00710 array( 'action' => 'edit' )
00711 );
00712 }
00713 return '<p class="mw-ipb-conveniencelinks">' . $wgLang->pipeList( $links ) . '</p>';
00714 }
00715
00723 private function getContribsLink( $skin ) {
00724 $contribsPage = SpecialPage::getTitleFor( 'Contributions', $this->BlockAddress );
00725 return $skin->link( $contribsPage, wfMsgExt( 'ipb-blocklist-contribs', 'escape', $this->BlockAddress ) );
00726 }
00727
00736 private function getUnblockLink( $skin ) {
00737 $list = SpecialPage::getTitleFor( 'Ipblocklist' );
00738 $query = array( 'action' => 'unblock' );
00739
00740 if( $this->BlockAddress ) {
00741 $addr = strtr( $this->BlockAddress, '_', ' ' );
00742 $message = wfMsg( 'ipb-unblock-addr', $addr );
00743 $query['ip'] = $this->BlockAddress;
00744 } else {
00745 $message = wfMsg( 'ipb-unblock' );
00746 }
00747 return $skin->linkKnown(
00748 $list,
00749 htmlspecialchars( $message ),
00750 array(),
00751 $query
00752 );
00753 }
00754
00761 private function getBlockListLink( $skin ) {
00762 $list = SpecialPage::getTitleFor( 'Ipblocklist' );
00763 $query = array();
00764
00765 if( $this->BlockAddress ) {
00766 $addr = strtr( $this->BlockAddress, '_', ' ' );
00767 $message = wfMsg( 'ipb-blocklist-addr', $addr );
00768 $query['ip'] = $this->BlockAddress;
00769 } else {
00770 $message = wfMsg( 'ipb-blocklist' );
00771 }
00772
00773 return $skin->linkKnown(
00774 $list,
00775 htmlspecialchars( $message ),
00776 array(),
00777 $query
00778 );
00779 }
00780
00789 public static function doMassUserBlock( $users, $reason = '', $tag = '', $talkTag = '' ) {
00790 global $wgUser;
00791 $counter = $blockSize = 0;
00792 $safeUsers = array();
00793 $log = new LogPage( 'block' );
00794 foreach( $users as $name ) {
00795 # Enforce limits
00796 $counter++;
00797 $blockSize++;
00798 # Lets not go *too* fast
00799 if( $blockSize >= 20 ) {
00800 $blockSize = 0;
00801 wfWaitForSlaves( 5 );
00802 }
00803 $u = User::newFromName( $name, false );
00804
00805 if( is_null( $u ) || ( !$u->getId() && !IP::isIPAddress( $u->getName() ) ) ) {
00806 continue;
00807 }
00808 $userTitle = $u->getUserPage();
00809 $userTalkTitle = $u->getTalkPage();
00810 $userpage = new Article( $userTitle );
00811 $usertalk = new Article( $userTalkTitle );
00812 $safeUsers[] = '[[' . $userTitle->getPrefixedText() . '|' . $userTitle->getText() . ']]';
00813 $expirestr = $u->getId() ? 'indefinite' : '1 week';
00814 $expiry = Block::parseExpiryInput( $expirestr );
00815 $anonOnly = IP::isIPAddress( $u->getName() ) ? 1 : 0;
00816
00817 $block = new Block( $u->getName(),
00818 $u->getId(),
00819 $wgUser->getId(),
00820 $reason,
00821 wfTimestampNow(),
00822 0,
00823 $expiry,
00824 $anonOnly,
00825 1,
00826 1,
00827 0,
00828 0
00829 );
00830 $oldblock = Block::newFromDB( $u->getName(), $u->getId() );
00831 if( !$oldblock ) {
00832 $block->insert();
00833 # Prepare log parameters
00834 $logParams = array();
00835 $logParams[] = $expirestr;
00836 if( $anonOnly ) {
00837 $logParams[] = 'anononly';
00838 }
00839 $logParams[] = 'nocreate';
00840 # Add log entry
00841 $log->addEntry( 'block', $userTitle, $reason, $logParams );
00842 }
00843 # Tag userpage! (check length to avoid mistakes)
00844 if( strlen( $tag ) > 2 ) {
00845 $userpage->doEdit( $tag, $reason, EDIT_MINOR );
00846 }
00847 if( strlen( $talkTag ) > 2 ) {
00848 $usertalk->doEdit( $talkTag, $reason, EDIT_MINOR );
00849 }
00850 }
00851 return $safeUsers;
00852 }
00853 }