3 * Constructor for Special:Blockip page
12 function wfSpecialBlockip( $par ) {
13 global $wgUser, $wgOut, $wgRequest;
15 # Can't block when the database is locked
17 $wgOut->readOnlyPage();
21 if( !$wgUser->isAllowed( 'block' ) ) {
22 $wgOut->permissionRequired( 'block' );
26 $ipb = new IPBlockForm( $par );
28 # bug 15810: blocked admins should have limited access here
29 if( $wgUser->isBlocked() ){
30 $status = IPBlockForm
::checkUnblockSelf( $ipb->BlockAddress
);
31 if( $status !== true ){
32 throw new ErrorPageError( 'badaccess', $status );
36 $action = $wgRequest->getVal( 'action' );
37 if( 'success' == $action ) {
39 } elseif( $wgRequest->wasPosted() && 'submit' == $action &&
40 $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
48 * Form object for the Special:Blockip page.
50 * @ingroup SpecialPage
53 var $BlockAddress, $BlockExpiry, $BlockReason;
54 // The maximum number of edits a user can have and still be hidden
55 const HIDEUSER_CONTRIBLIMIT
= 1000;
57 public function __construct( $par ) {
58 global $wgRequest, $wgUser, $wgBlockAllowsUTEdit;
60 $this->BlockAddress
= $wgRequest->getVal( 'wpBlockAddress', $wgRequest->getVal( 'ip', $par ) );
61 $this->BlockAddress
= strtr( $this->BlockAddress
, '_', ' ' );
62 $this->BlockReason
= $wgRequest->getText( 'wpBlockReason' );
63 $this->BlockReasonList
= $wgRequest->getText( 'wpBlockReasonList' );
64 $this->BlockExpiry
= $wgRequest->getVal( 'wpBlockExpiry', wfMsg( 'ipbotheroption' ) );
65 $this->BlockOther
= $wgRequest->getVal( 'wpBlockOther', '' );
67 # Unchecked checkboxes are not included in the form data at all, so having one
68 # that is true by default is a bit tricky
69 $byDefault = !$wgRequest->wasPosted();
70 $this->BlockAnonOnly
= $wgRequest->getBool( 'wpAnonOnly', $byDefault );
71 $this->BlockCreateAccount
= $wgRequest->getBool( 'wpCreateAccount', $byDefault );
72 $this->BlockEnableAutoblock
= $wgRequest->getBool( 'wpEnableAutoblock', $byDefault );
73 $this->BlockEmail
= false;
74 if( self
::canBlockEmail( $wgUser ) ) {
75 $this->BlockEmail
= $wgRequest->getBool( 'wpEmailBan', false );
77 $this->BlockWatchUser
= $wgRequest->getBool( 'wpWatchUser', false ) && $wgUser->isLoggedIn();
78 # Re-check user's rights to hide names, very serious, defaults to null
79 if( $wgUser->isAllowed( 'hideuser' ) ) {
80 $this->BlockHideName
= $wgRequest->getBool( 'wpHideName', null );
82 $this->BlockHideName
= false;
84 $this->BlockAllowUsertalk
= ( $wgRequest->getBool( 'wpAllowUsertalk', $byDefault ) && $wgBlockAllowsUTEdit );
85 $this->BlockReblock
= $wgRequest->getBool( 'wpChangeBlock', false );
87 $this->wasPosted
= $wgRequest->wasPosted();
90 public function showForm( $err ) {
91 global $wgOut, $wgUser, $wgSysopUserBans;
93 $wgOut->setPageTitle( wfMsg( 'blockip-title' ) );
94 $wgOut->addWikiMsg( 'blockiptext' );
96 if( $wgSysopUserBans ) {
97 $mIpaddress = Xml
::label( wfMsg( 'ipadressorusername' ), 'mw-bi-target' );
99 $mIpaddress = Xml
::label( wfMsg( 'ipaddress' ), 'mw-bi-target' );
101 $mIpbexpiry = Xml
::label( wfMsg( 'ipbexpiry' ), 'wpBlockExpiry' );
102 $mIpbother = Xml
::label( wfMsg( 'ipbother' ), 'mw-bi-other' );
103 $mIpbreasonother = Xml
::label( wfMsg( 'ipbreason' ), 'wpBlockReasonList' );
104 $mIpbreason = Xml
::label( wfMsg( 'ipbotherreason' ), 'mw-bi-reason' );
106 $titleObj = SpecialPage
::getTitleFor( 'Blockip' );
107 $user = User
::newFromName( $this->BlockAddress
);
109 $alreadyBlocked = false;
110 $otherBlockedMsgs = array();
111 if( $err && $err[0] != 'ipb_already_blocked' ) {
112 $key = array_shift( $err );
113 $msg = wfMsgReal( $key, $err );
114 $wgOut->setSubtitle( wfMsgHtml( 'formerror' ) );
115 $wgOut->addHTML( Xml
::tags( 'p', array( 'class' => 'error' ), $msg ) );
116 } elseif( $this->BlockAddress
!== null ) {
117 # Get other blocks, i.e. from GlobalBlocking or TorBlock extension
118 wfRunHooks( 'OtherBlockLogLink', array( &$otherBlockedMsgs, $this->BlockAddress
) );
120 $userId = is_object( $user ) ?
$user->getId() : 0;
121 $currentBlock = Block
::newFromDB( $this->BlockAddress
, $userId );
122 if( !is_null( $currentBlock ) && !$currentBlock->mAuto
&& # The block exists and isn't an autoblock
123 ( $currentBlock->mRangeStart
== $currentBlock->mRangeEnd ||
# The block isn't a rangeblock
124 # or if it is, the range is what we're about to block
125 ( $currentBlock->mAddress
== $this->BlockAddress
) )
127 $alreadyBlocked = true;
128 # Set the block form settings to the existing block
129 if( !$this->wasPosted
) {
130 $this->BlockAnonOnly
= $currentBlock->mAnonOnly
;
131 $this->BlockCreateAccount
= $currentBlock->mCreateAccount
;
132 $this->BlockEnableAutoblock
= $currentBlock->mEnableAutoblock
;
133 $this->BlockEmail
= $currentBlock->mBlockEmail
;
134 $this->BlockHideName
= $currentBlock->mHideName
;
135 $this->BlockAllowUsertalk
= $currentBlock->mAllowUsertalk
;
136 if( $currentBlock->mExpiry
== 'infinity' ) {
137 $this->BlockOther
= 'indefinite';
139 $this->BlockOther
= wfTimestamp( TS_ISO_8601
, $currentBlock->mExpiry
);
141 $this->BlockReason
= $currentBlock->mReason
;
146 # Show other blocks from extensions, i.e. GlockBlocking and TorBlock
147 if( count( $otherBlockedMsgs ) ) {
149 Html
::rawElement( 'h2', array(), wfMsgExt( 'ipb-otherblocks-header', 'parseinline', count( $otherBlockedMsgs ) ) ) . "\n"
152 foreach( $otherBlockedMsgs as $link ) {
153 $list .= Html
::rawElement( 'li', array(), $link ) . "\n";
155 $wgOut->addHTML( Html
::rawElement( 'ul', array( 'class' => 'mw-blockip-alreadyblocked' ), $list ) . "\n" );
158 # Username/IP is blocked already locally
159 if( $alreadyBlocked ) {
160 $wgOut->addWikiMsg( 'ipb-needreblock', $this->BlockAddress
);
163 $scBlockExpiryOptions = wfMsgForContent( 'ipboptions' );
165 $showblockoptions = $scBlockExpiryOptions != '-';
166 if( !$showblockoptions ) $mIpbother = $mIpbexpiry;
168 $blockExpiryFormOptions = Xml
::option( wfMsg( 'ipbotheroption' ), 'other' );
169 foreach( explode( ',', $scBlockExpiryOptions ) as $option ) {
170 if( strpos( $option, ':' ) === false ) $option = "$option:$option";
171 list( $show, $value ) = explode( ':', $option );
172 $show = htmlspecialchars( $show );
173 $value = htmlspecialchars( $value );
174 $blockExpiryFormOptions .= Xml
::option( $show, $value, $this->BlockExpiry
=== $value ?
true : false ) . "\n";
177 $reasonDropDown = Xml
::listDropDown( 'wpBlockReasonList',
178 wfMsgForContent( 'ipbreason-dropdown' ),
179 wfMsgForContent( 'ipbreasonotherlist' ), $this->BlockReasonList
, 'wpBlockDropDown', 4 );
181 global $wgStylePath, $wgStyleVersion;
183 Xml
::tags( 'script', array( 'type' => 'text/javascript', 'src' => "$wgStylePath/common/block.js?$wgStyleVersion" ), '' ) .
184 Xml
::openElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalURL( 'action=submit' ), 'id' => 'blockip' ) ) .
185 Xml
::openElement( 'fieldset' ) .
186 Xml
::element( 'legend', null, wfMsg( 'blockip-legend' ) ) .
187 Xml
::openElement( 'table', array( 'border' => '0', 'id' => 'mw-blockip-table' ) ) .
189 <td class='mw-label'>
192 <td class='mw-input'>" .
193 Html
::input( 'wpBlockAddress', $this->BlockAddress
, 'text', array(
195 'id' => 'mw-bi-target',
196 'onchange' => 'updateBlockOptions()',
199 ) +
( $this->BlockAddress ?
array() : array( 'autofocus' ) ) ). "
204 if( $showblockoptions ) {
206 <td class='mw-label'>
209 <td class='mw-input'>" .
212 'id' => 'wpBlockExpiry',
213 'name' => 'wpBlockExpiry',
214 'onchange' => 'considerChangingExpiryFocus()',
216 $blockExpiryFormOptions ) .
222 <tr id='wpBlockOther'>
223 <td class='mw-label'>
226 <td class='mw-input'>" .
227 Xml
::input( 'wpBlockOther', 45, $this->BlockOther
,
228 array( 'tabindex' => '3', 'id' => 'mw-bi-other' ) ) . "
232 <td class='mw-label'>
235 <td class='mw-input'>
239 <tr id=\"wpBlockReason\">
240 <td class='mw-label'>
243 <td class='mw-input'>" .
244 Html
::input( 'wpBlockReason', $this->BlockReason
, 'text', array(
246 'id' => 'mw-bi-reason',
247 'maxlength' => '200',
249 ) +
( $this->BlockAddress ?
array( 'autofocus' ) : array() ) ) . "
252 <tr id='wpAnonOnlyRow'>
254 <td class='mw-input'>" .
255 Xml
::checkLabel( wfMsg( 'ipbanononly' ),
256 'wpAnonOnly', 'wpAnonOnly', $this->BlockAnonOnly
,
257 array( 'tabindex' => '6' ) ) . "
260 <tr id='wpCreateAccountRow'>
262 <td class='mw-input'>" .
263 Xml
::checkLabel( wfMsg( 'ipbcreateaccount' ),
264 'wpCreateAccount', 'wpCreateAccount', $this->BlockCreateAccount
,
265 array( 'tabindex' => '7' ) ) . "
268 <tr id='wpEnableAutoblockRow'>
270 <td class='mw-input'>" .
271 Xml
::checkLabel( wfMsg( 'ipbenableautoblock' ),
272 'wpEnableAutoblock', 'wpEnableAutoblock', $this->BlockEnableAutoblock
,
273 array( 'tabindex' => '8' ) ) . "
278 if( self
::canBlockEmail( $wgUser ) ) {
280 <tr id='wpEnableEmailBan'>
282 <td class='mw-input'>" .
283 Xml
::checkLabel( wfMsg( 'ipbemailban' ),
284 'wpEmailBan', 'wpEmailBan', $this->BlockEmail
,
285 array( 'tabindex' => '9' ) ) . "
291 // Allow some users to hide name from block log, blocklist and listusers
292 if( $wgUser->isAllowed( 'hideuser' ) ) {
294 <tr id='wpEnableHideUser'>
296 <td class='mw-input'><strong>" .
297 Xml
::checkLabel( wfMsg( 'ipbhidename' ),
298 'wpHideName', 'wpHideName', $this->BlockHideName
,
299 array( 'tabindex' => '10' )
306 # Watchlist their user page? (Only if user is logged in)
307 if( $wgUser->isLoggedIn() ) {
309 <tr id='wpEnableWatchUser'>
311 <td class='mw-input'>" .
312 Xml
::checkLabel( wfMsg( 'ipbwatchuser' ),
313 'wpWatchUser', 'wpWatchUser', $this->BlockWatchUser
,
314 array( 'tabindex' => '11' ) ) . "
320 # Can we explicitly disallow the use of user_talk?
321 global $wgBlockAllowsUTEdit;
322 if( $wgBlockAllowsUTEdit ){
324 <tr id='wpAllowUsertalkRow'>
326 <td class='mw-input'>" .
327 Xml
::checkLabel( wfMsg( 'ipballowusertalk' ),
328 'wpAllowUsertalk', 'wpAllowUsertalk', $this->BlockAllowUsertalk
,
329 array( 'tabindex' => '12' ) ) . "
337 <td style='padding-top: 1em'> </td>
338 <td class='mw-submit' style='padding-top: 1em'>" .
339 Xml
::submitButton( wfMsg( $alreadyBlocked ?
'ipb-change-block' : 'ipbsubmit' ),
340 array( 'name' => 'wpBlock', 'tabindex' => '13', 'accesskey' => 's' ) ) . "
343 Xml
::closeElement( 'table' ) .
344 Xml
::hidden( 'wpEditToken', $wgUser->editToken() ) .
345 ( $alreadyBlocked ? Xml
::hidden( 'wpChangeBlock', 1 ) : "" ) .
346 Xml
::closeElement( 'fieldset' ) .
347 Xml
::closeElement( 'form' ) .
348 Xml
::tags( 'script', array( 'type' => 'text/javascript' ), 'updateBlockOptions()' ) . "\n"
351 $wgOut->addHTML( $this->getConvenienceLinks() );
353 if( is_object( $user ) ) {
354 $this->showLogFragment( $wgOut, $user->getUserPage() );
355 } elseif( preg_match( '/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/', $this->BlockAddress
) ) {
356 $this->showLogFragment( $wgOut, Title
::makeTitle( NS_USER
, $this->BlockAddress
) );
357 } 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
) ) {
358 $this->showLogFragment( $wgOut, Title
::makeTitle( NS_USER
, $this->BlockAddress
) );
363 * Can we do an email block?
364 * @param User $user The sysop wanting to make a block
367 public static function canBlockEmail( $user ) {
368 global $wgEnableUserEmail, $wgSysopEmailBans;
369 return ( $wgEnableUserEmail && $wgSysopEmailBans && $user->isAllowed( 'blockemail' ) );
373 * bug 15810: blocked admins should not be able to block/unblock
374 * others, and probably shouldn't be able to unblock themselves
376 * @param $user User, Int or String
378 public static function checkUnblockSelf( $user ){
380 if( is_int( $user ) ){
381 $user = User
::newFromId( $user );
382 } elseif ( is_string( $user ) ){
383 $user = User
::newFromName( $user );
385 if( $user instanceof User
386 && $user->getId() == $wgUser->getId() )
388 # User is trying to unblock themselves
389 if( $wgUser->isAllowed( 'unblockself' ) ){
392 return 'ipbnounblockself';
395 # User is trying to block/unblock someone else
401 * Backend block code.
402 * $userID and $expiry will be filled accordingly
403 * @return array(message key, arguments) on failure, empty array on success
405 function doBlock( &$userId = null, &$expiry = null ) {
406 global $wgUser, $wgSysopUserBans, $wgSysopRangeBans, $wgBlockAllowsUTEdit, $wgBlockCIDRLimit;
409 # Expand valid IPv6 addresses, usernames are left as is
410 $this->BlockAddress
= IP
::sanitizeIP( $this->BlockAddress
);
411 # isIPv4() and IPv6() are used for final validation
412 $rxIP4 = '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}';
413 $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}';
414 $rxIP = "($rxIP4|$rxIP6)";
416 # Check for invalid specifications
417 if( !preg_match( "/^$rxIP$/", $this->BlockAddress
) ) {
419 if( preg_match( "/^($rxIP4)\\/(\\d{1,2})$/", $this->BlockAddress
, $matches ) ) {
421 if( $wgSysopRangeBans ) {
422 if( !IP
::isIPv4( $this->BlockAddress
) ||
$matches[2] > 32 ) {
423 return array( 'ip_range_invalid' );
424 } elseif ( $matches[2] < $wgBlockCIDRLimit['IPv4'] ) {
425 return array( 'ip_range_toolarge', $wgBlockCIDRLimit['IPv4'] );
427 $this->BlockAddress
= Block
::normaliseRange( $this->BlockAddress
);
429 # Range block illegal
430 return array( 'range_block_disabled' );
432 } elseif( preg_match( "/^($rxIP6)\\/(\\d{1,3})$/", $this->BlockAddress
, $matches ) ) {
434 if( $wgSysopRangeBans ) {
435 if( !IP
::isIPv6( $this->BlockAddress
) ||
$matches[2] > 128 ) {
436 return array( 'ip_range_invalid' );
437 } elseif( $matches[2] < $wgBlockCIDRLimit['IPv6'] ) {
438 return array( 'ip_range_toolarge', $wgBlockCIDRLimit['IPv6'] );
440 $this->BlockAddress
= Block
::normaliseRange( $this->BlockAddress
);
442 # Range block illegal
443 return array('range_block_disabled');
447 if( $wgSysopUserBans ) {
448 $user = User
::newFromName( $this->BlockAddress
);
449 if( $user instanceof User
&& $user->getId() ) {
451 $userId = $user->getId();
452 $this->BlockAddress
= $user->getName();
454 return array( 'nosuchusershort', htmlspecialchars( $user ?
$user->getName() : $this->BlockAddress
) );
457 return array( 'badipaddress' );
462 if( $wgUser->isBlocked() && ( $wgUser->getId() !== $userId ) ) {
463 return array( 'cant-block-while-blocked' );
466 $reasonstr = $this->BlockReasonList
;
467 if( $reasonstr != 'other' && $this->BlockReason
!= '' ) {
468 // Entry from drop down menu + additional comment
469 $reasonstr .= wfMsgForContent( 'colon-separator' ) . $this->BlockReason
;
470 } elseif( $reasonstr == 'other' ) {
471 $reasonstr = $this->BlockReason
;
474 $expirestr = $this->BlockExpiry
;
475 if( $expirestr == 'other' )
476 $expirestr = $this->BlockOther
;
478 if( ( strlen( $expirestr ) == 0) ||
( strlen( $expirestr ) > 50 ) ) {
479 return array( 'ipb_expiry_invalid' );
482 if( false === ( $expiry = Block
::parseExpiryInput( $expirestr ) ) ) {
484 return array( 'ipb_expiry_invalid' );
487 if( $this->BlockHideName
) {
488 // Recheck params here...
489 if( !$userId ||
!$wgUser->isAllowed('hideuser') ) {
490 $this->BlockHideName
= false; // IP users should not be hidden
491 } elseif( $expiry !== 'infinity' ) {
493 return array( 'ipb_expiry_temp' );
494 } elseif( User
::edits( $userId ) > self
::HIDEUSER_CONTRIBLIMIT
) {
495 // Typically, the user should have a handful of edits.
496 // Disallow hiding users with many edits for performance.
497 return array( 'ipb_hide_invalid' );
501 # Create block object
502 # Note: for a user block, ipb_address is only for display purposes
503 $block = new Block( $this->BlockAddress
, $userId, $wgUser->getId(),
504 $reasonstr, wfTimestampNow(), 0, $expiry, $this->BlockAnonOnly
,
505 $this->BlockCreateAccount
, $this->BlockEnableAutoblock
, $this->BlockHideName
,
507 isset( $this->BlockAllowUsertalk
) ?
$this->BlockAllowUsertalk
: $wgBlockAllowsUTEdit
510 # Should this be privately logged?
511 $suppressLog = (bool)$this->BlockHideName
;
512 if( wfRunHooks( 'BlockIp', array( &$block, &$wgUser ) ) ) {
513 # Try to insert block. Is there a conflicting block?
514 if( !$block->insert() ) {
515 # Show form unless the user is already aware of this...
516 if( !$this->BlockReblock
) {
517 return array( 'ipb_already_blocked' );
518 # Otherwise, try to update the block...
520 # This returns direct blocks before autoblocks/rangeblocks, since we should
521 # be sure the user is blocked by now it should work for our purposes
522 $currentBlock = Block
::newFromDB( $this->BlockAddress
, $userId );
523 if( $block->equals( $currentBlock ) ) {
524 return array( 'ipb_already_blocked' );
526 # If the name was hidden and the blocking user cannot hide
527 # names, then don't allow any block changes...
528 if( $currentBlock->mHideName
&& !$wgUser->isAllowed( 'hideuser' ) ) {
529 return array( 'cant-see-hidden-user' );
531 $currentBlock->delete();
533 # If hiding/unhiding a name, this should go in the private logs
534 $suppressLog = $suppressLog ||
(bool)$currentBlock->mHideName
;
535 $log_action = 'reblock';
536 # Unset _deleted fields if requested
537 if( $currentBlock->mHideName
&& !$this->BlockHideName
) {
538 self
::unsuppressUserName( $this->BlockAddress
, $userId );
542 $log_action = 'block';
544 wfRunHooks( 'BlockIpComplete', array( $block, $wgUser ) );
546 # Set *_deleted fields if requested
547 if( $this->BlockHideName
) {
548 self
::suppressUserName( $this->BlockAddress
, $userId );
551 # Only show watch link when this is no range block
552 if( $this->BlockWatchUser
&& $block->mRangeStart
== $block->mRangeEnd
) {
553 $wgUser->addWatch( Title
::makeTitle( NS_USER
, $this->BlockAddress
) );
556 # Block constructor sanitizes certain block options on insert
557 $this->BlockEmail
= $block->mBlockEmail
;
558 $this->BlockEnableAutoblock
= $block->mEnableAutoblock
;
560 # Prepare log parameters
561 $logParams = array();
562 $logParams[] = $expirestr;
563 $logParams[] = $this->blockLogFlags();
565 # Make log entry, if the name is hidden, put it in the oversight log
566 $log_type = $suppressLog ?
'suppress' : 'block';
567 $log = new LogPage( $log_type );
568 $log->addEntry( $log_action, Title
::makeTitle( NS_USER
, $this->BlockAddress
),
569 $reasonstr, $logParams );
574 return array( 'hookaborted' );
578 public static function suppressUserName( $name, $userId, $dbw = null ) {
579 $op = '|'; // bitwise OR
580 return self
::setUsernameBitfields( $name, $userId, $op, $dbw );
583 public static function unsuppressUserName( $name, $userId, $dbw = null ) {
584 $op = '&'; // bitwise AND
585 return self
::setUsernameBitfields( $name, $userId, $op, $dbw );
588 private static function setUsernameBitfields( $name, $userId, $op, $dbw ) {
589 if( $op !== '|' && $op !== '&' ) return false; // sanity check
591 $dbw = wfGetDB( DB_MASTER
);
592 $delUser = Revision
::DELETED_USER | Revision
::DELETED_RESTRICTED
;
593 $delAction = LogPage
::DELETED_ACTION | Revision
::DELETED_RESTRICTED
;
594 # Normalize user name
595 $userTitle = Title
::makeTitleSafe( NS_USER
, $name );
596 $userDbKey = $userTitle->getDBkey();
597 # To suppress, we OR the current bitfields with Revision::DELETED_USER
598 # to put a 1 in the username *_deleted bit. To unsuppress we AND the
599 # current bitfields with the inverse of Revision::DELETED_USER. The
600 # username bit is made to 0 (x & 0 = 0), while others are unchanged (x & 1 = x).
601 # The same goes for the sysop-restricted *_deleted bit.
603 $delUser = "~{$delUser}";
604 $delAction = "~{$delAction}";
606 # Hide name from live edits
607 $dbw->update( 'revision', array( "rev_deleted = rev_deleted $op $delUser" ),
608 array( 'rev_user' => $userId ), __METHOD__
);
609 # Hide name from deleted edits
610 $dbw->update( 'archive', array( "ar_deleted = ar_deleted $op $delUser" ),
611 array( 'ar_user_text' => $name ), __METHOD__
);
612 # Hide name from logs
613 $dbw->update( 'logging', array( "log_deleted = log_deleted $op $delUser" ),
614 array( 'log_user' => $userId, "log_type != 'suppress'" ), __METHOD__
);
615 $dbw->update( 'logging', array( "log_deleted = log_deleted $op $delAction" ),
616 array( 'log_namespace' => NS_USER
, 'log_title' => $userDbKey,
617 "log_type != 'suppress'" ), __METHOD__
);
619 $dbw->update( 'recentchanges', array( "rc_deleted = rc_deleted $op $delUser" ),
620 array( 'rc_user_text' => $name ), __METHOD__
);
621 $dbw->update( 'recentchanges', array( "rc_deleted = rc_deleted $op $delAction" ),
622 array( 'rc_namespace' => NS_USER
, 'rc_title' => $userDbKey, 'rc_logid > 0' ), __METHOD__
);
623 # Hide name from live images
624 $dbw->update( 'oldimage', array( "oi_deleted = oi_deleted $op $delUser" ),
625 array( 'oi_user_text' => $name ), __METHOD__
);
626 # Hide name from deleted images
627 # WMF - schema change pending
628 # $dbw->update( 'filearchive', array( "fa_deleted = fa_deleted $op $delUser" ),
629 # array( 'fa_user_text' => $name ), __METHOD__ );
635 * UI entry point for blocking
636 * Wraps around doBlock()
638 public function doSubmit() {
640 $retval = $this->doBlock();
641 if( empty( $retval ) ) {
642 $titleObj = SpecialPage
::getTitleFor( 'Blockip' );
643 $wgOut->redirect( $titleObj->getFullURL( 'action=success&ip=' .
644 urlencode( $this->BlockAddress
) ) );
647 $this->showForm( $retval );
650 public function showSuccess() {
653 $wgOut->setPageTitle( wfMsg( 'blockip-title' ) );
654 $wgOut->setSubtitle( wfMsg( 'blockipsuccesssub' ) );
655 $text = wfMsgExt( 'blockipsuccesstext', array( 'parse' ), $this->BlockAddress
);
656 $wgOut->addHTML( $text );
659 private function showLogFragment( $out, $title ) {
662 // Used to support GENDER in 'blocklog-showlog' and 'blocklog-showsuppresslog'
663 $userBlocked = $title->getText();
665 LogEventsList
::showLogExtract(
668 $title->getPrefixedText(),
676 'showIfEmpty' => false
680 // Add suppression block entries if allowed
681 if( $wgUser->isAllowed( 'suppressionlog' ) ) {
682 LogEventsList
::showLogExtract( $out, 'suppress', $title->getPrefixedText(), '',
686 'log_action' => array(
693 'blocklog-showsuppresslog',
696 'showIfEmpty' => false
703 * Return a comma-delimited list of "flags" to be passed to the log
704 * reader for this block, to provide more information in the logs
708 private function blockLogFlags() {
709 global $wgBlockAllowsUTEdit;
711 if( $this->BlockAnonOnly
&& IP
::isIPAddress( $this->BlockAddress
) )
712 // when blocking a user the option 'anononly' is not available/has no effect -> do not write this into log
713 $flags[] = 'anononly';
714 if( $this->BlockCreateAccount
)
715 $flags[] = 'nocreate';
716 if( !$this->BlockEnableAutoblock
&& !IP
::isIPAddress( $this->BlockAddress
) )
717 // Same as anononly, this is not displayed when blocking an IP address
718 $flags[] = 'noautoblock';
719 if( $this->BlockEmail
)
720 $flags[] = 'noemail';
721 if( !$this->BlockAllowUsertalk
&& $wgBlockAllowsUTEdit )
722 $flags[] = 'nousertalk';
723 if( $this->BlockHideName
)
724 $flags[] = 'hiddenname';
725 return implode( ',', $flags );
729 * Builds unblock and block list links
733 private function getConvenienceLinks() {
734 global $wgUser, $wgLang;
735 $skin = $wgUser->getSkin();
736 if( $this->BlockAddress
)
737 $links[] = $this->getContribsLink( $skin );
738 $links[] = $this->getUnblockLink( $skin );
739 $links[] = $this->getBlockListLink( $skin );
740 if ( $wgUser->isAllowed( 'editinterface' ) ) {
741 $title = Title
::makeTitle( NS_MEDIAWIKI
, 'Ipbreason-dropdown' );
742 $links[] = $skin->link(
744 wfMsgHtml( 'ipb-edit-dropdown' ),
746 array( 'action' => 'edit' )
749 return '<p class="mw-ipb-conveniencelinks">' . $wgLang->pipeList( $links ) . '</p>';
753 * Build a convenient link to a user or IP's contribs
756 * @param $skin Skin to use
759 private function getContribsLink( $skin ) {
760 $contribsPage = SpecialPage
::getTitleFor( 'Contributions', $this->BlockAddress
);
761 return $skin->link( $contribsPage, wfMsgExt( 'ipb-blocklist-contribs', 'escape', $this->BlockAddress
) );
765 * Build a convenient link to unblock the given username or IP
766 * address, if available; otherwise link to a blank unblock
769 * @param $skin Skin to use
772 private function getUnblockLink( $skin ) {
773 $list = SpecialPage
::getTitleFor( 'Ipblocklist' );
774 $query = array( 'action' => 'unblock' );
776 if( $this->BlockAddress
) {
777 $addr = strtr( $this->BlockAddress
, '_', ' ' );
778 $message = wfMsg( 'ipb-unblock-addr', $addr );
779 $query['ip'] = $this->BlockAddress
;
781 $message = wfMsg( 'ipb-unblock' );
783 return $skin->linkKnown(
785 htmlspecialchars( $message ),
792 * Build a convenience link to the block list
794 * @param $skin Skin to use
797 private function getBlockListLink( $skin ) {
798 $list = SpecialPage
::getTitleFor( 'Ipblocklist' );
801 if( $this->BlockAddress
) {
802 $addr = strtr( $this->BlockAddress
, '_', ' ' );
803 $message = wfMsg( 'ipb-blocklist-addr', $addr );
804 $query['ip'] = $this->BlockAddress
;
806 $message = wfMsg( 'ipb-blocklist' );
809 return $skin->linkKnown(
811 htmlspecialchars( $message ),
818 * Block a list of selected users
819 * @param array $users
820 * @param string $reason
821 * @param string $tag replaces user pages
822 * @param string $talkTag replaces user talk pages
823 * @returns array, list of html-safe usernames
825 public static function doMassUserBlock( $users, $reason = '', $tag = '', $talkTag = '' ) {
827 $counter = $blockSize = 0;
828 $safeUsers = array();
829 $log = new LogPage( 'block' );
830 foreach( $users as $name ) {
834 # Lets not go *too* fast
835 if( $blockSize >= 20 ) {
837 wfWaitForSlaves( 5 );
839 $u = User
::newFromName( $name, false );
840 // If user doesn't exist, it ought to be an IP then
841 if( is_null( $u ) ||
( !$u->getId() && !IP
::isIPAddress( $u->getName() ) ) ) {
844 $userTitle = $u->getUserPage();
845 $userTalkTitle = $u->getTalkPage();
846 $userpage = new Article( $userTitle );
847 $usertalk = new Article( $userTalkTitle );
848 $safeUsers[] = '[[' . $userTitle->getPrefixedText() . '|' . $userTitle->getText() . ']]';
849 $expirestr = $u->getId() ?
'indefinite' : '1 week';
850 $expiry = Block
::parseExpiryInput( $expirestr );
851 $anonOnly = IP
::isIPAddress( $u->getName() ) ?
1 : 0;
853 $block = new Block( $u->getName(), // victim
855 $wgUser->getId(), // blocker
857 wfTimestampNow(), // block time
860 $anonOnly, // anononly?
861 1, // block account creation?
864 0 // block from sending email?
866 $oldblock = Block
::newFromDB( $u->getName(), $u->getId() );
869 # Prepare log parameters
870 $logParams = array();
871 $logParams[] = $expirestr;
873 $logParams[] = 'anononly';
875 $logParams[] = 'nocreate';
877 $log->addEntry( 'block', $userTitle, $reason, $logParams );
879 # Tag userpage! (check length to avoid mistakes)
880 if( strlen( $tag ) > 2 ) {
881 $userpage->doEdit( $tag, $reason, EDIT_MINOR
);
883 if( strlen( $talkTag ) > 2 ) {
884 $usertalk->doEdit( $talkTag, $reason, EDIT_MINOR
);