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 null
71 if( $wgUser->isAllowed( 'hideuser' ) ) {
72 $this->BlockHideName
= $wgRequest->getBool( 'wpHideName', null );
74 $this->BlockHideName
= false;
76 $this->BlockAllowUsertalk
= ( $wgRequest->getBool( 'wpAllowUsertalk', $byDefault ) && $wgBlockAllowsUTEdit );
77 $this->BlockReblock
= $wgRequest->getBool( 'wpChangeBlock', false );
79 $this->wasPosted
= $wgRequest->wasPosted();
82 public function showForm( $err ) {
83 global $wgOut, $wgUser, $wgSysopUserBans;
85 $wgOut->setPageTitle( wfMsg( 'blockip' ) );
86 $wgOut->addWikiMsg( 'blockiptext' );
88 if( $wgSysopUserBans ) {
89 $mIpaddress = Xml
::label( wfMsg( 'ipadressorusername' ), 'mw-bi-target' );
91 $mIpaddress = Xml
::label( wfMsg( 'ipaddress' ), 'mw-bi-target' );
93 $mIpbexpiry = Xml
::label( wfMsg( 'ipbexpiry' ), 'wpBlockExpiry' );
94 $mIpbother = Xml
::label( wfMsg( 'ipbother' ), 'mw-bi-other' );
95 $mIpbreasonother = Xml
::label( wfMsg( 'ipbreason' ), 'wpBlockReasonList' );
96 $mIpbreason = Xml
::label( wfMsg( 'ipbotherreason' ), 'mw-bi-reason' );
98 $titleObj = SpecialPage
::getTitleFor( 'Blockip' );
99 $user = User
::newFromName( $this->BlockAddress
);
101 $alreadyBlocked = false;
102 if( $err && $err[0] != 'ipb_already_blocked' ) {
103 $key = array_shift( $err );
104 $msg = wfMsgReal( $key, $err );
105 $wgOut->setSubtitle( wfMsgHtml( 'formerror' ) );
106 $wgOut->addHTML( Xml
::tags( 'p', array( 'class' => 'error' ), $msg ) );
107 } elseif( $this->BlockAddress
) {
108 # Get other blocks, i.e. from GlobalBlocking or TorBlock extension
109 wfRunHooks( 'getOtherBlockLogLink', array( &$otherBlockedMsgs, $this->BlockAddress
) );
111 $userId = is_object( $user ) ?
$user->getId() : 0;
112 $currentBlock = Block
::newFromDB( $this->BlockAddress
, $userId );
113 if( !is_null( $currentBlock ) && !$currentBlock->mAuto
&& # The block exists and isn't an autoblock
114 ( $currentBlock->mRangeStart
== $currentBlock->mRangeEnd ||
# The block isn't a rangeblock
115 # or if it is, the range is what we're about to block
116 ( $currentBlock->mAddress
== $this->BlockAddress
) )
118 $alreadyBlocked = true;
119 # Set the block form settings to the existing block
120 if( !$this->wasPosted
) {
121 $this->BlockAnonOnly
= $currentBlock->mAnonOnly
;
122 $this->BlockCreateAccount
= $currentBlock->mCreateAccount
;
123 $this->BlockEnableAutoblock
= $currentBlock->mEnableAutoblock
;
124 $this->BlockEmail
= $currentBlock->mBlockEmail
;
125 $this->BlockHideName
= $currentBlock->mHideName
;
126 $this->BlockAllowUsertalk
= $currentBlock->mAllowUsertalk
;
127 if( $currentBlock->mExpiry
== 'infinity' ) {
128 $this->BlockOther
= 'indefinite';
130 $this->BlockOther
= wfTimestamp( TS_ISO_8601
, $currentBlock->mExpiry
);
132 $this->BlockReason
= $currentBlock->mReason
;
137 # Show other blocks from extensions, i.e. GlockBlocking and TorBlock
138 if( count( $otherBlockedMsgs ) ) {
140 Html
::rawElement( 'h2', array(), wfMsgExt( 'ipb-otherblocks-header', 'parseinline', count( $otherBlockedMsgs ) ) ) . "\n"
143 foreach( $otherBlockedMsgs as $link ) {
144 $list .= Html
::rawElement( 'li', array(), $link ) . "\n";
146 $wgOut->addHTML( Html
::rawElement( 'ul', array( 'class' => 'mw-blockip-alreadyblocked' ), $list ) . "\n" );
149 # Username/IP is blocked already locally
150 if( $alreadyBlocked ) {
151 $wgOut->addWikiMsg( 'ipb-needreblock', $this->BlockAddress
);
154 $scBlockExpiryOptions = wfMsgForContent( 'ipboptions' );
156 $showblockoptions = $scBlockExpiryOptions != '-';
157 if( !$showblockoptions ) $mIpbother = $mIpbexpiry;
159 $blockExpiryFormOptions = Xml
::option( wfMsg( 'ipbotheroption' ), 'other' );
160 foreach( explode( ',', $scBlockExpiryOptions ) as $option ) {
161 if( strpos( $option, ':' ) === false ) $option = "$option:$option";
162 list( $show, $value ) = explode( ':', $option );
163 $show = htmlspecialchars( $show );
164 $value = htmlspecialchars( $value );
165 $blockExpiryFormOptions .= Xml
::option( $show, $value, $this->BlockExpiry
=== $value ?
true : false ) . "\n";
168 $reasonDropDown = Xml
::listDropDown( 'wpBlockReasonList',
169 wfMsgForContent( 'ipbreason-dropdown' ),
170 wfMsgForContent( 'ipbreasonotherlist' ), $this->BlockReasonList
, 'wpBlockDropDown', 4 );
172 global $wgStylePath, $wgStyleVersion;
174 Xml
::tags( 'script', array( 'type' => 'text/javascript', 'src' => "$wgStylePath/common/block.js?$wgStyleVersion" ), '' ) .
175 Xml
::openElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalURL( 'action=submit' ), 'id' => 'blockip' ) ) .
176 Xml
::openElement( 'fieldset' ) .
177 Xml
::element( 'legend', null, wfMsg( 'blockip-legend' ) ) .
178 Xml
::openElement( 'table', array( 'border' => '0', 'id' => 'mw-blockip-table' ) ) .
180 <td class='mw-label'>
183 <td class='mw-input'>" .
184 Html
::input( 'wpBlockAddress', $this->BlockAddress
, 'text', array(
186 'id' => 'mw-bi-target',
187 'onchange' => 'updateBlockOptions()',
190 ) +
( $this->BlockAddress ?
array() : array( 'autofocus' ) ) ). "
195 if( $showblockoptions ) {
197 <td class='mw-label'>
200 <td class='mw-input'>" .
203 'id' => 'wpBlockExpiry',
204 'name' => 'wpBlockExpiry',
205 'onchange' => 'considerChangingExpiryFocus()',
207 $blockExpiryFormOptions ) .
213 <tr id='wpBlockOther'>
214 <td class='mw-label'>
217 <td class='mw-input'>" .
218 Xml
::input( 'wpBlockOther', 45, $this->BlockOther
,
219 array( 'tabindex' => '3', 'id' => 'mw-bi-other' ) ) . "
223 <td class='mw-label'>
226 <td class='mw-input'>
230 <tr id=\"wpBlockReason\">
231 <td class='mw-label'>
234 <td class='mw-input'>" .
235 Html
::input( 'wpBlockReason', $this->BlockReason
, 'text', array(
237 'id' => 'mw-bi-reason',
238 'maxlength' => '200',
240 ) +
( $this->BlockAddress ?
array( 'autofocus' ) : array() ) ) . "
243 <tr id='wpAnonOnlyRow'>
245 <td class='mw-input'>" .
246 Xml
::checkLabel( wfMsg( 'ipbanononly' ),
247 'wpAnonOnly', 'wpAnonOnly', $this->BlockAnonOnly
,
248 array( 'tabindex' => '6' ) ) . "
251 <tr id='wpCreateAccountRow'>
253 <td class='mw-input'>" .
254 Xml
::checkLabel( wfMsg( 'ipbcreateaccount' ),
255 'wpCreateAccount', 'wpCreateAccount', $this->BlockCreateAccount
,
256 array( 'tabindex' => '7' ) ) . "
259 <tr id='wpEnableAutoblockRow'>
261 <td class='mw-input'>" .
262 Xml
::checkLabel( wfMsg( 'ipbenableautoblock' ),
263 'wpEnableAutoblock', 'wpEnableAutoblock', $this->BlockEnableAutoblock
,
264 array( 'tabindex' => '8' ) ) . "
269 if( self
::canBlockEmail( $wgUser ) ) {
271 <tr id='wpEnableEmailBan'>
273 <td class='mw-input'>" .
274 Xml
::checkLabel( wfMsg( 'ipbemailban' ),
275 'wpEmailBan', 'wpEmailBan', $this->BlockEmail
,
276 array( 'tabindex' => '9' ) ) . "
282 // Allow some users to hide name from block log, blocklist and listusers
283 if( $wgUser->isAllowed( 'hideuser' ) ) {
285 <tr id='wpEnableHideUser'>
287 <td class='mw-input'><strong>" .
288 Xml
::checkLabel( wfMsg( 'ipbhidename' ),
289 'wpHideName', 'wpHideName', $this->BlockHideName
,
290 array( 'tabindex' => '10' )
297 # Watchlist their user page?
299 <tr id='wpEnableWatchUser'>
301 <td class='mw-input'>" .
302 Xml
::checkLabel( wfMsg( 'ipbwatchuser' ),
303 'wpWatchUser', 'wpWatchUser', $this->BlockWatchUser
,
304 array( 'tabindex' => '11' ) ) . "
309 # Can we explicitly disallow the use of user_talk?
310 global $wgBlockAllowsUTEdit;
311 if( $wgBlockAllowsUTEdit ){
313 <tr id='wpAllowUsertalkRow'>
315 <td class='mw-input'>" .
316 Xml
::checkLabel( wfMsg( 'ipballowusertalk' ),
317 'wpAllowUsertalk', 'wpAllowUsertalk', $this->BlockAllowUsertalk
,
318 array( 'tabindex' => '12' ) ) . "
326 <td style='padding-top: 1em'> </td>
327 <td class='mw-submit' style='padding-top: 1em'>" .
328 Xml
::submitButton( wfMsg( $alreadyBlocked ?
'ipb-change-block' : 'ipbsubmit' ),
329 array( 'name' => 'wpBlock', 'tabindex' => '13', 'accesskey' => 's' ) ) . "
332 Xml
::closeElement( 'table' ) .
333 Xml
::hidden( 'wpEditToken', $wgUser->editToken() ) .
334 ( $alreadyBlocked ? Xml
::hidden( 'wpChangeBlock', 1 ) : "" ) .
335 Xml
::closeElement( 'fieldset' ) .
336 Xml
::closeElement( 'form' ) .
337 Xml
::tags( 'script', array( 'type' => 'text/javascript' ), 'updateBlockOptions()' ) . "\n"
340 $wgOut->addHTML( $this->getConvenienceLinks() );
342 if( is_object( $user ) ) {
343 $this->showLogFragment( $wgOut, $user->getUserPage() );
344 } elseif( preg_match( '/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/', $this->BlockAddress
) ) {
345 $this->showLogFragment( $wgOut, Title
::makeTitle( NS_USER
, $this->BlockAddress
) );
346 } 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
) ) {
347 $this->showLogFragment( $wgOut, Title
::makeTitle( NS_USER
, $this->BlockAddress
) );
352 * Can we do an email block?
353 * @param User $user The sysop wanting to make a block
356 public static function canBlockEmail( $user ) {
357 global $wgEnableUserEmail, $wgSysopEmailBans;
358 return ( $wgEnableUserEmail && $wgSysopEmailBans && $user->isAllowed( 'blockemail' ) );
362 * Backend block code.
363 * $userID and $expiry will be filled accordingly
364 * @return array(message key, arguments) on failure, empty array on success
366 function doBlock( &$userId = null, &$expiry = null ) {
367 global $wgUser, $wgSysopUserBans, $wgSysopRangeBans, $wgBlockAllowsUTEdit, $wgBlockCIDRLimit;
370 # Expand valid IPv6 addresses, usernames are left as is
371 $this->BlockAddress
= IP
::sanitizeIP( $this->BlockAddress
);
372 # isIPv4() and IPv6() are used for final validation
373 $rxIP4 = '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}';
374 $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}';
375 $rxIP = "($rxIP4|$rxIP6)";
377 # Check for invalid specifications
378 if( !preg_match( "/^$rxIP$/", $this->BlockAddress
) ) {
380 if( preg_match( "/^($rxIP4)\\/(\\d{1,2})$/", $this->BlockAddress
, $matches ) ) {
382 if( $wgSysopRangeBans ) {
383 if( !IP
::isIPv4( $this->BlockAddress
) ||
$matches[2] < $wgBlockCIDRLimit ||
$matches[2] > 32 ) {
384 return array( 'ip_range_invalid' );
386 $this->BlockAddress
= Block
::normaliseRange( $this->BlockAddress
);
388 # Range block illegal
389 return array( 'range_block_disabled' );
391 } elseif( preg_match( "/^($rxIP6)\\/(\\d{1,3})$/", $this->BlockAddress
, $matches ) ) {
393 if( $wgSysopRangeBans ) {
394 if( !IP
::isIPv6( $this->BlockAddress
) ||
$matches[2] < 64 ||
$matches[2] > 128 ) {
395 return array( 'ip_range_invalid' );
397 $this->BlockAddress
= Block
::normaliseRange( $this->BlockAddress
);
399 # Range block illegal
400 return array('range_block_disabled');
404 if( $wgSysopUserBans ) {
405 $user = User
::newFromName( $this->BlockAddress
);
406 if( !is_null( $user ) && $user->getId() ) {
408 $userId = $user->getId();
409 $this->BlockAddress
= $user->getName();
411 return array( 'nosuchusershort', htmlspecialchars( $user ?
$user->getName() : $this->BlockAddress
) );
414 return array( 'badipaddress' );
419 if( $wgUser->isBlocked() && ( $wgUser->getId() !== $userId ) ) {
420 return array( 'cant-block-while-blocked' );
423 $reasonstr = $this->BlockReasonList
;
424 if( $reasonstr != 'other' && $this->BlockReason
!= '' ) {
425 // Entry from drop down menu + additional comment
426 $reasonstr .= wfMsgForContent( 'colon-separator' ) . $this->BlockReason
;
427 } elseif( $reasonstr == 'other' ) {
428 $reasonstr = $this->BlockReason
;
431 $expirestr = $this->BlockExpiry
;
432 if( $expirestr == 'other' )
433 $expirestr = $this->BlockOther
;
435 if( ( strlen( $expirestr ) == 0) ||
( strlen( $expirestr ) > 50 ) ) {
436 return array( 'ipb_expiry_invalid' );
439 if( false === ( $expiry = Block
::parseExpiryInput( $expirestr ) ) ) {
441 return array( 'ipb_expiry_invalid' );
444 if( $this->BlockHideName
) {
445 // Recheck params here...
446 if( !$userId ||
!$wgUser->isAllowed('hideuser') ) {
447 $this->BlockHideName
= false; // IP users should not be hidden
448 } elseif( $expiry !== 'infinity' ) {
450 return array( 'ipb_expiry_temp' );
451 } elseif( User
::edits( $userId ) > self
::HIDEUSER_CONTRIBLIMIT
) {
452 // Typically, the user should have a handful of edits.
453 // Disallow hiding users with many edits for performance.
454 return array( 'ipb_hide_invalid' );
458 # Create block object
459 # Note: for a user block, ipb_address is only for display purposes
460 $block = new Block( $this->BlockAddress
, $userId, $wgUser->getId(),
461 $reasonstr, wfTimestampNow(), 0, $expiry, $this->BlockAnonOnly
,
462 $this->BlockCreateAccount
, $this->BlockEnableAutoblock
, $this->BlockHideName
,
464 isset( $this->BlockAllowUsertalk
) ?
$this->BlockAllowUsertalk
: $wgBlockAllowsUTEdit
467 # Should this be privately logged?
468 $suppressLog = (bool)$this->BlockHideName
;
469 if( wfRunHooks( 'BlockIp', array( &$block, &$wgUser ) ) ) {
470 # Try to insert block. Is there a conflicting block?
471 if( !$block->insert() ) {
472 # Show form unless the user is already aware of this...
473 if( !$this->BlockReblock
) {
474 return array( 'ipb_already_blocked' );
475 # Otherwise, try to update the block...
477 # This returns direct blocks before autoblocks/rangeblocks, since we should
478 # be sure the user is blocked by now it should work for our purposes
479 $currentBlock = Block
::newFromDB( $this->BlockAddress
, $userId );
480 if( $block->equals( $currentBlock ) ) {
481 return array( 'ipb_already_blocked' );
483 # If the name was hidden and the blocking user cannot hide
484 # names, then don't allow any block changes...
485 if( $currentBlock->mHideName
&& !$wgUser->isAllowed( 'hideuser' ) ) {
486 return array( 'cant-see-hidden-user' );
488 $currentBlock->delete();
490 # If hiding/unhiding a name, this should go in the private logs
491 $suppressLog = $suppressLog ||
(bool)$currentBlock->mHideName
;
492 $log_action = 'reblock';
493 # Unset _deleted fields if requested
494 if( $currentBlock->mHideName
&& !$this->BlockHideName
) {
495 self
::unsuppressUserName( $this->BlockAddress
, $userId );
499 $log_action = 'block';
501 wfRunHooks( 'BlockIpComplete', array( $block, $wgUser ) );
503 # Set *_deleted fields if requested
504 if( $this->BlockHideName
) {
505 self
::suppressUserName( $this->BlockAddress
, $userId );
508 # Only show watch link when this is no range block
509 if( $this->BlockWatchUser
&& $block->mRangeStart
== $block->mRangeEnd
) {
510 $wgUser->addWatch( Title
::makeTitle( NS_USER
, $this->BlockAddress
) );
513 # Block constructor sanitizes certain block options on insert
514 $this->BlockEmail
= $block->mBlockEmail
;
515 $this->BlockEnableAutoblock
= $block->mEnableAutoblock
;
517 # Prepare log parameters
518 $logParams = array();
519 $logParams[] = $expirestr;
520 $logParams[] = $this->blockLogFlags();
522 # Make log entry, if the name is hidden, put it in the oversight log
523 $log_type = $suppressLog ?
'suppress' : 'block';
524 $log = new LogPage( $log_type );
525 $log->addEntry( $log_action, Title
::makeTitle( NS_USER
, $this->BlockAddress
),
526 $reasonstr, $logParams );
531 return array( 'hookaborted' );
535 public static function suppressUserName( $name, $userId ) {
536 $op = '|'; // bitwise OR
537 return self
::setUsernameBitfields( $name, $userId, $op );
540 public static function unsuppressUserName( $name, $userId ) {
541 $op = '&'; // bitwise AND
542 return self
::setUsernameBitfields( $name, $userId, $op );
545 private static function setUsernameBitfields( $name, $userId, $op ) {
546 if( $op !== '|' && $op !== '&' ) return false; // sanity check
547 $dbw = wfGetDB( DB_MASTER
);
548 $delUser = Revision
::DELETED_USER | Revision
::DELETED_RESTRICTED
;
549 $delAction = LogPage
::DELETED_ACTION | Revision
::DELETED_RESTRICTED
;
550 # Normalize user name
551 $userTitle = Title
::makeTitleSafe( NS_USER
, $name );
552 $userDbKey = $userTitle->getDBkey();
553 # To suppress, we OR the current bitfields with Revision::DELETED_USER
554 # to put a 1 in the username *_deleted bit. To unsuppress we AND the
555 # current bitfields with the inverse of Revision::DELETED_USER. The
556 # username bit is made to 0 (x & 0 = 0), while others are unchanged (x & 1 = x).
557 # The same goes for the sysop-restricted *_deleted bit.
559 $delUser = "~{$delUser}";
560 $delAction = "~{$delAction}";
562 # Hide name from live edits
563 $dbw->update( 'revision', array( "rev_deleted = rev_deleted $op $delUser" ),
564 array( 'rev_user' => $userId ), __METHOD__
);
565 # Hide name from deleted edits
566 $dbw->update( 'archive', array( "ar_deleted = ar_deleted $op $delUser" ),
567 array( 'ar_user_text' => $name ), __METHOD__
);
568 # Hide name from logs
569 $dbw->update( 'logging', array( "log_deleted = log_deleted $op $delUser" ),
570 array( 'log_user' => $userId, "log_type != 'suppress'" ), __METHOD__
);
571 $dbw->update( 'logging', array( "log_deleted = log_deleted $op $delAction" ),
572 array( 'log_namespace' => NS_USER
, 'log_title' => $userDbKey,
573 "log_type != 'suppress'" ), __METHOD__
);
575 $dbw->update( 'recentchanges', array( "rc_deleted = rc_deleted $op $delUser" ),
576 array( 'rc_user_text' => $name ), __METHOD__
);
577 $dbw->update( 'recentchanges', array( "rc_deleted = rc_deleted $op $delAction" ),
578 array( 'rc_namespace' => NS_USER
, 'rc_title' => $userDbKey, 'rc_logid > 0' ), __METHOD__
);
579 # Hide name from live images
580 $dbw->update( 'oldimage', array( "oi_deleted = oi_deleted $op $delUser" ),
581 array( 'oi_user_text' => $name ), __METHOD__
);
582 # Hide name from deleted images
583 # WMF - schema change pending
584 # $dbw->update( 'filearchive', array( "fa_deleted = fa_deleted $op $delUser" ),
585 # array( 'fa_user_text' => $name ), __METHOD__ );
591 * UI entry point for blocking
592 * Wraps around doBlock()
594 public function doSubmit() {
596 $retval = $this->doBlock();
597 if( empty( $retval ) ) {
598 $titleObj = SpecialPage
::getTitleFor( 'Blockip' );
599 $wgOut->redirect( $titleObj->getFullURL( 'action=success&ip=' .
600 urlencode( $this->BlockAddress
) ) );
603 $this->showForm( $retval );
606 public function showSuccess() {
609 $wgOut->setPageTitle( wfMsg( 'blockip' ) );
610 $wgOut->setSubtitle( wfMsg( 'blockipsuccesssub' ) );
611 $text = wfMsgExt( 'blockipsuccesstext', array( 'parse' ), $this->BlockAddress
);
612 $wgOut->addHTML( $text );
615 private function showLogFragment( $out, $title ) {
618 // Used to support GENDER in 'blocklog-showlog' and 'blocklog-showsuppresslog'
619 $userBlocked = $title->getText();
621 LogEventsList
::showLogExtract(
624 $title->getPrefixedText(),
632 'showIfEmpty' => false
636 // Add suppression block entries if allowed
637 if( $wgUser->isAllowed( 'hideuser' ) ) {
638 LogEventsList
::showLogExtract( $out, 'suppress', $title->getPrefixedText(), '',
642 'log_action' => array(
649 'blocklog-showsuppresslog',
652 'showIfEmpty' => false
659 * Return a comma-delimited list of "flags" to be passed to the log
660 * reader for this block, to provide more information in the logs
664 private function blockLogFlags() {
665 global $wgBlockAllowsUTEdit;
667 if( $this->BlockAnonOnly
&& IP
::isIPAddress( $this->BlockAddress
) )
668 // when blocking a user the option 'anononly' is not available/has no effect -> do not write this into log
669 $flags[] = 'anononly';
670 if( $this->BlockCreateAccount
)
671 $flags[] = 'nocreate';
672 if( !$this->BlockEnableAutoblock
&& !IP
::isIPAddress( $this->BlockAddress
) )
673 // Same as anononly, this is not displayed when blocking an IP address
674 $flags[] = 'noautoblock';
675 if( $this->BlockEmail
)
676 $flags[] = 'noemail';
677 if( !$this->BlockAllowUsertalk
&& $wgBlockAllowsUTEdit )
678 $flags[] = 'nousertalk';
679 if( $this->BlockHideName
)
680 $flags[] = 'hiddenname';
681 return implode( ',', $flags );
685 * Builds unblock and block list links
689 private function getConvenienceLinks() {
690 global $wgUser, $wgLang;
691 $skin = $wgUser->getSkin();
692 if( $this->BlockAddress
)
693 $links[] = $this->getContribsLink( $skin );
694 $links[] = $this->getUnblockLink( $skin );
695 $links[] = $this->getBlockListLink( $skin );
696 $title = Title
::makeTitle( NS_MEDIAWIKI
, 'Ipbreason-dropdown' );
697 $links[] = $skin->link(
699 wfMsgHtml( 'ipb-edit-dropdown' ),
701 array( 'action' => 'edit' )
703 return '<p class="mw-ipb-conveniencelinks">' . $wgLang->pipeList( $links ) . '</p>';
707 * Build a convenient link to a user or IP's contribs
710 * @param $skin Skin to use
713 private function getContribsLink( $skin ) {
714 $contribsPage = SpecialPage
::getTitleFor( 'Contributions', $this->BlockAddress
);
715 return $skin->link( $contribsPage, wfMsgExt( 'ipb-blocklist-contribs', 'escape', $this->BlockAddress
) );
719 * Build a convenient link to unblock the given username or IP
720 * address, if available; otherwise link to a blank unblock
723 * @param $skin Skin to use
726 private function getUnblockLink( $skin ) {
727 $list = SpecialPage
::getTitleFor( 'Ipblocklist' );
728 $query = array( 'action' => 'unblock' );
730 if( $this->BlockAddress
) {
731 $addr = strtr( $this->BlockAddress
, '_', ' ' );
732 $message = wfMsg( 'ipb-unblock-addr', $addr );
733 $query['ip'] = $this->BlockAddress
;
735 $message = wfMsg( 'ipb-unblock' );
737 return $skin->linkKnown(
739 htmlspecialchars( $message ),
746 * Build a convenience link to the block list
748 * @param $skin Skin to use
751 private function getBlockListLink( $skin ) {
752 $list = SpecialPage
::getTitleFor( 'Ipblocklist' );
755 if( $this->BlockAddress
) {
756 $addr = strtr( $this->BlockAddress
, '_', ' ' );
757 $message = wfMsg( 'ipb-blocklist-addr', $addr );
758 $query['ip'] = $this->BlockAddress
;
760 $message = wfMsg( 'ipb-blocklist' );
763 return $skin->linkKnown(
765 htmlspecialchars( $message ),
772 * Block a list of selected users
773 * @param array $users
774 * @param string $reason
775 * @param string $tag replaces user pages
776 * @param string $talkTag replaces user talk pages
777 * @returns array, list of html-safe usernames
779 public static function doMassUserBlock( $users, $reason = '', $tag = '', $talkTag = '' ) {
781 $counter = $blockSize = 0;
782 $safeUsers = array();
783 $log = new LogPage( 'block' );
784 foreach( $users as $name ) {
788 # Lets not go *too* fast
789 if( $blockSize >= 20 ) {
791 wfWaitForSlaves( 5 );
793 $u = User
::newFromName( $name, false );
794 // If user doesn't exist, it ought to be an IP then
795 if( is_null( $u ) ||
( !$u->getId() && !IP
::isIPAddress( $u->getName() ) ) ) {
798 $userTitle = $u->getUserPage();
799 $userTalkTitle = $u->getTalkPage();
800 $userpage = new Article( $userTitle );
801 $usertalk = new Article( $userTalkTitle );
802 $safeUsers[] = '[[' . $userTitle->getPrefixedText() . '|' . $userTitle->getText() . ']]';
803 $expirestr = $u->getId() ?
'indefinite' : '1 week';
804 $expiry = Block
::parseExpiryInput( $expirestr );
805 $anonOnly = IP
::isIPAddress( $u->getName() ) ?
1 : 0;
807 $block = new Block( $u->getName(), // victim
809 $wgUser->getId(), // blocker
811 wfTimestampNow(), // block time
814 $anonOnly, // anononly?
815 1, // block account creation?
818 0 // block from sending email?
820 $oldblock = Block
::newFromDB( $u->getName(), $u->getId() );
823 # Prepare log parameters
824 $logParams = array();
825 $logParams[] = $expirestr;
827 $logParams[] = 'anononly';
829 $logParams[] = 'nocreate';
831 $log->addEntry( 'block', $userTitle, $reason, $logParams );
833 # Tag userpage! (check length to avoid mistakes)
834 if( strlen( $tag ) > 2 ) {
835 $userpage->doEdit( $tag, $reason, EDIT_MINOR
);
837 if( strlen( $talkTag ) > 2 ) {
838 $usertalk->doEdit( $talkTag, $reason, EDIT_MINOR
);