22f4edbec8f5ab786434e1db87554d69cc1aeae7
3 * Implements Special:Blockip
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
21 * @ingroup SpecialPage
25 * A special page that allows users with 'block' right to block users from
26 * editing pages and other actions
28 * @ingroup SpecialPage
30 class IPBlockForm
extends SpecialPage
{
31 var $BlockAddress, $BlockExpiry, $BlockReason, $BlockReasonList, $BlockOther, $BlockAnonOnly, $BlockCreateAccount,
32 $BlockEnableAutoblock, $BlockEmail, $BlockHideName, $BlockAllowUsertalk, $BlockReblock, $BlockWatchUser;
33 // The maximum number of edits a user can have and still be hidden
34 const HIDEUSER_CONTRIBLIMIT
= 1000;
36 public function __construct() {
37 parent
::__construct( 'Blockip', 'block' );
40 public function execute( $par ) {
41 global $wgUser, $wgOut, $wgRequest;
43 # Can't block when the database is locked
45 $wgOut->readOnlyPage();
49 if( !$this->userCanExecute( $wgUser ) ) {
50 $wgOut->permissionRequired( 'block' );
56 # bug 15810: blocked admins should have limited access here
57 if ( $wgUser->isBlocked() ) {
58 $status = IPBlockForm
::checkUnblockSelf( $this->BlockAddress
);
59 if ( $status !== true ) {
60 throw new ErrorPageError( 'badaccess', $status );
64 $action = $wgRequest->getVal( 'action' );
65 if( 'success' == $action ) {
67 } elseif( $wgRequest->wasPosted() && 'submit' == $action &&
68 $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
71 $this->showForm( '' );
75 private function setup( $par ) {
76 global $wgRequest, $wgUser, $wgBlockAllowsUTEdit;
78 $this->BlockAddress
= $wgRequest->getVal( 'wpBlockAddress', $wgRequest->getVal( 'ip', $par ) );
79 $this->BlockAddress
= strtr( $this->BlockAddress
, '_', ' ' );
80 $this->BlockReason
= $wgRequest->getText( 'wpBlockReason' );
81 $this->BlockReasonList
= $wgRequest->getText( 'wpBlockReasonList' );
82 $this->BlockExpiry
= $wgRequest->getVal( 'wpBlockExpiry', wfMsg( 'ipbotheroption' ) );
83 $this->BlockOther
= $wgRequest->getVal( 'wpBlockOther', '' );
85 # Unchecked checkboxes are not included in the form data at all, so having one
86 # that is true by default is a bit tricky
87 $byDefault = !$wgRequest->wasPosted();
88 $this->BlockAnonOnly
= $wgRequest->getBool( 'wpAnonOnly', $byDefault );
89 $this->BlockCreateAccount
= $wgRequest->getBool( 'wpCreateAccount', $byDefault );
90 $this->BlockEnableAutoblock
= $wgRequest->getBool( 'wpEnableAutoblock', $byDefault );
91 $this->BlockEmail
= false;
92 if( self
::canBlockEmail( $wgUser ) ) {
93 $this->BlockEmail
= $wgRequest->getBool( 'wpEmailBan', false );
95 $this->BlockWatchUser
= $wgRequest->getBool( 'wpWatchUser', false ) && $wgUser->isLoggedIn();
96 # Re-check user's rights to hide names, very serious, defaults to null
97 if( $wgUser->isAllowed( 'hideuser' ) ) {
98 $this->BlockHideName
= $wgRequest->getBool( 'wpHideName', null );
100 $this->BlockHideName
= false;
102 $this->BlockAllowUsertalk
= ( $wgRequest->getBool( 'wpAllowUsertalk', $byDefault ) && $wgBlockAllowsUTEdit );
103 $this->BlockReblock
= $wgRequest->getBool( 'wpChangeBlock', false );
105 $this->wasPosted
= $wgRequest->wasPosted();
108 public function showForm( $err ) {
109 global $wgOut, $wgUser;
111 $wgOut->setPageTitle( wfMsg( 'blockip-title' ) );
112 $wgOut->addWikiMsg( 'blockiptext' );
114 $mIpaddress = Xml
::label( wfMsg( 'ipadressorusername' ), 'mw-bi-target' );
115 $mIpbexpiry = Xml
::label( wfMsg( 'ipbexpiry' ), 'wpBlockExpiry' );
116 $mIpbother = Xml
::label( wfMsg( 'ipbother' ), 'mw-bi-other' );
117 $mIpbreasonother = Xml
::label( wfMsg( 'ipbreason' ), 'wpBlockReasonList' );
118 $mIpbreason = Xml
::label( wfMsg( 'ipbotherreason' ), 'mw-bi-reason' );
120 $titleObj = SpecialPage
::getTitleFor( 'Blockip' );
121 $user = User
::newFromName( $this->BlockAddress
);
122 if ( is_object( $user ) || User
::isIP( $this->BlockAddress
) ) {
123 $wgUser->getSkin()->setRelevantUser( is_object($user) ?
$user : User
::newFromName( $this->BlockAddress
, false ) );
126 $alreadyBlocked = false;
127 $otherBlockedMsgs = array();
128 if( $err && $err[0] != 'ipb_already_blocked' ) {
129 $key = array_shift( $err );
130 $msg = wfMsgExt( $key, 'parsemag', $err );
131 $wgOut->setSubtitle( wfMsgHtml( 'formerror' ) );
132 $wgOut->addHTML( Xml
::tags( 'p', array( 'class' => 'error' ), $msg ) );
133 } elseif( $this->BlockAddress
!== null ) {
134 # Get other blocks, i.e. from GlobalBlocking or TorBlock extension
135 wfRunHooks( 'OtherBlockLogLink', array( &$otherBlockedMsgs, $this->BlockAddress
) );
137 $userId = is_object( $user ) ?
$user->getId() : 0;
138 $currentBlock = Block
::newFromDB( $this->BlockAddress
, $userId );
139 if( !is_null( $currentBlock ) && !$currentBlock->mAuto
&& # The block exists and isn't an autoblock
140 ( $currentBlock->mRangeStart
== $currentBlock->mRangeEnd ||
# The block isn't a rangeblock
141 # or if it is, the range is what we're about to block
142 ( $currentBlock->mAddress
== $this->BlockAddress
) )
144 $alreadyBlocked = true;
145 # Set the block form settings to the existing block
146 if( !$this->wasPosted
) {
147 $this->BlockAnonOnly
= $currentBlock->mAnonOnly
;
148 $this->BlockCreateAccount
= $currentBlock->mCreateAccount
;
149 $this->BlockEnableAutoblock
= $currentBlock->mEnableAutoblock
;
150 $this->BlockEmail
= $currentBlock->mBlockEmail
;
151 $this->BlockHideName
= $currentBlock->mHideName
;
152 $this->BlockAllowUsertalk
= $currentBlock->mAllowUsertalk
;
153 if( $currentBlock->mExpiry
== 'infinity' ) {
154 $this->BlockOther
= 'indefinite';
156 $this->BlockOther
= wfTimestamp( TS_ISO_8601
, $currentBlock->mExpiry
);
158 $this->BlockReason
= $currentBlock->mReason
;
163 # Show other blocks from extensions, i.e. GlockBlocking and TorBlock
164 if( count( $otherBlockedMsgs ) ) {
166 Html
::rawElement( 'h2', array(), wfMsgExt( 'ipb-otherblocks-header', 'parseinline', count( $otherBlockedMsgs ) ) ) . "\n"
169 foreach( $otherBlockedMsgs as $link ) {
170 $list .= Html
::rawElement( 'li', array(), $link ) . "\n";
172 $wgOut->addHTML( Html
::rawElement( 'ul', array( 'class' => 'mw-blockip-alreadyblocked' ), $list ) . "\n" );
175 # Username/IP is blocked already locally
176 if( $alreadyBlocked ) {
177 $wgOut->wrapWikiMsg( "<div class='mw-ipb-needreblock'>\n$1\n</div>", array( 'ipb-needreblock', $this->BlockAddress
) );
180 $scBlockExpiryOptions = wfMsgForContent( 'ipboptions' );
182 $showblockoptions = $scBlockExpiryOptions != '-';
183 if( !$showblockoptions ) $mIpbother = $mIpbexpiry;
185 $blockExpiryFormOptions = Xml
::option( wfMsg( 'ipbotheroption' ), 'other' );
186 foreach( explode( ',', $scBlockExpiryOptions ) as $option ) {
187 if( strpos( $option, ':' ) === false ) $option = "$option:$option";
188 list( $show, $value ) = explode( ':', $option );
189 $show = htmlspecialchars( $show );
190 $value = htmlspecialchars( $value );
191 $blockExpiryFormOptions .= Xml
::option( $show, $value, $this->BlockExpiry
=== $value ) . "\n";
194 $reasonDropDown = Xml
::listDropDown( 'wpBlockReasonList',
195 wfMsgForContent( 'ipbreason-dropdown' ),
196 wfMsgForContent( 'ipbreasonotherlist' ), $this->BlockReasonList
, 'wpBlockDropDown', 4 );
198 # FIXME: this should actually use HTMLForm, not just some of its JavaScript
199 $wgOut->addModules( array( 'mediawiki.special.block', 'mediawiki.htmlform' ) );
202 Xml
::openElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalURL( 'action=submit' ), 'id' => 'blockip' ) ) .
203 Xml
::openElement( 'fieldset' ) .
204 Xml
::element( 'legend', null, wfMsg( 'blockip-legend' ) ) .
205 Xml
::openElement( 'table', array( 'border' => '0', 'id' => 'mw-blockip-table' ) ) .
207 <td class='mw-label'>
210 <td class='mw-input'>" .
211 Html
::input( 'wpBlockAddress', $this->BlockAddress
, 'text', array(
213 'id' => 'mw-bi-target',
216 ) +
( $this->BlockAddress ?
array() : array( 'autofocus' ) ) ). "
220 <td class='mw-label'>
223 <td class='mw-input'>"
225 if( $showblockoptions ) {
229 'id' => 'wpBlockExpiry',
230 'name' => 'wpBlockExpiry',
231 'class' => 'mw-htmlform-select-or-other', # FIXME: actually make this use HTMLForm
233 $blockExpiryFormOptions
244 'id' => 'wpBlockExpiry-other'
250 <td class='mw-label'>
253 <td class='mw-input'>
257 <tr id=\"wpBlockReason\">
258 <td class='mw-label'>
261 <td class='mw-input'>" .
262 Html
::input( 'wpBlockReason', $this->BlockReason
, 'text', array(
264 'id' => 'mw-bi-reason',
265 'maxlength' => '200',
267 ) +
( $this->BlockAddress ?
array( 'autofocus' ) : array() ) ) . "
270 <tr id='wpCreateAccountRow'>
272 <td class='mw-input'>" .
273 Xml
::checkLabel( wfMsg( 'ipbcreateaccount' ),
274 'wpCreateAccount', 'wpCreateAccount', $this->BlockCreateAccount
,
275 array( 'tabindex' => '7' ) ) . "
280 if( self
::canBlockEmail( $wgUser ) ) {
282 <tr id='wpEnableEmailBan'>
284 <td class='mw-input'>" .
285 Xml
::checkLabel( wfMsg( 'ipbemailban' ),
286 'wpEmailBan', 'wpEmailBan', $this->BlockEmail
,
287 array( 'tabindex' => '9' ) ) . "
293 # Can we explicitly disallow the use of user_talk?
294 global $wgBlockAllowsUTEdit;
295 if( $wgBlockAllowsUTEdit ){
297 <tr id='wpAllowUsertalkRow'>
299 <td class='mw-input'>" .
300 Xml
::checkLabel( wfMsg( 'ipballowusertalk' ),
301 'wpAllowUsertalk', 'wpAllowUsertalk', $this->BlockAllowUsertalk
,
302 array( 'tabindex' => '12' ) ) . "
309 <tr id='wpEnableAutoblockRow'>
311 <td class='mw-input'>" .
312 Xml
::checkLabel( wfMsg( 'ipbenableautoblock' ),
313 'wpEnableAutoblock', 'wpEnableAutoblock', $this->BlockEnableAutoblock
,
314 array( 'tabindex' => '8' ) ) . "
319 // Allow some users to hide name from block log, blocklist and listusers
320 if( $wgUser->isAllowed( 'hideuser' ) ) {
322 <tr id='wpEnableHideUser'>
324 <td class='mw-input'><strong>" .
325 Xml
::checkLabel( wfMsg( 'ipbhidename' ),
326 'wpHideName', 'wpHideName', $this->BlockHideName
,
327 array( 'tabindex' => '10' )
334 # Watchlist their user page? (Only if user is logged in)
335 if( $wgUser->isLoggedIn() ) {
337 <tr id='wpEnableWatchUser'>
339 <td class='mw-input'>" .
340 Xml
::checkLabel( wfMsg( 'ipbwatchuser' ),
341 'wpWatchUser', 'wpWatchUser', $this->BlockWatchUser
,
342 array( 'tabindex' => '11' ) ) . "
349 <tr id='wpAnonOnlyRow'>
351 <td class='mw-input'>" .
352 Xml
::checkLabel( wfMsg( 'ipbanononly' ),
353 'wpAnonOnly', 'wpAnonOnly', $this->BlockAnonOnly
,
354 array( 'tabindex' => '6' ) ) . "
358 <td style='padding-top: 1em'> </td>
359 <td class='mw-submit' style='padding-top: 1em'>" .
360 Xml
::submitButton( wfMsg( $alreadyBlocked ?
'ipb-change-block' : 'ipbsubmit' ),
361 array( 'name' => 'wpBlock', 'tabindex' => '13' )
362 +
$wgUser->getSkin()->tooltipAndAccessKeyAttribs( 'blockip-block' ) ). "
365 Xml
::closeElement( 'table' ) .
366 Html
::hidden( 'wpEditToken', $wgUser->editToken() ) .
367 ( $alreadyBlocked ? Html
::hidden( 'wpChangeBlock', 1 ) : "" ) .
368 Xml
::closeElement( 'fieldset' ) .
369 Xml
::closeElement( 'form' )
372 $wgOut->addHTML( $this->getConvenienceLinks() );
374 if( is_object( $user ) ) {
375 $this->showLogFragment( $wgOut, $user->getUserPage() );
376 } elseif( preg_match( '/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/', $this->BlockAddress
) ) {
377 $this->showLogFragment( $wgOut, Title
::makeTitle( NS_USER
, $this->BlockAddress
) );
378 } 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
) ) {
379 $this->showLogFragment( $wgOut, Title
::makeTitle( NS_USER
, $this->BlockAddress
) );
384 * Can we do an email block?
385 * @param $user User: the sysop wanting to make a block
388 public static function canBlockEmail( $user ) {
389 global $wgEnableUserEmail, $wgSysopEmailBans;
390 return ( $wgEnableUserEmail && $wgSysopEmailBans && $user->isAllowed( 'blockemail' ) );
394 * bug 15810: blocked admins should not be able to block/unblock
395 * others, and probably shouldn't be able to unblock themselves
397 * @param $user User|Int|String
399 public static function checkUnblockSelf( $user ) {
401 if ( is_int( $user ) ) {
402 $user = User
::newFromId( $user );
403 } elseif ( is_string( $user ) ) {
404 $user = User
::newFromName( $user );
406 if( $user instanceof User
&& $user->getId() == $wgUser->getId() ) {
407 # User is trying to unblock themselves
408 if ( $wgUser->isAllowed( 'unblockself' ) ) {
411 return 'ipbnounblockself';
414 # User is trying to block/unblock someone else
420 * Backend block code.
421 * $userID and $expiry will be filled accordingly
422 * @return array(message key, arguments) on failure, empty array on success
424 function doBlock( &$userId = null, &$expiry = null ) {
425 global $wgUser, $wgBlockAllowsUTEdit, $wgBlockCIDRLimit;
428 # Expand valid IPv6 addresses, usernames are left as is
429 $this->BlockAddress
= IP
::sanitizeIP( $this->BlockAddress
);
430 # isIPv4() and IPv6() are used for final validation
431 $rxIP4 = '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}';
432 $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}';
433 $rxIP = "($rxIP4|$rxIP6)";
435 # Check for invalid specifications
436 if( !preg_match( "/^$rxIP$/", $this->BlockAddress
) ) {
438 if( preg_match( "/^($rxIP4)\\/(\\d{1,2})$/", $this->BlockAddress
, $matches ) ) {
440 if( $wgBlockCIDRLimit['IPv4'] != 32 ){
441 if( !IP
::isIPv4( $this->BlockAddress
) ||
$matches[2] > 32 ) {
442 return array( 'ip_range_invalid' );
443 } elseif ( $matches[2] < $wgBlockCIDRLimit['IPv4'] ) {
444 return array( 'ip_range_toolarge', $wgBlockCIDRLimit['IPv4'] );
446 $this->BlockAddress
= Block
::normaliseRange( $this->BlockAddress
);
448 # Range block illegal
449 return array( 'range_block_disabled' );
451 } elseif( preg_match( "/^($rxIP6)\\/(\\d{1,3})$/", $this->BlockAddress
, $matches ) ) {
453 if( $wgBlockCIDRLimit['IPv6'] != 128 ) {
454 if( !IP
::isIPv6( $this->BlockAddress
) ||
$matches[2] > 128 ) {
455 return array( 'ip_range_invalid' );
456 } elseif( $matches[2] < $wgBlockCIDRLimit['IPv6'] ) {
457 return array( 'ip_range_toolarge', $wgBlockCIDRLimit['IPv6'] );
459 $this->BlockAddress
= Block
::normaliseRange( $this->BlockAddress
);
461 # Range block illegal
462 return array('range_block_disabled');
466 $user = User
::newFromName( $this->BlockAddress
);
467 if( $user instanceof User
&& $user->getId() ) {
469 $userId = $user->getId();
470 $this->BlockAddress
= $user->getName();
472 return array( 'nosuchusershort', htmlspecialchars( $user ?
$user->getName() : $this->BlockAddress
) );
477 if( $wgUser->isBlocked() && ( $wgUser->getId() !== $userId ) ) {
478 return array( 'cant-block-while-blocked' );
481 $reasonstr = $this->BlockReasonList
;
482 if( $reasonstr != 'other' && $this->BlockReason
!= '' ) {
483 // Entry from drop down menu + additional comment
484 $reasonstr .= wfMsgForContent( 'colon-separator' ) . $this->BlockReason
;
485 } elseif( $reasonstr == 'other' ) {
486 $reasonstr = $this->BlockReason
;
489 $expirestr = $this->BlockExpiry
;
490 if( $expirestr == 'other' )
491 $expirestr = $this->BlockOther
;
493 if( ( strlen( $expirestr ) == 0) ||
( strlen( $expirestr ) > 50 ) ) {
494 return array( 'ipb_expiry_invalid' );
497 if( false === ( $expiry = Block
::parseExpiryInput( $expirestr ) ) ) {
499 return array( 'ipb_expiry_invalid' );
502 if( $this->BlockHideName
) {
503 // Recheck params here...
504 if( !$userId ||
!$wgUser->isAllowed('hideuser') ) {
505 $this->BlockHideName
= false; // IP users should not be hidden
506 } elseif( $expiry !== 'infinity' ) {
508 return array( 'ipb_expiry_temp' );
509 } elseif( User
::edits( $userId ) > self
::HIDEUSER_CONTRIBLIMIT
) {
510 // Typically, the user should have a handful of edits.
511 // Disallow hiding users with many edits for performance.
512 return array( 'ipb_hide_invalid' );
516 # Create block object
517 # Note: for a user block, ipb_address is only for display purposes
518 $block = new Block( $this->BlockAddress
, $userId, $wgUser->getId(),
519 $reasonstr, wfTimestampNow(), 0, $expiry, $this->BlockAnonOnly
,
520 $this->BlockCreateAccount
, $this->BlockEnableAutoblock
, $this->BlockHideName
,
522 isset( $this->BlockAllowUsertalk
) ?
$this->BlockAllowUsertalk
: $wgBlockAllowsUTEdit
525 # Should this be privately logged?
526 $suppressLog = (bool)$this->BlockHideName
;
527 if( wfRunHooks( 'BlockIp', array( &$block, &$wgUser ) ) ) {
528 # Try to insert block. Is there a conflicting block?
529 if( !$block->insert() ) {
530 # Show form unless the user is already aware of this...
531 if( !$this->BlockReblock
) {
532 return array( 'ipb_already_blocked' );
533 # Otherwise, try to update the block...
535 # This returns direct blocks before autoblocks/rangeblocks, since we should
536 # be sure the user is blocked by now it should work for our purposes
537 $currentBlock = Block
::newFromDB( $this->BlockAddress
, $userId );
538 if( $block->equals( $currentBlock ) ) {
539 return array( 'ipb_already_blocked' );
541 # If the name was hidden and the blocking user cannot hide
542 # names, then don't allow any block changes...
543 if( $currentBlock->mHideName
&& !$wgUser->isAllowed( 'hideuser' ) ) {
544 return array( 'cant-see-hidden-user' );
546 $currentBlock->delete();
548 # If hiding/unhiding a name, this should go in the private logs
549 $suppressLog = $suppressLog ||
(bool)$currentBlock->mHideName
;
550 $log_action = 'reblock';
551 # Unset _deleted fields if requested
552 if( $currentBlock->mHideName
&& !$this->BlockHideName
) {
553 RevisionDeleteUser
::unsuppressUserName( $this->BlockAddress
, $userId );
557 $log_action = 'block';
559 wfRunHooks( 'BlockIpComplete', array( $block, $wgUser ) );
561 # Set *_deleted fields if requested
562 if( $this->BlockHideName
) {
563 RevisionDeleteUser
::suppressUserName( $this->BlockAddress
, $userId );
566 # Only show watch link when this is no range block
567 if( $this->BlockWatchUser
&& $block->mRangeStart
== $block->mRangeEnd
) {
568 $wgUser->addWatch( Title
::makeTitle( NS_USER
, $this->BlockAddress
) );
571 # Block constructor sanitizes certain block options on insert
572 $this->BlockEmail
= $block->mBlockEmail
;
573 $this->BlockEnableAutoblock
= $block->mEnableAutoblock
;
575 # Prepare log parameters
576 $logParams = array();
577 $logParams[] = $expirestr;
578 $logParams[] = $this->blockLogFlags();
580 # Make log entry, if the name is hidden, put it in the oversight log
581 $log_type = $suppressLog ?
'suppress' : 'block';
582 $log = new LogPage( $log_type );
583 $log->addEntry( $log_action, Title
::makeTitle( NS_USER
, $this->BlockAddress
),
584 $reasonstr, $logParams );
589 return array( 'hookaborted' );
593 # @deprecated since 1.18
594 public static function suppressUserName( $name, $userId, $dbw = null ) {
595 return RevisionDeleteUser
::suppressUserName( $name, $userId, $dbw );
598 # @deprecated since 1.18
599 public static function unsuppressUserName( $name, $userId, $dbw = null ) {
600 return RevisionDeleteUser
::unsuppressUserName( $name, $userId, $dbw );
604 * UI entry point for blocking
605 * Wraps around doBlock()
607 public function doSubmit() {
609 $retval = $this->doBlock();
610 if( empty( $retval ) ) {
611 $titleObj = SpecialPage
::getTitleFor( 'Blockip' );
612 $wgOut->redirect( $titleObj->getFullURL( 'action=success&ip=' .
613 urlencode( $this->BlockAddress
) ) );
616 $this->showForm( $retval );
619 public function showSuccess() {
622 $wgOut->setPageTitle( wfMsg( 'blockip-title' ) );
623 $wgOut->setSubtitle( wfMsg( 'blockipsuccesssub' ) );
624 $text = wfMsgExt( 'blockipsuccesstext', array( 'parse' ), $this->BlockAddress
);
625 $wgOut->addHTML( $text );
628 private function showLogFragment( $out, $title ) {
631 // Used to support GENDER in 'blocklog-showlog' and 'blocklog-showsuppresslog'
632 $userBlocked = $title->getText();
634 LogEventsList
::showLogExtract(
637 $title->getPrefixedText(),
645 'showIfEmpty' => false
649 // Add suppression block entries if allowed
650 if( $wgUser->isAllowed( 'suppressionlog' ) ) {
651 LogEventsList
::showLogExtract( $out, 'suppress', $title->getPrefixedText(), '',
655 'log_action' => array(
662 'blocklog-showsuppresslog',
665 'showIfEmpty' => false
672 * Return a comma-delimited list of "flags" to be passed to the log
673 * reader for this block, to provide more information in the logs
677 private function blockLogFlags() {
678 global $wgBlockAllowsUTEdit;
680 if( $this->BlockAnonOnly
&& IP
::isIPAddress( $this->BlockAddress
) )
681 // when blocking a user the option 'anononly' is not available/has no effect -> do not write this into log
682 $flags[] = 'anononly';
683 if( $this->BlockCreateAccount
)
684 $flags[] = 'nocreate';
685 if( !$this->BlockEnableAutoblock
&& !IP
::isIPAddress( $this->BlockAddress
) )
686 // Same as anononly, this is not displayed when blocking an IP address
687 $flags[] = 'noautoblock';
688 if( $this->BlockEmail
)
689 $flags[] = 'noemail';
690 if( !$this->BlockAllowUsertalk
&& $wgBlockAllowsUTEdit )
691 $flags[] = 'nousertalk';
692 if( $this->BlockHideName
)
693 $flags[] = 'hiddenname';
694 return implode( ',', $flags );
698 * Builds unblock and block list links
702 private function getConvenienceLinks() {
703 global $wgUser, $wgLang;
704 $skin = $wgUser->getSkin();
705 if( $this->BlockAddress
)
706 $links[] = $this->getContribsLink( $skin );
707 $links[] = $this->getUnblockLink( $skin );
708 $links[] = $this->getBlockListLink( $skin );
709 if ( $wgUser->isAllowed( 'editinterface' ) ) {
710 $title = Title
::makeTitle( NS_MEDIAWIKI
, 'Ipbreason-dropdown' );
711 $links[] = $skin->link(
713 wfMsgHtml( 'ipb-edit-dropdown' ),
715 array( 'action' => 'edit' )
718 return '<p class="mw-ipb-conveniencelinks">' . $wgLang->pipeList( $links ) . '</p>';
722 * Build a convenient link to a user or IP's contribs
725 * @param $skin Skin to use
728 private function getContribsLink( $skin ) {
729 $contribsPage = SpecialPage
::getTitleFor( 'Contributions', $this->BlockAddress
);
730 return $skin->link( $contribsPage, wfMsgExt( 'ipb-blocklist-contribs', 'escape', $this->BlockAddress
) );
734 * Build a convenient link to unblock the given username or IP
735 * address, if available; otherwise link to a blank unblock
738 * @param $skin Skin to use
741 private function getUnblockLink( $skin ) {
742 $list = SpecialPage
::getTitleFor( 'Ipblocklist' );
743 $query = array( 'action' => 'unblock' );
745 if( $this->BlockAddress
) {
746 $addr = strtr( $this->BlockAddress
, '_', ' ' );
747 $message = wfMsg( 'ipb-unblock-addr', $addr );
748 $query['ip'] = $this->BlockAddress
;
750 $message = wfMsg( 'ipb-unblock' );
752 return $skin->linkKnown(
754 htmlspecialchars( $message ),
761 * Build a convenience link to the block list
763 * @param $skin Skin to use
766 private function getBlockListLink( $skin ) {
767 return $skin->linkKnown(
768 SpecialPage
::getTitleFor( 'Ipblocklist' ),
769 wfMsg( 'ipb-blocklist' )
774 * Block a list of selected users
776 * @param $users Array
777 * @param $reason String
778 * @param $tag String: replaces user pages
779 * @param $talkTag String: replaces user talk pages
780 * @return Array: list of html-safe usernames
782 public static function doMassUserBlock( $users, $reason = '', $tag = '', $talkTag = '' ) {
784 $counter = $blockSize = 0;
785 $safeUsers = array();
786 $log = new LogPage( 'block' );
787 foreach( $users as $name ) {
791 # Lets not go *too* fast
792 if( $blockSize >= 20 ) {
794 wfWaitForSlaves( 5 );
796 $u = User
::newFromName( $name, false );
797 // If user doesn't exist, it ought to be an IP then
798 if( is_null( $u ) ||
( !$u->getId() && !IP
::isIPAddress( $u->getName() ) ) ) {
801 $userTitle = $u->getUserPage();
802 $userTalkTitle = $u->getTalkPage();
803 $userpage = new Article( $userTitle );
804 $usertalk = new Article( $userTalkTitle );
805 $safeUsers[] = '[[' . $userTitle->getPrefixedText() . '|' . $userTitle->getText() . ']]';
806 $expirestr = $u->getId() ?
'indefinite' : '1 week';
807 $expiry = Block
::parseExpiryInput( $expirestr );
808 $anonOnly = IP
::isIPAddress( $u->getName() ) ?
1 : 0;
810 $block = new Block( $u->getName(), // victim
812 $wgUser->getId(), // blocker
814 wfTimestampNow(), // block time
817 $anonOnly, // anononly?
818 1, // block account creation?
821 0 // block from sending email?
823 $oldblock = Block
::newFromDB( $u->getName(), $u->getId() );
826 # Prepare log parameters
827 $logParams = array();
828 $logParams[] = $expirestr;
830 $logParams[] = 'anononly';
832 $logParams[] = 'nocreate';
834 $log->addEntry( 'block', $userTitle, $reason, $logParams );
836 # Tag userpage! (check length to avoid mistakes)
837 if( strlen( $tag ) > 2 ) {
838 $userpage->doEdit( $tag, $reason, EDIT_MINOR
);
840 if( strlen( $talkTag ) > 2 ) {
841 $usertalk->doEdit( $talkTag, $reason, EDIT_MINOR
);