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 $action = $wgRequest->getVal( 'action' );
29 if( 'success' == $action ) {
31 } elseif( $wgRequest->wasPosted() && 'submit' == $action &&
32 $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
40 * Form object for the Special:Blockip page.
42 * @ingroup SpecialPage
45 var $BlockAddress, $BlockExpiry, $BlockReason;
46 // The maximum number of edits a user can have and still be hidden
47 const HIDEUSER_CONTRIBLIMIT
= 1000;
49 public function __construct( $par ) {
50 global $wgRequest, $wgUser, $wgBlockAllowsUTEdit;
52 $this->BlockAddress
= $wgRequest->getVal( 'wpBlockAddress', $wgRequest->getVal( 'ip', $par ) );
53 $this->BlockAddress
= strtr( $this->BlockAddress
, '_', ' ' );
54 $this->BlockReason
= $wgRequest->getText( 'wpBlockReason' );
55 $this->BlockReasonList
= $wgRequest->getText( 'wpBlockReasonList' );
56 $this->BlockExpiry
= $wgRequest->getVal( 'wpBlockExpiry', wfMsg( 'ipbotheroption' ) );
57 $this->BlockOther
= $wgRequest->getVal( 'wpBlockOther', '' );
59 # Unchecked checkboxes are not included in the form data at all, so having one
60 # that is true by default is a bit tricky
61 $byDefault = !$wgRequest->wasPosted();
62 $this->BlockAnonOnly
= $wgRequest->getBool( 'wpAnonOnly', $byDefault );
63 $this->BlockCreateAccount
= $wgRequest->getBool( 'wpCreateAccount', $byDefault );
64 $this->BlockEnableAutoblock
= $wgRequest->getBool( 'wpEnableAutoblock', $byDefault );
65 $this->BlockEmail
= false;
66 if( self
::canBlockEmail( $wgUser ) ) {
67 $this->BlockEmail
= $wgRequest->getBool( 'wpEmailBan', false );
69 $this->BlockWatchUser
= $wgRequest->getBool( 'wpWatchUser', false );
70 # Re-check user's rights to hide names, very serious, defaults to 0
71 $this->BlockHideName
= ( $wgRequest->getBool( 'wpHideName', 0 ) && $wgUser->isAllowed( 'hideuser' ) ) ?
1 : 0;
72 $this->BlockAllowUsertalk
= ( $wgRequest->getBool( 'wpAllowUsertalk', $byDefault ) && $wgBlockAllowsUTEdit );
73 $this->BlockReblock
= $wgRequest->getBool( 'wpChangeBlock', false );
76 public function showForm( $err ) {
77 global $wgOut, $wgUser, $wgSysopUserBans;
79 $wgOut->setPageTitle( wfMsg( 'blockip' ) );
80 $wgOut->addWikiMsg( 'blockiptext' );
82 if( $wgSysopUserBans ) {
83 $mIpaddress = Xml
::label( wfMsg( 'ipadressorusername' ), 'mw-bi-target' );
85 $mIpaddress = Xml
::label( wfMsg( 'ipaddress' ), 'mw-bi-target' );
87 $mIpbexpiry = Xml
::label( wfMsg( 'ipbexpiry' ), 'wpBlockExpiry' );
88 $mIpbother = Xml
::label( wfMsg( 'ipbother' ), 'mw-bi-other' );
89 $mIpbreasonother = Xml
::label( wfMsg( 'ipbreason' ), 'wpBlockReasonList' );
90 $mIpbreason = Xml
::label( wfMsg( 'ipbotherreason' ), 'mw-bi-reason' );
92 $titleObj = SpecialPage
::getTitleFor( 'Blockip' );
93 $user = User
::newFromName( $this->BlockAddress
);
95 $alreadyBlocked = false;
96 if( $err && $err[0] != 'ipb_already_blocked' ) {
97 $key = array_shift( $err );
98 $msg = wfMsgReal( $key, $err );
99 $wgOut->setSubtitle( wfMsgHtml( 'formerror' ) );
100 $wgOut->addHTML( Xml
::tags( 'p', array( 'class' => 'error' ), $msg ) );
101 } elseif( $this->BlockAddress
) {
103 if( is_object( $user ) )
104 $userId = $user->getId();
105 $currentBlock = Block
::newFromDB( $this->BlockAddress
, $userId );
106 if( !is_null( $currentBlock ) && !$currentBlock->mAuto
&& # The block exists and isn't an autoblock
107 ( $currentBlock->mRangeStart
== $currentBlock->mRangeEnd ||
# The block isn't a rangeblock
108 # or if it is, the range is what we're about to block
109 ( $currentBlock->mAddress
== $this->BlockAddress
) ) ) {
110 $wgOut->addWikiMsg( 'ipb-needreblock', $this->BlockAddress
);
111 $alreadyBlocked = true;
112 # Set the block form settings to the existing block
113 $this->BlockAnonOnly
= $currentBlock->mAnonOnly
;
114 $this->BlockCreateAccount
= $currentBlock->mCreateAccount
;
115 $this->BlockEnableAutoblock
= $currentBlock->mEnableAutoblock
;
116 $this->BlockEmail
= $currentBlock->mBlockEmail
;
117 $this->BlockHideName
= $currentBlock->mHideName
;
118 $this->BlockAllowUsertalk
= $currentBlock->mAllowUsertalk
;
119 if( $currentBlock->mExpiry
== 'infinity' ) {
120 $this->BlockOther
= 'indefinite';
122 $this->BlockOther
= wfTimestamp( TS_ISO_8601
, $currentBlock->mExpiry
);
124 $this->BlockReason
= $currentBlock->mReason
;
128 $scBlockExpiryOptions = wfMsgForContent( 'ipboptions' );
130 $showblockoptions = $scBlockExpiryOptions != '-';
131 if( !$showblockoptions ) $mIpbother = $mIpbexpiry;
133 $blockExpiryFormOptions = Xml
::option( wfMsg( 'ipbotheroption' ), 'other' );
134 foreach( explode( ',', $scBlockExpiryOptions ) as $option ) {
135 if( strpos( $option, ':' ) === false ) $option = "$option:$option";
136 list( $show, $value ) = explode( ':', $option );
137 $show = htmlspecialchars( $show );
138 $value = htmlspecialchars( $value );
139 $blockExpiryFormOptions .= Xml
::option( $show, $value, $this->BlockExpiry
=== $value ?
true : false ) . "\n";
142 $reasonDropDown = Xml
::listDropDown( 'wpBlockReasonList',
143 wfMsgForContent( 'ipbreason-dropdown' ),
144 wfMsgForContent( 'ipbreasonotherlist' ), $this->BlockReasonList
, 'wpBlockDropDown', 4 );
146 global $wgStylePath, $wgStyleVersion;
148 Xml
::tags( 'script', array( 'type' => 'text/javascript', 'src' => "$wgStylePath/common/block.js?$wgStyleVersion" ), '' ) .
149 Xml
::openElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalURL( 'action=submit' ), 'id' => 'blockip' ) ) .
150 Xml
::openElement( 'fieldset' ) .
151 Xml
::element( 'legend', null, wfMsg( 'blockip-legend' ) ) .
152 Xml
::openElement( 'table', array( 'border' => '0', 'id' => 'mw-blockip-table' ) ) .
154 <td class='mw-label'>
157 <td class='mw-input'>" .
158 Html
::input( 'wpBlockAddress', $this->BlockAddress
, 'text', array(
160 'id' => 'mw-bi-target',
161 'onchange' => 'updateBlockOptions()',
164 ) +
( $this->BlockAddress ?
array() : array( 'autofocus' ) ) ). "
169 if( $showblockoptions ) {
171 <td class='mw-label'>
174 <td class='mw-input'>" .
177 'id' => 'wpBlockExpiry',
178 'name' => 'wpBlockExpiry',
179 'onchange' => 'considerChangingExpiryFocus()',
181 $blockExpiryFormOptions ) .
187 <tr id='wpBlockOther'>
188 <td class='mw-label'>
191 <td class='mw-input'>" .
192 Xml
::input( 'wpBlockOther', 45, $this->BlockOther
,
193 array( 'tabindex' => '3', 'id' => 'mw-bi-other' ) ) . "
197 <td class='mw-label'>
200 <td class='mw-input'>
204 <tr id=\"wpBlockReason\">
205 <td class='mw-label'>
208 <td class='mw-input'>" .
209 Html
::input( 'wpBlockReason', $this->BlockReason
, 'text', array(
211 'id' => 'mw-bi-reason',
212 'maxlength' => '200',
214 ) +
( $this->BlockAddress ?
array( 'autofocus' ) : array() ) ) . "
217 <tr id='wpAnonOnlyRow'>
219 <td class='mw-input'>" .
220 Xml
::checkLabel( wfMsg( 'ipbanononly' ),
221 'wpAnonOnly', 'wpAnonOnly', $this->BlockAnonOnly
,
222 array( 'tabindex' => '6' ) ) . "
225 <tr id='wpCreateAccountRow'>
227 <td class='mw-input'>" .
228 Xml
::checkLabel( wfMsg( 'ipbcreateaccount' ),
229 'wpCreateAccount', 'wpCreateAccount', $this->BlockCreateAccount
,
230 array( 'tabindex' => '7' ) ) . "
233 <tr id='wpEnableAutoblockRow'>
235 <td class='mw-input'>" .
236 Xml
::checkLabel( wfMsg( 'ipbenableautoblock' ),
237 'wpEnableAutoblock', 'wpEnableAutoblock', $this->BlockEnableAutoblock
,
238 array( 'tabindex' => '8' ) ) . "
243 if( self
::canBlockEmail( $wgUser ) ) {
245 <tr id='wpEnableEmailBan'>
247 <td class='mw-input'>" .
248 Xml
::checkLabel( wfMsg( 'ipbemailban' ),
249 'wpEmailBan', 'wpEmailBan', $this->BlockEmail
,
250 array( 'tabindex' => '9' ) ) . "
256 // Allow some users to hide name from block log, blocklist and listusers
257 if( $wgUser->isAllowed( 'hideuser' ) ) {
259 <tr id='wpEnableHideUser'>
261 <td class='mw-input'><strong>" .
262 Xml
::checkLabel( wfMsg( 'ipbhidename' ),
263 'wpHideName', 'wpHideName', $this->BlockHideName
,
264 array( 'tabindex' => '10' ) ) . "
270 # Watchlist their user page?
272 <tr id='wpEnableWatchUser'>
274 <td class='mw-input'>" .
275 Xml
::checkLabel( wfMsg( 'ipbwatchuser' ),
276 'wpWatchUser', 'wpWatchUser', $this->BlockWatchUser
,
277 array( 'tabindex' => '11' ) ) . "
282 # Can we explicitly disallow the use of user_talk?
283 global $wgBlockAllowsUTEdit;
284 if( $wgBlockAllowsUTEdit ){
286 <tr id='wpAllowUsertalkRow'>
288 <td class='mw-input'>" .
289 Xml
::checkLabel( wfMsg( 'ipballowusertalk' ),
290 'wpAllowUsertalk', 'wpAllowUsertalk', $this->BlockAllowUsertalk
,
291 array( 'tabindex' => '12' ) ) . "
299 <td style='padding-top: 1em'> </td>
300 <td class='mw-submit' style='padding-top: 1em'>" .
301 Xml
::submitButton( wfMsg( $alreadyBlocked ?
'ipb-change-block' : 'ipbsubmit' ),
302 array( 'name' => 'wpBlock', 'tabindex' => '13', 'accesskey' => 's' ) ) . "
305 Xml
::closeElement( 'table' ) .
306 Xml
::hidden( 'wpEditToken', $wgUser->editToken() ) .
307 ( $alreadyBlocked ? Xml
::hidden( 'wpChangeBlock', 1 ) : "" ) .
308 Xml
::closeElement( 'fieldset' ) .
309 Xml
::closeElement( 'form' ) .
310 Xml
::tags( 'script', array( 'type' => 'text/javascript' ), 'updateBlockOptions()' ) . "\n"
313 $wgOut->addHTML( $this->getConvenienceLinks() );
315 if( is_object( $user ) ) {
316 $this->showLogFragment( $wgOut, $user->getUserPage() );
317 } elseif( preg_match( '/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/', $this->BlockAddress
) ) {
318 $this->showLogFragment( $wgOut, Title
::makeTitle( NS_USER
, $this->BlockAddress
) );
319 } 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
) ) {
320 $this->showLogFragment( $wgOut, Title
::makeTitle( NS_USER
, $this->BlockAddress
) );
325 * Can we do an email block?
326 * @param User $user The sysop wanting to make a block
329 public static function canBlockEmail( $user ) {
330 global $wgEnableUserEmail, $wgSysopEmailBans;
331 return ( $wgEnableUserEmail && $wgSysopEmailBans && $user->isAllowed( 'blockemail' ) );
335 * Backend block code.
336 * $userID and $expiry will be filled accordingly
337 * @return array(message key, arguments) on failure, empty array on success
339 function doBlock( &$userId = null, &$expiry = null ) {
340 global $wgUser, $wgSysopUserBans, $wgSysopRangeBans, $wgBlockAllowsUTEdit;
343 # Expand valid IPv6 addresses, usernames are left as is
344 $this->BlockAddress
= IP
::sanitizeIP( $this->BlockAddress
);
345 # isIPv4() and IPv6() are used for final validation
346 $rxIP4 = '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}';
347 $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}';
348 $rxIP = "($rxIP4|$rxIP6)";
350 # Check for invalid specifications
351 if( !preg_match( "/^$rxIP$/", $this->BlockAddress
) ) {
353 if( preg_match( "/^($rxIP4)\\/(\\d{1,2})$/", $this->BlockAddress
, $matches ) ) {
355 if( $wgSysopRangeBans ) {
356 if( !IP
::isIPv4( $this->BlockAddress
) ||
$matches[2] < 16 ||
$matches[2] > 32 ) {
357 return array( 'ip_range_invalid' );
359 $this->BlockAddress
= Block
::normaliseRange( $this->BlockAddress
);
361 # Range block illegal
362 return array( 'range_block_disabled' );
364 } elseif( preg_match( "/^($rxIP6)\\/(\\d{1,3})$/", $this->BlockAddress
, $matches ) ) {
366 if( $wgSysopRangeBans ) {
367 if( !IP
::isIPv6( $this->BlockAddress
) ||
$matches[2] < 64 ||
$matches[2] > 128 ) {
368 return array( 'ip_range_invalid' );
370 $this->BlockAddress
= Block
::normaliseRange( $this->BlockAddress
);
372 # Range block illegal
373 return array('range_block_disabled');
377 if( $wgSysopUserBans ) {
378 $user = User
::newFromName( $this->BlockAddress
);
379 if( !is_null( $user ) && $user->getId() ) {
381 $userId = $user->getId();
382 $this->BlockAddress
= $user->getName();
384 return array( 'nosuchusershort', htmlspecialchars( $user ?
$user->getName() : $this->BlockAddress
) );
387 return array( 'badipaddress' );
392 if( $wgUser->isBlocked() && ( $wgUser->getId() !== $userId ) ) {
393 return array( 'cant-block-while-blocked' );
396 $reasonstr = $this->BlockReasonList
;
397 if( $reasonstr != 'other' && $this->BlockReason
!= '' ) {
398 // Entry from drop down menu + additional comment
399 $reasonstr .= wfMsgForContent( 'colon-separator' ) . $this->BlockReason
;
400 } elseif( $reasonstr == 'other' ) {
401 $reasonstr = $this->BlockReason
;
404 $expirestr = $this->BlockExpiry
;
405 if( $expirestr == 'other' )
406 $expirestr = $this->BlockOther
;
408 if( ( strlen( $expirestr ) == 0) ||
( strlen( $expirestr ) > 50 ) ) {
409 return array( 'ipb_expiry_invalid' );
412 if( false === ( $expiry = Block
::parseExpiryInput( $expirestr ) ) ) {
414 return array( 'ipb_expiry_invalid' );
417 if( $this->BlockHideName
) {
418 // Recheck params here...
419 if( !$userId ||
!$wgUser->isAllowed('hideuser') ) {
420 $this->BlockHideName
= false; // IP users should not be hidden
421 } elseif( $expiry !== 'infinity' ) {
423 return array( 'ipb_expiry_temp' );
424 } elseif( User
::edits( $userId ) > self
::HIDEUSER_CONTRIBLIMIT
) {
425 // Typically, the user should have a handful of edits.
426 // Disallow hiding users with many edits for performance.
427 return array( 'ipb_hide_invalid' );
431 # Create block object
432 # Note: for a user block, ipb_address is only for display purposes
433 $block = new Block( $this->BlockAddress
, $userId, $wgUser->getId(),
434 $reasonstr, wfTimestampNow(), 0, $expiry, $this->BlockAnonOnly
,
435 $this->BlockCreateAccount
, $this->BlockEnableAutoblock
, $this->BlockHideName
,
436 $this->BlockEmail
, isset( $this->BlockAllowUsertalk
) ?
$this->BlockAllowUsertalk
: $wgBlockAllowsUTEdit
439 # Should this be privately logged?
440 $suppressLog = (bool)$this->BlockHideName
;
441 if( wfRunHooks( 'BlockIp', array( &$block, &$wgUser ) ) ) {
442 # Try to insert block. Is there a conflicting block?
443 if( !$block->insert() ) {
444 # Show form unless the user is already aware of this...
445 if( !$this->BlockReblock
) {
446 return array( 'ipb_already_blocked' );
447 # Otherwise, try to update the block...
449 # This returns direct blocks before autoblocks/rangeblocks, since we should
450 # be sure the user is blocked by now it should work for our purposes
451 $currentBlock = Block
::newFromDB( $this->BlockAddress
, $userId );
452 if( $block->equals( $currentBlock ) ) {
453 return array( 'ipb_already_blocked' );
455 # If the name was hidden and the blocking user cannot hide
456 # names, then don't allow any block changes...
457 if( $currentBlock->mHideName
&& !$wgUser->isAllowed( 'hideuser' ) ) {
458 return array( 'cant-see-hidden-user' );
460 $currentBlock->delete();
462 # If hiding/unhiding a name, this should go in the private logs
463 $suppressLog = $suppressLog ||
(bool)$currentBlock->mHideName
;
464 $log_action = 'reblock';
465 # Unset _deleted fields if requested
466 if( $currentBlock->mHideName
&& !$this->BlockHideName
) {
467 self
::unsuppressUserName( $this->BlockAddress
, $userId );
471 $log_action = 'block';
473 wfRunHooks( 'BlockIpComplete', array( $block, $wgUser ) );
475 # Set *_deleted fields if requested
476 if( $this->BlockHideName
) {
477 self
::suppressUserName( $this->BlockAddress
, $userId );
480 # Only show watch link when this is no range block
481 if( $this->BlockWatchUser
&& $block->mRangeStart
== $block->mRangeEnd
) {
482 $wgUser->addWatch( Title
::makeTitle( NS_USER
, $this->BlockAddress
) );
485 # Block constructor sanitizes certain block options on insert
486 $this->BlockEmail
= $block->mBlockEmail
;
487 $this->BlockEnableAutoblock
= $block->mEnableAutoblock
;
489 # Prepare log parameters
490 $logParams = array();
491 $logParams[] = $expirestr;
492 $logParams[] = $this->blockLogFlags();
494 # Make log entry, if the name is hidden, put it in the oversight log
495 $log_type = $suppressLog ?
'suppress' : 'block';
496 $log = new LogPage( $log_type );
497 $log->addEntry( $log_action, Title
::makeTitle( NS_USER
, $this->BlockAddress
),
498 $reasonstr, $logParams );
503 return array( 'hookaborted' );
507 public static function suppressUserName( $name, $userId ) {
508 $op = '|'; // bitwise OR
509 return self
::setUsernameBitfields( $name, $userId, $op );
512 public static function unsuppressUserName( $name, $userId ) {
513 $op = '&'; // bitwise AND
514 return self
::setUsernameBitfields( $name, $userId, $op );
517 private static function setUsernameBitfields( $name, $userId, $op ) {
518 if( $op !== '|' && $op !== '&' ) return false; // sanity check
519 $dbw = wfGetDB( DB_MASTER
);
520 $delUser = Revision
::DELETED_USER | Revision
::DELETED_RESTRICTED
;
521 $delAction = LogPage
::DELETED_ACTION | Revision
::DELETED_RESTRICTED
;
522 # Normalize user name
523 $userTitle = Title
::makeTitleSafe( NS_USER
, $name );
524 $userDbKey = $userTitle->getDBkey();
525 # To suppress, we OR the current bitfields with Revision::DELETED_USER
526 # to put a 1 in the username *_deleted bit. To unsuppress we AND the
527 # current bitfields with the inverse of Revision::DELETED_USER. The
528 # username bit is made to 0 (x & 0 = 0), while others are unchanged (x & 1 = x).
529 # The same goes for the sysop-restricted *_deleted bit.
531 $delUser = "~{$delUser}";
532 $delAction = "~{$delAction}";
534 # Hide name from live edits
535 $dbw->update( 'revision', array( "rev_deleted = rev_deleted $op $delUser" ),
536 array( 'rev_user' => $userId ), __METHOD__
);
537 # Hide name from deleted edits
538 $dbw->update( 'archive', array( "ar_deleted = ar_deleted $op $delUser" ),
539 array( 'ar_user_text' => $name ), __METHOD__
);
540 # Hide name from logs
541 $dbw->update( 'logging', array( "log_deleted = log_deleted $op $delUser" ),
542 array( 'log_user' => $userId, "log_type != 'suppress'" ), __METHOD__
);
543 $dbw->update( 'logging', array( "log_deleted = log_deleted $op $delAction" ),
544 array( 'log_namespace' => NS_USER
, 'log_title' => $userDbKey,
545 "log_type != 'suppress'" ), __METHOD__
);
547 $dbw->update( 'recentchanges', array( "rc_deleted = rc_deleted $op $delUser" ),
548 array( 'rc_user_text' => $name ), __METHOD__
);
549 $dbw->update( 'recentchanges', array( "rc_deleted = rc_deleted $op $delAction" ),
550 array( 'rc_namespace' => NS_USER
, 'rc_title' => $userDbKey, 'rc_logid > 0' ), __METHOD__
);
551 # Hide name from live images
552 $dbw->update( 'oldimage', array( "oi_deleted = oi_deleted $op $delUser" ),
553 array( 'oi_user_text' => $name ), __METHOD__
);
554 # Hide name from deleted images
555 # WMF - schema change pending
556 # $dbw->update( 'filearchive', array( "fa_deleted = fa_deleted $op $delUser" ),
557 # array( 'fa_user_text' => $name ), __METHOD__ );
563 * UI entry point for blocking
564 * Wraps around doBlock()
566 public function doSubmit() {
568 $retval = $this->doBlock();
569 if( empty( $retval ) ) {
570 $titleObj = SpecialPage
::getTitleFor( 'Blockip' );
571 $wgOut->redirect( $titleObj->getFullURL( 'action=success&ip=' .
572 urlencode( $this->BlockAddress
) ) );
575 $this->showForm( $retval );
578 public function showSuccess() {
581 $wgOut->setPageTitle( wfMsg( 'blockip' ) );
582 $wgOut->setSubtitle( wfMsg( 'blockipsuccesssub' ) );
583 $text = wfMsgExt( 'blockipsuccesstext', array( 'parse' ), $this->BlockAddress
);
584 $wgOut->addHTML( $text );
587 private function showLogFragment( $out, $title ) {
590 // Used to support GENDER in 'blocklog-showlog' and 'blocklog-showsuppresslog'
591 $userBlocked = $title->getText();
593 LogEventsList
::showLogExtract(
596 $title->getPrefixedText(),
604 'showIfEmpty' => false
608 // Add suppression block entries if allowed
609 if( $wgUser->isAllowed( 'hideuser' ) ) {
610 LogEventsList
::showLogExtract( $out, 'suppress', $title->getPrefixedText(), '',
614 'log_action' => array(
621 'blocklog-showsuppresslog',
624 'showIfEmpty' => false
631 * Return a comma-delimited list of "flags" to be passed to the log
632 * reader for this block, to provide more information in the logs
636 private function blockLogFlags() {
637 global $wgBlockAllowsUTEdit;
639 if( $this->BlockAnonOnly
&& IP
::isIPAddress( $this->BlockAddress
) )
640 // when blocking a user the option 'anononly' is not available/has no effect -> do not write this into log
641 $flags[] = 'anononly';
642 if( $this->BlockCreateAccount
)
643 $flags[] = 'nocreate';
644 if( !$this->BlockEnableAutoblock
&& !IP
::isIPAddress( $this->BlockAddress
) )
645 // Same as anononly, this is not displayed when blocking an IP address
646 $flags[] = 'noautoblock';
647 if( $this->BlockEmail
)
648 $flags[] = 'noemail';
649 if( !$this->BlockAllowUsertalk
&& $wgBlockAllowsUTEdit )
650 $flags[] = 'nousertalk';
651 if( $this->BlockHideName
)
652 $flags[] = 'hiddenname';
653 return implode( ',', $flags );
657 * Builds unblock and block list links
661 private function getConvenienceLinks() {
662 global $wgUser, $wgLang;
663 $skin = $wgUser->getSkin();
664 if( $this->BlockAddress
)
665 $links[] = $this->getContribsLink( $skin );
666 $links[] = $this->getUnblockLink( $skin );
667 $links[] = $this->getBlockListLink( $skin );
668 $title = Title
::makeTitle( NS_MEDIAWIKI
, 'Ipbreason-dropdown' );
669 $links[] = $skin->link(
671 wfMsgHtml( 'ipb-edit-dropdown' ),
673 array( 'action' => 'edit' )
675 return '<p class="mw-ipb-conveniencelinks">' . $wgLang->pipeList( $links ) . '</p>';
679 * Build a convenient link to a user or IP's contribs
682 * @param $skin Skin to use
685 private function getContribsLink( $skin ) {
686 $contribsPage = SpecialPage
::getTitleFor( 'Contributions', $this->BlockAddress
);
687 return $skin->link( $contribsPage, wfMsgExt( 'ipb-blocklist-contribs', 'escape', $this->BlockAddress
) );
691 * Build a convenient link to unblock the given username or IP
692 * address, if available; otherwise link to a blank unblock
695 * @param $skin Skin to use
698 private function getUnblockLink( $skin ) {
699 $list = SpecialPage
::getTitleFor( 'Ipblocklist' );
700 $query = array( 'action' => 'unblock' );
702 if( $this->BlockAddress
) {
703 $addr = strtr( $this->BlockAddress
, '_', ' ' );
704 $message = wfMsg( 'ipb-unblock-addr', $addr );
705 $query['ip'] = $this->BlockAddress
;
707 $message = wfMsg( 'ipb-unblock' );
709 return $skin->linkKnown(
711 htmlspecialchars( $message ),
718 * Build a convenience link to the block list
720 * @param $skin Skin to use
723 private function getBlockListLink( $skin ) {
724 $list = SpecialPage
::getTitleFor( 'Ipblocklist' );
727 if( $this->BlockAddress
) {
728 $addr = strtr( $this->BlockAddress
, '_', ' ' );
729 $message = wfMsg( 'ipb-blocklist-addr', $addr );
730 $query['ip'] = $this->BlockAddress
;
732 $message = wfMsg( 'ipb-blocklist' );
735 return $skin->linkKnown(
737 htmlspecialchars( $message ),
744 * Block a list of selected users
745 * @param array $users
746 * @param string $reason
747 * @param string $tag replaces user pages
748 * @param string $talkTag replaces user talk pages
749 * @returns array, list of html-safe usernames
751 public static function doMassUserBlock( $users, $reason = '', $tag = '', $talkTag = '' ) {
753 $counter = $blockSize = 0;
754 $safeUsers = array();
755 $log = new LogPage( 'block' );
756 foreach( $users as $name ) {
760 # Lets not go *too* fast
761 if( $blockSize >= 20 ) {
763 wfWaitForSlaves( 5 );
765 $u = User
::newFromName( $name, false );
766 // If user doesn't exist, it ought to be an IP then
767 if( is_null( $u ) ||
( !$u->getId() && !IP
::isIPAddress( $u->getName() ) ) ) {
770 $userTitle = $u->getUserPage();
771 $userTalkTitle = $u->getTalkPage();
772 $userpage = new Article( $userTitle );
773 $usertalk = new Article( $userTalkTitle );
774 $safeUsers[] = '[[' . $userTitle->getPrefixedText() . '|' . $userTitle->getText() . ']]';
775 $expirestr = $u->getId() ?
'indefinite' : '1 week';
776 $expiry = Block
::parseExpiryInput( $expirestr );
777 $anonOnly = IP
::isIPAddress( $u->getName() ) ?
1 : 0;
779 $block = new Block( $u->getName(), // victim
781 $wgUser->getId(), // blocker
783 wfTimestampNow(), // block time
786 $anonOnly, // anononly?
787 1, // block account creation?
790 0 // block from sending email?
792 $oldblock = Block
::newFromDB( $u->getName(), $u->getId() );
795 # Prepare log parameters
796 $logParams = array();
797 $logParams[] = $expirestr;
799 $logParams[] = 'anononly';
801 $logParams[] = 'nocreate';
803 $log->addEntry( 'block', $userTitle, $reason, $logParams );
805 # Tag userpage! (check length to avoid mistakes)
806 if( strlen( $tag ) > 2 ) {
807 $userpage->doEdit( $tag, $reason, EDIT_MINOR
);
809 if( strlen( $talkTag ) > 2 ) {
810 $usertalk->doEdit( $talkTag, $reason, EDIT_MINOR
);