Oracle support: added a DB piped function & collection type for getting of DBMS_OUTPU...
[mediawiki.git] / includes / specials / SpecialBlockip.php
bloba32092ee0c431b0bfc5c8ca5efe7d7f906fd05a3
1 <?php
2 /**
3 * Constructor for Special:Blockip page
5 * @file
6 * @ingroup SpecialPage
7 */
9 /**
10 * Constructor
12 function wfSpecialBlockip( $par ) {
13 global $wgUser, $wgOut, $wgRequest;
15 # Can't block when the database is locked
16 if( wfReadOnly() ) {
17 $wgOut->readOnlyPage();
18 return;
20 # Permission check
21 if( !$wgUser->isAllowed( 'block' ) ) {
22 $wgOut->permissionRequired( 'block' );
23 return;
26 $ipb = new IPBlockForm( $par );
28 $action = $wgRequest->getVal( 'action' );
29 if( 'success' == $action ) {
30 $ipb->showSuccess();
31 } elseif( $wgRequest->wasPosted() && 'submit' == $action &&
32 $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
33 $ipb->doSubmit();
34 } else {
35 $ipb->showForm( '' );
39 /**
40 * Form object for the Special:Blockip page.
42 * @ingroup SpecialPage
44 class IPBlockForm {
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 );
73 } else {
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' );
90 } else {
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 $userId = is_object( $user ) ? $user->getId() : 0;
109 $currentBlock = Block::newFromDB( $this->BlockAddress, $userId );
110 if( !is_null( $currentBlock ) && !$currentBlock->mAuto && # The block exists and isn't an autoblock
111 ( $currentBlock->mRangeStart == $currentBlock->mRangeEnd || # The block isn't a rangeblock
112 # or if it is, the range is what we're about to block
113 ( $currentBlock->mAddress == $this->BlockAddress ) )
115 $wgOut->addWikiMsg( 'ipb-needreblock', $this->BlockAddress );
116 $alreadyBlocked = true;
117 # Set the block form settings to the existing block
118 if( !$this->wasPosted ) {
119 $this->BlockAnonOnly = $currentBlock->mAnonOnly;
120 $this->BlockCreateAccount = $currentBlock->mCreateAccount;
121 $this->BlockEnableAutoblock = $currentBlock->mEnableAutoblock;
122 $this->BlockEmail = $currentBlock->mBlockEmail;
123 $this->BlockHideName = $currentBlock->mHideName;
124 $this->BlockAllowUsertalk = $currentBlock->mAllowUsertalk;
125 if( $currentBlock->mExpiry == 'infinity' ) {
126 $this->BlockOther = 'indefinite';
127 } else {
128 $this->BlockOther = wfTimestamp( TS_ISO_8601, $currentBlock->mExpiry );
130 $this->BlockReason = $currentBlock->mReason;
135 $scBlockExpiryOptions = wfMsgForContent( 'ipboptions' );
137 $showblockoptions = $scBlockExpiryOptions != '-';
138 if( !$showblockoptions ) $mIpbother = $mIpbexpiry;
140 $blockExpiryFormOptions = Xml::option( wfMsg( 'ipbotheroption' ), 'other' );
141 foreach( explode( ',', $scBlockExpiryOptions ) as $option ) {
142 if( strpos( $option, ':' ) === false ) $option = "$option:$option";
143 list( $show, $value ) = explode( ':', $option );
144 $show = htmlspecialchars( $show );
145 $value = htmlspecialchars( $value );
146 $blockExpiryFormOptions .= Xml::option( $show, $value, $this->BlockExpiry === $value ? true : false ) . "\n";
149 $reasonDropDown = Xml::listDropDown( 'wpBlockReasonList',
150 wfMsgForContent( 'ipbreason-dropdown' ),
151 wfMsgForContent( 'ipbreasonotherlist' ), $this->BlockReasonList, 'wpBlockDropDown', 4 );
153 global $wgStylePath, $wgStyleVersion;
154 $wgOut->addHTML(
155 Xml::tags( 'script', array( 'type' => 'text/javascript', 'src' => "$wgStylePath/common/block.js?$wgStyleVersion" ), '' ) .
156 Xml::openElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalURL( 'action=submit' ), 'id' => 'blockip' ) ) .
157 Xml::openElement( 'fieldset' ) .
158 Xml::element( 'legend', null, wfMsg( 'blockip-legend' ) ) .
159 Xml::openElement( 'table', array( 'border' => '0', 'id' => 'mw-blockip-table' ) ) .
160 "<tr>
161 <td class='mw-label'>
162 {$mIpaddress}
163 </td>
164 <td class='mw-input'>" .
165 Html::input( 'wpBlockAddress', $this->BlockAddress, 'text', array(
166 'tabindex' => '1',
167 'id' => 'mw-bi-target',
168 'onchange' => 'updateBlockOptions()',
169 'size' => '45',
170 'required' => ''
171 ) + ( $this->BlockAddress ? array() : array( 'autofocus' ) ) ). "
172 </td>
173 </tr>
174 <tr>"
176 if( $showblockoptions ) {
177 $wgOut->addHTML("
178 <td class='mw-label'>
179 {$mIpbexpiry}
180 </td>
181 <td class='mw-input'>" .
182 Xml::tags( 'select',
183 array(
184 'id' => 'wpBlockExpiry',
185 'name' => 'wpBlockExpiry',
186 'onchange' => 'considerChangingExpiryFocus()',
187 'tabindex' => '2' ),
188 $blockExpiryFormOptions ) .
189 "</td>"
192 $wgOut->addHTML("
193 </tr>
194 <tr id='wpBlockOther'>
195 <td class='mw-label'>
196 {$mIpbother}
197 </td>
198 <td class='mw-input'>" .
199 Xml::input( 'wpBlockOther', 45, $this->BlockOther,
200 array( 'tabindex' => '3', 'id' => 'mw-bi-other' ) ) . "
201 </td>
202 </tr>
203 <tr>
204 <td class='mw-label'>
205 {$mIpbreasonother}
206 </td>
207 <td class='mw-input'>
208 {$reasonDropDown}
209 </td>
210 </tr>
211 <tr id=\"wpBlockReason\">
212 <td class='mw-label'>
213 {$mIpbreason}
214 </td>
215 <td class='mw-input'>" .
216 Html::input( 'wpBlockReason', $this->BlockReason, 'text', array(
217 'tabindex' => '5',
218 'id' => 'mw-bi-reason',
219 'maxlength' => '200',
220 'size' => '45'
221 ) + ( $this->BlockAddress ? array( 'autofocus' ) : array() ) ) . "
222 </td>
223 </tr>
224 <tr id='wpAnonOnlyRow'>
225 <td>&nbsp;</td>
226 <td class='mw-input'>" .
227 Xml::checkLabel( wfMsg( 'ipbanononly' ),
228 'wpAnonOnly', 'wpAnonOnly', $this->BlockAnonOnly,
229 array( 'tabindex' => '6' ) ) . "
230 </td>
231 </tr>
232 <tr id='wpCreateAccountRow'>
233 <td>&nbsp;</td>
234 <td class='mw-input'>" .
235 Xml::checkLabel( wfMsg( 'ipbcreateaccount' ),
236 'wpCreateAccount', 'wpCreateAccount', $this->BlockCreateAccount,
237 array( 'tabindex' => '7' ) ) . "
238 </td>
239 </tr>
240 <tr id='wpEnableAutoblockRow'>
241 <td>&nbsp;</td>
242 <td class='mw-input'>" .
243 Xml::checkLabel( wfMsg( 'ipbenableautoblock' ),
244 'wpEnableAutoblock', 'wpEnableAutoblock', $this->BlockEnableAutoblock,
245 array( 'tabindex' => '8' ) ) . "
246 </td>
247 </tr>"
250 if( self::canBlockEmail( $wgUser ) ) {
251 $wgOut->addHTML("
252 <tr id='wpEnableEmailBan'>
253 <td>&nbsp;</td>
254 <td class='mw-input'>" .
255 Xml::checkLabel( wfMsg( 'ipbemailban' ),
256 'wpEmailBan', 'wpEmailBan', $this->BlockEmail,
257 array( 'tabindex' => '9' ) ) . "
258 </td>
259 </tr>"
263 // Allow some users to hide name from block log, blocklist and listusers
264 if( $wgUser->isAllowed( 'hideuser' ) ) {
265 $wgOut->addHTML("
266 <tr id='wpEnableHideUser'>
267 <td>&nbsp;</td>
268 <td class='mw-input'><strong>" .
269 Xml::checkLabel( wfMsg( 'ipbhidename' ),
270 'wpHideName', 'wpHideName', $this->BlockHideName,
271 array( 'tabindex' => '10' )
272 ) . "
273 </strong></td>
274 </tr>"
278 # Watchlist their user page?
279 $wgOut->addHTML("
280 <tr id='wpEnableWatchUser'>
281 <td>&nbsp;</td>
282 <td class='mw-input'>" .
283 Xml::checkLabel( wfMsg( 'ipbwatchuser' ),
284 'wpWatchUser', 'wpWatchUser', $this->BlockWatchUser,
285 array( 'tabindex' => '11' ) ) . "
286 </td>
287 </tr>"
290 # Can we explicitly disallow the use of user_talk?
291 global $wgBlockAllowsUTEdit;
292 if( $wgBlockAllowsUTEdit ){
293 $wgOut->addHTML("
294 <tr id='wpAllowUsertalkRow'>
295 <td>&nbsp;</td>
296 <td class='mw-input'>" .
297 Xml::checkLabel( wfMsg( 'ipballowusertalk' ),
298 'wpAllowUsertalk', 'wpAllowUsertalk', $this->BlockAllowUsertalk,
299 array( 'tabindex' => '12' ) ) . "
300 </td>
301 </tr>"
305 $wgOut->addHTML("
306 <tr>
307 <td style='padding-top: 1em'>&nbsp;</td>
308 <td class='mw-submit' style='padding-top: 1em'>" .
309 Xml::submitButton( wfMsg( $alreadyBlocked ? 'ipb-change-block' : 'ipbsubmit' ),
310 array( 'name' => 'wpBlock', 'tabindex' => '13', 'accesskey' => 's' ) ) . "
311 </td>
312 </tr>" .
313 Xml::closeElement( 'table' ) .
314 Xml::hidden( 'wpEditToken', $wgUser->editToken() ) .
315 ( $alreadyBlocked ? Xml::hidden( 'wpChangeBlock', 1 ) : "" ) .
316 Xml::closeElement( 'fieldset' ) .
317 Xml::closeElement( 'form' ) .
318 Xml::tags( 'script', array( 'type' => 'text/javascript' ), 'updateBlockOptions()' ) . "\n"
321 $wgOut->addHTML( $this->getConvenienceLinks() );
323 if( is_object( $user ) ) {
324 $this->showLogFragment( $wgOut, $user->getUserPage() );
325 } elseif( preg_match( '/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/', $this->BlockAddress ) ) {
326 $this->showLogFragment( $wgOut, Title::makeTitle( NS_USER, $this->BlockAddress ) );
327 } 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 ) ) {
328 $this->showLogFragment( $wgOut, Title::makeTitle( NS_USER, $this->BlockAddress ) );
333 * Can we do an email block?
334 * @param User $user The sysop wanting to make a block
335 * @return boolean
337 public static function canBlockEmail( $user ) {
338 global $wgEnableUserEmail, $wgSysopEmailBans;
339 return ( $wgEnableUserEmail && $wgSysopEmailBans && $user->isAllowed( 'blockemail' ) );
343 * Backend block code.
344 * $userID and $expiry will be filled accordingly
345 * @return array(message key, arguments) on failure, empty array on success
347 function doBlock( &$userId = null, &$expiry = null ) {
348 global $wgUser, $wgSysopUserBans, $wgSysopRangeBans, $wgBlockAllowsUTEdit;
350 $userId = 0;
351 # Expand valid IPv6 addresses, usernames are left as is
352 $this->BlockAddress = IP::sanitizeIP( $this->BlockAddress );
353 # isIPv4() and IPv6() are used for final validation
354 $rxIP4 = '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}';
355 $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}';
356 $rxIP = "($rxIP4|$rxIP6)";
358 # Check for invalid specifications
359 if( !preg_match( "/^$rxIP$/", $this->BlockAddress ) ) {
360 $matches = array();
361 if( preg_match( "/^($rxIP4)\\/(\\d{1,2})$/", $this->BlockAddress, $matches ) ) {
362 # IPv4
363 if( $wgSysopRangeBans ) {
364 if( !IP::isIPv4( $this->BlockAddress ) || $matches[2] < 16 || $matches[2] > 32 ) {
365 return array( 'ip_range_invalid' );
367 $this->BlockAddress = Block::normaliseRange( $this->BlockAddress );
368 } else {
369 # Range block illegal
370 return array( 'range_block_disabled' );
372 } elseif( preg_match( "/^($rxIP6)\\/(\\d{1,3})$/", $this->BlockAddress, $matches ) ) {
373 # IPv6
374 if( $wgSysopRangeBans ) {
375 if( !IP::isIPv6( $this->BlockAddress ) || $matches[2] < 64 || $matches[2] > 128 ) {
376 return array( 'ip_range_invalid' );
378 $this->BlockAddress = Block::normaliseRange( $this->BlockAddress );
379 } else {
380 # Range block illegal
381 return array('range_block_disabled');
383 } else {
384 # Username block
385 if( $wgSysopUserBans ) {
386 $user = User::newFromName( $this->BlockAddress );
387 if( !is_null( $user ) && $user->getId() ) {
388 # Use canonical name
389 $userId = $user->getId();
390 $this->BlockAddress = $user->getName();
391 } else {
392 return array( 'nosuchusershort', htmlspecialchars( $user ? $user->getName() : $this->BlockAddress ) );
394 } else {
395 return array( 'badipaddress' );
400 if( $wgUser->isBlocked() && ( $wgUser->getId() !== $userId ) ) {
401 return array( 'cant-block-while-blocked' );
404 $reasonstr = $this->BlockReasonList;
405 if( $reasonstr != 'other' && $this->BlockReason != '' ) {
406 // Entry from drop down menu + additional comment
407 $reasonstr .= wfMsgForContent( 'colon-separator' ) . $this->BlockReason;
408 } elseif( $reasonstr == 'other' ) {
409 $reasonstr = $this->BlockReason;
412 $expirestr = $this->BlockExpiry;
413 if( $expirestr == 'other' )
414 $expirestr = $this->BlockOther;
416 if( ( strlen( $expirestr ) == 0) || ( strlen( $expirestr ) > 50 ) ) {
417 return array( 'ipb_expiry_invalid' );
420 if( false === ( $expiry = Block::parseExpiryInput( $expirestr ) ) ) {
421 // Bad expiry.
422 return array( 'ipb_expiry_invalid' );
425 if( $this->BlockHideName ) {
426 // Recheck params here...
427 if( !$userId || !$wgUser->isAllowed('hideuser') ) {
428 $this->BlockHideName = false; // IP users should not be hidden
429 } elseif( $expiry !== 'infinity' ) {
430 // Bad expiry.
431 return array( 'ipb_expiry_temp' );
432 } elseif( User::edits( $userId ) > self::HIDEUSER_CONTRIBLIMIT ) {
433 // Typically, the user should have a handful of edits.
434 // Disallow hiding users with many edits for performance.
435 return array( 'ipb_hide_invalid' );
439 # Create block object
440 # Note: for a user block, ipb_address is only for display purposes
441 $block = new Block( $this->BlockAddress, $userId, $wgUser->getId(),
442 $reasonstr, wfTimestampNow(), 0, $expiry, $this->BlockAnonOnly,
443 $this->BlockCreateAccount, $this->BlockEnableAutoblock, $this->BlockHideName,
444 $this->BlockEmail,
445 isset( $this->BlockAllowUsertalk ) ? $this->BlockAllowUsertalk : $wgBlockAllowsUTEdit
448 # Should this be privately logged?
449 $suppressLog = (bool)$this->BlockHideName;
450 if( wfRunHooks( 'BlockIp', array( &$block, &$wgUser ) ) ) {
451 # Try to insert block. Is there a conflicting block?
452 if( !$block->insert() ) {
453 # Show form unless the user is already aware of this...
454 if( !$this->BlockReblock ) {
455 return array( 'ipb_already_blocked' );
456 # Otherwise, try to update the block...
457 } else {
458 # This returns direct blocks before autoblocks/rangeblocks, since we should
459 # be sure the user is blocked by now it should work for our purposes
460 $currentBlock = Block::newFromDB( $this->BlockAddress, $userId );
461 if( $block->equals( $currentBlock ) ) {
462 return array( 'ipb_already_blocked' );
464 # If the name was hidden and the blocking user cannot hide
465 # names, then don't allow any block changes...
466 if( $currentBlock->mHideName && !$wgUser->isAllowed( 'hideuser' ) ) {
467 return array( 'cant-see-hidden-user' );
469 $currentBlock->delete();
470 $block->insert();
471 # If hiding/unhiding a name, this should go in the private logs
472 $suppressLog = $suppressLog || (bool)$currentBlock->mHideName;
473 $log_action = 'reblock';
474 # Unset _deleted fields if requested
475 if( $currentBlock->mHideName && !$this->BlockHideName ) {
476 self::unsuppressUserName( $this->BlockAddress, $userId );
479 } else {
480 $log_action = 'block';
482 wfRunHooks( 'BlockIpComplete', array( $block, $wgUser ) );
484 # Set *_deleted fields if requested
485 if( $this->BlockHideName ) {
486 self::suppressUserName( $this->BlockAddress, $userId );
489 # Only show watch link when this is no range block
490 if( $this->BlockWatchUser && $block->mRangeStart == $block->mRangeEnd ) {
491 $wgUser->addWatch( Title::makeTitle( NS_USER, $this->BlockAddress ) );
494 # Block constructor sanitizes certain block options on insert
495 $this->BlockEmail = $block->mBlockEmail;
496 $this->BlockEnableAutoblock = $block->mEnableAutoblock;
498 # Prepare log parameters
499 $logParams = array();
500 $logParams[] = $expirestr;
501 $logParams[] = $this->blockLogFlags();
503 # Make log entry, if the name is hidden, put it in the oversight log
504 $log_type = $suppressLog ? 'suppress' : 'block';
505 $log = new LogPage( $log_type );
506 $log->addEntry( $log_action, Title::makeTitle( NS_USER, $this->BlockAddress ),
507 $reasonstr, $logParams );
509 # Report to the user
510 return array();
511 } else {
512 return array( 'hookaborted' );
516 public static function suppressUserName( $name, $userId ) {
517 $op = '|'; // bitwise OR
518 return self::setUsernameBitfields( $name, $userId, $op );
521 public static function unsuppressUserName( $name, $userId ) {
522 $op = '&'; // bitwise AND
523 return self::setUsernameBitfields( $name, $userId, $op );
526 private static function setUsernameBitfields( $name, $userId, $op ) {
527 if( $op !== '|' && $op !== '&' ) return false; // sanity check
528 $dbw = wfGetDB( DB_MASTER );
529 $delUser = Revision::DELETED_USER | Revision::DELETED_RESTRICTED;
530 $delAction = LogPage::DELETED_ACTION | Revision::DELETED_RESTRICTED;
531 # Normalize user name
532 $userTitle = Title::makeTitleSafe( NS_USER, $name );
533 $userDbKey = $userTitle->getDBkey();
534 # To suppress, we OR the current bitfields with Revision::DELETED_USER
535 # to put a 1 in the username *_deleted bit. To unsuppress we AND the
536 # current bitfields with the inverse of Revision::DELETED_USER. The
537 # username bit is made to 0 (x & 0 = 0), while others are unchanged (x & 1 = x).
538 # The same goes for the sysop-restricted *_deleted bit.
539 if( $op == '&' ) {
540 $delUser = "~{$delUser}";
541 $delAction = "~{$delAction}";
543 # Hide name from live edits
544 $dbw->update( 'revision', array( "rev_deleted = rev_deleted $op $delUser" ),
545 array( 'rev_user' => $userId ), __METHOD__ );
546 # Hide name from deleted edits
547 $dbw->update( 'archive', array( "ar_deleted = ar_deleted $op $delUser" ),
548 array( 'ar_user_text' => $name ), __METHOD__ );
549 # Hide name from logs
550 $dbw->update( 'logging', array( "log_deleted = log_deleted $op $delUser" ),
551 array( 'log_user' => $userId, "log_type != 'suppress'" ), __METHOD__ );
552 $dbw->update( 'logging', array( "log_deleted = log_deleted $op $delAction" ),
553 array( 'log_namespace' => NS_USER, 'log_title' => $userDbKey,
554 "log_type != 'suppress'" ), __METHOD__ );
555 # Hide name from RC
556 $dbw->update( 'recentchanges', array( "rc_deleted = rc_deleted $op $delUser" ),
557 array( 'rc_user_text' => $name ), __METHOD__ );
558 $dbw->update( 'recentchanges', array( "rc_deleted = rc_deleted $op $delAction" ),
559 array( 'rc_namespace' => NS_USER, 'rc_title' => $userDbKey, 'rc_logid > 0' ), __METHOD__ );
560 # Hide name from live images
561 $dbw->update( 'oldimage', array( "oi_deleted = oi_deleted $op $delUser" ),
562 array( 'oi_user_text' => $name ), __METHOD__ );
563 # Hide name from deleted images
564 # WMF - schema change pending
565 # $dbw->update( 'filearchive', array( "fa_deleted = fa_deleted $op $delUser" ),
566 # array( 'fa_user_text' => $name ), __METHOD__ );
567 # Done!
568 return true;
572 * UI entry point for blocking
573 * Wraps around doBlock()
575 public function doSubmit() {
576 global $wgOut;
577 $retval = $this->doBlock();
578 if( empty( $retval ) ) {
579 $titleObj = SpecialPage::getTitleFor( 'Blockip' );
580 $wgOut->redirect( $titleObj->getFullURL( 'action=success&ip=' .
581 urlencode( $this->BlockAddress ) ) );
582 return;
584 $this->showForm( $retval );
587 public function showSuccess() {
588 global $wgOut;
590 $wgOut->setPageTitle( wfMsg( 'blockip' ) );
591 $wgOut->setSubtitle( wfMsg( 'blockipsuccesssub' ) );
592 $text = wfMsgExt( 'blockipsuccesstext', array( 'parse' ), $this->BlockAddress );
593 $wgOut->addHTML( $text );
596 private function showLogFragment( $out, $title ) {
597 global $wgUser;
599 // Used to support GENDER in 'blocklog-showlog' and 'blocklog-showsuppresslog'
600 $userBlocked = $title->getText();
602 LogEventsList::showLogExtract(
603 $out,
604 'block',
605 $title->getPrefixedText(),
607 array(
608 'lim' => 10,
609 'msgKey' => array(
610 'blocklog-showlog',
611 $userBlocked
613 'showIfEmpty' => false
617 // Add suppression block entries if allowed
618 if( $wgUser->isAllowed( 'hideuser' ) ) {
619 LogEventsList::showLogExtract( $out, 'suppress', $title->getPrefixedText(), '',
620 array(
621 'lim' => 10,
622 'conds' => array(
623 'log_action' => array(
624 'block',
625 'reblock',
626 'unblock'
629 'msgKey' => array(
630 'blocklog-showsuppresslog',
631 $userBlocked
633 'showIfEmpty' => false
640 * Return a comma-delimited list of "flags" to be passed to the log
641 * reader for this block, to provide more information in the logs
643 * @return array
645 private function blockLogFlags() {
646 global $wgBlockAllowsUTEdit;
647 $flags = array();
648 if( $this->BlockAnonOnly && IP::isIPAddress( $this->BlockAddress ) )
649 // when blocking a user the option 'anononly' is not available/has no effect -> do not write this into log
650 $flags[] = 'anononly';
651 if( $this->BlockCreateAccount )
652 $flags[] = 'nocreate';
653 if( !$this->BlockEnableAutoblock && !IP::isIPAddress( $this->BlockAddress ) )
654 // Same as anononly, this is not displayed when blocking an IP address
655 $flags[] = 'noautoblock';
656 if( $this->BlockEmail )
657 $flags[] = 'noemail';
658 if( !$this->BlockAllowUsertalk && $wgBlockAllowsUTEdit )
659 $flags[] = 'nousertalk';
660 if( $this->BlockHideName )
661 $flags[] = 'hiddenname';
662 return implode( ',', $flags );
666 * Builds unblock and block list links
668 * @return string
670 private function getConvenienceLinks() {
671 global $wgUser, $wgLang;
672 $skin = $wgUser->getSkin();
673 if( $this->BlockAddress )
674 $links[] = $this->getContribsLink( $skin );
675 $links[] = $this->getUnblockLink( $skin );
676 $links[] = $this->getBlockListLink( $skin );
677 $title = Title::makeTitle( NS_MEDIAWIKI, 'Ipbreason-dropdown' );
678 $links[] = $skin->link(
679 $title,
680 wfMsgHtml( 'ipb-edit-dropdown' ),
681 array(),
682 array( 'action' => 'edit' )
684 return '<p class="mw-ipb-conveniencelinks">' . $wgLang->pipeList( $links ) . '</p>';
688 * Build a convenient link to a user or IP's contribs
689 * form
691 * @param $skin Skin to use
692 * @return string
694 private function getContribsLink( $skin ) {
695 $contribsPage = SpecialPage::getTitleFor( 'Contributions', $this->BlockAddress );
696 return $skin->link( $contribsPage, wfMsgExt( 'ipb-blocklist-contribs', 'escape', $this->BlockAddress ) );
700 * Build a convenient link to unblock the given username or IP
701 * address, if available; otherwise link to a blank unblock
702 * form
704 * @param $skin Skin to use
705 * @return string
707 private function getUnblockLink( $skin ) {
708 $list = SpecialPage::getTitleFor( 'Ipblocklist' );
709 $query = array( 'action' => 'unblock' );
711 if( $this->BlockAddress ) {
712 $addr = strtr( $this->BlockAddress, '_', ' ' );
713 $message = wfMsg( 'ipb-unblock-addr', $addr );
714 $query['ip'] = $this->BlockAddress;
715 } else {
716 $message = wfMsg( 'ipb-unblock' );
718 return $skin->linkKnown(
719 $list,
720 htmlspecialchars( $message ),
721 array(),
722 $query
727 * Build a convenience link to the block list
729 * @param $skin Skin to use
730 * @return string
732 private function getBlockListLink( $skin ) {
733 $list = SpecialPage::getTitleFor( 'Ipblocklist' );
734 $query = array();
736 if( $this->BlockAddress ) {
737 $addr = strtr( $this->BlockAddress, '_', ' ' );
738 $message = wfMsg( 'ipb-blocklist-addr', $addr );
739 $query['ip'] = $this->BlockAddress;
740 } else {
741 $message = wfMsg( 'ipb-blocklist' );
744 return $skin->linkKnown(
745 $list,
746 htmlspecialchars( $message ),
747 array(),
748 $query
753 * Block a list of selected users
754 * @param array $users
755 * @param string $reason
756 * @param string $tag replaces user pages
757 * @param string $talkTag replaces user talk pages
758 * @returns array, list of html-safe usernames
760 public static function doMassUserBlock( $users, $reason = '', $tag = '', $talkTag = '' ) {
761 global $wgUser;
762 $counter = $blockSize = 0;
763 $safeUsers = array();
764 $log = new LogPage( 'block' );
765 foreach( $users as $name ) {
766 # Enforce limits
767 $counter++;
768 $blockSize++;
769 # Lets not go *too* fast
770 if( $blockSize >= 20 ) {
771 $blockSize = 0;
772 wfWaitForSlaves( 5 );
774 $u = User::newFromName( $name, false );
775 // If user doesn't exist, it ought to be an IP then
776 if( is_null( $u ) || ( !$u->getId() && !IP::isIPAddress( $u->getName() ) ) ) {
777 continue;
779 $userTitle = $u->getUserPage();
780 $userTalkTitle = $u->getTalkPage();
781 $userpage = new Article( $userTitle );
782 $usertalk = new Article( $userTalkTitle );
783 $safeUsers[] = '[[' . $userTitle->getPrefixedText() . '|' . $userTitle->getText() . ']]';
784 $expirestr = $u->getId() ? 'indefinite' : '1 week';
785 $expiry = Block::parseExpiryInput( $expirestr );
786 $anonOnly = IP::isIPAddress( $u->getName() ) ? 1 : 0;
787 // Create the block
788 $block = new Block( $u->getName(), // victim
789 $u->getId(), // uid
790 $wgUser->getId(), // blocker
791 $reason, // comment
792 wfTimestampNow(), // block time
793 0, // auto ?
794 $expiry, // duration
795 $anonOnly, // anononly?
796 1, // block account creation?
797 1, // autoblocking?
798 0, // suppress name?
799 0 // block from sending email?
801 $oldblock = Block::newFromDB( $u->getName(), $u->getId() );
802 if( !$oldblock ) {
803 $block->insert();
804 # Prepare log parameters
805 $logParams = array();
806 $logParams[] = $expirestr;
807 if( $anonOnly ) {
808 $logParams[] = 'anononly';
810 $logParams[] = 'nocreate';
811 # Add log entry
812 $log->addEntry( 'block', $userTitle, $reason, $logParams );
814 # Tag userpage! (check length to avoid mistakes)
815 if( strlen( $tag ) > 2 ) {
816 $userpage->doEdit( $tag, $reason, EDIT_MINOR );
818 if( strlen( $talkTag ) > 2 ) {
819 $usertalk->doEdit( $talkTag, $reason, EDIT_MINOR );
822 return $safeUsers;