adding newline to end of wfDebug calls where it was missing.
[lhc/web/wiklou.git] / includes / specials / SpecialBlockip.php
1 <?php
2 /**
3 * Constructor for Special:Blockip page
4 *
5 * @file
6 * @ingroup SpecialPage
7 */
8
9 /**
10 * Constructor
11 */
12 function wfSpecialBlockip( $par ) {
13 global $wgUser, $wgOut, $wgRequest;
14
15 # Can't block when the database is locked
16 if( wfReadOnly() ) {
17 $wgOut->readOnlyPage();
18 return;
19 }
20
21 # Permission check
22 if( !$wgUser->isAllowed( 'block' ) ) {
23 $wgOut->permissionRequired( 'block' );
24 return;
25 }
26
27 $ipb = new IPBlockForm( $par );
28
29 $action = $wgRequest->getVal( 'action' );
30 if ( 'success' == $action ) {
31 $ipb->showSuccess();
32 } else if ( $wgRequest->wasPosted() && 'submit' == $action &&
33 $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
34 $ipb->doSubmit();
35 } else {
36 $ipb->showForm( '' );
37 }
38 }
39
40 /**
41 * Form object for the Special:Blockip page.
42 *
43 * @ingroup SpecialPage
44 */
45 class IPBlockForm {
46 var $BlockAddress, $BlockExpiry, $BlockReason;
47 # var $BlockEmail;
48
49 function IPBlockForm( $par ) {
50 global $wgRequest, $wgUser, $wgBlockAllowsUTEdit;
51
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', '' );
58
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 = $wgRequest->getBool( 'wpEmailBan', false );
66 $this->BlockWatchUser = $wgRequest->getBool( 'wpWatchUser', false );
67 # Re-check user's rights to hide names, very serious, defaults to 0
68 $this->BlockHideName = ( $wgRequest->getBool( 'wpHideName', 0 ) && $wgUser->isAllowed( 'hideuser' ) ) ? 1 : 0;
69 $this->BlockAllowUsertalk = ( $wgRequest->getBool( 'wpAllowUsertalk', $byDefault ) && $wgBlockAllowsUTEdit );
70 $this->BlockReblock = $wgRequest->getBool( 'wpChangeBlock', false );
71 }
72
73 function showForm( $err ) {
74 global $wgOut, $wgUser, $wgSysopUserBans;
75
76 $wgOut->setPagetitle( wfMsg( 'blockip' ) );
77 $wgOut->addWikiMsg( 'blockiptext' );
78
79 if($wgSysopUserBans) {
80 $mIpaddress = Xml::label( wfMsg( 'ipadressorusername' ), 'mw-bi-target' );
81 } else {
82 $mIpaddress = Xml::label( wfMsg( 'ipaddress' ), 'mw-bi-target' );
83 }
84 $mIpbexpiry = Xml::label( wfMsg( 'ipbexpiry' ), 'wpBlockExpiry' );
85 $mIpbother = Xml::label( wfMsg( 'ipbother' ), 'mw-bi-other' );
86 $mIpbreasonother = Xml::label( wfMsg( 'ipbreason' ), 'wpBlockReasonList' );
87 $mIpbreason = Xml::label( wfMsg( 'ipbotherreason' ), 'mw-bi-reason' );
88
89 $titleObj = SpecialPage::getTitleFor( 'Blockip' );
90 $user = User::newFromName( $this->BlockAddress );
91
92 $alreadyBlocked = false;
93 if ( $err && $err[0] != 'ipb_already_blocked' ) {
94 $key = array_shift($err);
95 $msg = wfMsgReal($key, $err);
96 $wgOut->setSubtitle( wfMsgHtml( 'formerror' ) );
97 $wgOut->addHTML( Xml::tags( 'p', array( 'class' => 'error' ), $msg ) );
98 } elseif ( $this->BlockAddress ) {
99 $userId = 0;
100 if ( is_object( $user ) )
101 $userId = $user->getId();
102 $currentBlock = Block::newFromDB( $this->BlockAddress, $userId );
103 if ( !is_null($currentBlock) && !$currentBlock->mAuto && # The block exists and isn't an autoblock
104 ( $currentBlock->mRangeStart == $currentBlock->mRangeEnd || # The block isn't a rangeblock
105 # or if it is, the range is what we're about to block
106 ( $currentBlock->mAddress == $this->BlockAddress ) ) ) {
107 $wgOut->addWikiMsg( 'ipb-needreblock', $this->BlockAddress );
108 $alreadyBlocked = true;
109 }
110 }
111
112 $scBlockExpiryOptions = wfMsgForContent( 'ipboptions' );
113
114 $showblockoptions = $scBlockExpiryOptions != '-';
115 if (!$showblockoptions)
116 $mIpbother = $mIpbexpiry;
117
118 $blockExpiryFormOptions = Xml::option( wfMsg( 'ipbotheroption' ), 'other' );
119 foreach (explode(',', $scBlockExpiryOptions) as $option) {
120 if ( strpos($option, ":") === false ) $option = "$option:$option";
121 list($show, $value) = explode(":", $option);
122 $show = htmlspecialchars($show);
123 $value = htmlspecialchars($value);
124 $blockExpiryFormOptions .= Xml::option( $show, $value, $this->BlockExpiry === $value ? true : false ) . "\n";
125 }
126
127 $reasonDropDown = Xml::listDropDown( 'wpBlockReasonList',
128 wfMsgForContent( 'ipbreason-dropdown' ),
129 wfMsgForContent( 'ipbreasonotherlist' ), $this->BlockReasonList, 'wpBlockDropDown', 4 );
130
131 global $wgStylePath, $wgStyleVersion;
132 $wgOut->addHTML(
133 Xml::tags( 'script', array( 'type' => 'text/javascript', 'src' => "$wgStylePath/common/block.js?$wgStyleVersion" ), '' ) .
134 Xml::openElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalURL( "action=submit" ), 'id' => 'blockip' ) ) .
135 Xml::openElement( 'fieldset' ) .
136 Xml::element( 'legend', null, wfMsg( 'blockip-legend' ) ) .
137 Xml::openElement( 'table', array ( 'border' => '0', 'id' => 'mw-blockip-table' ) ) .
138 "<tr>
139 <td class='mw-label'>
140 {$mIpaddress}
141 </td>
142 <td class='mw-input'>" .
143 Xml::input( 'wpBlockAddress', 45, $this->BlockAddress,
144 array(
145 'tabindex' => '1',
146 'id' => 'mw-bi-target',
147 'onchange' => 'updateBlockOptions()' ) ). "
148 </td>
149 </tr>
150 <tr>"
151 );
152 if ( $showblockoptions ) {
153 $wgOut->addHTML("
154 <td class='mw-label'>
155 {$mIpbexpiry}
156 </td>
157 <td class='mw-input'>" .
158 Xml::tags( 'select',
159 array(
160 'id' => 'wpBlockExpiry',
161 'name' => 'wpBlockExpiry',
162 'onchange' => 'considerChangingExpiryFocus()',
163 'tabindex' => '2' ),
164 $blockExpiryFormOptions ) .
165 "</td>"
166 );
167 }
168 $wgOut->addHTML("
169 </tr>
170 <tr id='wpBlockOther'>
171 <td class='mw-label'>
172 {$mIpbother}
173 </td>
174 <td class='mw-input'>" .
175 Xml::input( 'wpBlockOther', 45, $this->BlockOther,
176 array( 'tabindex' => '3', 'id' => 'mw-bi-other' ) ) . "
177 </td>
178 </tr>
179 <tr>
180 <td class='mw-label'>
181 {$mIpbreasonother}
182 </td>
183 <td class='mw-input'>
184 {$reasonDropDown}
185 </td>
186 </tr>
187 <tr id=\"wpBlockReason\">
188 <td class='mw-label'>
189 {$mIpbreason}
190 </td>
191 <td class='mw-input'>" .
192 Xml::input( 'wpBlockReason', 45, $this->BlockReason,
193 array( 'tabindex' => '5', 'id' => 'mw-bi-reason', 'maxlength'=> '200' ) ) . "
194 </td>
195 </tr>
196 <tr id='wpAnonOnlyRow'>
197 <td>&nbsp;</td>
198 <td class='mw-input'>" .
199 Xml::checkLabel( wfMsg( 'ipbanononly' ),
200 'wpAnonOnly', 'wpAnonOnly', $this->BlockAnonOnly,
201 array( 'tabindex' => '6' ) ) . "
202 </td>
203 </tr>
204 <tr id='wpCreateAccountRow'>
205 <td>&nbsp;</td>
206 <td class='mw-input'>" .
207 Xml::checkLabel( wfMsg( 'ipbcreateaccount' ),
208 'wpCreateAccount', 'wpCreateAccount', $this->BlockCreateAccount,
209 array( 'tabindex' => '7' ) ) . "
210 </td>
211 </tr>
212 <tr id='wpEnableAutoblockRow'>
213 <td>&nbsp;</td>
214 <td class='mw-input'>" .
215 Xml::checkLabel( wfMsg( 'ipbenableautoblock' ),
216 'wpEnableAutoblock', 'wpEnableAutoblock', $this->BlockEnableAutoblock,
217 array( 'tabindex' => '8' ) ) . "
218 </td>
219 </tr>"
220 );
221
222 global $wgSysopEmailBans, $wgBlockAllowsUTEdit;
223 if ( $wgSysopEmailBans && $wgUser->isAllowed( 'blockemail' ) ) {
224 $wgOut->addHTML("
225 <tr id='wpEnableEmailBan'>
226 <td>&nbsp;</td>
227 <td class='mw-input'>" .
228 Xml::checkLabel( wfMsg( 'ipbemailban' ),
229 'wpEmailBan', 'wpEmailBan', $this->BlockEmail,
230 array( 'tabindex' => '9' )) . "
231 </td>
232 </tr>"
233 );
234 }
235
236 // Allow some users to hide name from block log, blocklist and listusers
237 if ( $wgUser->isAllowed( 'hideuser' ) ) {
238 $wgOut->addHTML("
239 <tr id='wpEnableHideUser'>
240 <td>&nbsp;</td>
241 <td class='mw-input'>" .
242 Xml::checkLabel( wfMsg( 'ipbhidename' ),
243 'wpHideName', 'wpHideName', $this->BlockHideName,
244 array( 'tabindex' => '10' ) ) . "
245 </td>
246 </tr>"
247 );
248 }
249
250 # Watchlist their user page?
251 $wgOut->addHTML("
252 <tr id='wpEnableWatchUser'>
253 <td>&nbsp;</td>
254 <td class='mw-input'>" .
255 Xml::checkLabel( wfMsg( 'ipbwatchuser' ),
256 'wpWatchUser', 'wpWatchUser', $this->BlockWatchUser,
257 array( 'tabindex' => '11' ) ) . "
258 </td>
259 </tr>"
260 );
261 if( $wgBlockAllowsUTEdit ){
262 $wgOut->addHTML("
263 <tr id='wpAllowUsertalkRow'>
264 <td>&nbsp;</td>
265 <td class='mw-input'>" .
266 Xml::checkLabel( wfMsg( 'ipballowusertalk' ),
267 'wpAllowUsertalk', 'wpAllowUsertalk', $this->BlockAllowUsertalk,
268 array( 'tabindex' => '12' ) ) . "
269 </td>
270 </tr>"
271 );
272 }
273
274 $wgOut->addHTML("
275 <tr>
276 <td style='padding-top: 1em'>&nbsp;</td>
277 <td class='mw-submit' style='padding-top: 1em'>" .
278 Xml::submitButton( wfMsg( $alreadyBlocked ? 'ipb-change-block' : 'ipbsubmit' ),
279 array( 'name' => 'wpBlock', 'tabindex' => '13', 'accesskey' => 's' ) ) . "
280 </td>
281 </tr>" .
282 Xml::closeElement( 'table' ) .
283 Xml::hidden( 'wpEditToken', $wgUser->editToken() ) .
284 ( $alreadyBlocked ? Xml::hidden( 'wpChangeBlock', 1 ) : "" ) .
285 Xml::closeElement( 'fieldset' ) .
286 Xml::closeElement( 'form' ) .
287 Xml::tags( 'script', array( 'type' => 'text/javascript' ), 'updateBlockOptions()' ) . "\n"
288 );
289
290 $wgOut->addHTML( $this->getConvenienceLinks() );
291
292 if( is_object( $user ) ) {
293 $this->showLogFragment( $wgOut, $user->getUserPage() );
294 } elseif( preg_match( '/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/', $this->BlockAddress ) ) {
295 $this->showLogFragment( $wgOut, Title::makeTitle( NS_USER, $this->BlockAddress ) );
296 } 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 ) ) {
297 $this->showLogFragment( $wgOut, Title::makeTitle( NS_USER, $this->BlockAddress ) );
298 }
299 }
300
301 /**
302 * Backend block code.
303 * $userID and $expiry will be filled accordingly
304 * @return array(message key, arguments) on failure, empty array on success
305 */
306 function doBlock( &$userId = null, &$expiry = null ) {
307 global $wgUser, $wgSysopUserBans, $wgSysopRangeBans, $wgBlockAllowsUTEdit;
308
309 $userId = 0;
310 # Expand valid IPv6 addresses, usernames are left as is
311 $this->BlockAddress = IP::sanitizeIP( $this->BlockAddress );
312 # isIPv4() and IPv6() are used for final validation
313 $rxIP4 = '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}';
314 $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}';
315 $rxIP = "($rxIP4|$rxIP6)";
316
317 # Check for invalid specifications
318 if ( !preg_match( "/^$rxIP$/", $this->BlockAddress ) ) {
319 $matches = array();
320 if ( preg_match( "/^($rxIP4)\\/(\\d{1,2})$/", $this->BlockAddress, $matches ) ) {
321 # IPv4
322 if ( $wgSysopRangeBans ) {
323 if ( !IP::isIPv4( $this->BlockAddress ) || $matches[2] < 16 || $matches[2] > 32 ) {
324 return array('ip_range_invalid');
325 }
326 $this->BlockAddress = Block::normaliseRange( $this->BlockAddress );
327 } else {
328 # Range block illegal
329 return array('range_block_disabled');
330 }
331 } else if ( preg_match( "/^($rxIP6)\\/(\\d{1,3})$/", $this->BlockAddress, $matches ) ) {
332 # IPv6
333 if ( $wgSysopRangeBans ) {
334 if ( !IP::isIPv6( $this->BlockAddress ) || $matches[2] < 64 || $matches[2] > 128 ) {
335 return array('ip_range_invalid');
336 }
337 $this->BlockAddress = Block::normaliseRange( $this->BlockAddress );
338 } else {
339 # Range block illegal
340 return array('range_block_disabled');
341 }
342 } else {
343 # Username block
344 if ( $wgSysopUserBans ) {
345 $user = User::newFromName( $this->BlockAddress );
346 if( !is_null( $user ) && $user->getId() ) {
347 # Use canonical name
348 $userId = $user->getId();
349 $this->BlockAddress = $user->getName();
350 } else {
351 return array('nosuchusershort', htmlspecialchars( $user ? $user->getName() : $this->BlockAddress ) );
352 }
353 } else {
354 return array('badipaddress');
355 }
356 }
357 }
358
359 if ( $wgUser->isBlocked() && ( $wgUser->getId() !== $userId ) ) {
360 return array( 'cant-block-while-blocked' );
361 }
362
363 $reasonstr = $this->BlockReasonList;
364 if ( $reasonstr != 'other' && $this->BlockReason != '' ) {
365 // Entry from drop down menu + additional comment
366 $reasonstr .= wfMsgForContent( 'colon-separator' ) . $this->BlockReason;
367 } elseif ( $reasonstr == 'other' ) {
368 $reasonstr = $this->BlockReason;
369 }
370
371 $expirestr = $this->BlockExpiry;
372 if( $expirestr == 'other' )
373 $expirestr = $this->BlockOther;
374
375 if ( ( strlen( $expirestr ) == 0) || ( strlen( $expirestr ) > 50) ) {
376 return array('ipb_expiry_invalid');
377 }
378
379 if ( false === ($expiry = Block::parseExpiryInput( $expirestr )) ) {
380 // Bad expiry.
381 return array('ipb_expiry_invalid');
382 }
383
384 if( $this->BlockHideName && $expiry != 'infinity' ) {
385 // Bad expiry.
386 return array('ipb_expiry_temp');
387 }
388
389 # Create block
390 # Note: for a user block, ipb_address is only for display purposes
391 $block = new Block( $this->BlockAddress, $userId, $wgUser->getId(),
392 $reasonstr, wfTimestampNow(), 0, $expiry, $this->BlockAnonOnly,
393 $this->BlockCreateAccount, $this->BlockEnableAutoblock, $this->BlockHideName,
394 $this->BlockEmail, isset( $this->BlockAllowUsertalk ) ? $this->BlockAllowUsertalk : $wgBlockAllowsUTEdit );
395
396 if ( wfRunHooks('BlockIp', array(&$block, &$wgUser)) ) {
397
398 if ( !$block->insert() ) {
399 if ( !$this->BlockReblock ) {
400 return array( 'ipb_already_blocked' );
401 } else {
402 # This returns direct blocks before autoblocks/rangeblocks, since we should
403 # be sure the user is blocked by now it should work for our purposes
404 $currentBlock = Block::newFromDB( $this->BlockAddress, $userId );
405 if( $block->equals( $currentBlock ) ) {
406 return array( 'ipb_already_blocked' );
407 }
408 $currentBlock->delete();
409 $block->insert();
410 $log_action = 'reblock';
411 }
412 } else {
413 $log_action = 'block';
414 }
415 wfRunHooks('BlockIpComplete', array($block, $wgUser));
416
417 if ( $this->BlockWatchUser ) {
418 $wgUser->addWatch ( Title::makeTitle( NS_USER, $this->BlockAddress ) );
419 }
420
421 # Prepare log parameters
422 $logParams = array();
423 $logParams[] = $expirestr;
424 $logParams[] = $this->blockLogFlags();
425
426 # Make log entry, if the name is hidden, put it in the oversight log
427 $log_type = ($this->BlockHideName) ? 'suppress' : 'block';
428 $log = new LogPage( $log_type );
429 $log->addEntry( $log_action, Title::makeTitle( NS_USER, $this->BlockAddress ),
430 $reasonstr, $logParams );
431
432 # Report to the user
433 return array();
434 }
435 else
436 return array('hookaborted');
437 }
438
439 /**
440 * UI entry point for blocking
441 * Wraps around doBlock()
442 */
443 function doSubmit()
444 {
445 global $wgOut;
446 $retval = $this->doBlock();
447 if(empty($retval)) {
448 $titleObj = SpecialPage::getTitleFor( 'Blockip' );
449 $wgOut->redirect( $titleObj->getFullURL( 'action=success&ip=' .
450 urlencode( $this->BlockAddress ) ) );
451 return;
452 }
453 $this->showForm( $retval );
454 }
455
456 function showSuccess() {
457 global $wgOut;
458
459 $wgOut->setPagetitle( wfMsg( 'blockip' ) );
460 $wgOut->setSubtitle( wfMsg( 'blockipsuccesssub' ) );
461 $text = wfMsgExt( 'blockipsuccesstext', array( 'parse' ), $this->BlockAddress );
462 $wgOut->addHTML( $text );
463 }
464
465 function showLogFragment( $out, $title ) {
466 global $wgUser;
467 $out->addHTML( Xml::element( 'h2', NULL, LogPage::logName( 'block' ) ) );
468 $count = LogEventsList::showLogExtract( $out, 'block', $title->getPrefixedText(), '', 10 );
469 if($count > 10){
470 $out->addHTML( $wgUser->getSkin()->link(
471 SpecialPage::getTitleFor( 'Log' ),
472 wfMsgHtml( 'blocklog-fulllog' ),
473 array(),
474 array(
475 'type' => 'block',
476 'page' => $title->getPrefixedText() ) ) );
477 }
478 }
479
480 /**
481 * Return a comma-delimited list of "flags" to be passed to the log
482 * reader for this block, to provide more information in the logs
483 *
484 * @return array
485 */
486 private function blockLogFlags() {
487 global $wgBlockAllowsUTEdit;
488 $flags = array();
489 if( $this->BlockAnonOnly && IP::isIPAddress( $this->BlockAddress ) )
490 // when blocking a user the option 'anononly' is not available/has no effect -> do not write this into log
491 $flags[] = 'anononly';
492 if( $this->BlockCreateAccount )
493 $flags[] = 'nocreate';
494 if( !$this->BlockEnableAutoblock )
495 $flags[] = 'noautoblock';
496 if ( $this->BlockEmail )
497 $flags[] = 'noemail';
498 if ( !$this->BlockAllowUsertalk && $wgBlockAllowsUTEdit )
499 $flags[] = 'nousertalk';
500 return implode( ',', $flags );
501 }
502
503 /**
504 * Builds unblock and block list links
505 *
506 * @return string
507 */
508 private function getConvenienceLinks() {
509 global $wgUser;
510 $skin = $wgUser->getSkin();
511 if( $this->BlockAddress )
512 $links[] = $this->getContribsLink( $skin );
513 $links[] = $this->getUnblockLink( $skin );
514 $links[] = $this->getBlockListLink( $skin );
515 $links[] = $skin->makeLink ( 'MediaWiki:Ipbreason-dropdown', wfMsgHtml( 'ipb-edit-dropdown' ) );
516 return '<p class="mw-ipb-conveniencelinks">' . implode( ' | ', $links ) . '</p>';
517 }
518
519 /**
520 * Build a convenient link to a user or IP's contribs
521 * form
522 *
523 * @param $skin Skin to use
524 * @return string
525 */
526 private function getContribsLink( $skin ) {
527 $contribsPage = SpecialPage::getTitleFor( 'Contributions', $this->BlockAddress );
528 return $skin->link( $contribsPage, wfMsgHtml( 'ipb-blocklist-contribs', $this->BlockAddress ) );
529 }
530
531 /**
532 * Build a convenient link to unblock the given username or IP
533 * address, if available; otherwise link to a blank unblock
534 * form
535 *
536 * @param $skin Skin to use
537 * @return string
538 */
539 private function getUnblockLink( $skin ) {
540 $list = SpecialPage::getTitleFor( 'Ipblocklist' );
541 if( $this->BlockAddress ) {
542 $addr = htmlspecialchars( strtr( $this->BlockAddress, '_', ' ' ) );
543 return $skin->makeKnownLinkObj( $list, wfMsgHtml( 'ipb-unblock-addr', $addr ),
544 'action=unblock&ip=' . urlencode( $this->BlockAddress ) );
545 } else {
546 return $skin->makeKnownLinkObj( $list, wfMsgHtml( 'ipb-unblock' ), 'action=unblock' );
547 }
548 }
549
550 /**
551 * Build a convenience link to the block list
552 *
553 * @param $skin Skin to use
554 * @return string
555 */
556 private function getBlockListLink( $skin ) {
557 $list = SpecialPage::getTitleFor( 'Ipblocklist' );
558 if( $this->BlockAddress ) {
559 $addr = htmlspecialchars( strtr( $this->BlockAddress, '_', ' ' ) );
560 return $skin->makeKnownLinkObj( $list, wfMsgHtml( 'ipb-blocklist-addr', $addr ),
561 'ip=' . urlencode( $this->BlockAddress ) );
562 } else {
563 return $skin->makeKnownLinkObj( $list, wfMsgHtml( 'ipb-blocklist' ) );
564 }
565 }
566
567 /**
568 * Block a list of selected users
569 * @param array $users
570 * @param string $reason
571 * @param string $tag replaces user pages
572 * @param string $talkTag replaces user talk pages
573 * @returns array, list of html-safe usernames
574 */
575 public static function doMassUserBlock( $users, $reason = '', $tag = '', $talkTag = '' ) {
576 global $wgUser;
577 $counter = $blockSize = 0;
578 $safeUsers = array();
579 $log = new LogPage( 'block' );
580 foreach( $users as $name ) {
581 # Enforce limits
582 $counter++;
583 $blockSize++;
584 # Lets not go *too* fast
585 if( $blockSize >= 20 ) {
586 $blockSize = 0;
587 wfWaitForSlaves( 5 );
588 }
589 $u = User::newFromName( $name, false );
590 // If user doesn't exist, it ought to be an IP then
591 if( is_null($u) || (!$u->getId() && !IP::isIPAddress( $u->getName() )) ) {
592 continue;
593 }
594 $userTitle = $u->getUserPage();
595 $userTalkTitle = $u->getTalkPage();
596 $userpage = new Article( $userTitle );
597 $usertalk = new Article( $userTalkTitle );
598 $safeUsers[] = '[[' . $userTitle->getPrefixedText() . '|' . $userTitle->getText() . ']]';
599 $expirestr = $u->getId() ? 'indefinite' : '1 week';
600 $expiry = Block::parseExpiryInput( $expirestr );
601 $anonOnly = IP::isIPAddress( $u->getName() ) ? 1 : 0;
602 // Create the block
603 $block = new Block( $u->getName(), // victim
604 $u->getId(), // uid
605 $wgUser->getId(), // blocker
606 $reason, // comment
607 wfTimestampNow(), // block time
608 0, // auto ?
609 $expiry, // duration
610 $anonOnly, // anononly?
611 1, // block account creation?
612 1, // autoblocking?
613 0, // suppress name?
614 0 // block from sending email?
615 );
616 $oldblock = Block::newFromDB( $u->getName(), $u->getId() );
617 if( !$oldblock ) {
618 $block->insert();
619 # Prepare log parameters
620 $logParams = array();
621 $logParams[] = $expirestr;
622 if( $anonOnly ) {
623 $logParams[] = 'anononly';
624 }
625 $logParams[] = 'nocreate';
626 # Add log entry
627 $log->addEntry( 'block', $userTitle, $reason, $logParams );
628 }
629 # Tag userpage! (check length to avoid mistakes)
630 if( strlen($tag) > 2 ) {
631 $userpage->doEdit( $tag, $reason, EDIT_MINOR );
632 }
633 if( strlen($talkTag) > 2 ) {
634 $usertalk->doEdit( $talkTag, $reason, EDIT_MINOR );
635 }
636 }
637 return $safeUsers;
638 }
639 }