From 7fe05a9fb609589fce7437fa265e92c088a0accd Mon Sep 17 00:00:00 2001 From: Reedy Date: Wed, 2 Oct 2013 22:39:06 +0100 Subject: [PATCH] Add page purge limiter Change-Id: I737dc77ce803432b0792f7e49323a29661bc056f --- includes/DefaultSettings.php | 7 +++++++ includes/actions/PurgeAction.php | 9 ++++++++- includes/api/ApiPurge.php | 12 +++++++++--- languages/i18n/en.json | 2 +- 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 2793161ea2..339ae9bf78 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -5247,6 +5247,13 @@ $wgRateLimits = array( 'user' => null, 'newbie' => null, ), + 'purge' => array( // purging pages + 'anon' => null, + 'user' => null, + 'newbie' => null, + 'ip' => null, + 'subnet' => null, + ), ); /** diff --git a/includes/actions/PurgeAction.php b/includes/actions/PurgeAction.php index e5da172393..7e77846884 100644 --- a/includes/actions/PurgeAction.php +++ b/includes/actions/PurgeAction.php @@ -58,7 +58,14 @@ class PurgeAction extends FormAction { // This will throw exceptions if there's a problem $this->checkCanExecute( $this->getUser() ); - if ( $this->getUser()->isAllowed( 'purge' ) ) { + $user = $this->getUser(); + + if ( $user->pingLimiter( 'purge' ) ) { + // TODO: Display actionthrottledtext + return; + } + + if ( $user->isAllowed( 'purge' ) ) { $this->redirectParams = wfArrayToCgi( array_diff_key( $this->getRequest()->getQueryValues(), array( 'title' => null, 'action' => null ) diff --git a/includes/api/ApiPurge.php b/includes/api/ApiPurge.php index a22be498c5..34f9b6c84e 100644 --- a/includes/api/ApiPurge.php +++ b/includes/api/ApiPurge.php @@ -47,16 +47,22 @@ class ApiPurge extends ApiBase { $pageSet->execute(); $result = $pageSet->getInvalidTitlesAndRevisions(); + $user = $this->getUser(); foreach ( $pageSet->getGoodTitles() as $title ) { $r = array(); ApiQueryBase::addTitleInfo( $r, $title ); $page = WikiPage::factory( $title ); - $page->doPurge(); // Directly purge and skip the UI part of purge(). - $r['purged'] = true; + if ( !$user->pingLimiter( 'purge' ) ) { + $page->doPurge(); // Directly purge and skip the UI part of purge(). + $r['purged'] = true; + } else { + $error = $this->parseMsg( array( 'actionthrottledtext' ) ); + $this->setWarning( $error['info'] ); + } if ( $forceLinkUpdate || $forceRecursiveLinkUpdate ) { - if ( !$this->getUser()->pingLimiter( 'linkpurge' ) ) { + if ( !$user->pingLimiter( 'linkpurge' ) ) { $popts = $page->makeParserOptions( 'canonical' ); # Parse content; note that HTML generation is only needed if we want to cache the result. diff --git a/languages/i18n/en.json b/languages/i18n/en.json index 818edffd3e..2005ee81a2 100644 --- a/languages/i18n/en.json +++ b/languages/i18n/en.json @@ -355,7 +355,7 @@ "viewsource": "View source", "viewsource-title": "View source for $1", "actionthrottled": "Action throttled", - "actionthrottledtext": "As an anti-spam measure, you are limited from performing this action too many times in a short space of time, and you have exceeded this limit.\nPlease try again in a few minutes.", + "actionthrottledtext": "As an anti-abuse measure, you are limited from performing this action too many times in a short space of time, and you have exceeded this limit.\nPlease try again in a few minutes.", "protectedpagetext": "This page has been protected to prevent editing or other actions.", "viewsourcetext": "You can view and copy the source of this page.", "viewyourtext": "You can view and copy the source of your edits to this page.", -- 2.20.1