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