Index: trunk/phase3/includes/specials/SpecialBlockip.php |
— | — | @@ -11,13 +11,11 @@ |
12 | 12 | */ |
13 | 13 | function wfSpecialBlockip( $par ) { |
14 | 14 | global $wgUser, $wgOut, $wgRequest; |
15 | | - |
16 | 15 | # Can't block when the database is locked |
17 | 16 | if( wfReadOnly() ) { |
18 | 17 | $wgOut->readOnlyPage(); |
19 | 18 | return; |
20 | 19 | } |
21 | | - |
22 | 20 | # Permission check |
23 | 21 | if( !$wgUser->isAllowed( 'block' ) ) { |
24 | 22 | $wgOut->permissionRequired( 'block' ); |
— | — | @@ -27,9 +25,9 @@ |
28 | 26 | $ipb = new IPBlockForm( $par ); |
29 | 27 | |
30 | 28 | $action = $wgRequest->getVal( 'action' ); |
31 | | - if ( 'success' == $action ) { |
| 29 | + if( 'success' == $action ) { |
32 | 30 | $ipb->showSuccess(); |
33 | | - } else if ( $wgRequest->wasPosted() && 'submit' == $action && |
| 31 | + } else if( $wgRequest->wasPosted() && 'submit' == $action && |
34 | 32 | $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) { |
35 | 33 | $ipb->doSubmit(); |
36 | 34 | } else { |
— | — | @@ -44,9 +42,8 @@ |
45 | 43 | */ |
46 | 44 | class IPBlockForm { |
47 | 45 | var $BlockAddress, $BlockExpiry, $BlockReason; |
48 | | -# var $BlockEmail; |
49 | 46 | |
50 | | - function IPBlockForm( $par ) { |
| 47 | + public function __construct( $par ) { |
51 | 48 | global $wgRequest, $wgUser, $wgBlockAllowsUTEdit; |
52 | 49 | |
53 | 50 | $this->BlockAddress = $wgRequest->getVal( 'wpBlockAddress', $wgRequest->getVal( 'ip', $par ) ); |
— | — | @@ -70,7 +67,7 @@ |
71 | 68 | $this->BlockReblock = $wgRequest->getBool( 'wpChangeBlock', false ); |
72 | 69 | } |
73 | 70 | |
74 | | - function showForm( $err ) { |
| 71 | + public function showForm( $err ) { |
75 | 72 | global $wgOut, $wgUser, $wgSysopUserBans; |
76 | 73 | |
77 | 74 | $wgOut->setPagetitle( wfMsg( 'blockip' ) ); |
— | — | @@ -90,17 +87,17 @@ |
91 | 88 | $user = User::newFromName( $this->BlockAddress ); |
92 | 89 | |
93 | 90 | $alreadyBlocked = false; |
94 | | - if ( $err && $err[0] != 'ipb_already_blocked' ) { |
| 91 | + if( $err && $err[0] != 'ipb_already_blocked' ) { |
95 | 92 | $key = array_shift($err); |
96 | 93 | $msg = wfMsgReal($key, $err); |
97 | 94 | $wgOut->setSubtitle( wfMsgHtml( 'formerror' ) ); |
98 | 95 | $wgOut->addHTML( Xml::tags( 'p', array( 'class' => 'error' ), $msg ) ); |
99 | | - } elseif ( $this->BlockAddress ) { |
| 96 | + } elseif( $this->BlockAddress ) { |
100 | 97 | $userId = 0; |
101 | | - if ( is_object( $user ) ) |
| 98 | + if( is_object( $user ) ) |
102 | 99 | $userId = $user->getId(); |
103 | 100 | $currentBlock = Block::newFromDB( $this->BlockAddress, $userId ); |
104 | | - if ( !is_null($currentBlock) && !$currentBlock->mAuto && # The block exists and isn't an autoblock |
| 101 | + if( !is_null($currentBlock) && !$currentBlock->mAuto && # The block exists and isn't an autoblock |
105 | 102 | ( $currentBlock->mRangeStart == $currentBlock->mRangeEnd || # The block isn't a rangeblock |
106 | 103 | # or if it is, the range is what we're about to block |
107 | 104 | ( $currentBlock->mAddress == $this->BlockAddress ) ) ) { |
— | — | @@ -125,12 +122,11 @@ |
126 | 123 | $scBlockExpiryOptions = wfMsgForContent( 'ipboptions' ); |
127 | 124 | |
128 | 125 | $showblockoptions = $scBlockExpiryOptions != '-'; |
129 | | - if (!$showblockoptions) |
130 | | - $mIpbother = $mIpbexpiry; |
| 126 | + if( !$showblockoptions ) $mIpbother = $mIpbexpiry; |
131 | 127 | |
132 | 128 | $blockExpiryFormOptions = Xml::option( wfMsg( 'ipbotheroption' ), 'other' ); |
133 | 129 | foreach (explode(',', $scBlockExpiryOptions) as $option) { |
134 | | - if ( strpos($option, ":") === false ) $option = "$option:$option"; |
| 130 | + if( strpos($option, ":") === false ) $option = "$option:$option"; |
135 | 131 | list($show, $value) = explode(":", $option); |
136 | 132 | $show = htmlspecialchars($show); |
137 | 133 | $value = htmlspecialchars($value); |
— | — | @@ -162,7 +158,7 @@ |
163 | 159 | </tr> |
164 | 160 | <tr>" |
165 | 161 | ); |
166 | | - if ( $showblockoptions ) { |
| 162 | + if( $showblockoptions ) { |
167 | 163 | $wgOut->addHTML(" |
168 | 164 | <td class='mw-label'> |
169 | 165 | {$mIpbexpiry} |
— | — | @@ -233,7 +229,7 @@ |
234 | 230 | ); |
235 | 231 | |
236 | 232 | global $wgSysopEmailBans, $wgBlockAllowsUTEdit; |
237 | | - if ( $wgSysopEmailBans && $wgUser->isAllowed( 'blockemail' ) ) { |
| 233 | + if( $wgSysopEmailBans && $wgUser->isAllowed( 'blockemail' ) ) { |
238 | 234 | $wgOut->addHTML(" |
239 | 235 | <tr id='wpEnableEmailBan'> |
240 | 236 | <td> </td> |
— | — | @@ -247,7 +243,7 @@ |
248 | 244 | } |
249 | 245 | |
250 | 246 | // Allow some users to hide name from block log, blocklist and listusers |
251 | | - if ( $wgUser->isAllowed( 'hideuser' ) ) { |
| 247 | + if( $wgUser->isAllowed( 'hideuser' ) ) { |
252 | 248 | $wgOut->addHTML(" |
253 | 249 | <tr id='wpEnableHideUser'> |
254 | 250 | <td> </td> |
— | — | @@ -328,12 +324,12 @@ |
329 | 325 | $rxIP = "($rxIP4|$rxIP6)"; |
330 | 326 | |
331 | 327 | # Check for invalid specifications |
332 | | - if ( !preg_match( "/^$rxIP$/", $this->BlockAddress ) ) { |
| 328 | + if( !preg_match( "/^$rxIP$/", $this->BlockAddress ) ) { |
333 | 329 | $matches = array(); |
334 | | - if ( preg_match( "/^($rxIP4)\\/(\\d{1,2})$/", $this->BlockAddress, $matches ) ) { |
| 330 | + if( preg_match( "/^($rxIP4)\\/(\\d{1,2})$/", $this->BlockAddress, $matches ) ) { |
335 | 331 | # IPv4 |
336 | | - if ( $wgSysopRangeBans ) { |
337 | | - if ( !IP::isIPv4( $this->BlockAddress ) || $matches[2] < 16 || $matches[2] > 32 ) { |
| 332 | + if( $wgSysopRangeBans ) { |
| 333 | + if( !IP::isIPv4( $this->BlockAddress ) || $matches[2] < 16 || $matches[2] > 32 ) { |
338 | 334 | return array('ip_range_invalid'); |
339 | 335 | } |
340 | 336 | $this->BlockAddress = Block::normaliseRange( $this->BlockAddress ); |
— | — | @@ -341,10 +337,10 @@ |
342 | 338 | # Range block illegal |
343 | 339 | return array('range_block_disabled'); |
344 | 340 | } |
345 | | - } else if ( preg_match( "/^($rxIP6)\\/(\\d{1,3})$/", $this->BlockAddress, $matches ) ) { |
| 341 | + } else if( preg_match( "/^($rxIP6)\\/(\\d{1,3})$/", $this->BlockAddress, $matches ) ) { |
346 | 342 | # IPv6 |
347 | | - if ( $wgSysopRangeBans ) { |
348 | | - if ( !IP::isIPv6( $this->BlockAddress ) || $matches[2] < 64 || $matches[2] > 128 ) { |
| 343 | + if( $wgSysopRangeBans ) { |
| 344 | + if( !IP::isIPv6( $this->BlockAddress ) || $matches[2] < 64 || $matches[2] > 128 ) { |
349 | 345 | return array('ip_range_invalid'); |
350 | 346 | } |
351 | 347 | $this->BlockAddress = Block::normaliseRange( $this->BlockAddress ); |
— | — | @@ -354,7 +350,7 @@ |
355 | 351 | } |
356 | 352 | } else { |
357 | 353 | # Username block |
358 | | - if ( $wgSysopUserBans ) { |
| 354 | + if( $wgSysopUserBans ) { |
359 | 355 | $user = User::newFromName( $this->BlockAddress ); |
360 | 356 | if( !is_null( $user ) && $user->getId() ) { |
361 | 357 | # Use canonical name |
— | — | @@ -369,15 +365,15 @@ |
370 | 366 | } |
371 | 367 | } |
372 | 368 | |
373 | | - if ( $wgUser->isBlocked() && ( $wgUser->getId() !== $userId ) ) { |
| 369 | + if( $wgUser->isBlocked() && ( $wgUser->getId() !== $userId ) ) { |
374 | 370 | return array( 'cant-block-while-blocked' ); |
375 | 371 | } |
376 | 372 | |
377 | 373 | $reasonstr = $this->BlockReasonList; |
378 | | - if ( $reasonstr != 'other' && $this->BlockReason != '' ) { |
| 374 | + if( $reasonstr != 'other' && $this->BlockReason != '' ) { |
379 | 375 | // Entry from drop down menu + additional comment |
380 | 376 | $reasonstr .= wfMsgForContent( 'colon-separator' ) . $this->BlockReason; |
381 | | - } elseif ( $reasonstr == 'other' ) { |
| 377 | + } elseif( $reasonstr == 'other' ) { |
382 | 378 | $reasonstr = $this->BlockReason; |
383 | 379 | } |
384 | 380 | |
— | — | @@ -385,11 +381,11 @@ |
386 | 382 | if( $expirestr == 'other' ) |
387 | 383 | $expirestr = $this->BlockOther; |
388 | 384 | |
389 | | - if ( ( strlen( $expirestr ) == 0) || ( strlen( $expirestr ) > 50) ) { |
| 385 | + if( ( strlen( $expirestr ) == 0) || ( strlen( $expirestr ) > 50) ) { |
390 | 386 | return array('ipb_expiry_invalid'); |
391 | 387 | } |
392 | 388 | |
393 | | - if ( false === ($expiry = Block::parseExpiryInput( $expirestr )) ) { |
| 389 | + if( false === ($expiry = Block::parseExpiryInput( $expirestr )) ) { |
394 | 390 | // Bad expiry. |
395 | 391 | return array('ipb_expiry_invalid'); |
396 | 392 | } |
— | — | @@ -397,8 +393,7 @@ |
398 | 394 | if( $this->BlockHideName ) { |
399 | 395 | // Recheck params here... |
400 | 396 | if( !$userId || !$wgUser->isAllowed('hideuser') ) { |
401 | | - // IP users should not be hidden |
402 | | - $this->BlockHideName = false; |
| 397 | + $this->BlockHideName = false; // IP users should not be hidden |
403 | 398 | } else if( $expiry !== 'infinity' ) { |
404 | 399 | // Bad expiry. |
405 | 400 | return array('ipb_expiry_temp'); |
— | — | @@ -409,7 +404,7 @@ |
410 | 405 | } |
411 | 406 | } |
412 | 407 | |
413 | | - # Create block |
| 408 | + # Create block object |
414 | 409 | # Note: for a user block, ipb_address is only for display purposes |
415 | 410 | $block = new Block( $this->BlockAddress, $userId, $wgUser->getId(), |
416 | 411 | $reasonstr, wfTimestampNow(), 0, $expiry, $this->BlockAnonOnly, |
— | — | @@ -419,11 +414,11 @@ |
420 | 415 | |
421 | 416 | # Should this be privately logged? |
422 | 417 | $suppressLog = (bool)$this->BlockHideName; |
423 | | - if ( wfRunHooks('BlockIp', array(&$block, &$wgUser)) ) { |
| 418 | + if( wfRunHooks('BlockIp', array(&$block, &$wgUser)) ) { |
424 | 419 | # Try to insert block. Is there a conflicting block? |
425 | | - if ( !$block->insert() ) { |
| 420 | + if( !$block->insert() ) { |
426 | 421 | # Show form unless the user is already aware of this... |
427 | | - if ( !$this->BlockReblock ) { |
| 422 | + if( !$this->BlockReblock ) { |
428 | 423 | return array( 'ipb_already_blocked' ); |
429 | 424 | # Otherwise, try to update the block... |
430 | 425 | } else { |
— | — | @@ -458,7 +453,7 @@ |
459 | 454 | self::suppressUserName( $this->BlockAddress, $userId ); |
460 | 455 | } |
461 | 456 | |
462 | | - if ( $this->BlockWatchUser && |
| 457 | + if( $this->BlockWatchUser && |
463 | 458 | # Only show watch link when this is no range block |
464 | 459 | $block->mRangeStart == $block->mRangeEnd) { |
465 | 460 | $wgUser->addWatch ( Title::makeTitle( NS_USER, $this->BlockAddress ) ); |
— | — | @@ -477,7 +472,7 @@ |
478 | 473 | $log_type = $suppressLog ? 'suppress' : 'block'; |
479 | 474 | $log = new LogPage( $log_type ); |
480 | 475 | $log->addEntry( $log_action, Title::makeTitle( NS_USER, $this->BlockAddress ), |
481 | | - $reasonstr, $logParams ); |
| 476 | + $reasonstr, $logParams ); |
482 | 477 | |
483 | 478 | # Report to the user |
484 | 479 | return array(); |
— | — | @@ -545,11 +540,10 @@ |
546 | 541 | * UI entry point for blocking |
547 | 542 | * Wraps around doBlock() |
548 | 543 | */ |
549 | | - function doSubmit() |
550 | | - { |
| 544 | + public function doSubmit() { |
551 | 545 | global $wgOut; |
552 | 546 | $retval = $this->doBlock(); |
553 | | - if(empty($retval)) { |
| 547 | + if( empty($retval) ) { |
554 | 548 | $titleObj = SpecialPage::getTitleFor( 'Blockip' ); |
555 | 549 | $wgOut->redirect( $titleObj->getFullURL( 'action=success&ip=' . |
556 | 550 | urlencode( $this->BlockAddress ) ) ); |
— | — | @@ -558,7 +552,7 @@ |
559 | 553 | $this->showForm( $retval ); |
560 | 554 | } |
561 | 555 | |
562 | | - function showSuccess() { |
| 556 | + public function showSuccess() { |
563 | 557 | global $wgOut; |
564 | 558 | |
565 | 559 | $wgOut->setPagetitle( wfMsg( 'blockip' ) ); |
— | — | @@ -567,7 +561,7 @@ |
568 | 562 | $wgOut->addHTML( $text ); |
569 | 563 | } |
570 | 564 | |
571 | | - function showLogFragment( $out, $title ) { |
| 565 | + private function showLogFragment( $out, $title ) { |
572 | 566 | global $wgUser; |
573 | 567 | $out->addHTML( Xml::element( 'h2', NULL, LogPage::logName( 'block' ) ) ); |
574 | 568 | $count = LogEventsList::showLogExtract( $out, 'block', $title->getPrefixedText(), '', 10 ); |
— | — | @@ -605,11 +599,11 @@ |
606 | 600 | if( !$this->BlockEnableAutoblock && !IP::isIPAddress( $this->BlockAddress ) ) |
607 | 601 | // Same as anononly, this is not displayed when blocking an IP address |
608 | 602 | $flags[] = 'noautoblock'; |
609 | | - if ( $this->BlockEmail ) |
| 603 | + if( $this->BlockEmail ) |
610 | 604 | $flags[] = 'noemail'; |
611 | | - if ( !$this->BlockAllowUsertalk && $wgBlockAllowsUTEdit ) |
| 605 | + if( !$this->BlockAllowUsertalk && $wgBlockAllowsUTEdit ) |
612 | 606 | $flags[] = 'nousertalk'; |
613 | | - if ( $this->BlockHideName ) |
| 607 | + if( $this->BlockHideName ) |
614 | 608 | $flags[] = 'hiddenname'; |
615 | 609 | return implode( ',', $flags ); |
616 | 610 | } |