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
&& $user->getId() == $wgUser->getId() ) {
386 # User is trying to unblock themselves
387 if ( $wgUser->isAllowed( 'unblockself' ) ) {
390 return 'ipbnounblockself';
393 # User is trying to block/unblock someone else
399 * Backend block code.
400 * $userID and $expiry will be filled accordingly
401 * @return array(message key, arguments) on failure, empty array on success
403 function doBlock( &$userId = null, &$expiry = null ) {
404 global $wgUser, $wgSysopUserBans, $wgSysopRangeBans, $wgBlockAllowsUTEdit, $wgBlockCIDRLimit;
407 # Expand valid IPv6 addresses, usernames are left as is
408 $this->BlockAddress
= IP
::sanitizeIP( $this->BlockAddress
);
409 # isIPv4() and IPv6() are used for final validation
410 $rxIP4 = '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}';
411 $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}';
412 $rxIP = "($rxIP4|$rxIP6)";
414 # Check for invalid specifications
415 if( !preg_match( "/^$rxIP$/", $this->BlockAddress
) ) {
417 if( preg_match( "/^($rxIP4)\\/(\\d{1,2})$/", $this->BlockAddress
, $matches ) ) {
419 if( $wgSysopRangeBans ) {
420 if( !IP
::isIPv4( $this->BlockAddress
) ||
$matches[2] > 32 ) {
421 return array( 'ip_range_invalid' );
422 } elseif ( $matches[2] < $wgBlockCIDRLimit['IPv4'] ) {
423 return array( 'ip_range_toolarge', $wgBlockCIDRLimit['IPv4'] );
425 $this->BlockAddress
= Block
::normaliseRange( $this->BlockAddress
);
427 # Range block illegal
428 return array( 'range_block_disabled' );
430 } elseif( preg_match( "/^($rxIP6)\\/(\\d{1,3})$/", $this->BlockAddress
, $matches ) ) {
432 if( $wgSysopRangeBans ) {
433 if( !IP
::isIPv6( $this->BlockAddress
) ||
$matches[2] > 128 ) {
434 return array( 'ip_range_invalid' );
435 } elseif( $matches[2] < $wgBlockCIDRLimit['IPv6'] ) {
436 return array( 'ip_range_toolarge', $wgBlockCIDRLimit['IPv6'] );
438 $this->BlockAddress
= Block
::normaliseRange( $this->BlockAddress
);
440 # Range block illegal
441 return array('range_block_disabled');
445 if( $wgSysopUserBans ) {
446 $user = User
::newFromName( $this->BlockAddress
);
447 if( $user instanceof User
&& $user->getId() ) {
449 $userId = $user->getId();
450 $this->BlockAddress
= $user->getName();
452 return array( 'nosuchusershort', htmlspecialchars( $user ?
$user->getName() : $this->BlockAddress
) );
455 return array( 'badipaddress' );
460 if( $wgUser->isBlocked() && ( $wgUser->getId() !== $userId ) ) {
461 return array( 'cant-block-while-blocked' );
464 $reasonstr = $this->BlockReasonList
;
465 if( $reasonstr != 'other' && $this->BlockReason
!= '' ) {
466 // Entry from drop down menu + additional comment
467 $reasonstr .= wfMsgForContent( 'colon-separator' ) . $this->BlockReason
;
468 } elseif( $reasonstr == 'other' ) {
469 $reasonstr = $this->BlockReason
;
472 $expirestr = $this->BlockExpiry
;
473 if( $expirestr == 'other' )
474 $expirestr = $this->BlockOther
;
476 if( ( strlen( $expirestr ) == 0) ||
( strlen( $expirestr ) > 50 ) ) {
477 return array( 'ipb_expiry_invalid' );
480 if( false === ( $expiry = Block
::parseExpiryInput( $expirestr ) ) ) {
482 return array( 'ipb_expiry_invalid' );
485 if( $this->BlockHideName
) {
486 // Recheck params here...
487 if( !$userId ||
!$wgUser->isAllowed('hideuser') ) {
488 $this->BlockHideName
= false; // IP users should not be hidden
489 } elseif( $expiry !== 'infinity' ) {
491 return array( 'ipb_expiry_temp' );
492 } elseif( User
::edits( $userId ) > self
::HIDEUSER_CONTRIBLIMIT
) {
493 // Typically, the user should have a handful of edits.
494 // Disallow hiding users with many edits for performance.
495 return array( 'ipb_hide_invalid' );
499 # Create block object
500 # Note: for a user block, ipb_address is only for display purposes
501 $block = new Block( $this->BlockAddress
, $userId, $wgUser->getId(),
502 $reasonstr, wfTimestampNow(), 0, $expiry, $this->BlockAnonOnly
,
503 $this->BlockCreateAccount
, $this->BlockEnableAutoblock
, $this->BlockHideName
,
505 isset( $this->BlockAllowUsertalk
) ?
$this->BlockAllowUsertalk
: $wgBlockAllowsUTEdit
508 # Should this be privately logged?
509 $suppressLog = (bool)$this->BlockHideName
;
510 if( wfRunHooks( 'BlockIp', array( &$block, &$wgUser ) ) ) {
511 # Try to insert block. Is there a conflicting block?
512 if( !$block->insert() ) {
513 # Show form unless the user is already aware of this...
514 if( !$this->BlockReblock
) {
515 return array( 'ipb_already_blocked' );
516 # Otherwise, try to update the block...
518 # This returns direct blocks before autoblocks/rangeblocks, since we should
519 # be sure the user is blocked by now it should work for our purposes
520 $currentBlock = Block
::newFromDB( $this->BlockAddress
, $userId );
521 if( $block->equals( $currentBlock ) ) {
522 return array( 'ipb_already_blocked' );
524 # If the name was hidden and the blocking user cannot hide
525 # names, then don't allow any block changes...
526 if( $currentBlock->mHideName
&& !$wgUser->isAllowed( 'hideuser' ) ) {
527 return array( 'cant-see-hidden-user' );
529 $currentBlock->delete();
531 # If hiding/unhiding a name, this should go in the private logs
532 $suppressLog = $suppressLog ||
(bool)$currentBlock->mHideName
;
533 $log_action = 'reblock';
534 # Unset _deleted fields if requested
535 if( $currentBlock->mHideName
&& !$this->BlockHideName
) {
536 self
::unsuppressUserName( $this->BlockAddress
, $userId );
540 $log_action = 'block';
542 wfRunHooks( 'BlockIpComplete', array( $block, $wgUser ) );
544 # Set *_deleted fields if requested
545 if( $this->BlockHideName
) {
546 self
::suppressUserName( $this->BlockAddress
, $userId );
549 # Only show watch link when this is no range block
550 if( $this->BlockWatchUser
&& $block->mRangeStart
== $block->mRangeEnd
) {
551 $wgUser->addWatch( Title
::makeTitle( NS_USER
, $this->BlockAddress
) );
554 # Block constructor sanitizes certain block options on insert
555 $this->BlockEmail
= $block->mBlockEmail
;
556 $this->BlockEnableAutoblock
= $block->mEnableAutoblock
;
558 # Prepare log parameters
559 $logParams = array();
560 $logParams[] = $expirestr;
561 $logParams[] = $this->blockLogFlags();
563 # Make log entry, if the name is hidden, put it in the oversight log
564 $log_type = $suppressLog ?
'suppress' : 'block';
565 $log = new LogPage( $log_type );
566 $log->addEntry( $log_action, Title
::makeTitle( NS_USER
, $this->BlockAddress
),
567 $reasonstr, $logParams );
572 return array( 'hookaborted' );
576 public static function suppressUserName( $name, $userId, $dbw = null ) {
577 $op = '|'; // bitwise OR
578 return self
::setUsernameBitfields( $name, $userId, $op, $dbw );
581 public static function unsuppressUserName( $name, $userId, $dbw = null ) {
582 $op = '&'; // bitwise AND
583 return self
::setUsernameBitfields( $name, $userId, $op, $dbw );
586 private static function setUsernameBitfields( $name, $userId, $op, $dbw ) {
587 if( $op !== '|' && $op !== '&' ) return false; // sanity check
589 $dbw = wfGetDB( DB_MASTER
);
590 $delUser = Revision
::DELETED_USER | Revision
::DELETED_RESTRICTED
;
591 $delAction = LogPage
::DELETED_ACTION | Revision
::DELETED_RESTRICTED
;
592 # Normalize user name
593 $userTitle = Title
::makeTitleSafe( NS_USER
, $name );
594 $userDbKey = $userTitle->getDBkey();
595 # To suppress, we OR the current bitfields with Revision::DELETED_USER
596 # to put a 1 in the username *_deleted bit. To unsuppress we AND the
597 # current bitfields with the inverse of Revision::DELETED_USER. The
598 # username bit is made to 0 (x & 0 = 0), while others are unchanged (x & 1 = x).
599 # The same goes for the sysop-restricted *_deleted bit.
601 $delUser = "~{$delUser}";
602 $delAction = "~{$delAction}";
604 # Hide name from live edits
605 $dbw->update( 'revision', array( "rev_deleted = rev_deleted $op $delUser" ),
606 array( 'rev_user' => $userId ), __METHOD__
);
607 # Hide name from deleted edits
608 $dbw->update( 'archive', array( "ar_deleted = ar_deleted $op $delUser" ),
609 array( 'ar_user_text' => $name ), __METHOD__
);
610 # Hide name from logs
611 $dbw->update( 'logging', array( "log_deleted = log_deleted $op $delUser" ),
612 array( 'log_user' => $userId, "log_type != 'suppress'" ), __METHOD__
);
613 $dbw->update( 'logging', array( "log_deleted = log_deleted $op $delAction" ),
614 array( 'log_namespace' => NS_USER
, 'log_title' => $userDbKey,
615 "log_type != 'suppress'" ), __METHOD__
);
617 $dbw->update( 'recentchanges', array( "rc_deleted = rc_deleted $op $delUser" ),
618 array( 'rc_user_text' => $name ), __METHOD__
);
619 $dbw->update( 'recentchanges', array( "rc_deleted = rc_deleted $op $delAction" ),
620 array( 'rc_namespace' => NS_USER
, 'rc_title' => $userDbKey, 'rc_logid > 0' ), __METHOD__
);
621 # Hide name from live images
622 $dbw->update( 'oldimage', array( "oi_deleted = oi_deleted $op $delUser" ),
623 array( 'oi_user_text' => $name ), __METHOD__
);
624 # Hide name from deleted images
625 # WMF - schema change pending
626 # $dbw->update( 'filearchive', array( "fa_deleted = fa_deleted $op $delUser" ),
627 # array( 'fa_user_text' => $name ), __METHOD__ );
633 * UI entry point for blocking
634 * Wraps around doBlock()
636 public function doSubmit() {
638 $retval = $this->doBlock();
639 if( empty( $retval ) ) {
640 $titleObj = SpecialPage
::getTitleFor( 'Blockip' );
641 $wgOut->redirect( $titleObj->getFullURL( 'action=success&ip=' .
642 urlencode( $this->BlockAddress
) ) );
645 $this->showForm( $retval );
648 public function showSuccess() {
651 $wgOut->setPageTitle( wfMsg( 'blockip-title' ) );
652 $wgOut->setSubtitle( wfMsg( 'blockipsuccesssub' ) );
653 $text = wfMsgExt( 'blockipsuccesstext', array( 'parse' ), $this->BlockAddress
);
654 $wgOut->addHTML( $text );
657 private function showLogFragment( $out, $title ) {
660 // Used to support GENDER in 'blocklog-showlog' and 'blocklog-showsuppresslog'
661 $userBlocked = $title->getText();
663 LogEventsList
::showLogExtract(
666 $title->getPrefixedText(),
674 'showIfEmpty' => false
678 // Add suppression block entries if allowed
679 if( $wgUser->isAllowed( 'suppressionlog' ) ) {
680 LogEventsList
::showLogExtract( $out, 'suppress', $title->getPrefixedText(), '',
684 'log_action' => array(
691 'blocklog-showsuppresslog',
694 'showIfEmpty' => false
701 * Return a comma-delimited list of "flags" to be passed to the log
702 * reader for this block, to provide more information in the logs
706 private function blockLogFlags() {
707 global $wgBlockAllowsUTEdit;
709 if( $this->BlockAnonOnly
&& IP
::isIPAddress( $this->BlockAddress
) )
710 // when blocking a user the option 'anononly' is not available/has no effect -> do not write this into log
711 $flags[] = 'anononly';
712 if( $this->BlockCreateAccount
)
713 $flags[] = 'nocreate';
714 if( !$this->BlockEnableAutoblock
&& !IP
::isIPAddress( $this->BlockAddress
) )
715 // Same as anononly, this is not displayed when blocking an IP address
716 $flags[] = 'noautoblock';
717 if( $this->BlockEmail
)
718 $flags[] = 'noemail';
719 if( !$this->BlockAllowUsertalk
&& $wgBlockAllowsUTEdit )
720 $flags[] = 'nousertalk';
721 if( $this->BlockHideName
)
722 $flags[] = 'hiddenname';
723 return implode( ',', $flags );
727 * Builds unblock and block list links
731 private function getConvenienceLinks() {
732 global $wgUser, $wgLang;
733 $skin = $wgUser->getSkin();
734 if( $this->BlockAddress
)
735 $links[] = $this->getContribsLink( $skin );
736 $links[] = $this->getUnblockLink( $skin );
737 $links[] = $this->getBlockListLink( $skin );
738 if ( $wgUser->isAllowed( 'editinterface' ) ) {
739 $title = Title
::makeTitle( NS_MEDIAWIKI
, 'Ipbreason-dropdown' );
740 $links[] = $skin->link(
742 wfMsgHtml( 'ipb-edit-dropdown' ),
744 array( 'action' => 'edit' )
747 return '<p class="mw-ipb-conveniencelinks">' . $wgLang->pipeList( $links ) . '</p>';
751 * Build a convenient link to a user or IP's contribs
754 * @param $skin Skin to use
757 private function getContribsLink( $skin ) {
758 $contribsPage = SpecialPage
::getTitleFor( 'Contributions', $this->BlockAddress
);
759 return $skin->link( $contribsPage, wfMsgExt( 'ipb-blocklist-contribs', 'escape', $this->BlockAddress
) );
763 * Build a convenient link to unblock the given username or IP
764 * address, if available; otherwise link to a blank unblock
767 * @param $skin Skin to use
770 private function getUnblockLink( $skin ) {
771 $list = SpecialPage
::getTitleFor( 'Ipblocklist' );
772 $query = array( 'action' => 'unblock' );
774 if( $this->BlockAddress
) {
775 $addr = strtr( $this->BlockAddress
, '_', ' ' );
776 $message = wfMsg( 'ipb-unblock-addr', $addr );
777 $query['ip'] = $this->BlockAddress
;
779 $message = wfMsg( 'ipb-unblock' );
781 return $skin->linkKnown(
783 htmlspecialchars( $message ),
790 * Build a convenience link to the block list
792 * @param $skin Skin to use
795 private function getBlockListLink( $skin ) {
796 $list = SpecialPage
::getTitleFor( 'Ipblocklist' );
799 if( $this->BlockAddress
) {
800 $addr = strtr( $this->BlockAddress
, '_', ' ' );
801 $message = wfMsg( 'ipb-blocklist-addr', $addr );
802 $query['ip'] = $this->BlockAddress
;
804 $message = wfMsg( 'ipb-blocklist' );
807 return $skin->linkKnown(
809 htmlspecialchars( $message ),
816 * Block a list of selected users
817 * @param array $users
818 * @param string $reason
819 * @param string $tag replaces user pages
820 * @param string $talkTag replaces user talk pages
821 * @returns array, list of html-safe usernames
823 public static function doMassUserBlock( $users, $reason = '', $tag = '', $talkTag = '' ) {
825 $counter = $blockSize = 0;
826 $safeUsers = array();
827 $log = new LogPage( 'block' );
828 foreach( $users as $name ) {
832 # Lets not go *too* fast
833 if( $blockSize >= 20 ) {
835 wfWaitForSlaves( 5 );
837 $u = User
::newFromName( $name, false );
838 // If user doesn't exist, it ought to be an IP then
839 if( is_null( $u ) ||
( !$u->getId() && !IP
::isIPAddress( $u->getName() ) ) ) {
842 $userTitle = $u->getUserPage();
843 $userTalkTitle = $u->getTalkPage();
844 $userpage = new Article( $userTitle );
845 $usertalk = new Article( $userTalkTitle );
846 $safeUsers[] = '[[' . $userTitle->getPrefixedText() . '|' . $userTitle->getText() . ']]';
847 $expirestr = $u->getId() ?
'indefinite' : '1 week';
848 $expiry = Block
::parseExpiryInput( $expirestr );
849 $anonOnly = IP
::isIPAddress( $u->getName() ) ?
1 : 0;
851 $block = new Block( $u->getName(), // victim
853 $wgUser->getId(), // blocker
855 wfTimestampNow(), // block time
858 $anonOnly, // anononly?
859 1, // block account creation?
862 0 // block from sending email?
864 $oldblock = Block
::newFromDB( $u->getName(), $u->getId() );
867 # Prepare log parameters
868 $logParams = array();
869 $logParams[] = $expirestr;
871 $logParams[] = 'anononly';
873 $logParams[] = 'nocreate';
875 $log->addEntry( 'block', $userTitle, $reason, $logParams );
877 # Tag userpage! (check length to avoid mistakes)
878 if( strlen( $tag ) > 2 ) {
879 $userpage->doEdit( $tag, $reason, EDIT_MINOR
);
881 if( strlen( $talkTag ) > 2 ) {
882 $usertalk->doEdit( $talkTag, $reason, EDIT_MINOR
);