3 * Constructor for Special:Blockip page
12 function wfSpecialBlockip( $par ) {
13 global $wgUser, $wgOut, $wgRequest;
14 # Can't block when the database is locked
16 $wgOut->readOnlyPage();
20 if( !$wgUser->isAllowed( 'block' ) ) {
21 $wgOut->permissionRequired( 'block' );
25 $ipb = new IPBlockForm( $par );
27 $action = $wgRequest->getVal( 'action' );
28 if( 'success' == $action ) {
30 } else if( $wgRequest->wasPosted() && 'submit' == $action &&
31 $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
39 * Form object for the Special:Blockip page.
41 * @ingroup SpecialPage
44 var $BlockAddress, $BlockExpiry, $BlockReason;
45 // The maximum number of edits a user can have and still be hidden
46 const HIDEUSER_CONTRIBLIMIT
= 1000;
48 public function __construct( $par ) {
49 global $wgRequest, $wgUser, $wgBlockAllowsUTEdit;
51 $this->BlockAddress
= $wgRequest->getVal( 'wpBlockAddress', $wgRequest->getVal( 'ip', $par ) );
52 $this->BlockAddress
= strtr( $this->BlockAddress
, '_', ' ' );
53 $this->BlockReason
= $wgRequest->getText( 'wpBlockReason' );
54 $this->BlockReasonList
= $wgRequest->getText( 'wpBlockReasonList' );
55 $this->BlockExpiry
= $wgRequest->getVal( 'wpBlockExpiry', wfMsg('ipbotheroption') );
56 $this->BlockOther
= $wgRequest->getVal( 'wpBlockOther', '' );
58 # Unchecked checkboxes are not included in the form data at all, so having one
59 # that is true by default is a bit tricky
60 $byDefault = !$wgRequest->wasPosted();
61 $this->BlockAnonOnly
= $wgRequest->getBool( 'wpAnonOnly', $byDefault );
62 $this->BlockCreateAccount
= $wgRequest->getBool( 'wpCreateAccount', $byDefault );
63 $this->BlockEnableAutoblock
= $wgRequest->getBool( 'wpEnableAutoblock', $byDefault );
64 $this->BlockEmail
= false;
65 if( self
::canBlockEmail( $wgUser ) ) {
66 $this->BlockEmail
= $wgRequest->getBool( 'wpEmailBan', false );
68 $this->BlockWatchUser
= $wgRequest->getBool( 'wpWatchUser', false );
69 # Re-check user's rights to hide names, very serious, defaults to 0
70 $this->BlockHideName
= ( $wgRequest->getBool( 'wpHideName', 0 ) && $wgUser->isAllowed( 'hideuser' ) ) ?
1 : 0;
71 $this->BlockAllowUsertalk
= ( $wgRequest->getBool( 'wpAllowUsertalk', $byDefault ) && $wgBlockAllowsUTEdit );
72 $this->BlockReblock
= $wgRequest->getBool( 'wpChangeBlock', false );
75 public function showForm( $err ) {
76 global $wgOut, $wgUser, $wgSysopUserBans;
78 $wgOut->setPagetitle( wfMsg( 'blockip' ) );
79 $wgOut->addWikiMsg( 'blockiptext' );
81 if($wgSysopUserBans) {
82 $mIpaddress = Xml
::label( wfMsg( 'ipadressorusername' ), 'mw-bi-target' );
84 $mIpaddress = Xml
::label( wfMsg( 'ipaddress' ), 'mw-bi-target' );
86 $mIpbexpiry = Xml
::label( wfMsg( 'ipbexpiry' ), 'wpBlockExpiry' );
87 $mIpbother = Xml
::label( wfMsg( 'ipbother' ), 'mw-bi-other' );
88 $mIpbreasonother = Xml
::label( wfMsg( 'ipbreason' ), 'wpBlockReasonList' );
89 $mIpbreason = Xml
::label( wfMsg( 'ipbotherreason' ), 'mw-bi-reason' );
91 $titleObj = SpecialPage
::getTitleFor( 'Blockip' );
92 $user = User
::newFromName( $this->BlockAddress
);
94 $alreadyBlocked = false;
95 if( $err && $err[0] != 'ipb_already_blocked' ) {
96 $key = array_shift($err);
97 $msg = wfMsgReal($key, $err);
98 $wgOut->setSubtitle( wfMsgHtml( 'formerror' ) );
99 $wgOut->addHTML( Xml
::tags( 'p', array( 'class' => 'error' ), $msg ) );
100 } elseif( $this->BlockAddress
) {
102 if( is_object( $user ) )
103 $userId = $user->getId();
104 $currentBlock = Block
::newFromDB( $this->BlockAddress
, $userId );
105 if( !is_null($currentBlock) && !$currentBlock->mAuto
&& # The block exists and isn't an autoblock
106 ( $currentBlock->mRangeStart
== $currentBlock->mRangeEnd ||
# The block isn't a rangeblock
107 # or if it is, the range is what we're about to block
108 ( $currentBlock->mAddress
== $this->BlockAddress
) ) ) {
109 $wgOut->addWikiMsg( 'ipb-needreblock', $this->BlockAddress
);
110 $alreadyBlocked = true;
111 # Set the block form settings to the existing block
112 $this->BlockAnonOnly
= $currentBlock->mAnonOnly
;
113 $this->BlockCreateAccount
= $currentBlock->mCreateAccount
;
114 $this->BlockEnableAutoblock
= $currentBlock->mEnableAutoblock
;
115 $this->BlockEmail
= $currentBlock->mBlockEmail
;
116 $this->BlockHideName
= $currentBlock->mHideName
;
117 $this->BlockAllowUsertalk
= $currentBlock->mAllowUsertalk
;
118 if( $currentBlock->mExpiry
== 'infinity' ) {
119 $this->BlockOther
= 'indefinite';
121 $this->BlockOther
= wfTimestamp( TS_ISO_8601
, $currentBlock->mExpiry
);
123 $this->BlockReason
= $currentBlock->mReason
;
127 $scBlockExpiryOptions = wfMsgForContent( 'ipboptions' );
129 $showblockoptions = $scBlockExpiryOptions != '-';
130 if( !$showblockoptions ) $mIpbother = $mIpbexpiry;
132 $blockExpiryFormOptions = Xml
::option( wfMsg( 'ipbotheroption' ), 'other' );
133 foreach (explode(',', $scBlockExpiryOptions) as $option) {
134 if( strpos($option, ":") === false ) $option = "$option:$option";
135 list($show, $value) = explode(":", $option);
136 $show = htmlspecialchars($show);
137 $value = htmlspecialchars($value);
138 $blockExpiryFormOptions .= Xml
::option( $show, $value, $this->BlockExpiry
=== $value ?
true : false ) . "\n";
141 $reasonDropDown = Xml
::listDropDown( 'wpBlockReasonList',
142 wfMsgForContent( 'ipbreason-dropdown' ),
143 wfMsgForContent( 'ipbreasonotherlist' ), $this->BlockReasonList
, 'wpBlockDropDown', 4 );
145 global $wgStylePath, $wgStyleVersion;
147 Xml
::tags( 'script', array( 'type' => 'text/javascript', 'src' => "$wgStylePath/common/block.js?$wgStyleVersion" ), '' ) .
148 Xml
::openElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalURL( "action=submit" ), 'id' => 'blockip' ) ) .
149 Xml
::openElement( 'fieldset' ) .
150 Xml
::element( 'legend', null, wfMsg( 'blockip-legend' ) ) .
151 Xml
::openElement( 'table', array ( 'border' => '0', 'id' => 'mw-blockip-table' ) ) .
153 <td class='mw-label'>
156 <td class='mw-input'>" .
157 Xml
::input( 'wpBlockAddress', 45, $this->BlockAddress
,
160 'id' => 'mw-bi-target',
161 'onchange' => 'updateBlockOptions()' ) ). "
166 if( $showblockoptions ) {
168 <td class='mw-label'>
171 <td class='mw-input'>" .
174 'id' => 'wpBlockExpiry',
175 'name' => 'wpBlockExpiry',
176 'onchange' => 'considerChangingExpiryFocus()',
178 $blockExpiryFormOptions ) .
184 <tr id='wpBlockOther'>
185 <td class='mw-label'>
188 <td class='mw-input'>" .
189 Xml
::input( 'wpBlockOther', 45, $this->BlockOther
,
190 array( 'tabindex' => '3', 'id' => 'mw-bi-other' ) ) . "
194 <td class='mw-label'>
197 <td class='mw-input'>
201 <tr id=\"wpBlockReason\">
202 <td class='mw-label'>
205 <td class='mw-input'>" .
206 Xml
::input( 'wpBlockReason', 45, $this->BlockReason
,
207 array( 'tabindex' => '5', 'id' => 'mw-bi-reason', 'maxlength'=> '200' ) ) . "
210 <tr id='wpAnonOnlyRow'>
212 <td class='mw-input'>" .
213 Xml
::checkLabel( wfMsg( 'ipbanononly' ),
214 'wpAnonOnly', 'wpAnonOnly', $this->BlockAnonOnly
,
215 array( 'tabindex' => '6' ) ) . "
218 <tr id='wpCreateAccountRow'>
220 <td class='mw-input'>" .
221 Xml
::checkLabel( wfMsg( 'ipbcreateaccount' ),
222 'wpCreateAccount', 'wpCreateAccount', $this->BlockCreateAccount
,
223 array( 'tabindex' => '7' ) ) . "
226 <tr id='wpEnableAutoblockRow'>
228 <td class='mw-input'>" .
229 Xml
::checkLabel( wfMsg( 'ipbenableautoblock' ),
230 'wpEnableAutoblock', 'wpEnableAutoblock', $this->BlockEnableAutoblock
,
231 array( 'tabindex' => '8' ) ) . "
236 if( self
::canBlockEmail( $wgUser ) ) {
238 <tr id='wpEnableEmailBan'>
240 <td class='mw-input'>" .
241 Xml
::checkLabel( wfMsg( 'ipbemailban' ),
242 'wpEmailBan', 'wpEmailBan', $this->BlockEmail
,
243 array( 'tabindex' => '9' )) . "
249 // Allow some users to hide name from block log, blocklist and listusers
250 if( $wgUser->isAllowed( 'hideuser' ) ) {
252 <tr id='wpEnableHideUser'>
254 <td class='mw-input'><strong>" .
255 Xml
::checkLabel( wfMsg( 'ipbhidename' ),
256 'wpHideName', 'wpHideName', $this->BlockHideName
,
257 array( 'tabindex' => '10' ) ) . "
263 # Watchlist their user page?
265 <tr id='wpEnableWatchUser'>
267 <td class='mw-input'>" .
268 Xml
::checkLabel( wfMsg( 'ipbwatchuser' ),
269 'wpWatchUser', 'wpWatchUser', $this->BlockWatchUser
,
270 array( 'tabindex' => '11' ) ) . "
275 # Can we explicitly disallow the use of user_talk?
276 global $wgBlockAllowsUTEdit;
277 if( $wgBlockAllowsUTEdit ){
279 <tr id='wpAllowUsertalkRow'>
281 <td class='mw-input'>" .
282 Xml
::checkLabel( wfMsg( 'ipballowusertalk' ),
283 'wpAllowUsertalk', 'wpAllowUsertalk', $this->BlockAllowUsertalk
,
284 array( 'tabindex' => '12' ) ) . "
292 <td style='padding-top: 1em'> </td>
293 <td class='mw-submit' style='padding-top: 1em'>" .
294 Xml
::submitButton( wfMsg( $alreadyBlocked ?
'ipb-change-block' : 'ipbsubmit' ),
295 array( 'name' => 'wpBlock', 'tabindex' => '13', 'accesskey' => 's' ) ) . "
298 Xml
::closeElement( 'table' ) .
299 Xml
::hidden( 'wpEditToken', $wgUser->editToken() ) .
300 ( $alreadyBlocked ? Xml
::hidden( 'wpChangeBlock', 1 ) : "" ) .
301 Xml
::closeElement( 'fieldset' ) .
302 Xml
::closeElement( 'form' ) .
303 Xml
::tags( 'script', array( 'type' => 'text/javascript' ), 'updateBlockOptions()' ) . "\n"
306 $wgOut->addHTML( $this->getConvenienceLinks() );
308 if( is_object( $user ) ) {
309 $this->showLogFragment( $wgOut, $user->getUserPage() );
310 } elseif( preg_match( '/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/', $this->BlockAddress
) ) {
311 $this->showLogFragment( $wgOut, Title
::makeTitle( NS_USER
, $this->BlockAddress
) );
312 } 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
) ) {
313 $this->showLogFragment( $wgOut, Title
::makeTitle( NS_USER
, $this->BlockAddress
) );
318 * Can we do an email block?
319 * @param User $user The sysop wanting to make a block
322 public static function canBlockEmail( $user ) {
323 global $wgEnableUserEmail, $wgSysopEmailBans;
324 return ($wgEnableUserEmail && $wgSysopEmailBans && $user->isAllowed( 'blockemail' ));
328 * Backend block code.
329 * $userID and $expiry will be filled accordingly
330 * @return array(message key, arguments) on failure, empty array on success
332 function doBlock( &$userId = null, &$expiry = null ) {
333 global $wgUser, $wgSysopUserBans, $wgSysopRangeBans, $wgBlockAllowsUTEdit;
336 # Expand valid IPv6 addresses, usernames are left as is
337 $this->BlockAddress
= IP
::sanitizeIP( $this->BlockAddress
);
338 # isIPv4() and IPv6() are used for final validation
339 $rxIP4 = '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}';
340 $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}';
341 $rxIP = "($rxIP4|$rxIP6)";
343 # Check for invalid specifications
344 if( !preg_match( "/^$rxIP$/", $this->BlockAddress
) ) {
346 if( preg_match( "/^($rxIP4)\\/(\\d{1,2})$/", $this->BlockAddress
, $matches ) ) {
348 if( $wgSysopRangeBans ) {
349 if( !IP
::isIPv4( $this->BlockAddress
) ||
$matches[2] < 16 ||
$matches[2] > 32 ) {
350 return array('ip_range_invalid');
352 $this->BlockAddress
= Block
::normaliseRange( $this->BlockAddress
);
354 # Range block illegal
355 return array('range_block_disabled');
357 } else if( preg_match( "/^($rxIP6)\\/(\\d{1,3})$/", $this->BlockAddress
, $matches ) ) {
359 if( $wgSysopRangeBans ) {
360 if( !IP
::isIPv6( $this->BlockAddress
) ||
$matches[2] < 64 ||
$matches[2] > 128 ) {
361 return array('ip_range_invalid');
363 $this->BlockAddress
= Block
::normaliseRange( $this->BlockAddress
);
365 # Range block illegal
366 return array('range_block_disabled');
370 if( $wgSysopUserBans ) {
371 $user = User
::newFromName( $this->BlockAddress
);
372 if( !is_null( $user ) && $user->getId() ) {
374 $userId = $user->getId();
375 $this->BlockAddress
= $user->getName();
377 return array('nosuchusershort', htmlspecialchars( $user ?
$user->getName() : $this->BlockAddress
) );
380 return array('badipaddress');
385 if( $wgUser->isBlocked() && ( $wgUser->getId() !== $userId ) ) {
386 return array( 'cant-block-while-blocked' );
389 $reasonstr = $this->BlockReasonList
;
390 if( $reasonstr != 'other' && $this->BlockReason
!= '' ) {
391 // Entry from drop down menu + additional comment
392 $reasonstr .= wfMsgForContent( 'colon-separator' ) . $this->BlockReason
;
393 } elseif( $reasonstr == 'other' ) {
394 $reasonstr = $this->BlockReason
;
397 $expirestr = $this->BlockExpiry
;
398 if( $expirestr == 'other' )
399 $expirestr = $this->BlockOther
;
401 if( ( strlen( $expirestr ) == 0) ||
( strlen( $expirestr ) > 50) ) {
402 return array('ipb_expiry_invalid');
405 if( false === ($expiry = Block
::parseExpiryInput( $expirestr )) ) {
407 return array('ipb_expiry_invalid');
410 if( $this->BlockHideName
) {
411 // Recheck params here...
412 if( !$userId ||
!$wgUser->isAllowed('hideuser') ) {
413 $this->BlockHideName
= false; // IP users should not be hidden
414 } else if( $expiry !== 'infinity' ) {
416 return array('ipb_expiry_temp');
417 } else if( User
::edits($userId) > self
::HIDEUSER_CONTRIBLIMIT
) {
418 // Typically, the user should have a handful of edits.
419 // Disallow hiding users with many edits for performance.
420 return array('ipb_hide_invalid');
424 # Create block object
425 # Note: for a user block, ipb_address is only for display purposes
426 $block = new Block( $this->BlockAddress
, $userId, $wgUser->getId(),
427 $reasonstr, wfTimestampNow(), 0, $expiry, $this->BlockAnonOnly
,
428 $this->BlockCreateAccount
, $this->BlockEnableAutoblock
, $this->BlockHideName
,
429 $this->BlockEmail
, isset( $this->BlockAllowUsertalk
) ?
$this->BlockAllowUsertalk
: $wgBlockAllowsUTEdit
432 # Should this be privately logged?
433 $suppressLog = (bool)$this->BlockHideName
;
434 if( wfRunHooks('BlockIp', array(&$block, &$wgUser)) ) {
435 # Try to insert block. Is there a conflicting block?
436 if( !$block->insert() ) {
437 # Show form unless the user is already aware of this...
438 if( !$this->BlockReblock
) {
439 return array( 'ipb_already_blocked' );
440 # Otherwise, try to update the block...
442 # This returns direct blocks before autoblocks/rangeblocks, since we should
443 # be sure the user is blocked by now it should work for our purposes
444 $currentBlock = Block
::newFromDB( $this->BlockAddress
, $userId );
445 if( $block->equals( $currentBlock ) ) {
446 return array( 'ipb_already_blocked' );
448 # If the name was hidden and the blocking user cannot hide
449 # names, then don't allow any block changes...
450 if( $currentBlock->mHideName
&& !$wgUser->isAllowed('hideuser') ) {
451 return array( 'hookaborted' );
453 $currentBlock->delete();
455 # If hiding/unhiding a name, this should go in the private logs
456 $suppressLog = $suppressLog ||
(bool)$currentBlock->mHideName
;
457 $log_action = 'reblock';
458 # Unset _deleted fields if requested
459 if( $currentBlock->mHideName
&& !$this->BlockHideName
) {
460 self
::unsuppressUserName( $this->BlockAddress
, $userId );
464 $log_action = 'block';
466 wfRunHooks('BlockIpComplete', array($block, $wgUser));
468 # Set *_deleted fields if requested
469 if( $this->BlockHideName
) {
470 self
::suppressUserName( $this->BlockAddress
, $userId );
473 # Only show watch link when this is no range block
474 if( $this->BlockWatchUser
&& $block->mRangeStart
== $block->mRangeEnd
) {
475 $wgUser->addWatch( Title
::makeTitle( NS_USER
, $this->BlockAddress
) );
478 # Block constructor sanitizes certain block options on insert
479 $this->BlockEmail
= $block->mBlockEmail
;
480 $this->BlockEnableAutoblock
= $block->mEnableAutoblock
;
482 # Prepare log parameters
483 $logParams = array();
484 $logParams[] = $expirestr;
485 $logParams[] = $this->blockLogFlags();
487 # Make log entry, if the name is hidden, put it in the oversight log
488 $log_type = $suppressLog ?
'suppress' : 'block';
489 $log = new LogPage( $log_type );
490 $log->addEntry( $log_action, Title
::makeTitle( NS_USER
, $this->BlockAddress
),
491 $reasonstr, $logParams );
496 return array('hookaborted');
500 public static function suppressUserName( $name, $userId ) {
501 $op = '|'; // bitwise OR
502 return self
::setUsernameBitfields( $name, $userId, $op );
505 public static function unsuppressUserName( $name, $userId ) {
506 $op = '&'; // bitwise AND
507 return self
::setUsernameBitfields( $name, $userId, $op );
510 private static function setUsernameBitfields( $name, $userId, $op ) {
511 if( $op !== '|' && $op !== '&' ) return false; // sanity check
512 $dbw = wfGetDB( DB_MASTER
);
513 $delUser = Revision
::DELETED_USER | Revision
::DELETED_RESTRICTED
;
514 $delAction = LogPage
::DELETED_ACTION | Revision
::DELETED_RESTRICTED
;
515 # Normalize user name
516 $userTitle = Title
::makeTitleSafe( NS_USER
, $name );
517 $userDbKey = $userTitle->getDBkey();
518 # To suppress, we OR the current bitfields with Revision::DELETED_USER
519 # to put a 1 in the username *_deleted bit. To unsuppress we AND the
520 # current bitfields with the inverse of Revision::DELETED_USER. The
521 # username bit is made to 0 (x & 0 = 0), while others are unchanged (x & 1 = x).
522 # The same goes for the sysop-restricted *_deleted bit.
524 $delUser = "~{$delUser}";
525 $delAction = "~{$delAction}";
527 # Hide name from live edits
528 $dbw->update( 'revision', array("rev_deleted = rev_deleted $op $delUser"),
529 array('rev_user' => $userId), __METHOD__
);
530 # Hide name from deleted edits
531 $dbw->update( 'archive', array("ar_deleted = ar_deleted $op $delUser"),
532 array('ar_user_text' => $name), __METHOD__
);
533 # Hide name from logs
534 $dbw->update( 'logging', array("log_deleted = log_deleted $op $delUser"),
535 array('log_user' => $userId, "log_type != 'suppress'"), __METHOD__
);
536 $dbw->update( 'logging', array("log_deleted = log_deleted $op $delAction"),
537 array('log_namespace' => NS_USER
, 'log_title' => $userDbKey,
538 "log_type != 'suppress'"), __METHOD__
);
540 $dbw->update( 'recentchanges', array("rc_deleted = rc_deleted $op $delUser"),
541 array('rc_user_text' => $name), __METHOD__
);
542 $dbw->update( 'recentchanges', array("rc_deleted = rc_deleted $op $delAction"),
543 array('rc_namespace' => NS_USER
, 'rc_title' => $userDbKey, 'rc_logid > 0'), __METHOD__
);
544 # Hide name from live images
545 $dbw->update( 'oldimage', array("oi_deleted = oi_deleted $op $delUser"),
546 array('oi_user_text' => $name), __METHOD__
);
547 # Hide name from deleted images
548 # WMF - schema change pending
549 # $dbw->update( 'filearchive', array("fa_deleted = fa_deleted $op $delUser"),
550 # array('fa_user_text' => $name), __METHOD__ );
556 * UI entry point for blocking
557 * Wraps around doBlock()
559 public function doSubmit() {
561 $retval = $this->doBlock();
562 if( empty($retval) ) {
563 $titleObj = SpecialPage
::getTitleFor( 'Blockip' );
564 $wgOut->redirect( $titleObj->getFullURL( 'action=success&ip=' .
565 urlencode( $this->BlockAddress
) ) );
568 $this->showForm( $retval );
571 public function showSuccess() {
574 $wgOut->setPagetitle( wfMsg( 'blockip' ) );
575 $wgOut->setSubtitle( wfMsg( 'blockipsuccesssub' ) );
576 $text = wfMsgExt( 'blockipsuccesstext', array( 'parse' ), $this->BlockAddress
);
577 $wgOut->addHTML( $text );
580 private function showLogFragment( $out, $title ) {
582 $out->addHTML( Xml
::element( 'h2', NULL, LogPage
::logName( 'block' ) ) );
583 $count = LogEventsList
::showLogExtract( $out, 'block', $title->getPrefixedText(), '', 10 );
585 $out->addHTML( $wgUser->getSkin()->link(
586 SpecialPage
::getTitleFor( 'Log' ),
587 wfMsgHtml( 'blocklog-fulllog' ),
591 'page' => $title->getPrefixedText() ) ) );
593 // Add suppression block entries if allowed
594 if( $wgUser->isAllowed('hideuser') ) {
595 $out->addHTML( Xml
::element( 'h2', NULL, LogPage
::logName( 'suppress' ) ) );
596 LogEventsList
::showLogExtract( $out, 'suppress', $title->getPrefixedText(), '',
597 10, array('log_action' => array('block','reblock','unblock')) );
602 * Return a comma-delimited list of "flags" to be passed to the log
603 * reader for this block, to provide more information in the logs
607 private function blockLogFlags() {
608 global $wgBlockAllowsUTEdit;
610 if( $this->BlockAnonOnly
&& IP
::isIPAddress( $this->BlockAddress
) )
611 // when blocking a user the option 'anononly' is not available/has no effect -> do not write this into log
612 $flags[] = 'anononly';
613 if( $this->BlockCreateAccount
)
614 $flags[] = 'nocreate';
615 if( !$this->BlockEnableAutoblock
&& !IP
::isIPAddress( $this->BlockAddress
) )
616 // Same as anononly, this is not displayed when blocking an IP address
617 $flags[] = 'noautoblock';
618 if( $this->BlockEmail
)
619 $flags[] = 'noemail';
620 if( !$this->BlockAllowUsertalk
&& $wgBlockAllowsUTEdit )
621 $flags[] = 'nousertalk';
622 if( $this->BlockHideName
)
623 $flags[] = 'hiddenname';
624 return implode( ',', $flags );
628 * Builds unblock and block list links
632 private function getConvenienceLinks() {
633 global $wgUser, $wgLang;
634 $skin = $wgUser->getSkin();
635 if( $this->BlockAddress
)
636 $links[] = $this->getContribsLink( $skin );
637 $links[] = $this->getUnblockLink( $skin );
638 $links[] = $this->getBlockListLink( $skin );
639 $title = Title
::makeTitle( NS_MEDIAWIKI
, 'Ipbreason-dropdown' );
640 $links[] = $skin->link(
642 wfMsgHtml( 'ipb-edit-dropdown' ),
644 array( 'action' => 'edit' )
646 return '<p class="mw-ipb-conveniencelinks">' . $wgLang->pipeList( $links ) . '</p>';
650 * Build a convenient link to a user or IP's contribs
653 * @param $skin Skin to use
656 private function getContribsLink( $skin ) {
657 $contribsPage = SpecialPage
::getTitleFor( 'Contributions', $this->BlockAddress
);
658 return $skin->link( $contribsPage, wfMsgHtml( 'ipb-blocklist-contribs', $this->BlockAddress
) );
662 * Build a convenient link to unblock the given username or IP
663 * address, if available; otherwise link to a blank unblock
666 * @param $skin Skin to use
669 private function getUnblockLink( $skin ) {
670 $list = SpecialPage
::getTitleFor( 'Ipblocklist' );
671 $query = array( 'action' => 'unblock' );
673 if( $this->BlockAddress
) {
674 $addr = htmlspecialchars( strtr( $this->BlockAddress
, '_', ' ' ) );
675 $message = wfMsgHtml( 'ipb-unblock-addr', $addr );
676 $query['ip'] = $this->BlockAddress
;
678 $message = wfMsgHtml( 'ipb-unblock' );
680 return $skin->linkKnown(
689 * Build a convenience link to the block list
691 * @param $skin Skin to use
694 private function getBlockListLink( $skin ) {
695 $list = SpecialPage
::getTitleFor( 'Ipblocklist' );
698 if( $this->BlockAddress
) {
699 $addr = htmlspecialchars( strtr( $this->BlockAddress
, '_', ' ' ) );
700 $message = wfMsgHtml( 'ipb-blocklist-addr', $addr );
701 $query['ip'] = $this->BlockAddress
;
703 $message = wfMsgHtml( 'ipb-blocklist' );
706 return $skin->linkKnown(
715 * Block a list of selected users
716 * @param array $users
717 * @param string $reason
718 * @param string $tag replaces user pages
719 * @param string $talkTag replaces user talk pages
720 * @returns array, list of html-safe usernames
722 public static function doMassUserBlock( $users, $reason = '', $tag = '', $talkTag = '' ) {
724 $counter = $blockSize = 0;
725 $safeUsers = array();
726 $log = new LogPage( 'block' );
727 foreach( $users as $name ) {
731 # Lets not go *too* fast
732 if( $blockSize >= 20 ) {
734 wfWaitForSlaves( 5 );
736 $u = User
::newFromName( $name, false );
737 // If user doesn't exist, it ought to be an IP then
738 if( is_null($u) ||
(!$u->getId() && !IP
::isIPAddress( $u->getName() )) ) {
741 $userTitle = $u->getUserPage();
742 $userTalkTitle = $u->getTalkPage();
743 $userpage = new Article( $userTitle );
744 $usertalk = new Article( $userTalkTitle );
745 $safeUsers[] = '[[' . $userTitle->getPrefixedText() . '|' . $userTitle->getText() . ']]';
746 $expirestr = $u->getId() ?
'indefinite' : '1 week';
747 $expiry = Block
::parseExpiryInput( $expirestr );
748 $anonOnly = IP
::isIPAddress( $u->getName() ) ?
1 : 0;
750 $block = new Block( $u->getName(), // victim
752 $wgUser->getId(), // blocker
754 wfTimestampNow(), // block time
757 $anonOnly, // anononly?
758 1, // block account creation?
761 0 // block from sending email?
763 $oldblock = Block
::newFromDB( $u->getName(), $u->getId() );
766 # Prepare log parameters
767 $logParams = array();
768 $logParams[] = $expirestr;
770 $logParams[] = 'anononly';
772 $logParams[] = 'nocreate';
774 $log->addEntry( 'block', $userTitle, $reason, $logParams );
776 # Tag userpage! (check length to avoid mistakes)
777 if( strlen($tag) > 2 ) {
778 $userpage->doEdit( $tag, $reason, EDIT_MINOR
);
780 if( strlen($talkTag) > 2 ) {
781 $usertalk->doEdit( $talkTag, $reason, EDIT_MINOR
);