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;
46 public function __construct( $par ) {
47 global $wgRequest, $wgUser, $wgBlockAllowsUTEdit;
49 $this->BlockAddress
= $wgRequest->getVal( 'wpBlockAddress', $wgRequest->getVal( 'ip', $par ) );
50 $this->BlockAddress
= strtr( $this->BlockAddress
, '_', ' ' );
51 $this->BlockReason
= $wgRequest->getText( 'wpBlockReason' );
52 $this->BlockReasonList
= $wgRequest->getText( 'wpBlockReasonList' );
53 $this->BlockExpiry
= $wgRequest->getVal( 'wpBlockExpiry', wfMsg('ipbotheroption') );
54 $this->BlockOther
= $wgRequest->getVal( 'wpBlockOther', '' );
56 # Unchecked checkboxes are not included in the form data at all, so having one
57 # that is true by default is a bit tricky
58 $byDefault = !$wgRequest->wasPosted();
59 $this->BlockAnonOnly
= $wgRequest->getBool( 'wpAnonOnly', $byDefault );
60 $this->BlockCreateAccount
= $wgRequest->getBool( 'wpCreateAccount', $byDefault );
61 $this->BlockEnableAutoblock
= $wgRequest->getBool( 'wpEnableAutoblock', $byDefault );
62 $this->BlockEmail
= $wgRequest->getBool( 'wpEmailBan', false );
63 $this->BlockWatchUser
= $wgRequest->getBool( 'wpWatchUser', false );
64 # Re-check user's rights to hide names, very serious, defaults to 0
65 $this->BlockHideName
= ( $wgRequest->getBool( 'wpHideName', 0 ) && $wgUser->isAllowed( 'hideuser' ) ) ?
1 : 0;
66 $this->BlockAllowUsertalk
= ( $wgRequest->getBool( 'wpAllowUsertalk', $byDefault ) && $wgBlockAllowsUTEdit );
67 $this->BlockReblock
= $wgRequest->getBool( 'wpChangeBlock', false );
70 public function showForm( $err ) {
71 global $wgOut, $wgUser, $wgSysopUserBans;
73 $wgOut->setPagetitle( wfMsg( 'blockip' ) );
74 $wgOut->addWikiMsg( 'blockiptext' );
76 if($wgSysopUserBans) {
77 $mIpaddress = Xml
::label( wfMsg( 'ipadressorusername' ), 'mw-bi-target' );
79 $mIpaddress = Xml
::label( wfMsg( 'ipaddress' ), 'mw-bi-target' );
81 $mIpbexpiry = Xml
::label( wfMsg( 'ipbexpiry' ), 'wpBlockExpiry' );
82 $mIpbother = Xml
::label( wfMsg( 'ipbother' ), 'mw-bi-other' );
83 $mIpbreasonother = Xml
::label( wfMsg( 'ipbreason' ), 'wpBlockReasonList' );
84 $mIpbreason = Xml
::label( wfMsg( 'ipbotherreason' ), 'mw-bi-reason' );
86 $titleObj = SpecialPage
::getTitleFor( 'Blockip' );
87 $user = User
::newFromName( $this->BlockAddress
);
89 $alreadyBlocked = false;
90 if( $err && $err[0] != 'ipb_already_blocked' ) {
91 $key = array_shift($err);
92 $msg = wfMsgReal($key, $err);
93 $wgOut->setSubtitle( wfMsgHtml( 'formerror' ) );
94 $wgOut->addHTML( Xml
::tags( 'p', array( 'class' => 'error' ), $msg ) );
95 } elseif( $this->BlockAddress
) {
97 if( is_object( $user ) )
98 $userId = $user->getId();
99 $currentBlock = Block
::newFromDB( $this->BlockAddress
, $userId );
100 if( !is_null($currentBlock) && !$currentBlock->mAuto
&& # The block exists and isn't an autoblock
101 ( $currentBlock->mRangeStart
== $currentBlock->mRangeEnd ||
# The block isn't a rangeblock
102 # or if it is, the range is what we're about to block
103 ( $currentBlock->mAddress
== $this->BlockAddress
) ) ) {
104 $wgOut->addWikiMsg( 'ipb-needreblock', $this->BlockAddress
);
105 $alreadyBlocked = true;
106 # Set the block form settings to the existing block
107 $this->BlockAnonOnly
= $currentBlock->mAnonOnly
;
108 $this->BlockCreateAccount
= $currentBlock->mCreateAccount
;
109 $this->BlockEnableAutoblock
= $currentBlock->mEnableAutoblock
;
110 $this->BlockEmail
= $currentBlock->mBlockEmail
;
111 $this->BlockHideName
= $currentBlock->mHideName
;
112 $this->BlockAllowUsertalk
= $currentBlock->mAllowUsertalk
;
113 if( $currentBlock->mExpiry
== 'infinity' ) {
114 $this->BlockOther
= 'indefinite';
116 $this->BlockOther
= wfTimestamp( TS_ISO_8601
, $currentBlock->mExpiry
);
118 $this->BlockReason
= $currentBlock->mReason
;
122 $scBlockExpiryOptions = wfMsgForContent( 'ipboptions' );
124 $showblockoptions = $scBlockExpiryOptions != '-';
125 if( !$showblockoptions ) $mIpbother = $mIpbexpiry;
127 $blockExpiryFormOptions = Xml
::option( wfMsg( 'ipbotheroption' ), 'other' );
128 foreach (explode(',', $scBlockExpiryOptions) as $option) {
129 if( strpos($option, ":") === false ) $option = "$option:$option";
130 list($show, $value) = explode(":", $option);
131 $show = htmlspecialchars($show);
132 $value = htmlspecialchars($value);
133 $blockExpiryFormOptions .= Xml
::option( $show, $value, $this->BlockExpiry
=== $value ?
true : false ) . "\n";
136 $reasonDropDown = Xml
::listDropDown( 'wpBlockReasonList',
137 wfMsgForContent( 'ipbreason-dropdown' ),
138 wfMsgForContent( 'ipbreasonotherlist' ), $this->BlockReasonList
, 'wpBlockDropDown', 4 );
140 global $wgStylePath, $wgStyleVersion;
142 Xml
::tags( 'script', array( 'type' => 'text/javascript', 'src' => "$wgStylePath/common/block.js?$wgStyleVersion" ), '' ) .
143 Xml
::openElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalURL( "action=submit" ), 'id' => 'blockip' ) ) .
144 Xml
::openElement( 'fieldset' ) .
145 Xml
::element( 'legend', null, wfMsg( 'blockip-legend' ) ) .
146 Xml
::openElement( 'table', array ( 'border' => '0', 'id' => 'mw-blockip-table' ) ) .
148 <td class='mw-label'>
151 <td class='mw-input'>" .
152 Xml
::input( 'wpBlockAddress', 45, $this->BlockAddress
,
155 'id' => 'mw-bi-target',
156 'onchange' => 'updateBlockOptions()' ) ). "
161 if( $showblockoptions ) {
163 <td class='mw-label'>
166 <td class='mw-input'>" .
169 'id' => 'wpBlockExpiry',
170 'name' => 'wpBlockExpiry',
171 'onchange' => 'considerChangingExpiryFocus()',
173 $blockExpiryFormOptions ) .
179 <tr id='wpBlockOther'>
180 <td class='mw-label'>
183 <td class='mw-input'>" .
184 Xml
::input( 'wpBlockOther', 45, $this->BlockOther
,
185 array( 'tabindex' => '3', 'id' => 'mw-bi-other' ) ) . "
189 <td class='mw-label'>
192 <td class='mw-input'>
196 <tr id=\"wpBlockReason\">
197 <td class='mw-label'>
200 <td class='mw-input'>" .
201 Xml
::input( 'wpBlockReason', 45, $this->BlockReason
,
202 array( 'tabindex' => '5', 'id' => 'mw-bi-reason', 'maxlength'=> '200' ) ) . "
205 <tr id='wpAnonOnlyRow'>
207 <td class='mw-input'>" .
208 Xml
::checkLabel( wfMsg( 'ipbanononly' ),
209 'wpAnonOnly', 'wpAnonOnly', $this->BlockAnonOnly
,
210 array( 'tabindex' => '6' ) ) . "
213 <tr id='wpCreateAccountRow'>
215 <td class='mw-input'>" .
216 Xml
::checkLabel( wfMsg( 'ipbcreateaccount' ),
217 'wpCreateAccount', 'wpCreateAccount', $this->BlockCreateAccount
,
218 array( 'tabindex' => '7' ) ) . "
221 <tr id='wpEnableAutoblockRow'>
223 <td class='mw-input'>" .
224 Xml
::checkLabel( wfMsg( 'ipbenableautoblock' ),
225 'wpEnableAutoblock', 'wpEnableAutoblock', $this->BlockEnableAutoblock
,
226 array( 'tabindex' => '8' ) ) . "
231 global $wgSysopEmailBans, $wgBlockAllowsUTEdit;
232 if( $wgSysopEmailBans && $wgUser->isAllowed( 'blockemail' ) ) {
234 <tr id='wpEnableEmailBan'>
236 <td class='mw-input'>" .
237 Xml
::checkLabel( wfMsg( 'ipbemailban' ),
238 'wpEmailBan', 'wpEmailBan', $this->BlockEmail
,
239 array( 'tabindex' => '9' )) . "
245 // Allow some users to hide name from block log, blocklist and listusers
246 if( $wgUser->isAllowed( 'hideuser' ) ) {
248 <tr id='wpEnableHideUser'>
250 <td class='mw-input'><strong>" .
251 Xml
::checkLabel( wfMsg( 'ipbhidename' ),
252 'wpHideName', 'wpHideName', $this->BlockHideName
,
253 array( 'tabindex' => '10' ) ) . "
259 # Watchlist their user page?
261 <tr id='wpEnableWatchUser'>
263 <td class='mw-input'>" .
264 Xml
::checkLabel( wfMsg( 'ipbwatchuser' ),
265 'wpWatchUser', 'wpWatchUser', $this->BlockWatchUser
,
266 array( 'tabindex' => '11' ) ) . "
270 if( $wgBlockAllowsUTEdit ){
272 <tr id='wpAllowUsertalkRow'>
274 <td class='mw-input'>" .
275 Xml
::checkLabel( wfMsg( 'ipballowusertalk' ),
276 'wpAllowUsertalk', 'wpAllowUsertalk', $this->BlockAllowUsertalk
,
277 array( 'tabindex' => '12' ) ) . "
285 <td style='padding-top: 1em'> </td>
286 <td class='mw-submit' style='padding-top: 1em'>" .
287 Xml
::submitButton( wfMsg( $alreadyBlocked ?
'ipb-change-block' : 'ipbsubmit' ),
288 array( 'name' => 'wpBlock', 'tabindex' => '13', 'accesskey' => 's' ) ) . "
291 Xml
::closeElement( 'table' ) .
292 Xml
::hidden( 'wpEditToken', $wgUser->editToken() ) .
293 ( $alreadyBlocked ? Xml
::hidden( 'wpChangeBlock', 1 ) : "" ) .
294 Xml
::closeElement( 'fieldset' ) .
295 Xml
::closeElement( 'form' ) .
296 Xml
::tags( 'script', array( 'type' => 'text/javascript' ), 'updateBlockOptions()' ) . "\n"
299 $wgOut->addHTML( $this->getConvenienceLinks() );
301 if( is_object( $user ) ) {
302 $this->showLogFragment( $wgOut, $user->getUserPage() );
303 } elseif( preg_match( '/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/', $this->BlockAddress
) ) {
304 $this->showLogFragment( $wgOut, Title
::makeTitle( NS_USER
, $this->BlockAddress
) );
305 } 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
) ) {
306 $this->showLogFragment( $wgOut, Title
::makeTitle( NS_USER
, $this->BlockAddress
) );
311 * Backend block code.
312 * $userID and $expiry will be filled accordingly
313 * @return array(message key, arguments) on failure, empty array on success
315 function doBlock( &$userId = null, &$expiry = null ) {
316 global $wgUser, $wgSysopUserBans, $wgSysopRangeBans, $wgBlockAllowsUTEdit;
319 # Expand valid IPv6 addresses, usernames are left as is
320 $this->BlockAddress
= IP
::sanitizeIP( $this->BlockAddress
);
321 # isIPv4() and IPv6() are used for final validation
322 $rxIP4 = '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}';
323 $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}';
324 $rxIP = "($rxIP4|$rxIP6)";
326 # Check for invalid specifications
327 if( !preg_match( "/^$rxIP$/", $this->BlockAddress
) ) {
329 if( preg_match( "/^($rxIP4)\\/(\\d{1,2})$/", $this->BlockAddress
, $matches ) ) {
331 if( $wgSysopRangeBans ) {
332 if( !IP
::isIPv4( $this->BlockAddress
) ||
$matches[2] < 16 ||
$matches[2] > 32 ) {
333 return array('ip_range_invalid');
335 $this->BlockAddress
= Block
::normaliseRange( $this->BlockAddress
);
337 # Range block illegal
338 return array('range_block_disabled');
340 } else if( preg_match( "/^($rxIP6)\\/(\\d{1,3})$/", $this->BlockAddress
, $matches ) ) {
342 if( $wgSysopRangeBans ) {
343 if( !IP
::isIPv6( $this->BlockAddress
) ||
$matches[2] < 64 ||
$matches[2] > 128 ) {
344 return array('ip_range_invalid');
346 $this->BlockAddress
= Block
::normaliseRange( $this->BlockAddress
);
348 # Range block illegal
349 return array('range_block_disabled');
353 if( $wgSysopUserBans ) {
354 $user = User
::newFromName( $this->BlockAddress
);
355 if( !is_null( $user ) && $user->getId() ) {
357 $userId = $user->getId();
358 $this->BlockAddress
= $user->getName();
360 return array('nosuchusershort', htmlspecialchars( $user ?
$user->getName() : $this->BlockAddress
) );
363 return array('badipaddress');
368 if( $wgUser->isBlocked() && ( $wgUser->getId() !== $userId ) ) {
369 return array( 'cant-block-while-blocked' );
372 $reasonstr = $this->BlockReasonList
;
373 if( $reasonstr != 'other' && $this->BlockReason
!= '' ) {
374 // Entry from drop down menu + additional comment
375 $reasonstr .= wfMsgForContent( 'colon-separator' ) . $this->BlockReason
;
376 } elseif( $reasonstr == 'other' ) {
377 $reasonstr = $this->BlockReason
;
380 $expirestr = $this->BlockExpiry
;
381 if( $expirestr == 'other' )
382 $expirestr = $this->BlockOther
;
384 if( ( strlen( $expirestr ) == 0) ||
( strlen( $expirestr ) > 50) ) {
385 return array('ipb_expiry_invalid');
388 if( false === ($expiry = Block
::parseExpiryInput( $expirestr )) ) {
390 return array('ipb_expiry_invalid');
393 if( $this->BlockHideName
) {
394 // Recheck params here...
395 if( !$userId ||
!$wgUser->isAllowed('hideuser') ) {
396 $this->BlockHideName
= false; // IP users should not be hidden
397 } else if( $expiry !== 'infinity' ) {
399 return array('ipb_expiry_temp');
400 } else if( User
::edits($userId) > 3000 ) {
401 // Typically, the user should have a handful of edits.
402 // Disallow hiding users with many edits for performance.
403 return array('ipb_hide_invalid');
407 # Create block object
408 # Note: for a user block, ipb_address is only for display purposes
409 $block = new Block( $this->BlockAddress
, $userId, $wgUser->getId(),
410 $reasonstr, wfTimestampNow(), 0, $expiry, $this->BlockAnonOnly
,
411 $this->BlockCreateAccount
, $this->BlockEnableAutoblock
, $this->BlockHideName
,
412 $this->BlockEmail
, isset( $this->BlockAllowUsertalk
) ?
$this->BlockAllowUsertalk
: $wgBlockAllowsUTEdit
415 # Should this be privately logged?
416 $suppressLog = (bool)$this->BlockHideName
;
417 if( wfRunHooks('BlockIp', array(&$block, &$wgUser)) ) {
418 # Try to insert block. Is there a conflicting block?
419 if( !$block->insert() ) {
420 # Show form unless the user is already aware of this...
421 if( !$this->BlockReblock
) {
422 return array( 'ipb_already_blocked' );
423 # Otherwise, try to update the block...
425 # This returns direct blocks before autoblocks/rangeblocks, since we should
426 # be sure the user is blocked by now it should work for our purposes
427 $currentBlock = Block
::newFromDB( $this->BlockAddress
, $userId );
428 if( $block->equals( $currentBlock ) ) {
429 return array( 'ipb_already_blocked' );
431 # If the name was hidden and the blocking user cannot hide
432 # names, then don't allow any block changes...
433 if( $currentBlock->mHideName
&& !$wgUser->isAllowed('hideuser') ) {
434 return array( 'hookaborted' );
436 $currentBlock->delete();
438 # If hiding/unhiding a name, this should go in the private logs
439 $suppressLog = $suppressLog ||
(bool)$currentBlock->mHideName
;
440 $log_action = 'reblock';
441 # Unset _deleted fields if requested
442 if( $currentBlock->mHideName
&& !$this->BlockHideName
) {
443 self
::unsuppressUserName( $this->BlockAddress
, $userId );
447 $log_action = 'block';
449 wfRunHooks('BlockIpComplete', array($block, $wgUser));
451 # Set *_deleted fields if requested
452 if( $this->BlockHideName
) {
453 self
::suppressUserName( $this->BlockAddress
, $userId, $reasonstr );
456 # Only show watch link when this is no range block
457 if( $this->BlockWatchUser
&& $block->mRangeStart
== $block->mRangeEnd
) {
458 $wgUser->addWatch( Title
::makeTitle( NS_USER
, $this->BlockAddress
) );
461 # Block constructor sanitizes certain block options on insert
462 $this->BlockEmail
= $block->mBlockEmail
;
463 $this->BlockEnableAutoblock
= $block->mEnableAutoblock
;
465 # Prepare log parameters
466 $logParams = array();
467 $logParams[] = $expirestr;
468 $logParams[] = $this->blockLogFlags();
470 # Make log entry, if the name is hidden, put it in the oversight log
471 $log_type = $suppressLog ?
'suppress' : 'block';
472 $log = new LogPage( $log_type );
473 $log->addEntry( $log_action, Title
::makeTitle( NS_USER
, $this->BlockAddress
),
474 $reasonstr, $logParams );
479 return array('hookaborted');
483 public static function suppressUserName( $name, $userId, $reason = '' ) {
484 $user = User
::newFromName( $name, false );
485 # Delete the user pages that exists
486 $title = $user->getUserPage();
487 if( ($id = $title->getArticleID(GAID_FOR_UPDATE
)) ) {
488 $article = new Article( $title );
489 $article->doDeleteArticle( $reason, true /*suppress*/, $id );
491 # Delete the user talk pages that exists
492 $title = $user->getTalkPage();
493 if( $id = $title->getArticleID(GAID_FOR_UPDATE
) ) {
494 $article = new Article( $title );
495 $article->doDeleteArticle( $reason, true /*suppress*/, $id );
497 $op = '|'; // bitwise OR
498 return self
::setUsernameBitfields( $name, $userId, $op );
501 public static function unsuppressUserName( $name, $userId ) {
502 $op = '&'; // bitwise AND
503 return self
::setUsernameBitfields( $name, $userId, $op );
506 private static function setUsernameBitfields( $name, $userId, $op ) {
507 if( $op !== '|' && $op !== '&' ) return false; // sanity check
508 $dbw = wfGetDB( DB_MASTER
);
509 $delUser = Revision
::DELETED_USER | Revision
::DELETED_RESTRICTED
;
510 $delAction = LogPage
::DELETED_ACTION | Revision
::DELETED_RESTRICTED
;
511 # Normalize user name
512 $userTitle = Title
::makeTitleSafe( NS_USER
, $name );
513 $userDbKey = $userTitle->getDBKey();
514 # To suppress, we OR the current bitfields with Revision::DELETED_USER
515 # to put a 1 in the username *_deleted bit. To unsuppress we AND the
516 # current bitfields with the inverse of Revision::DELETED_USER. The
517 # username bit is made to 0 (x & 0 = 0), while others are unchanged (x & 1 = x).
518 # The same goes for the sysop-restricted *_deleted bit.
520 $delUser = "~{$delUser}";
521 $delAction = "~{$delAction}";
523 # Hide name from live edits
524 $dbw->update( 'revision', array("rev_deleted = rev_deleted $op $delUser"),
525 array('rev_user' => $userId), __METHOD__
);
526 # Hide name from deleted edits
527 $dbw->update( 'archive', array("ar_deleted = ar_deleted $op $delUser"),
528 array('ar_user_text' => $name), __METHOD__
);
529 # Hide name from logs
530 $dbw->update( 'logging', array("log_deleted = log_deleted $op $delUser"),
531 array('log_user' => $userId, "log_type != 'suppress'"), __METHOD__
);
532 $dbw->update( 'logging', array("log_deleted = log_deleted $op $delAction"),
533 array('log_namespace' => NS_USER
, 'log_title' => $userDbKey,
534 "log_type != 'suppress'"), __METHOD__
);
536 $dbw->update( 'recentchanges', array("rc_deleted = rc_deleted $op $delUser"),
537 array('rc_user_text' => $name), __METHOD__
);
538 $dbw->update( 'recentchanges', array("rc_deleted = rc_deleted $op $delAction"),
539 array('rc_namespace' => NS_USER
, 'rc_title' => $userDbKey, 'rc_logid > 0'), __METHOD__
);
540 # Hide name from live images
541 $dbw->update( 'oldimage', array("oi_deleted = oi_deleted $op $delUser"),
542 array('oi_user_text' => $name), __METHOD__
);
543 # Hide name from deleted images
544 # WMF - schema change pending
545 # $dbw->update( 'filearchive', array("fa_deleted = fa_deleted $op $delUser"),
546 # array('fa_user_text' => $name), __METHOD__ );
552 * UI entry point for blocking
553 * Wraps around doBlock()
555 public function doSubmit() {
557 $retval = $this->doBlock();
558 if( empty($retval) ) {
559 $titleObj = SpecialPage
::getTitleFor( 'Blockip' );
560 $wgOut->redirect( $titleObj->getFullURL( 'action=success&ip=' .
561 urlencode( $this->BlockAddress
) ) );
564 $this->showForm( $retval );
567 public function showSuccess() {
570 $wgOut->setPagetitle( wfMsg( 'blockip' ) );
571 $wgOut->setSubtitle( wfMsg( 'blockipsuccesssub' ) );
572 $text = wfMsgExt( 'blockipsuccesstext', array( 'parse' ), $this->BlockAddress
);
573 $wgOut->addHTML( $text );
576 private function showLogFragment( $out, $title ) {
578 $out->addHTML( Xml
::element( 'h2', NULL, LogPage
::logName( 'block' ) ) );
579 $count = LogEventsList
::showLogExtract( $out, 'block', $title->getPrefixedText(), '', 10 );
581 $out->addHTML( $wgUser->getSkin()->link(
582 SpecialPage
::getTitleFor( 'Log' ),
583 wfMsgHtml( 'blocklog-fulllog' ),
587 'page' => $title->getPrefixedText() ) ) );
589 // Add suppression block entries if allowed
590 if( $wgUser->isAllowed('hideuser') ) {
591 $out->addHTML( Xml
::element( 'h2', NULL, LogPage
::logName( 'suppress' ) ) );
592 LogEventsList
::showLogExtract( $out, 'suppress', $title->getPrefixedText(), '',
593 10, array('log_action' => array('block','reblock','unblock')) );
598 * Return a comma-delimited list of "flags" to be passed to the log
599 * reader for this block, to provide more information in the logs
603 private function blockLogFlags() {
604 global $wgBlockAllowsUTEdit;
606 if( $this->BlockAnonOnly
&& IP
::isIPAddress( $this->BlockAddress
) )
607 // when blocking a user the option 'anononly' is not available/has no effect -> do not write this into log
608 $flags[] = 'anononly';
609 if( $this->BlockCreateAccount
)
610 $flags[] = 'nocreate';
611 if( !$this->BlockEnableAutoblock
&& !IP
::isIPAddress( $this->BlockAddress
) )
612 // Same as anononly, this is not displayed when blocking an IP address
613 $flags[] = 'noautoblock';
614 if( $this->BlockEmail
)
615 $flags[] = 'noemail';
616 if( !$this->BlockAllowUsertalk
&& $wgBlockAllowsUTEdit )
617 $flags[] = 'nousertalk';
618 if( $this->BlockHideName
)
619 $flags[] = 'hiddenname';
620 return implode( ',', $flags );
624 * Builds unblock and block list links
628 private function getConvenienceLinks() {
629 global $wgUser, $wgLang;
630 $skin = $wgUser->getSkin();
631 if( $this->BlockAddress
)
632 $links[] = $this->getContribsLink( $skin );
633 $links[] = $this->getUnblockLink( $skin );
634 $links[] = $this->getBlockListLink( $skin );
635 $links[] = $skin->makeLink ( 'MediaWiki:Ipbreason-dropdown', wfMsgHtml( 'ipb-edit-dropdown' ) );
636 return '<p class="mw-ipb-conveniencelinks">' . $wgLang->pipeList( $links ) . '</p>';
640 * Build a convenient link to a user or IP's contribs
643 * @param $skin Skin to use
646 private function getContribsLink( $skin ) {
647 $contribsPage = SpecialPage
::getTitleFor( 'Contributions', $this->BlockAddress
);
648 return $skin->link( $contribsPage, wfMsgHtml( 'ipb-blocklist-contribs', $this->BlockAddress
) );
652 * Build a convenient link to unblock the given username or IP
653 * address, if available; otherwise link to a blank unblock
656 * @param $skin Skin to use
659 private function getUnblockLink( $skin ) {
660 $list = SpecialPage
::getTitleFor( 'Ipblocklist' );
661 if( $this->BlockAddress
) {
662 $addr = htmlspecialchars( strtr( $this->BlockAddress
, '_', ' ' ) );
663 return $skin->makeKnownLinkObj( $list, wfMsgHtml( 'ipb-unblock-addr', $addr ),
664 'action=unblock&ip=' . urlencode( $this->BlockAddress
) );
666 return $skin->makeKnownLinkObj( $list, wfMsgHtml( 'ipb-unblock' ), 'action=unblock' );
671 * Build a convenience link to the block list
673 * @param $skin Skin to use
676 private function getBlockListLink( $skin ) {
677 $list = SpecialPage
::getTitleFor( 'Ipblocklist' );
678 if( $this->BlockAddress
) {
679 $addr = htmlspecialchars( strtr( $this->BlockAddress
, '_', ' ' ) );
680 return $skin->makeKnownLinkObj( $list, wfMsgHtml( 'ipb-blocklist-addr', $addr ),
681 'ip=' . urlencode( $this->BlockAddress
) );
683 return $skin->makeKnownLinkObj( $list, wfMsgHtml( 'ipb-blocklist' ) );
688 * Block a list of selected users
689 * @param array $users
690 * @param string $reason
691 * @param string $tag replaces user pages
692 * @param string $talkTag replaces user talk pages
693 * @returns array, list of html-safe usernames
695 public static function doMassUserBlock( $users, $reason = '', $tag = '', $talkTag = '' ) {
697 $counter = $blockSize = 0;
698 $safeUsers = array();
699 $log = new LogPage( 'block' );
700 foreach( $users as $name ) {
704 # Lets not go *too* fast
705 if( $blockSize >= 20 ) {
707 wfWaitForSlaves( 5 );
709 $u = User
::newFromName( $name, false );
710 // If user doesn't exist, it ought to be an IP then
711 if( is_null($u) ||
(!$u->getId() && !IP
::isIPAddress( $u->getName() )) ) {
714 $userTitle = $u->getUserPage();
715 $userTalkTitle = $u->getTalkPage();
716 $userpage = new Article( $userTitle );
717 $usertalk = new Article( $userTalkTitle );
718 $safeUsers[] = '[[' . $userTitle->getPrefixedText() . '|' . $userTitle->getText() . ']]';
719 $expirestr = $u->getId() ?
'indefinite' : '1 week';
720 $expiry = Block
::parseExpiryInput( $expirestr );
721 $anonOnly = IP
::isIPAddress( $u->getName() ) ?
1 : 0;
723 $block = new Block( $u->getName(), // victim
725 $wgUser->getId(), // blocker
727 wfTimestampNow(), // block time
730 $anonOnly, // anononly?
731 1, // block account creation?
734 0 // block from sending email?
736 $oldblock = Block
::newFromDB( $u->getName(), $u->getId() );
739 # Prepare log parameters
740 $logParams = array();
741 $logParams[] = $expirestr;
743 $logParams[] = 'anononly';
745 $logParams[] = 'nocreate';
747 $log->addEntry( 'block', $userTitle, $reason, $logParams );
749 # Tag userpage! (check length to avoid mistakes)
750 if( strlen($tag) > 2 ) {
751 $userpage->doEdit( $tag, $reason, EDIT_MINOR
);
753 if( strlen($talkTag) > 2 ) {
754 $usertalk->doEdit( $talkTag, $reason, EDIT_MINOR
);