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 ) && $wgUser->isLoggedIn();
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 $otherBlockedMsgs = array();
103 if( $err && $err[0] != 'ipb_already_blocked' ) {
104 $key = array_shift( $err );
105 $msg = wfMsgReal( $key, $err );
106 $wgOut->setSubtitle( wfMsgHtml( 'formerror' ) );
107 $wgOut->addHTML( Xml
::tags( 'p', array( 'class' => 'error' ), $msg ) );
108 } elseif( $this->BlockAddress
) {
109 # Get other blocks, i.e. from GlobalBlocking or TorBlock extension
110 wfRunHooks( 'getOtherBlockLogLink', array( &$otherBlockedMsgs, $this->BlockAddress
) );
112 $userId = is_object( $user ) ?
$user->getId() : 0;
113 $currentBlock = Block
::newFromDB( $this->BlockAddress
, $userId );
114 if( !is_null( $currentBlock ) && !$currentBlock->mAuto
&& # The block exists and isn't an autoblock
115 ( $currentBlock->mRangeStart
== $currentBlock->mRangeEnd ||
# The block isn't a rangeblock
116 # or if it is, the range is what we're about to block
117 ( $currentBlock->mAddress
== $this->BlockAddress
) )
119 $alreadyBlocked = true;
120 # Set the block form settings to the existing block
121 if( !$this->wasPosted
) {
122 $this->BlockAnonOnly
= $currentBlock->mAnonOnly
;
123 $this->BlockCreateAccount
= $currentBlock->mCreateAccount
;
124 $this->BlockEnableAutoblock
= $currentBlock->mEnableAutoblock
;
125 $this->BlockEmail
= $currentBlock->mBlockEmail
;
126 $this->BlockHideName
= $currentBlock->mHideName
;
127 $this->BlockAllowUsertalk
= $currentBlock->mAllowUsertalk
;
128 if( $currentBlock->mExpiry
== 'infinity' ) {
129 $this->BlockOther
= 'indefinite';
131 $this->BlockOther
= wfTimestamp( TS_ISO_8601
, $currentBlock->mExpiry
);
133 $this->BlockReason
= $currentBlock->mReason
;
138 # Show other blocks from extensions, i.e. GlockBlocking and TorBlock
139 if( count( $otherBlockedMsgs ) ) {
141 Html
::rawElement( 'h2', array(), wfMsgExt( 'ipb-otherblocks-header', 'parseinline', count( $otherBlockedMsgs ) ) ) . "\n"
144 foreach( $otherBlockedMsgs as $link ) {
145 $list .= Html
::rawElement( 'li', array(), $link ) . "\n";
147 $wgOut->addHTML( Html
::rawElement( 'ul', array( 'class' => 'mw-blockip-alreadyblocked' ), $list ) . "\n" );
150 # Username/IP is blocked already locally
151 if( $alreadyBlocked ) {
152 $wgOut->addWikiMsg( 'ipb-needreblock', $this->BlockAddress
);
155 $scBlockExpiryOptions = wfMsgForContent( 'ipboptions' );
157 $showblockoptions = $scBlockExpiryOptions != '-';
158 if( !$showblockoptions ) $mIpbother = $mIpbexpiry;
160 $blockExpiryFormOptions = Xml
::option( wfMsg( 'ipbotheroption' ), 'other' );
161 foreach( explode( ',', $scBlockExpiryOptions ) as $option ) {
162 if( strpos( $option, ':' ) === false ) $option = "$option:$option";
163 list( $show, $value ) = explode( ':', $option );
164 $show = htmlspecialchars( $show );
165 $value = htmlspecialchars( $value );
166 $blockExpiryFormOptions .= Xml
::option( $show, $value, $this->BlockExpiry
=== $value ?
true : false ) . "\n";
169 $reasonDropDown = Xml
::listDropDown( 'wpBlockReasonList',
170 wfMsgForContent( 'ipbreason-dropdown' ),
171 wfMsgForContent( 'ipbreasonotherlist' ), $this->BlockReasonList
, 'wpBlockDropDown', 4 );
173 global $wgStylePath, $wgStyleVersion;
175 Xml
::tags( 'script', array( 'type' => 'text/javascript', 'src' => "$wgStylePath/common/block.js?$wgStyleVersion" ), '' ) .
176 Xml
::openElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalURL( 'action=submit' ), 'id' => 'blockip' ) ) .
177 Xml
::openElement( 'fieldset' ) .
178 Xml
::element( 'legend', null, wfMsg( 'blockip-legend' ) ) .
179 Xml
::openElement( 'table', array( 'border' => '0', 'id' => 'mw-blockip-table' ) ) .
181 <td class='mw-label'>
184 <td class='mw-input'>" .
185 Html
::input( 'wpBlockAddress', $this->BlockAddress
, 'text', array(
187 'id' => 'mw-bi-target',
188 'onchange' => 'updateBlockOptions()',
191 ) +
( $this->BlockAddress ?
array() : array( 'autofocus' ) ) ). "
196 if( $showblockoptions ) {
198 <td class='mw-label'>
201 <td class='mw-input'>" .
204 'id' => 'wpBlockExpiry',
205 'name' => 'wpBlockExpiry',
206 'onchange' => 'considerChangingExpiryFocus()',
208 $blockExpiryFormOptions ) .
214 <tr id='wpBlockOther'>
215 <td class='mw-label'>
218 <td class='mw-input'>" .
219 Xml
::input( 'wpBlockOther', 45, $this->BlockOther
,
220 array( 'tabindex' => '3', 'id' => 'mw-bi-other' ) ) . "
224 <td class='mw-label'>
227 <td class='mw-input'>
231 <tr id=\"wpBlockReason\">
232 <td class='mw-label'>
235 <td class='mw-input'>" .
236 Html
::input( 'wpBlockReason', $this->BlockReason
, 'text', array(
238 'id' => 'mw-bi-reason',
239 'maxlength' => '200',
241 ) +
( $this->BlockAddress ?
array( 'autofocus' ) : array() ) ) . "
244 <tr id='wpAnonOnlyRow'>
246 <td class='mw-input'>" .
247 Xml
::checkLabel( wfMsg( 'ipbanononly' ),
248 'wpAnonOnly', 'wpAnonOnly', $this->BlockAnonOnly
,
249 array( 'tabindex' => '6' ) ) . "
252 <tr id='wpCreateAccountRow'>
254 <td class='mw-input'>" .
255 Xml
::checkLabel( wfMsg( 'ipbcreateaccount' ),
256 'wpCreateAccount', 'wpCreateAccount', $this->BlockCreateAccount
,
257 array( 'tabindex' => '7' ) ) . "
260 <tr id='wpEnableAutoblockRow'>
262 <td class='mw-input'>" .
263 Xml
::checkLabel( wfMsg( 'ipbenableautoblock' ),
264 'wpEnableAutoblock', 'wpEnableAutoblock', $this->BlockEnableAutoblock
,
265 array( 'tabindex' => '8' ) ) . "
270 if( self
::canBlockEmail( $wgUser ) ) {
272 <tr id='wpEnableEmailBan'>
274 <td class='mw-input'>" .
275 Xml
::checkLabel( wfMsg( 'ipbemailban' ),
276 'wpEmailBan', 'wpEmailBan', $this->BlockEmail
,
277 array( 'tabindex' => '9' ) ) . "
283 // Allow some users to hide name from block log, blocklist and listusers
284 if( $wgUser->isAllowed( 'hideuser' ) ) {
286 <tr id='wpEnableHideUser'>
288 <td class='mw-input'><strong>" .
289 Xml
::checkLabel( wfMsg( 'ipbhidename' ),
290 'wpHideName', 'wpHideName', $this->BlockHideName
,
291 array( 'tabindex' => '10' )
298 # Watchlist their user page? (Only if user is logged in)
299 if( $wgUser->isLoggedIn() ) {
301 <tr id='wpEnableWatchUser'>
303 <td class='mw-input'>" .
304 Xml
::checkLabel( wfMsg( 'ipbwatchuser' ),
305 'wpWatchUser', 'wpWatchUser', $this->BlockWatchUser
,
306 array( 'tabindex' => '11' ) ) . "
312 # Can we explicitly disallow the use of user_talk?
313 global $wgBlockAllowsUTEdit;
314 if( $wgBlockAllowsUTEdit ){
316 <tr id='wpAllowUsertalkRow'>
318 <td class='mw-input'>" .
319 Xml
::checkLabel( wfMsg( 'ipballowusertalk' ),
320 'wpAllowUsertalk', 'wpAllowUsertalk', $this->BlockAllowUsertalk
,
321 array( 'tabindex' => '12' ) ) . "
329 <td style='padding-top: 1em'> </td>
330 <td class='mw-submit' style='padding-top: 1em'>" .
331 Xml
::submitButton( wfMsg( $alreadyBlocked ?
'ipb-change-block' : 'ipbsubmit' ),
332 array( 'name' => 'wpBlock', 'tabindex' => '13', 'accesskey' => 's' ) ) . "
335 Xml
::closeElement( 'table' ) .
336 Xml
::hidden( 'wpEditToken', $wgUser->editToken() ) .
337 ( $alreadyBlocked ? Xml
::hidden( 'wpChangeBlock', 1 ) : "" ) .
338 Xml
::closeElement( 'fieldset' ) .
339 Xml
::closeElement( 'form' ) .
340 Xml
::tags( 'script', array( 'type' => 'text/javascript' ), 'updateBlockOptions()' ) . "\n"
343 $wgOut->addHTML( $this->getConvenienceLinks() );
345 if( is_object( $user ) ) {
346 $this->showLogFragment( $wgOut, $user->getUserPage() );
347 } elseif( preg_match( '/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/', $this->BlockAddress
) ) {
348 $this->showLogFragment( $wgOut, Title
::makeTitle( NS_USER
, $this->BlockAddress
) );
349 } 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
) ) {
350 $this->showLogFragment( $wgOut, Title
::makeTitle( NS_USER
, $this->BlockAddress
) );
355 * Can we do an email block?
356 * @param User $user The sysop wanting to make a block
359 public static function canBlockEmail( $user ) {
360 global $wgEnableUserEmail, $wgSysopEmailBans;
361 return ( $wgEnableUserEmail && $wgSysopEmailBans && $user->isAllowed( 'blockemail' ) );
365 * Backend block code.
366 * $userID and $expiry will be filled accordingly
367 * @return array(message key, arguments) on failure, empty array on success
369 function doBlock( &$userId = null, &$expiry = null ) {
370 global $wgUser, $wgSysopUserBans, $wgSysopRangeBans, $wgBlockAllowsUTEdit, $wgBlockCIDRLimit;
373 # Expand valid IPv6 addresses, usernames are left as is
374 $this->BlockAddress
= IP
::sanitizeIP( $this->BlockAddress
);
375 # isIPv4() and IPv6() are used for final validation
376 $rxIP4 = '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}';
377 $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}';
378 $rxIP = "($rxIP4|$rxIP6)";
380 # Check for invalid specifications
381 if( !preg_match( "/^$rxIP$/", $this->BlockAddress
) ) {
383 if( preg_match( "/^($rxIP4)\\/(\\d{1,2})$/", $this->BlockAddress
, $matches ) ) {
385 if( $wgSysopRangeBans ) {
386 if( !IP
::isIPv4( $this->BlockAddress
) ||
$matches[2] < $wgBlockCIDRLimit ||
$matches[2] > 32 ) {
387 return array( 'ip_range_invalid' );
389 $this->BlockAddress
= Block
::normaliseRange( $this->BlockAddress
);
391 # Range block illegal
392 return array( 'range_block_disabled' );
394 } elseif( preg_match( "/^($rxIP6)\\/(\\d{1,3})$/", $this->BlockAddress
, $matches ) ) {
396 if( $wgSysopRangeBans ) {
397 if( !IP
::isIPv6( $this->BlockAddress
) ||
$matches[2] < 64 ||
$matches[2] > 128 ) {
398 return array( 'ip_range_invalid' );
400 $this->BlockAddress
= Block
::normaliseRange( $this->BlockAddress
);
402 # Range block illegal
403 return array('range_block_disabled');
407 if( $wgSysopUserBans ) {
408 $user = User
::newFromName( $this->BlockAddress
);
409 if( !is_null( $user ) && $user->getId() ) {
411 $userId = $user->getId();
412 $this->BlockAddress
= $user->getName();
414 return array( 'nosuchusershort', htmlspecialchars( $user ?
$user->getName() : $this->BlockAddress
) );
417 return array( 'badipaddress' );
422 if( $wgUser->isBlocked() && ( $wgUser->getId() !== $userId ) ) {
423 return array( 'cant-block-while-blocked' );
426 $reasonstr = $this->BlockReasonList
;
427 if( $reasonstr != 'other' && $this->BlockReason
!= '' ) {
428 // Entry from drop down menu + additional comment
429 $reasonstr .= wfMsgForContent( 'colon-separator' ) . $this->BlockReason
;
430 } elseif( $reasonstr == 'other' ) {
431 $reasonstr = $this->BlockReason
;
434 $expirestr = $this->BlockExpiry
;
435 if( $expirestr == 'other' )
436 $expirestr = $this->BlockOther
;
438 if( ( strlen( $expirestr ) == 0) ||
( strlen( $expirestr ) > 50 ) ) {
439 return array( 'ipb_expiry_invalid' );
442 if( false === ( $expiry = Block
::parseExpiryInput( $expirestr ) ) ) {
444 return array( 'ipb_expiry_invalid' );
447 if( $this->BlockHideName
) {
448 // Recheck params here...
449 if( !$userId ||
!$wgUser->isAllowed('hideuser') ) {
450 $this->BlockHideName
= false; // IP users should not be hidden
451 } elseif( $expiry !== 'infinity' ) {
453 return array( 'ipb_expiry_temp' );
454 } elseif( User
::edits( $userId ) > self
::HIDEUSER_CONTRIBLIMIT
) {
455 // Typically, the user should have a handful of edits.
456 // Disallow hiding users with many edits for performance.
457 return array( 'ipb_hide_invalid' );
461 # Create block object
462 # Note: for a user block, ipb_address is only for display purposes
463 $block = new Block( $this->BlockAddress
, $userId, $wgUser->getId(),
464 $reasonstr, wfTimestampNow(), 0, $expiry, $this->BlockAnonOnly
,
465 $this->BlockCreateAccount
, $this->BlockEnableAutoblock
, $this->BlockHideName
,
467 isset( $this->BlockAllowUsertalk
) ?
$this->BlockAllowUsertalk
: $wgBlockAllowsUTEdit
470 # Should this be privately logged?
471 $suppressLog = (bool)$this->BlockHideName
;
472 if( wfRunHooks( 'BlockIp', array( &$block, &$wgUser ) ) ) {
473 # Try to insert block. Is there a conflicting block?
474 if( !$block->insert() ) {
475 # Show form unless the user is already aware of this...
476 if( !$this->BlockReblock
) {
477 return array( 'ipb_already_blocked' );
478 # Otherwise, try to update the block...
480 # This returns direct blocks before autoblocks/rangeblocks, since we should
481 # be sure the user is blocked by now it should work for our purposes
482 $currentBlock = Block
::newFromDB( $this->BlockAddress
, $userId );
483 if( $block->equals( $currentBlock ) ) {
484 return array( 'ipb_already_blocked' );
486 # If the name was hidden and the blocking user cannot hide
487 # names, then don't allow any block changes...
488 if( $currentBlock->mHideName
&& !$wgUser->isAllowed( 'hideuser' ) ) {
489 return array( 'cant-see-hidden-user' );
491 $currentBlock->delete();
493 # If hiding/unhiding a name, this should go in the private logs
494 $suppressLog = $suppressLog ||
(bool)$currentBlock->mHideName
;
495 $log_action = 'reblock';
496 # Unset _deleted fields if requested
497 if( $currentBlock->mHideName
&& !$this->BlockHideName
) {
498 self
::unsuppressUserName( $this->BlockAddress
, $userId );
502 $log_action = 'block';
504 wfRunHooks( 'BlockIpComplete', array( $block, $wgUser ) );
506 # Set *_deleted fields if requested
507 if( $this->BlockHideName
) {
508 self
::suppressUserName( $this->BlockAddress
, $userId );
511 # Only show watch link when this is no range block
512 if( $this->BlockWatchUser
&& $block->mRangeStart
== $block->mRangeEnd
) {
513 $wgUser->addWatch( Title
::makeTitle( NS_USER
, $this->BlockAddress
) );
516 # Block constructor sanitizes certain block options on insert
517 $this->BlockEmail
= $block->mBlockEmail
;
518 $this->BlockEnableAutoblock
= $block->mEnableAutoblock
;
520 # Prepare log parameters
521 $logParams = array();
522 $logParams[] = $expirestr;
523 $logParams[] = $this->blockLogFlags();
525 # Make log entry, if the name is hidden, put it in the oversight log
526 $log_type = $suppressLog ?
'suppress' : 'block';
527 $log = new LogPage( $log_type );
528 $log->addEntry( $log_action, Title
::makeTitle( NS_USER
, $this->BlockAddress
),
529 $reasonstr, $logParams );
534 return array( 'hookaborted' );
538 public static function suppressUserName( $name, $userId ) {
539 $op = '|'; // bitwise OR
540 return self
::setUsernameBitfields( $name, $userId, $op );
543 public static function unsuppressUserName( $name, $userId ) {
544 $op = '&'; // bitwise AND
545 return self
::setUsernameBitfields( $name, $userId, $op );
548 private static function setUsernameBitfields( $name, $userId, $op ) {
549 if( $op !== '|' && $op !== '&' ) return false; // sanity check
550 $dbw = wfGetDB( DB_MASTER
);
551 $delUser = Revision
::DELETED_USER | Revision
::DELETED_RESTRICTED
;
552 $delAction = LogPage
::DELETED_ACTION | Revision
::DELETED_RESTRICTED
;
553 # Normalize user name
554 $userTitle = Title
::makeTitleSafe( NS_USER
, $name );
555 $userDbKey = $userTitle->getDBkey();
556 # To suppress, we OR the current bitfields with Revision::DELETED_USER
557 # to put a 1 in the username *_deleted bit. To unsuppress we AND the
558 # current bitfields with the inverse of Revision::DELETED_USER. The
559 # username bit is made to 0 (x & 0 = 0), while others are unchanged (x & 1 = x).
560 # The same goes for the sysop-restricted *_deleted bit.
562 $delUser = "~{$delUser}";
563 $delAction = "~{$delAction}";
565 # Hide name from live edits
566 $dbw->update( 'revision', array( "rev_deleted = rev_deleted $op $delUser" ),
567 array( 'rev_user' => $userId ), __METHOD__
);
568 # Hide name from deleted edits
569 $dbw->update( 'archive', array( "ar_deleted = ar_deleted $op $delUser" ),
570 array( 'ar_user_text' => $name ), __METHOD__
);
571 # Hide name from logs
572 $dbw->update( 'logging', array( "log_deleted = log_deleted $op $delUser" ),
573 array( 'log_user' => $userId, "log_type != 'suppress'" ), __METHOD__
);
574 $dbw->update( 'logging', array( "log_deleted = log_deleted $op $delAction" ),
575 array( 'log_namespace' => NS_USER
, 'log_title' => $userDbKey,
576 "log_type != 'suppress'" ), __METHOD__
);
578 $dbw->update( 'recentchanges', array( "rc_deleted = rc_deleted $op $delUser" ),
579 array( 'rc_user_text' => $name ), __METHOD__
);
580 $dbw->update( 'recentchanges', array( "rc_deleted = rc_deleted $op $delAction" ),
581 array( 'rc_namespace' => NS_USER
, 'rc_title' => $userDbKey, 'rc_logid > 0' ), __METHOD__
);
582 # Hide name from live images
583 $dbw->update( 'oldimage', array( "oi_deleted = oi_deleted $op $delUser" ),
584 array( 'oi_user_text' => $name ), __METHOD__
);
585 # Hide name from deleted images
586 # WMF - schema change pending
587 # $dbw->update( 'filearchive', array( "fa_deleted = fa_deleted $op $delUser" ),
588 # array( 'fa_user_text' => $name ), __METHOD__ );
594 * UI entry point for blocking
595 * Wraps around doBlock()
597 public function doSubmit() {
599 $retval = $this->doBlock();
600 if( empty( $retval ) ) {
601 $titleObj = SpecialPage
::getTitleFor( 'Blockip' );
602 $wgOut->redirect( $titleObj->getFullURL( 'action=success&ip=' .
603 urlencode( $this->BlockAddress
) ) );
606 $this->showForm( $retval );
609 public function showSuccess() {
612 $wgOut->setPageTitle( wfMsg( 'blockip' ) );
613 $wgOut->setSubtitle( wfMsg( 'blockipsuccesssub' ) );
614 $text = wfMsgExt( 'blockipsuccesstext', array( 'parse' ), $this->BlockAddress
);
615 $wgOut->addHTML( $text );
618 private function showLogFragment( $out, $title ) {
621 // Used to support GENDER in 'blocklog-showlog' and 'blocklog-showsuppresslog'
622 $userBlocked = $title->getText();
624 LogEventsList
::showLogExtract(
627 $title->getPrefixedText(),
635 'showIfEmpty' => false
639 // Add suppression block entries if allowed
640 if( $wgUser->isAllowed( 'hideuser' ) ) {
641 LogEventsList
::showLogExtract( $out, 'suppress', $title->getPrefixedText(), '',
645 'log_action' => array(
652 'blocklog-showsuppresslog',
655 'showIfEmpty' => false
662 * Return a comma-delimited list of "flags" to be passed to the log
663 * reader for this block, to provide more information in the logs
667 private function blockLogFlags() {
668 global $wgBlockAllowsUTEdit;
670 if( $this->BlockAnonOnly
&& IP
::isIPAddress( $this->BlockAddress
) )
671 // when blocking a user the option 'anononly' is not available/has no effect -> do not write this into log
672 $flags[] = 'anononly';
673 if( $this->BlockCreateAccount
)
674 $flags[] = 'nocreate';
675 if( !$this->BlockEnableAutoblock
&& !IP
::isIPAddress( $this->BlockAddress
) )
676 // Same as anononly, this is not displayed when blocking an IP address
677 $flags[] = 'noautoblock';
678 if( $this->BlockEmail
)
679 $flags[] = 'noemail';
680 if( !$this->BlockAllowUsertalk
&& $wgBlockAllowsUTEdit )
681 $flags[] = 'nousertalk';
682 if( $this->BlockHideName
)
683 $flags[] = 'hiddenname';
684 return implode( ',', $flags );
688 * Builds unblock and block list links
692 private function getConvenienceLinks() {
693 global $wgUser, $wgLang;
694 $skin = $wgUser->getSkin();
695 if( $this->BlockAddress
)
696 $links[] = $this->getContribsLink( $skin );
697 $links[] = $this->getUnblockLink( $skin );
698 $links[] = $this->getBlockListLink( $skin );
699 if ( $wgUser->isAllowed( 'editinterface' ) ) {
700 $title = Title
::makeTitle( NS_MEDIAWIKI
, 'Ipbreason-dropdown' );
701 $links[] = $skin->link(
703 wfMsgHtml( 'ipb-edit-dropdown' ),
705 array( 'action' => 'edit' )
708 return '<p class="mw-ipb-conveniencelinks">' . $wgLang->pipeList( $links ) . '</p>';
712 * Build a convenient link to a user or IP's contribs
715 * @param $skin Skin to use
718 private function getContribsLink( $skin ) {
719 $contribsPage = SpecialPage
::getTitleFor( 'Contributions', $this->BlockAddress
);
720 return $skin->link( $contribsPage, wfMsgExt( 'ipb-blocklist-contribs', 'escape', $this->BlockAddress
) );
724 * Build a convenient link to unblock the given username or IP
725 * address, if available; otherwise link to a blank unblock
728 * @param $skin Skin to use
731 private function getUnblockLink( $skin ) {
732 $list = SpecialPage
::getTitleFor( 'Ipblocklist' );
733 $query = array( 'action' => 'unblock' );
735 if( $this->BlockAddress
) {
736 $addr = strtr( $this->BlockAddress
, '_', ' ' );
737 $message = wfMsg( 'ipb-unblock-addr', $addr );
738 $query['ip'] = $this->BlockAddress
;
740 $message = wfMsg( 'ipb-unblock' );
742 return $skin->linkKnown(
744 htmlspecialchars( $message ),
751 * Build a convenience link to the block list
753 * @param $skin Skin to use
756 private function getBlockListLink( $skin ) {
757 $list = SpecialPage
::getTitleFor( 'Ipblocklist' );
760 if( $this->BlockAddress
) {
761 $addr = strtr( $this->BlockAddress
, '_', ' ' );
762 $message = wfMsg( 'ipb-blocklist-addr', $addr );
763 $query['ip'] = $this->BlockAddress
;
765 $message = wfMsg( 'ipb-blocklist' );
768 return $skin->linkKnown(
770 htmlspecialchars( $message ),
777 * Block a list of selected users
778 * @param array $users
779 * @param string $reason
780 * @param string $tag replaces user pages
781 * @param string $talkTag replaces user talk pages
782 * @returns array, list of html-safe usernames
784 public static function doMassUserBlock( $users, $reason = '', $tag = '', $talkTag = '' ) {
786 $counter = $blockSize = 0;
787 $safeUsers = array();
788 $log = new LogPage( 'block' );
789 foreach( $users as $name ) {
793 # Lets not go *too* fast
794 if( $blockSize >= 20 ) {
796 wfWaitForSlaves( 5 );
798 $u = User
::newFromName( $name, false );
799 // If user doesn't exist, it ought to be an IP then
800 if( is_null( $u ) ||
( !$u->getId() && !IP
::isIPAddress( $u->getName() ) ) ) {
803 $userTitle = $u->getUserPage();
804 $userTalkTitle = $u->getTalkPage();
805 $userpage = new Article( $userTitle );
806 $usertalk = new Article( $userTalkTitle );
807 $safeUsers[] = '[[' . $userTitle->getPrefixedText() . '|' . $userTitle->getText() . ']]';
808 $expirestr = $u->getId() ?
'indefinite' : '1 week';
809 $expiry = Block
::parseExpiryInput( $expirestr );
810 $anonOnly = IP
::isIPAddress( $u->getName() ) ?
1 : 0;
812 $block = new Block( $u->getName(), // victim
814 $wgUser->getId(), // blocker
816 wfTimestampNow(), // block time
819 $anonOnly, // anononly?
820 1, // block account creation?
823 0 // block from sending email?
825 $oldblock = Block
::newFromDB( $u->getName(), $u->getId() );
828 # Prepare log parameters
829 $logParams = array();
830 $logParams[] = $expirestr;
832 $logParams[] = 'anononly';
834 $logParams[] = 'nocreate';
836 $log->addEntry( 'block', $userTitle, $reason, $logParams );
838 # Tag userpage! (check length to avoid mistakes)
839 if( strlen( $tag ) > 2 ) {
840 $userpage->doEdit( $tag, $reason, EDIT_MINOR
);
842 if( strlen( $talkTag ) > 2 ) {
843 $usertalk->doEdit( $talkTag, $reason, EDIT_MINOR
);