* Ensure that rate-limiting is applied to rollbacks.
authorAndrew Garrett <werdna@users.mediawiki.org>
Tue, 20 Nov 2007 08:34:59 +0000 (08:34 +0000)
committerAndrew Garrett <werdna@users.mediawiki.org>
Tue, 20 Nov 2007 08:34:59 +0000 (08:34 +0000)
* Make a better rate-limiting error message (i.e. a normal MW error, rather than an "Internal Server Error").

RELEASE-NOTES
includes/Article.php
includes/EditPage.php
includes/OutputPage.php
languages/messages/MessagesEn.php

index c813cfa..d9d871f 100644 (file)
@@ -170,6 +170,9 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
   fix) was faulty. Now fixed.
 * Fixed wpReason URL parameter to action=delete.
 * Do not force a password for account creation by email
+* Ensure that rate-limiting is applied to rollbacks.
+* Make a better rate-limiting error message (i.e. a normal MW error,
+  rather than an "Internal Server Error").
 
 === API changes in 1.12 ===
 
index 8f72108..e982410 100644 (file)
@@ -47,6 +47,7 @@ class Article {
        const BAD_TITLE = 5;            // $this is not a valid Article
        const ALREADY_ROLLED = 6;       // Someone else already rolled this back. $from and $summary will be set
        const ONLY_AUTHOR = 7;          // User is the only author of the page
+       const RATE_LIMITED = 8;
  
        /**
         * Constructor and clear the article
@@ -2243,6 +2244,10 @@ class Article {
                if( !$wgUser->matchEditToken( $token, array( $this->mTitle->getPrefixedText(), $fromP ) ) )
                        return self::BAD_TOKEN;
 
+               if ( $wgUser->pingLimiter('rollback') || $wgUser->pingLimiter() ) {
+                       return self::RATE_LIMITED;
+               }
+
                $dbw = wfGetDB( DB_MASTER );
 
                # Get the last editor
@@ -2379,6 +2384,9 @@ class Article {
                                $wgOut->setPageTitle( wfMsg( 'rollbackfailed' ) );
                                $wgOut->addHtml( wfMsg( 'cantrollback' ) );
                                break;
+                       case self::RATE_LIMITED:
+                               $wgOut->rateLimited();
+                               break;
                        case self::SUCCESS:
                                $current = $details['current'];
                                $target = $details['target'];
index 3526061..682939c 100644 (file)
@@ -2130,7 +2130,7 @@ END
                if( $value == self::AS_SUCCESS_UPDATE || $value == self::AS_SUCCESS_NEW_ARTICLE ) {
                        $this->didSave = true;
                }
-               
+
                switch ($value)
                {
                        case self::AS_HOOK_ERROR_EXPECTED:
index 25385f0..db91c14 100644 (file)
@@ -1337,10 +1337,17 @@ class OutputPage {
         */
        public function rateLimited() {
                global $wgOut;
-               $wgOut->disable();
-               wfHttpError( 500, 'Internal Server Error',
-                       'Sorry, the server has encountered an internal error. ' .
-                       'Please wait a moment and hit "refresh" to submit the request again.' );
+
+               $this->setPageTitle(wfMsg('actionthrottled'));
+               $this->setRobotPolicy( 'noindex,nofollow' );
+               $this->setArticleRelated( false );
+               $this->enableClientCache( false );
+               $this->mRedirect = '';
+               $this->clearHTML();
+               $this->setStatusCode(503);
+               $this->addWikiText( wfMsg('actionthrottledtext') );
+
+               $this->returnToMain( false, $wgTitle );
        }
        
        /**
index b4f9811..87eda82 100644 (file)
@@ -787,6 +787,8 @@ Function: $1<br />
 Query: $2',
 'viewsource'           => 'View source',
 'viewsourcefor'        => '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. Please try again in a few minutes.",
 'protectedpagetext'    => 'This page has been locked to prevent editing.',
 'viewsourcetext'       => 'You can view and copy the source of this page:',
 'protectedinterface'   => 'This page provides interface text for the software, and is locked to prevent abuse.',