r92223 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r92222‎ | r92223 | r92224 >
Date:00:48, 15 July 2011
Author:aaron
Status:ok (Comments)
Tags:
Comment:
Follow-up r92220: changed autoblock handling to use PerformRetroactiveAutoblock hook instead of a global. Also made CheckUser always override autoblocks (no config).
Modified paths:
  • /trunk/extensions/CheckUser/CheckUser.hooks.php (modified) (history)
  • /trunk/extensions/CheckUser/CheckUser.php (modified) (history)
  • /trunk/phase3/docs/hooks.txt (modified) (history)
  • /trunk/phase3/includes/Block.php (modified) (history)
  • /trunk/phase3/includes/DefaultSettings.php (modified) (history)

Diff [purge]

Index: trunk/phase3/docs/hooks.txt
@@ -595,6 +595,10 @@
596596 &$scalerParams: Array with scaler parameters
597597 &$mto: null, set to a MediaTransformOutput
598598
 599+'PerformRetroactiveAutoblock': called before a retroactive autoblock is applied to a user
 600+$block: Block object (which is set to be autoblocking)
 601+&$blockIds: Array of block IDs of the autoblock
 602+
599603 'BlockIp': before an IP address or user is blocked
600604 $block: the Block object about to be saved
601605 $user: the user _doing_ the block (not the one being blocked)
Index: trunk/phase3/includes/DefaultSettings.php
@@ -3261,14 +3261,6 @@
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 -/**
32733265 * If true, blocked users will not be allowed to login. When using this with
32743266 * a public wiki, the effect of logging out blocked users may actually be
32753267 * avers: unless the user's address is also blocked (e.g. auto-block),
Index: trunk/phase3/includes/Block.php
@@ -486,27 +486,18 @@
487487 * @return Array: block IDs of retroactive autoblocks made
488488 */
489489 protected function doRetroactiveAutoblock() {
490 - global $wgAutoblockHandlers;
491 -
492490 $blockIds = array();
493491 # If autoblock is enabled, autoblock the LAST IP(s) used
494492 if ( $this->isAutoblocking() && $this->getType() == self::TYPE_USER ) {
495493 wfDebug( "Doing retroactive autoblocks for " . $this->getTarget() . "\n" );
496494
497 - $call = isset( $wgAutoblockHandlers['retroactiveAutoblock'] )
498 - ? $wgAutoblockHandlers['retroactiveAutoblock']
499 - : null; // default
 495+ $continue = wfRunHooks(
 496+ 'PerformRetroactiveAutoblock', array( $this, &$blockIds ) );
500497
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 );
 498+ if ( $continue ) {
 499+ self::defaultRetroactiveAutoblock( $this, $blockIds );
508500 }
509501 }
510 -
511502 return $blockIds;
512503 }
513504
@@ -514,9 +505,11 @@
515506 * Retroactively autoblocks the last IP used by the user (if it is a user)
516507 * blocked by this Block. This will use the recentchanges table.
517508 *
 509+ * @param Block $block
 510+ * @param Array &$blockIds
518511 * @return Array: block IDs of retroactive autoblocks made
519512 */
520 - protected static function defaultRetroactiveAutoblock( Block $block ) {
 513+ protected static function defaultRetroactiveAutoblock( Block $block, array &$blockIds ) {
521514 $dbr = wfGetDB( DB_SLAVE );
522515
523516 $options = array( 'ORDER BY' => 'rc_timestamp DESC' );
@@ -539,8 +532,6 @@
540533 }
541534 }
542535 }
543 -
544 - return $blockIds;
545536 }
546537
547538 /**
Index: trunk/extensions/CheckUser/CheckUser.php
@@ -68,6 +68,9 @@
6969 $wgHooks['LoadExtensionSchemaUpdates'][] = 'CheckUserHooks::checkUserSchemaUpdates';
7070 $wgHooks['ContributionsToolLinks'][] = 'CheckUserHooks::loadCheckUserLink';
7171
 72+# Take over autoblocking
 73+$wgHooks['PerformRetroactiveAutoblock'][] = 'CheckUserHooks::doRetroactiveAutoblock';
 74+
7275 $wgResourceModules['ext.checkUser'] = array(
7376 'scripts' => 'checkuser.js',
7477 'dependencies' => array( 'mediawiki.util' ), // IP stuff
Index: trunk/extensions/CheckUser/CheckUser.hooks.php
@@ -362,9 +362,10 @@
363363 * Retroactively autoblocks the last IP used by the user (if it is a user)
364364 * blocked by this Block.
365365 *
366 - * @return Array: block IDs of retroactive autoblocks made
 366+ * @param Block $block
 367+ * @param Array &$blockIds
367368 */
368 - public static function doRetroactiveAutoblock( Block $block ) {
 369+ public static function doRetroactiveAutoblock( Block $block, array &$blockIds ) {
369370 $dbr = wfGetDB( DB_SLAVE );
370371
371372 $user = User::newFromName( (string)$block->getTarget(), false );
@@ -390,6 +391,6 @@
391392 }
392393 }
393394
394 - return $blockIds;
 395+ return false; // autoblock handled
395396 }
396397 }

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r92220* Removed angry autoblock code - unused by anything...aaron00:05, 15 July 2011

Comments

#Comment by 😂 (talk | contribs)   22:57, 22 July 2011

Needs release notes.

Status & tagging log