Consistent casing for addHTML()
[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 if ( $alreadyBlocked ) {
274 $wgOut->addHTML("
275 <tr id='wpChangeBlockRow'>
276 <td>&nbsp;</td>
277 <td class='mw-input'>" .
278 Xml::checkLabel( wfMsg( 'ipb-change-block' ),
279 'wpChangeBlock', 'wpChangeBlock', $this->BlockReblock,
280 array( 'tabindex' => '13' ) ) . "
281 </td>
282 </tr>"
283 );
284 }
285
286 $wgOut->addHTML("
287 <tr>
288 <td style='padding-top: 1em'>&nbsp;</td>
289 <td class='mw-submit' style='padding-top: 1em'>" .
290 Xml::submitButton( wfMsg( 'ipbsubmit' ),
291 array( 'name' => 'wpBlock', 'tabindex' => '13', 'accesskey' => 's' ) ) . "
292 </td>
293 </tr>" .
294 Xml::closeElement( 'table' ) .
295 Xml::hidden( 'wpEditToken', $wgUser->editToken() ) .
296 Xml::closeElement( 'fieldset' ) .
297 Xml::closeElement( 'form' ) .
298 Xml::tags( 'script', array( 'type' => 'text/javascript' ), 'updateBlockOptions()' ) . "\n"
299 );
300
301 $wgOut->addHTML( $this->getConvenienceLinks() );
302
303 if( is_object( $user ) ) {
304 $this->showLogFragment( $wgOut, $user->getUserPage() );
305 } elseif( preg_match( '/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/', $this->BlockAddress ) ) {
306 $this->showLogFragment( $wgOut, Title::makeTitle( NS_USER, $this->BlockAddress ) );
307 } 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 ) ) {
308 $this->showLogFragment( $wgOut, Title::makeTitle( NS_USER, $this->BlockAddress ) );
309 }
310 }
311
312 /**
313 * Backend block code.
314 * $userID and $expiry will be filled accordingly
315 * @return array(message key, arguments) on failure, empty array on success
316 */
317 function doBlock( &$userId = null, &$expiry = null ) {
318 global $wgUser, $wgSysopUserBans, $wgSysopRangeBans, $wgBlockAllowsUTEdit;
319
320 $userId = 0;
321 # Expand valid IPv6 addresses, usernames are left as is
322 $this->BlockAddress = IP::sanitizeIP( $this->BlockAddress );
323 # isIPv4() and IPv6() are used for final validation
324 $rxIP4 = '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}';
325 $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}';
326 $rxIP = "($rxIP4|$rxIP6)";
327
328 # Check for invalid specifications
329 if ( !preg_match( "/^$rxIP$/", $this->BlockAddress ) ) {
330 $matches = array();
331 if ( preg_match( "/^($rxIP4)\\/(\\d{1,2})$/", $this->BlockAddress, $matches ) ) {
332 # IPv4
333 if ( $wgSysopRangeBans ) {
334 if ( !IP::isIPv4( $this->BlockAddress ) || $matches[2] < 16 || $matches[2] > 32 ) {
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 if ( preg_match( "/^($rxIP6)\\/(\\d{1,3})$/", $this->BlockAddress, $matches ) ) {
343 # IPv6
344 if ( $wgSysopRangeBans ) {
345 if ( !IP::isIPv6( $this->BlockAddress ) || $matches[2] < 64 || $matches[2] > 128 ) {
346 return array('ip_range_invalid');
347 }
348 $this->BlockAddress = Block::normaliseRange( $this->BlockAddress );
349 } else {
350 # Range block illegal
351 return array('range_block_disabled');
352 }
353 } else {
354 # Username block
355 if ( $wgSysopUserBans ) {
356 $user = User::newFromName( $this->BlockAddress );
357 if( !is_null( $user ) && $user->getId() ) {
358 # Use canonical name
359 $userId = $user->getId();
360 $this->BlockAddress = $user->getName();
361 } else {
362 return array('nosuchusershort', htmlspecialchars( $user ? $user->getName() : $this->BlockAddress ) );
363 }
364 } else {
365 return array('badipaddress');
366 }
367 }
368 }
369
370 if ( $wgUser->isBlocked() && ( $wgUser->getId() !== $userId ) ) {
371 return array( 'cant-block-while-blocked' );
372 }
373
374 $reasonstr = $this->BlockReasonList;
375 if ( $reasonstr != 'other' && $this->BlockReason != '' ) {
376 // Entry from drop down menu + additional comment
377 $reasonstr .= ': ' . $this->BlockReason;
378 } elseif ( $reasonstr == 'other' ) {
379 $reasonstr = $this->BlockReason;
380 }
381
382 $expirestr = $this->BlockExpiry;
383 if( $expirestr == 'other' )
384 $expirestr = $this->BlockOther;
385
386 if ( ( strlen( $expirestr ) == 0) || ( strlen( $expirestr ) > 50) ) {
387 return array('ipb_expiry_invalid');
388 }
389
390 if ( false === ($expiry = Block::parseExpiryInput( $expirestr )) ) {
391 // Bad expiry.
392 return array('ipb_expiry_invalid');
393 }
394
395 if( $this->BlockHideName && $expiry != 'infinity' ) {
396 // Bad expiry.
397 return array('ipb_expiry_temp');
398 }
399
400 # Create block
401 # Note: for a user block, ipb_address is only for display purposes
402 $block = new Block( $this->BlockAddress, $userId, $wgUser->getId(),
403 $reasonstr, wfTimestampNow(), 0, $expiry, $this->BlockAnonOnly,
404 $this->BlockCreateAccount, $this->BlockEnableAutoblock, $this->BlockHideName,
405 $this->BlockEmail, isset( $this->BlockAllowUsertalk ) ? $this->BlockAllowUsertalk : $wgBlockAllowsUTEdit );
406
407 if ( wfRunHooks('BlockIp', array(&$block, &$wgUser)) ) {
408
409 if ( !$block->insert() ) {
410 if ( !$this->BlockReblock ) {
411 return array( 'ipb_already_blocked' );
412 } else {
413 # This returns direct blocks before autoblocks/rangeblocks, since we should be sure the user is blocked by now it should work for our purposes
414 $currentBlock = Block::newFromDB( $this->BlockAddress, $userId );
415 $currentBlock->delete();
416 $block->insert();
417 $log_action = 'reblock';
418 }
419 } else {
420 $log_action = 'block';
421 }
422 wfRunHooks('BlockIpComplete', array($block, $wgUser));
423
424 if ( $this->BlockWatchUser ) {
425 $wgUser->addWatch ( Title::makeTitle( NS_USER, $this->BlockAddress ) );
426 }
427
428 # Prepare log parameters
429 $logParams = array();
430 $logParams[] = $expirestr;
431 $logParams[] = $this->blockLogFlags();
432
433 # Make log entry, if the name is hidden, put it in the oversight log
434 $log_type = ($this->BlockHideName) ? 'suppress' : 'block';
435 $log = new LogPage( $log_type );
436 $log->addEntry( $log_action, Title::makeTitle( NS_USER, $this->BlockAddress ),
437 $reasonstr, $logParams );
438
439 # Report to the user
440 return array();
441 }
442 else
443 return array('hookaborted');
444 }
445
446 /**
447 * UI entry point for blocking
448 * Wraps around doBlock()
449 */
450 function doSubmit()
451 {
452 global $wgOut;
453 $retval = $this->doBlock();
454 if(empty($retval)) {
455 $titleObj = SpecialPage::getTitleFor( 'Blockip' );
456 $wgOut->redirect( $titleObj->getFullURL( 'action=success&ip=' .
457 urlencode( $this->BlockAddress ) ) );
458 return;
459 }
460 $this->showForm( $retval );
461 }
462
463 function showSuccess() {
464 global $wgOut;
465
466 $wgOut->setPagetitle( wfMsg( 'blockip' ) );
467 $wgOut->setSubtitle( wfMsg( 'blockipsuccesssub' ) );
468 $text = wfMsgExt( 'blockipsuccesstext', array( 'parse' ), $this->BlockAddress );
469 $wgOut->addHTML( $text );
470 }
471
472 function showLogFragment( $out, $title ) {
473 global $wgUser;
474 $out->addHTML( Xml::element( 'h2', NULL, LogPage::logName( 'block' ) ) );
475 $count = LogEventsList::showLogExtract( $out, 'block', $title->getPrefixedText(), '', 10 );
476 if($count > 10){
477 $out->addHTML( $wgUser->getSkin()->link(
478 SpecialPage::getTitleFor( 'Log' ),
479 wfMsgHtml( 'blocklog-fulllog' ),
480 array(),
481 array(
482 'type' => 'block',
483 'page' => $title->getPrefixedText() ) ) );
484 }
485 }
486
487 /**
488 * Return a comma-delimited list of "flags" to be passed to the log
489 * reader for this block, to provide more information in the logs
490 *
491 * @return array
492 */
493 private function blockLogFlags() {
494 global $wgBlockAllowsUTEdit;
495 $flags = array();
496 if( $this->BlockAnonOnly && IP::isIPAddress( $this->BlockAddress ) )
497 // when blocking a user the option 'anononly' is not available/has no effect -> do not write this into log
498 $flags[] = 'anononly';
499 if( $this->BlockCreateAccount )
500 $flags[] = 'nocreate';
501 if( !$this->BlockEnableAutoblock )
502 $flags[] = 'noautoblock';
503 if ( $this->BlockEmail )
504 $flags[] = 'noemail';
505 if ( !$this->BlockAllowUsertalk && $wgBlockAllowsUTEdit )
506 $flags[] = 'nousertalk';
507 return implode( ',', $flags );
508 }
509
510 /**
511 * Builds unblock and block list links
512 *
513 * @return string
514 */
515 private function getConvenienceLinks() {
516 global $wgUser;
517 $skin = $wgUser->getSkin();
518 if( $this->BlockAddress )
519 $links[] = $this->getContribsLink( $skin );
520 $links[] = $this->getUnblockLink( $skin );
521 $links[] = $this->getBlockListLink( $skin );
522 $links[] = $skin->makeLink ( 'MediaWiki:Ipbreason-dropdown', wfMsgHtml( 'ipb-edit-dropdown' ) );
523 return '<p class="mw-ipb-conveniencelinks">' . implode( ' | ', $links ) . '</p>';
524 }
525
526 /**
527 * Build a convenient link to a user or IP's contribs
528 * form
529 *
530 * @param $skin Skin to use
531 * @return string
532 */
533 private function getContribsLink( $skin ) {
534 $contribsPage = SpecialPage::getTitleFor( 'Contributions', $this->BlockAddress );
535 return $skin->link( $contribsPage, wfMsgHtml( 'ipb-blocklist-contribs', $this->BlockAddress ) );
536 }
537
538 /**
539 * Build a convenient link to unblock the given username or IP
540 * address, if available; otherwise link to a blank unblock
541 * form
542 *
543 * @param $skin Skin to use
544 * @return string
545 */
546 private function getUnblockLink( $skin ) {
547 $list = SpecialPage::getTitleFor( 'Ipblocklist' );
548 if( $this->BlockAddress ) {
549 $addr = htmlspecialchars( strtr( $this->BlockAddress, '_', ' ' ) );
550 return $skin->makeKnownLinkObj( $list, wfMsgHtml( 'ipb-unblock-addr', $addr ),
551 'action=unblock&ip=' . urlencode( $this->BlockAddress ) );
552 } else {
553 return $skin->makeKnownLinkObj( $list, wfMsgHtml( 'ipb-unblock' ), 'action=unblock' );
554 }
555 }
556
557 /**
558 * Build a convenience link to the block list
559 *
560 * @param $skin Skin to use
561 * @return string
562 */
563 private function getBlockListLink( $skin ) {
564 $list = SpecialPage::getTitleFor( 'Ipblocklist' );
565 if( $this->BlockAddress ) {
566 $addr = htmlspecialchars( strtr( $this->BlockAddress, '_', ' ' ) );
567 return $skin->makeKnownLinkObj( $list, wfMsgHtml( 'ipb-blocklist-addr', $addr ),
568 'ip=' . urlencode( $this->BlockAddress ) );
569 } else {
570 return $skin->makeKnownLinkObj( $list, wfMsgHtml( 'ipb-blocklist' ) );
571 }
572 }
573
574 /**
575 * Block a list of selected users
576 * @param array $users
577 * @param string $reason
578 * @param string $tag
579 * @returns array, list of html-safe usernames
580 */
581 public static function doMassUserBlock( $users, $reason = '', $tag = '' ) {
582 global $wgUser;
583 $counter = $blockSize = 0;
584 $safeUsers = array();
585 $log = new LogPage( 'block' );
586 foreach( $users as $name ) {
587 # Enforce limits
588 $counter++;
589 $blockSize++;
590 # Lets not go *too* fast
591 if( $blockSize >= 20 ) {
592 $blockSize = 0;
593 wfWaitForSlaves( 5 );
594 }
595 $u = User::newFromName( $name, false );
596 // If user doesn't exist, it ought to be an IP then
597 if( is_null($u) || (!$u->getId() && !IP::isIPAddress( $u->getName() )) ) {
598 continue;
599 }
600 $usertitle = Title::makeTitle( NS_USER, $u->getName() );
601 $userpage = new Article( $usertitle );
602 $safeUsers[] = '[[' . $usertitle->getPrefixedText() . '|' . $usertitle->getText() . ']]';
603 $expirestr = $u->getId() ? 'indefinite' : '1 week';
604 $expiry = Block::parseExpiryInput( $expirestr );
605 $anonOnly = IP::isIPAddress( $u->getName() ) ? 1 : 0;
606 // Create the block
607 $block = new Block( $u->getName(), // victim
608 $u->getId(), // uid
609 $wgUser->getId(), // blocker
610 $reason, // comment
611 wfTimestampNow(), // block time
612 0, // auto ?
613 $expiry, // duration
614 $anonOnly, // anononly?
615 1, // block account creation?
616 1, // autoblocking?
617 0, // suppress name?
618 0 // block from sending email?
619 );
620 $oldblock = Block::newFromDB( $u->getName(), $u->getId() );
621 if( !$oldblock ) {
622 $block->insert();
623 # Prepare log parameters
624 $logParams = array();
625 $logParams[] = $expirestr;
626 if( $anonOnly ) {
627 $logParams[] = 'anononly';
628 }
629 $logParams[] = 'nocreate';
630 # Add log entry
631 $log->addEntry( 'block', $usertitle, $reason, $logParams );
632 }
633 # Tag userpage! (check length to avoid mistakes)
634 if( strlen($tag) > 2 ) {
635 $userpage->doEdit( $tag, $reason, EDIT_MINOR );
636 }
637 }
638 return $safeUsers;
639 }
640 }