From bc69502492030842510a83505bd14fd4a8d19f6f Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Fri, 20 Sep 2013 15:26:08 -0700 Subject: [PATCH] Support rate limiting backlink purges, including null edits Change-Id: I86e45b7d0eba7d87f65150b34e190e04d8342b3e --- docs/hooks.txt | 1 + includes/DefaultSettings.php | 7 +++++++ includes/EditPage.php | 6 +++++- includes/User.php | 13 +++++++++---- includes/api/ApiPurge.php | 2 +- 5 files changed, 23 insertions(+), 6 deletions(-) diff --git a/docs/hooks.txt b/docs/hooks.txt index 5d6a6e420a..377a669d59 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -1879,6 +1879,7 @@ $action : Action being performed &$result : Whether or not the action should be prevented Change $result and return false to give a definitive answer, otherwise the built-in rate limiting checks are used, if enabled. +$incrBy: Amount to increment counter by 'PlaceNewSection': Override placement of new sections. Return false and put the merged text into $text to override the default behavior. diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 4d8c032059..5b1d4b3089 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -4653,6 +4653,13 @@ $wgRateLimits = array( 'emailuser' => array( 'user' => null, ), + 'linkpurge' => array( + 'anon' => null, + 'user' => null, + 'newbie' => null, + 'ip' => null, + 'subnet' => null, + ), ); /** diff --git a/includes/EditPage.php b/includes/EditPage.php index 63e3e66826..12cd4b3d83 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -1493,7 +1493,7 @@ class EditPage { wfProfileOut( __METHOD__ ); return $status; } - if ( $wgUser->pingLimiter() ) { + if ( $wgUser->pingLimiter() || $wgUser->pingLimiter( 'linkpurge', 0 ) ) { $status->fatal( 'actionthrottledtext' ); $status->value = self::AS_RATE_LIMITED; wfProfileOut( __METHOD__ . '-checks' ); @@ -1771,6 +1771,10 @@ class EditPage { } $result['nullEdit'] = $doEditStatus->hasMessage( 'edit-no-change' ); + if ( $result['nullEdit'] ) { + // We don't know if it was a null edit until now, so increment here + $wgUser->pingLimiter( 'linkpurge' ); + } $result['redirect'] = $content->isRedirect(); $this->updateWatchlist(); wfProfileOut( __METHOD__ ); diff --git a/includes/User.php b/includes/User.php index 60efc9d41e..12912e1c0a 100644 --- a/includes/User.php +++ b/includes/User.php @@ -1489,12 +1489,13 @@ class User { * last-hit counters will be shared across wikis. * * @param string $action Action to enforce; 'edit' if unspecified + * @param integer $incrBy Positive amount to increment counter by [defaults to 1] * @return bool True if a rate limiter was tripped */ - public function pingLimiter( $action = 'edit' ) { + public function pingLimiter( $action = 'edit', $incrBy = 1 ) { // Call the 'PingLimiter' hook $result = false; - if ( !wfRunHooks( 'PingLimiter', array( &$this, $action, &$result ) ) ) { + if ( !wfRunHooks( 'PingLimiter', array( &$this, $action, &$result, $incrBy ) ) ) { return $result; } @@ -1583,9 +1584,13 @@ class User { } } else { wfDebug( __METHOD__ . ": adding record for $key $summary\n" ); - $wgMemc->add( $key, 0, intval( $period ) ); // first ping + if ( $incrBy > 0 ) { + $wgMemc->add( $key, 0, intval( $period ) ); // first ping + } + } + if ( $incrBy > 0 ) { + $wgMemc->incr( $key, $incrBy ); } - $wgMemc->incr( $key ); } wfProfileOut( __METHOD__ ); diff --git a/includes/api/ApiPurge.php b/includes/api/ApiPurge.php index e2eae613a5..0812ba5171 100644 --- a/includes/api/ApiPurge.php +++ b/includes/api/ApiPurge.php @@ -84,7 +84,7 @@ class ApiPurge extends ApiBase { $r['purged'] = ''; if ( $forceLinkUpdate || $forceRecursiveLinkUpdate ) { - if ( !$this->getUser()->pingLimiter() ) { + if ( !$this->getUser()->pingLimiter( 'linkpurge' ) ) { global $wgEnableParserCache; $popts = $page->makeParserOptions( 'canonical' ); -- 2.20.1