r92220 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r92219‎ | r92220 | r92221 >
Date:00:05, 15 July 2011
Author:aaron
Status:resolved (Comments)
Tags:
Comment:
* Removed angry autoblock code - unused by anything
* Added $wgAutoblockHandlers variable for alternative autoblock handling functions
* Gave CheckUser a potential $wgAutoblockHandlers function (bug 29330)
Modified paths:
  • /trunk/extensions/CheckUser/CheckUser.hooks.php (modified) (history)
  • /trunk/phase3/includes/Block.php (modified) (history)
  • /trunk/phase3/includes/DefaultSettings.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/DefaultSettings.php
@@ -3261,6 +3261,14 @@
32623262 );
32633263
32643264 /**
 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+/**
32653273 * If true, blocked users will not be allowed to login. When using this with
32663274 * a public wiki, the effect of logging out blocked users may actually be
32673275 * avers: unless the user's address is also blocked (e.g. auto-block),
Index: trunk/phase3/includes/Block.php
@@ -20,7 +20,7 @@
2121 * @file
2222 */
2323 class Block {
24 - /* public*/ var $mReason, $mTimestamp, $mAuto, $mExpiry, $mHideName, $mAngryAutoblock;
 24+ /* public*/ var $mReason, $mTimestamp, $mAuto, $mExpiry, $mHideName;
2525
2626 protected
2727 $mId,
@@ -84,7 +84,6 @@
8585 $this->prevents( 'editownusertalk', !$allowUsertalk );
8686
8787 $this->mFromMaster = false;
88 - $this->mAngryAutoblock = false;
8988 }
9089
9190 /**
@@ -487,43 +486,60 @@
488487 * @return Array: block IDs of retroactive autoblocks made
489488 */
490489 protected function doRetroactiveAutoblock() {
 490+ global $wgAutoblockHandlers;
 491+
491492 $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
497494 if ( $this->isAutoblocking() && $this->getType() == self::TYPE_USER ) {
498495 wfDebug( "Doing retroactive autoblocks for " . $this->getTarget() . "\n" );
499496
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
502500
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 );
511508 }
 509+ }
512510
513 - $res = $dbr->select( 'recentchanges', array( 'rc_ip' ), $conds,
514 - __METHOD__ , $options );
 511+ return $blockIds;
 512+ }
515513
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;
525540 }
526541 }
527542 }
 543+
528544 return $blockIds;
529545 }
530546
Index: trunk/extensions/CheckUser/CheckUser.hooks.php
@@ -357,4 +357,39 @@
358358 }
359359 return true;
360360 }
 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+ }
361396 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r92223Follow-up r92220: changed autoblock handling to use PerformRetroactiveAutoblo...aaron00:48, 15 July 2011

Comments

#Comment by Brion VIBBER (talk | contribs)   00:28, 15 July 2011

As noted on IRC, just recording so we don't forget --

My inclination is to use wfRunHooks here and go ahead and have CheckUser set its hook when it loads; I think that'll be more consistent than creating another callback structure. The logic itself looks like it should be ok either way though!

#Comment by Bawolff (talk | contribs)   07:45, 2 January 2012

Abuse filter still seems to add angry-autoblock to the log params when blocking people.

Status & tagging log