Index: trunk/phase3/includes/DefaultSettings.php |
— | — | @@ -3261,6 +3261,14 @@ |
3262 | 3262 | ); |
3263 | 3263 | |
3264 | 3264 | /** |
| 3265 | + * Functions to handle autoblocking users. The default handlers will be used |
| 3266 | + * where null is given. They can otherwise be overridden with custom callbacks. |
| 3267 | + * |
| 3268 | + * 'retroactiveAutoblock' handlers must return the array of autoblock IDs |
| 3269 | + */ |
| 3270 | +$wgAutoblockHandlers = array( 'retroactiveAutoblock' => null ); |
| 3271 | + |
| 3272 | +/** |
3265 | 3273 | * If true, blocked users will not be allowed to login. When using this with |
3266 | 3274 | * a public wiki, the effect of logging out blocked users may actually be |
3267 | 3275 | * avers: unless the user's address is also blocked (e.g. auto-block), |
Index: trunk/phase3/includes/Block.php |
— | — | @@ -20,7 +20,7 @@ |
21 | 21 | * @file |
22 | 22 | */ |
23 | 23 | class Block { |
24 | | - /* public*/ var $mReason, $mTimestamp, $mAuto, $mExpiry, $mHideName, $mAngryAutoblock; |
| 24 | + /* public*/ var $mReason, $mTimestamp, $mAuto, $mExpiry, $mHideName; |
25 | 25 | |
26 | 26 | protected |
27 | 27 | $mId, |
— | — | @@ -84,7 +84,6 @@ |
85 | 85 | $this->prevents( 'editownusertalk', !$allowUsertalk ); |
86 | 86 | |
87 | 87 | $this->mFromMaster = false; |
88 | | - $this->mAngryAutoblock = false; |
89 | 88 | } |
90 | 89 | |
91 | 90 | /** |
— | — | @@ -487,43 +486,60 @@ |
488 | 487 | * @return Array: block IDs of retroactive autoblocks made |
489 | 488 | */ |
490 | 489 | protected function doRetroactiveAutoblock() { |
| 490 | + global $wgAutoblockHandlers; |
| 491 | + |
491 | 492 | $blockIds = array(); |
492 | | - |
493 | | - $dbr = wfGetDB( DB_SLAVE ); |
494 | | - # If autoblock is enabled, autoblock the LAST IP used |
495 | | - # - stolen shamelessly from CheckUser_body.php |
496 | | - |
| 493 | + # If autoblock is enabled, autoblock the LAST IP(s) used |
497 | 494 | if ( $this->isAutoblocking() && $this->getType() == self::TYPE_USER ) { |
498 | 495 | wfDebug( "Doing retroactive autoblocks for " . $this->getTarget() . "\n" ); |
499 | 496 | |
500 | | - $options = array( 'ORDER BY' => 'rc_timestamp DESC' ); |
501 | | - $conds = array( 'rc_user_text' => (string)$this->getTarget() ); |
| 497 | + $call = isset( $wgAutoblockHandlers['retroactiveAutoblock'] ) |
| 498 | + ? $wgAutoblockHandlers['retroactiveAutoblock'] |
| 499 | + : null; // default |
502 | 500 | |
503 | | - if ( $this->mAngryAutoblock ) { |
504 | | - // Block any IP used in the last 7 days. Up to five IPs. |
505 | | - $conds[] = 'rc_timestamp < ' . |
506 | | - $dbr->addQuotes( $dbr->timestamp( time() - ( 7 * 86400 ) ) ); |
507 | | - $options['LIMIT'] = 5; |
508 | | - } else { |
509 | | - // Just the last IP used. |
510 | | - $options['LIMIT'] = 1; |
| 501 | + if ( is_callable( $call ) ) { // custom handler |
| 502 | + $blockIds = MWFunction::call( $call, $this ); |
| 503 | + } else { // regular handler |
| 504 | + if ( $call !== null ) { // something given, but bad |
| 505 | + wfWarn( 'doRetroactiveAutoblock given uncallable handler, check $wgAutoblockHandlers; using default handler.' ); |
| 506 | + } |
| 507 | + $blockIds = self::defaultRetroactiveAutoblock( $this ); |
511 | 508 | } |
| 509 | + } |
512 | 510 | |
513 | | - $res = $dbr->select( 'recentchanges', array( 'rc_ip' ), $conds, |
514 | | - __METHOD__ , $options ); |
| 511 | + return $blockIds; |
| 512 | + } |
515 | 513 | |
516 | | - if ( !$dbr->numRows( $res ) ) { |
517 | | - # No results, don't autoblock anything |
518 | | - wfDebug( "No IP found to retroactively autoblock\n" ); |
519 | | - } else { |
520 | | - foreach ( $res as $row ) { |
521 | | - if ( $row->rc_ip ) { |
522 | | - $id = $this->doAutoblock( $row->rc_ip ); |
523 | | - if ( $id ) $blockIds[] = $id; |
524 | | - } |
| 514 | + /** |
| 515 | + * Retroactively autoblocks the last IP used by the user (if it is a user) |
| 516 | + * blocked by this Block. This will use the recentchanges table. |
| 517 | + * |
| 518 | + * @return Array: block IDs of retroactive autoblocks made |
| 519 | + */ |
| 520 | + protected static function defaultRetroactiveAutoblock( Block $block ) { |
| 521 | + $dbr = wfGetDB( DB_SLAVE ); |
| 522 | + |
| 523 | + $options = array( 'ORDER BY' => 'rc_timestamp DESC' ); |
| 524 | + $conds = array( 'rc_user_text' => (string)$block->getTarget() ); |
| 525 | + |
| 526 | + // Just the last IP used. |
| 527 | + $options['LIMIT'] = 1; |
| 528 | + |
| 529 | + $res = $dbr->select( 'recentchanges', array( 'rc_ip' ), $conds, |
| 530 | + __METHOD__ , $options ); |
| 531 | + |
| 532 | + if ( !$dbr->numRows( $res ) ) { |
| 533 | + # No results, don't autoblock anything |
| 534 | + wfDebug( "No IP found to retroactively autoblock\n" ); |
| 535 | + } else { |
| 536 | + foreach ( $res as $row ) { |
| 537 | + if ( $row->rc_ip ) { |
| 538 | + $id = $block->doAutoblock( $row->rc_ip ); |
| 539 | + if ( $id ) $blockIds[] = $id; |
525 | 540 | } |
526 | 541 | } |
527 | 542 | } |
| 543 | + |
528 | 544 | return $blockIds; |
529 | 545 | } |
530 | 546 | |
Index: trunk/extensions/CheckUser/CheckUser.hooks.php |
— | — | @@ -357,4 +357,39 @@ |
358 | 358 | } |
359 | 359 | return true; |
360 | 360 | } |
| 361 | + |
| 362 | + /** |
| 363 | + * Retroactively autoblocks the last IP used by the user (if it is a user) |
| 364 | + * blocked by this Block. |
| 365 | + * |
| 366 | + * @return Array: block IDs of retroactive autoblocks made |
| 367 | + */ |
| 368 | + public static function doRetroactiveAutoblock( Block $block ) { |
| 369 | + $dbr = wfGetDB( DB_SLAVE ); |
| 370 | + |
| 371 | + $user = User::newFromName( (string)$block->getTarget(), false ); |
| 372 | + if ( !$user->getId() ) { |
| 373 | + return array(); // user in an IP? |
| 374 | + } |
| 375 | + |
| 376 | + $options = array( 'ORDER BY' => 'cuc_timestamp DESC' ); |
| 377 | + $options['LIMIT'] = 1; // just the last IP used |
| 378 | + |
| 379 | + $res = $dbr->select( 'cu_changes', |
| 380 | + array( 'cuc_ip' ), |
| 381 | + array( 'cuc_user' => $user->getId() ), |
| 382 | + __METHOD__ , |
| 383 | + $options |
| 384 | + ); |
| 385 | + |
| 386 | + # Iterate through IPs used (this is just one or zero for now) |
| 387 | + foreach ( $res as $row ) { |
| 388 | + if ( $row->cuc_ip ) { |
| 389 | + $id = $block->doAutoblock( $row->cuc_ip ); |
| 390 | + if ( $id ) $blockIds[] = $id; |
| 391 | + } |
| 392 | + } |
| 393 | + |
| 394 | + return $blockIds; |
| 395 | + } |
361 | 396 | } |