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();
22 if( !$wgUser->isAllowed( 'block' ) ) {
23 $wgOut->permissionRequired( 'block' );
27 $ipb = new IPBlockForm( $par );
29 $action = $wgRequest->getVal( 'action' );
30 if ( 'success' == $action ) {
32 } else if ( $wgRequest->wasPosted() && 'submit' == $action &&
33 $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
41 * Form object for the Special:Blockip page.
43 * @ingroup SpecialPage
46 var $BlockAddress, $BlockExpiry, $BlockReason;
48 // The maximum number of edits a user can have and still be hidden
49 const HIDEUSER_CONTRIBLIMIT = 1000;
51 function IPBlockForm( $par ) {
52 global $wgRequest, $wgUser, $wgBlockAllowsUTEdit;
54 $this->BlockAddress = $wgRequest->getVal( 'wpBlockAddress', $wgRequest->getVal( 'ip', $par ) );
55 $this->BlockAddress = strtr( $this->BlockAddress, '_', ' ' );
56 $this->BlockReason = $wgRequest->getText( 'wpBlockReason' );
57 $this->BlockReasonList = $wgRequest->getText( 'wpBlockReasonList' );
58 $this->BlockExpiry = $wgRequest->getVal( 'wpBlockExpiry', wfMsg('ipbotheroption') );
59 $this->BlockOther = $wgRequest->getVal( 'wpBlockOther', '' );
61 # Unchecked checkboxes are not included in the form data at all, so having one
62 # that is true by default is a bit tricky
63 $byDefault = !$wgRequest->wasPosted();
64 $this->BlockAnonOnly = $wgRequest->getBool( 'wpAnonOnly', $byDefault );
65 $this->BlockCreateAccount = $wgRequest->getBool( 'wpCreateAccount', $byDefault );
66 $this->BlockEnableAutoblock = $wgRequest->getBool( 'wpEnableAutoblock', $byDefault );
67 $this->BlockEmail = $wgRequest->getBool( 'wpEmailBan', false );
68 $this->BlockWatchUser = $wgRequest->getBool( 'wpWatchUser', false );
69 # Re-check user's rights to hide names, very serious, defaults to 0
70 $this->BlockHideName = ( $wgRequest->getBool( 'wpHideName', 0 ) && $wgUser->isAllowed( 'hideuser' ) ) ? 1 : 0;
71 $this->BlockAllowUsertalk = ( $wgRequest->getBool( 'wpAllowUsertalk', $byDefault ) && $wgBlockAllowsUTEdit );
72 $this->BlockReblock = $wgRequest->getBool( 'wpChangeBlock', false );
75 function showForm( $err ) {
76 global $wgOut, $wgUser, $wgSysopUserBans;
78 $wgOut->setPagetitle( wfMsg( 'blockip' ) );
79 $wgOut->addWikiMsg( 'blockiptext' );
81 if($wgSysopUserBans) {
82 $mIpaddress = Xml::label( wfMsg( 'ipadressorusername' ), 'mw-bi-target' );
84 $mIpaddress = Xml::label( wfMsg( 'ipaddress' ), 'mw-bi-target' );
86 $mIpbexpiry = Xml::label( wfMsg( 'ipbexpiry' ), 'wpBlockExpiry' );
87 $mIpbother = Xml::label( wfMsg( 'ipbother' ), 'mw-bi-other' );
88 $mIpbreasonother = Xml::label( wfMsg( 'ipbreason' ), 'wpBlockReasonList' );
89 $mIpbreason = Xml::label( wfMsg( 'ipbotherreason' ), 'mw-bi-reason' );
91 $titleObj = SpecialPage::getTitleFor( 'Blockip' );
92 $user = User::newFromName( $this->BlockAddress );
94 $alreadyBlocked = false;
95 if ( $err && $err[0] != 'ipb_already_blocked' ) {
96 $key = array_shift($err);
97 $msg = wfMsgReal($key, $err);
98 $wgOut->setSubtitle( wfMsgHtml( 'formerror' ) );
99 $wgOut->addHTML( Xml::tags( 'p', array( 'class' => 'error' ), $msg ) );
100 } elseif ( $this->BlockAddress ) {
102 if ( is_object( $user ) )
103 $userId = $user->getId();
104 $currentBlock = Block::newFromDB( $this->BlockAddress, $userId );
105 if ( !is_null($currentBlock) && !$currentBlock->mAuto && # The block exists and isn't an autoblock
106 ( $currentBlock->mRangeStart == $currentBlock->mRangeEnd || # The block isn't a rangeblock
107 # or if it is, the range is what we're about to block
108 ( $currentBlock->mAddress == $this->BlockAddress ) ) ) {
109 $wgOut->addWikiMsg( 'ipb-needreblock', $this->BlockAddress );
110 $alreadyBlocked = true;
111 # Set the block form settings to the existing block
112 $this->BlockAnonOnly = $currentBlock->mAnonOnly;
113 $this->BlockCreateAccount = $currentBlock->mCreateAccount;
114 $this->BlockEnableAutoblock = $currentBlock->mEnableAutoblock;
115 $this->BlockEmail = $currentBlock->mBlockEmail;
116 $this->BlockHideName = $currentBlock->mHideName;
117 $this->BlockAllowUsertalk = $currentBlock->mAllowUsertalk;
118 if( $currentBlock->mExpiry == 'infinity' ) {
119 $this->BlockOther = 'indefinite';
121 $this->BlockOther = wfTimestamp( TS_ISO_8601, $currentBlock->mExpiry );
123 $this->BlockReason = $currentBlock->mReason;
127 $scBlockExpiryOptions = wfMsgForContent( 'ipboptions' );
129 $showblockoptions = $scBlockExpiryOptions != '-';
130 if (!$showblockoptions)
131 $mIpbother = $mIpbexpiry;
133 $blockExpiryFormOptions = Xml::option( wfMsg( 'ipbotheroption' ), 'other' );
134 foreach (explode(',', $scBlockExpiryOptions) as $option) {
135 if ( strpos($option, ":") === false ) $option = "$option:$option";
136 list($show, $value) = explode(":", $option);
137 $show = htmlspecialchars($show);
138 $value = htmlspecialchars($value);
139 $blockExpiryFormOptions .= Xml::option( $show, $value, $this->BlockExpiry === $value ? true : false ) . "\n";
142 $reasonDropDown = Xml::listDropDown( 'wpBlockReasonList',
143 wfMsgForContent( 'ipbreason-dropdown' ),
144 wfMsgForContent( 'ipbreasonotherlist' ), $this->BlockReasonList, 'wpBlockDropDown', 4 );
146 global $wgStylePath, $wgStyleVersion;
148 Xml::tags( 'script', array( 'type' => 'text/javascript', 'src' => "$wgStylePath/common/block.js?$wgStyleVersion" ), '' ) .
149 Xml::openElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalURL( "action=submit" ), 'id' => 'blockip' ) ) .
150 Xml::openElement( 'fieldset' ) .
151 Xml::element( 'legend', null, wfMsg( 'blockip-legend' ) ) .
152 Xml::openElement( 'table', array ( 'border' => '0', 'id' => 'mw-blockip-table' ) ) .
154 <td class='mw-label'>
157 <td class='mw-input'>" .
158 Xml::input( 'wpBlockAddress', 45, $this->BlockAddress,
161 'id' => 'mw-bi-target',
162 'onchange' => 'updateBlockOptions()' ) ). "
167 if ( $showblockoptions ) {
169 <td class='mw-label'>
172 <td class='mw-input'>" .
175 'id' => 'wpBlockExpiry',
176 'name' => 'wpBlockExpiry',
177 'onchange' => 'considerChangingExpiryFocus()',
179 $blockExpiryFormOptions ) .
185 <tr id='wpBlockOther'>
186 <td class='mw-label'>
189 <td class='mw-input'>" .
190 Xml::input( 'wpBlockOther', 45, $this->BlockOther,
191 array( 'tabindex' => '3', 'id' => 'mw-bi-other' ) ) . "
195 <td class='mw-label'>
198 <td class='mw-input'>
202 <tr id=\"wpBlockReason\">
203 <td class='mw-label'>
206 <td class='mw-input'>" .
207 Xml::input( 'wpBlockReason', 45, $this->BlockReason,
208 array( 'tabindex' => '5', 'id' => 'mw-bi-reason', 'maxlength'=> '200' ) ) . "
211 <tr id='wpAnonOnlyRow'>
213 <td class='mw-input'>" .
214 Xml::checkLabel( wfMsg( 'ipbanononly' ),
215 'wpAnonOnly', 'wpAnonOnly', $this->BlockAnonOnly,
216 array( 'tabindex' => '6' ) ) . "
219 <tr id='wpCreateAccountRow'>
221 <td class='mw-input'>" .
222 Xml::checkLabel( wfMsg( 'ipbcreateaccount' ),
223 'wpCreateAccount', 'wpCreateAccount', $this->BlockCreateAccount,
224 array( 'tabindex' => '7' ) ) . "
227 <tr id='wpEnableAutoblockRow'>
229 <td class='mw-input'>" .
230 Xml::checkLabel( wfMsg( 'ipbenableautoblock' ),
231 'wpEnableAutoblock', 'wpEnableAutoblock', $this->BlockEnableAutoblock,
232 array( 'tabindex' => '8' ) ) . "
237 global $wgSysopEmailBans, $wgBlockAllowsUTEdit;
238 if ( $wgSysopEmailBans && $wgUser->isAllowed( 'blockemail' ) ) {
240 <tr id='wpEnableEmailBan'>
242 <td class='mw-input'>" .
243 Xml::checkLabel( wfMsg( 'ipbemailban' ),
244 'wpEmailBan', 'wpEmailBan', $this->BlockEmail,
245 array( 'tabindex' => '9' )) . "
251 // Allow some users to hide name from block log, blocklist and listusers
252 if ( $wgUser->isAllowed( 'hideuser' ) ) {
254 <tr id='wpEnableHideUser'>
256 <td class='mw-input'><strong>" .
257 Xml::checkLabel( wfMsg( 'ipbhidename' ),
258 'wpHideName', 'wpHideName', $this->BlockHideName,
259 array( 'tabindex' => '10' ) ) . "
265 # Watchlist their user page?
267 <tr id='wpEnableWatchUser'>
269 <td class='mw-input'>" .
270 Xml::checkLabel( wfMsg( 'ipbwatchuser' ),
271 'wpWatchUser', 'wpWatchUser', $this->BlockWatchUser,
272 array( 'tabindex' => '11' ) ) . "
276 if( $wgBlockAllowsUTEdit ){
278 <tr id='wpAllowUsertalkRow'>
280 <td class='mw-input'>" .
281 Xml::checkLabel( wfMsg( 'ipballowusertalk' ),
282 'wpAllowUsertalk', 'wpAllowUsertalk', $this->BlockAllowUsertalk,
283 array( 'tabindex' => '12' ) ) . "
291 <td style='padding-top: 1em'> </td>
292 <td class='mw-submit' style='padding-top: 1em'>" .
293 Xml::submitButton( wfMsg( $alreadyBlocked ? 'ipb-change-block' : 'ipbsubmit' ),
294 array( 'name' => 'wpBlock', 'tabindex' => '13', 'accesskey' => 's' ) ) . "
297 Xml::closeElement( 'table' ) .
298 Xml::hidden( 'wpEditToken', $wgUser->editToken() ) .
299 ( $alreadyBlocked ? Xml::hidden( 'wpChangeBlock', 1 ) : "" ) .
300 Xml::closeElement( 'fieldset' ) .
301 Xml::closeElement( 'form' ) .
302 Xml::tags( 'script', array( 'type' => 'text/javascript' ), 'updateBlockOptions()' ) . "\n"
305 $wgOut->addHTML( $this->getConvenienceLinks() );
307 if( is_object( $user ) ) {
308 $this->showLogFragment( $wgOut, $user->getUserPage() );
309 } elseif( preg_match( '/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/', $this->BlockAddress ) ) {
310 $this->showLogFragment( $wgOut, Title::makeTitle( NS_USER, $this->BlockAddress ) );
311 } 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 ) ) {
312 $this->showLogFragment( $wgOut, Title::makeTitle( NS_USER, $this->BlockAddress ) );
317 * Backend block code.
318 * $userID and $expiry will be filled accordingly
319 * @return array(message key, arguments) on failure, empty array on success
321 function doBlock( &$userId = null, &$expiry = null ) {
322 global $wgUser, $wgSysopUserBans, $wgSysopRangeBans, $wgBlockAllowsUTEdit;
325 # Expand valid IPv6 addresses, usernames are left as is
326 $this->BlockAddress = IP::sanitizeIP( $this->BlockAddress );
327 # isIPv4() and IPv6() are used for final validation
328 $rxIP4 = '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}';
329 $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}';
330 $rxIP = "($rxIP4|$rxIP6)";
332 # Check for invalid specifications
333 if ( !preg_match( "/^$rxIP$/", $this->BlockAddress ) ) {
335 if ( preg_match( "/^($rxIP4)\\/(\\d{1,2})$/", $this->BlockAddress, $matches ) ) {
337 if ( $wgSysopRangeBans ) {
338 if ( !IP::isIPv4( $this->BlockAddress ) || $matches[2] < 16 || $matches[2] > 32 ) {
339 return array('ip_range_invalid');
341 $this->BlockAddress = Block::normaliseRange( $this->BlockAddress );
343 # Range block illegal
344 return array('range_block_disabled');
346 } else if ( preg_match( "/^($rxIP6)\\/(\\d{1,3})$/", $this->BlockAddress, $matches ) ) {
348 if ( $wgSysopRangeBans ) {
349 if ( !IP::isIPv6( $this->BlockAddress ) || $matches[2] < 64 || $matches[2] > 128 ) {
350 return array('ip_range_invalid');
352 $this->BlockAddress = Block::normaliseRange( $this->BlockAddress );
354 # Range block illegal
355 return array('range_block_disabled');
359 if ( $wgSysopUserBans ) {
360 $user = User::newFromName( $this->BlockAddress );
361 if( !is_null( $user ) && $user->getId() ) {
363 $userId = $user->getId();
364 $this->BlockAddress = $user->getName();
366 return array('nosuchusershort', htmlspecialchars( $user ? $user->getName() : $this->BlockAddress ) );
369 return array('badipaddress');
374 if ( $wgUser->isBlocked() && ( $wgUser->getId() !== $userId ) ) {
375 return array( 'cant-block-while-blocked' );
378 $reasonstr = $this->BlockReasonList;
379 if ( $reasonstr != 'other' && $this->BlockReason != '' ) {
380 // Entry from drop down menu + additional comment
381 $reasonstr .= wfMsgForContent( 'colon-separator' ) . $this->BlockReason;
382 } elseif ( $reasonstr == 'other' ) {
383 $reasonstr = $this->BlockReason;
386 $expirestr = $this->BlockExpiry;
387 if( $expirestr == 'other' )
388 $expirestr = $this->BlockOther;
390 if ( ( strlen( $expirestr ) == 0) || ( strlen( $expirestr ) > 50) ) {
391 return array('ipb_expiry_invalid');
394 if ( false === ($expiry = Block::parseExpiryInput( $expirestr )) ) {
396 return array('ipb_expiry_invalid');
399 if( $this->BlockHideName ) {
401 // IP users should not be hidden
402 $this->BlockHideName = false;
403 } else if( $expiry !== 'infinity' ) {
405 return array('ipb_expiry_temp');
406 } else if( User::edits($userId) > self::HIDEUSER_CONTRIBLIMIT ) {
407 // Typically, the user should have a handful of edits.
408 // Disallow hiding users with many edits for performance.
409 return array('ipb_hide_invalid');
414 # Note: for a user block, ipb_address is only for display purposes
415 $block = new Block( $this->BlockAddress, $userId, $wgUser->getId(),
416 $reasonstr, wfTimestampNow(), 0, $expiry, $this->BlockAnonOnly,
417 $this->BlockCreateAccount, $this->BlockEnableAutoblock, $this->BlockHideName,
418 $this->BlockEmail, isset( $this->BlockAllowUsertalk ) ? $this->BlockAllowUsertalk : $wgBlockAllowsUTEdit
421 # Should this be privately logged?
422 $suppressLog = (bool)$this->BlockHideName;
423 if ( wfRunHooks('BlockIp', array(&$block, &$wgUser)) ) {
424 # Try to insert block. Is there a conflicting block?
425 if ( !$block->insert() ) {
426 # Show form unless the user is already aware of this...
427 if ( !$this->BlockReblock ) {
428 return array( 'ipb_already_blocked' );
429 # Otherwise, try to update the block...
431 # This returns direct blocks before autoblocks/rangeblocks, since we should
432 # be sure the user is blocked by now it should work for our purposes
433 $currentBlock = Block::newFromDB( $this->BlockAddress, $userId );
434 if( $block->equals( $currentBlock ) ) {
435 return array( 'ipb_already_blocked' );
437 # If the name was hidden and the blocking user cannot hide
438 # names, then don't allow any block changes...
439 if( $currentBlock->mHideName && !$wgUser->isAllowed('hideuser') ) {
440 return array( 'hookaborted' );
442 $currentBlock->delete();
444 # If hiding/unhiding a name, this should go in the private logs
445 $suppressLog = $suppressLog || (bool)$currentBlock->mHideName;
446 $log_action = 'reblock';
447 # Unset _deleted fields if requested
448 if( $currentBlock->mHideName && !$this->BlockHideName ) {
449 self::unsuppressUserName( $this->BlockAddress, $userId );
453 $log_action = 'block';
455 wfRunHooks('BlockIpComplete', array($block, $wgUser));
457 # Set *_deleted fields if requested
458 if( $this->BlockHideName ) {
459 self::suppressUserName( $this->BlockAddress, $userId );
462 if ( $this->BlockWatchUser &&
463 # Only show watch link when this is no range block
464 $block->mRangeStart == $block->mRangeEnd) {
465 $wgUser->addWatch ( Title::makeTitle( NS_USER, $this->BlockAddress ) );
468 # Block constructor sanitizes certain block options on insert
469 $this->BlockEmail = $block->mBlockEmail;
470 $this->BlockEnableAutoblock = $block->mEnableAutoblock;
472 # Prepare log parameters
473 $logParams = array();
474 $logParams[] = $expirestr;
475 $logParams[] = $this->blockLogFlags();
477 # Make log entry, if the name is hidden, put it in the oversight log
478 $log_type = $suppressLog ? 'suppress' : 'block';
479 $log = new LogPage( $log_type );
480 $log->addEntry( $log_action, Title::makeTitle( NS_USER, $this->BlockAddress ),
481 $reasonstr, $logParams );
486 return array('hookaborted');
490 public static function suppressUserName( $name, $userId ) {
491 $op = '|'; // bitwise OR
492 return self::setUsernameBitfields( $name, $userId, $op );
495 public static function unsuppressUserName( $name, $userId ) {
496 $op = '&'; // bitwise AND
497 return self::setUsernameBitfields( $name, $userId, $op );
500 private static function setUsernameBitfields( $name, $userId, $op ) {
501 if( $op !== '|' && $op !== '&' )
502 return false; // sanity check
503 $dbw = wfGetDB( DB_MASTER );
504 $delUser = Revision::DELETED_USER | Revision::DELETED_RESTRICTED;
505 $delAction = LogPage::DELETED_ACTION | Revision::DELETED_RESTRICTED;
506 # Normalize user name
507 $userTitle = Title::makeTitleSafe( NS_USER, $name );
508 $userDbKey = $userTitle->getDBKey();
509 # To suppress, we OR the current bitfields with Revision::DELETED_USER
510 # to put a 1 in the username *_deleted bit. To unsuppress we AND the
511 # current bitfields with the inverse of Revision::DELETED_USER. The
512 # username bit is made to 0 (x & 0 = 0), while others are unchanged (x & 1 = x).
513 # The same goes for the sysop-restricted *_deleted bit.
515 $delUser = "~{$delUser}";
516 $delAction = "~{$delAction}";
518 # Hide name from live edits
519 $dbw->update( 'revision', array("rev_deleted = rev_deleted $op $delUser"),
520 array('rev_user' => $userId), __METHOD__ );
521 # Hide name from deleted edits
522 $dbw->update( 'archive', array("ar_deleted = ar_deleted $op $delUser"),
523 array('ar_user_text' => $name), __METHOD__ );
524 # Hide name from logs
525 $dbw->update( 'logging', array("log_deleted = log_deleted $op $delUser"),
526 array('log_user' => $userId, "log_type != 'suppress'"), __METHOD__ );
527 $dbw->update( 'logging', array("log_deleted = log_deleted $op $delAction"),
528 array('log_namespace' => NS_USER, 'log_title' => $userDbKey,
529 "log_type != 'suppress'"), __METHOD__ );
531 $dbw->update( 'recentchanges', array("rc_deleted = rc_deleted $op $delUser"),
532 array('rc_user_text' => $name), __METHOD__ );
533 # Hide name from live images
534 $dbw->update( 'oldimage', array("oi_deleted = oi_deleted $op $delUser"),
535 array('oi_user_text' => $name), __METHOD__ );
536 # Hide name from deleted images
537 # WMF - schema change pending
538 # $dbw->update( 'filearchive', array("fa_deleted = fa_deleted $op $delUser"),
539 # array('fa_user_text' => $name), __METHOD__ );
545 * UI entry point for blocking
546 * Wraps around doBlock()
551 $retval = $this->doBlock();
553 $titleObj = SpecialPage::getTitleFor( 'Blockip' );
554 $wgOut->redirect( $titleObj->getFullURL( 'action=success&ip=' .
555 urlencode( $this->BlockAddress ) ) );
558 $this->showForm( $retval );
561 function showSuccess() {
564 $wgOut->setPagetitle( wfMsg( 'blockip' ) );
565 $wgOut->setSubtitle( wfMsg( 'blockipsuccesssub' ) );
566 $text = wfMsgExt( 'blockipsuccesstext', array( 'parse' ), $this->BlockAddress );
567 $wgOut->addHTML( $text );
570 function showLogFragment( $out, $title ) {
572 $out->addHTML( Xml::element( 'h2', NULL, LogPage::logName( 'block' ) ) );
573 $count = LogEventsList::showLogExtract( $out, 'block', $title->getPrefixedText(), '', 10 );
575 $out->addHTML( $wgUser->getSkin()->link(
576 SpecialPage::getTitleFor( 'Log' ),
577 wfMsgHtml( 'blocklog-fulllog' ),
581 'page' => $title->getPrefixedText() ) ) );
586 * Return a comma-delimited list of "flags" to be passed to the log
587 * reader for this block, to provide more information in the logs
591 private function blockLogFlags() {
592 global $wgBlockAllowsUTEdit;
594 if( $this->BlockAnonOnly && IP::isIPAddress( $this->BlockAddress ) )
595 // when blocking a user the option 'anononly' is not available/has no effect -> do not write this into log
596 $flags[] = 'anononly';
597 if( $this->BlockCreateAccount )
598 $flags[] = 'nocreate';
599 if( !$this->BlockEnableAutoblock )
600 $flags[] = 'noautoblock';
601 if ( $this->BlockEmail )
602 $flags[] = 'noemail';
603 if ( !$this->BlockAllowUsertalk && $wgBlockAllowsUTEdit )
604 $flags[] = 'nousertalk';
605 if ( $this->BlockHideName )
606 $flags[] = 'hiddenname';
607 return implode( ',', $flags );
611 * Builds unblock and block list links
615 private function getConvenienceLinks() {
616 global $wgUser, $wgLang;
617 $skin = $wgUser->getSkin();
618 if( $this->BlockAddress )
619 $links[] = $this->getContribsLink( $skin );
620 $links[] = $this->getUnblockLink( $skin );
621 $links[] = $this->getBlockListLink( $skin );
622 $links[] = $skin->makeLink ( 'MediaWiki:Ipbreason-dropdown', wfMsgHtml( 'ipb-edit-dropdown' ) );
623 return '<p class="mw-ipb-conveniencelinks">' . $wgLang->pipeList( $links ) . '</p>';
627 * Build a convenient link to a user or IP's contribs
630 * @param $skin Skin to use
633 private function getContribsLink( $skin ) {
634 $contribsPage = SpecialPage::getTitleFor( 'Contributions', $this->BlockAddress );
635 return $skin->link( $contribsPage, wfMsgExt( 'ipb-blocklist-contribs', 'escape', $this->BlockAddress ) );
639 * Build a convenient link to unblock the given username or IP
640 * address, if available; otherwise link to a blank unblock
643 * @param $skin Skin to use
646 private function getUnblockLink( $skin ) {
647 $list = SpecialPage::getTitleFor( 'Ipblocklist' );
648 if( $this->BlockAddress ) {
649 $addr = htmlspecialchars( strtr( $this->BlockAddress, '_', ' ' ) );
650 return $skin->makeKnownLinkObj( $list, wfMsgHtml( 'ipb-unblock-addr', $addr ),
651 'action=unblock&ip=' . urlencode( $this->BlockAddress ) );
653 return $skin->makeKnownLinkObj( $list, wfMsgHtml( 'ipb-unblock' ), 'action=unblock' );
658 * Build a convenience link to the block list
660 * @param $skin Skin to use
663 private function getBlockListLink( $skin ) {
664 $list = SpecialPage::getTitleFor( 'Ipblocklist' );
665 if( $this->BlockAddress ) {
666 $addr = htmlspecialchars( strtr( $this->BlockAddress, '_', ' ' ) );
667 return $skin->makeKnownLinkObj( $list, wfMsgHtml( 'ipb-blocklist-addr', $addr ),
668 'ip=' . urlencode( $this->BlockAddress ) );
670 return $skin->makeKnownLinkObj( $list, wfMsgHtml( 'ipb-blocklist' ) );
675 * Block a list of selected users
676 * @param array $users
677 * @param string $reason
678 * @param string $tag replaces user pages
679 * @param string $talkTag replaces user talk pages
680 * @returns array, list of html-safe usernames
682 public static function doMassUserBlock( $users, $reason = '', $tag = '', $talkTag = '' ) {
684 $counter = $blockSize = 0;
685 $safeUsers = array();
686 $log = new LogPage( 'block' );
687 foreach( $users as $name ) {
691 # Lets not go *too* fast
692 if( $blockSize >= 20 ) {
694 wfWaitForSlaves( 5 );
696 $u = User::newFromName( $name, false );
697 // If user doesn't exist, it ought to be an IP then
698 if( is_null($u) || (!$u->getId() && !IP::isIPAddress( $u->getName() )) ) {
701 $userTitle = $u->getUserPage();
702 $userTalkTitle = $u->getTalkPage();
703 $userpage = new Article( $userTitle );
704 $usertalk = new Article( $userTalkTitle );
705 $safeUsers[] = '[[' . $userTitle->getPrefixedText() . '|' . $userTitle->getText() . ']]';
706 $expirestr = $u->getId() ? 'indefinite' : '1 week';
707 $expiry = Block::parseExpiryInput( $expirestr );
708 $anonOnly = IP::isIPAddress( $u->getName() ) ? 1 : 0;
710 $block = new Block( $u->getName(), // victim
712 $wgUser->getId(), // blocker
714 wfTimestampNow(), // block time
717 $anonOnly, // anononly?
718 1, // block account creation?
721 0 // block from sending email?
723 $oldblock = Block::newFromDB( $u->getName(), $u->getId() );
726 # Prepare log parameters
727 $logParams = array();
728 $logParams[] = $expirestr;
730 $logParams[] = 'anononly';
732 $logParams[] = 'nocreate';
734 $log->addEntry( 'block', $userTitle, $reason, $logParams );
736 # Tag userpage! (check length to avoid mistakes)
737 if( strlen($tag) > 2 ) {
738 $userpage->doEdit( $tag, $reason, EDIT_MINOR );
740 if( strlen($talkTag) > 2 ) {
741 $usertalk->doEdit( $talkTag, $reason, EDIT_MINOR );