Add page purge limiter
authorReedy <reedy@wikimedia.org>
Wed, 2 Oct 2013 21:39:06 +0000 (22:39 +0100)
committerReedy <reedy@wikimedia.org>
Fri, 2 Oct 2015 20:27:44 +0000 (20:27 +0000)
Change-Id: I737dc77ce803432b0792f7e49323a29661bc056f

includes/DefaultSettings.php
includes/actions/PurgeAction.php
includes/api/ApiPurge.php
languages/i18n/en.json

index 2793161..339ae9b 100644 (file)
@@ -5247,6 +5247,13 @@ $wgRateLimits = array(
                'user' => null,
                'newbie' => null,
        ),
+       'purge' => array( // purging pages
+               'anon' => null,
+               'user' => null,
+               'newbie' => null,
+               'ip' => null,
+               'subnet' => null,
+       ),
 );
 
 /**
index e5da172..7e77846 100644 (file)
@@ -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 )
index a22be49..34f9b6c 100644 (file)
@@ -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.
index 818edff..2005ee8 100644 (file)
        "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 <strong>your edits</strong> to this page.",