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