API: Making a bunch of state-changing modules require POST requests.
authorRoan Kattouw <catrope@users.mediawiki.org>
Fri, 18 Jan 2008 20:43:59 +0000 (20:43 +0000)
committerRoan Kattouw <catrope@users.mediawiki.org>
Fri, 18 Jan 2008 20:43:59 +0000 (20:43 +0000)
RELEASE-NOTES
includes/api/ApiBase.php
includes/api/ApiBlock.php
includes/api/ApiDelete.php
includes/api/ApiLogin.php
includes/api/ApiMain.php
includes/api/ApiMove.php
includes/api/ApiProtect.php
includes/api/ApiRollback.php
includes/api/ApiUnblock.php
includes/api/ApiUndelete.php

index e560cab..5b350ff 100644 (file)
@@ -441,6 +441,7 @@ Full API documentation is available at http://www.mediawiki.org/wiki/API
 * Added cascade flag to prop=info&inprop=protections
 * Added wlshow parameter to list=watchlist, similar to rcshow (list=recentchanges)
 * Added support for image thumbnailing to prop=imageinfo
+* action={login,block,delete,move,protect,rollback,unblock,undelete} now must be POSTed
 
 === Languages updated in 1.12 ===
 
index 400d0c5..c1f7d58 100644 (file)
@@ -652,6 +652,13 @@ abstract class ApiBase {
        public function isEditMode() {
                return false;
        }
+       
+       /**
+        * Indicates whether this module must be called with a POST request
+        */
+       public function mustBePosted() {
+               return false;
+       }
 
 
        /**
index f59e235..43103d0 100644 (file)
@@ -113,6 +113,8 @@ class ApiBlock extends ApiBase {
                $this->getResult()->addValue(null, $this->getModuleName(), $res);
        }
 
+       public function mustBePosted() { return true; }
+
        protected function getAllowedParams() {
                return array (
                        'user' => null,
index 635d316..1ae5876 100644 (file)
@@ -118,6 +118,8 @@ class ApiDelete extends ApiBase {
                return array(array('cannotdelete', $article->mTitle->getPrefixedText()));
        }
        
+       public function mustBePosted() { return true; }
+       
        protected function getAllowedParams() {
                return array (
                        'title' => null,
index 82d32bb..54a8a5d 100644 (file)
@@ -217,6 +217,8 @@ class ApiLogin extends ApiBase {
        private function getMemCacheKey() {
                return wfMemcKey( 'apilogin', 'badlogin', 'ip', wfGetIP() );
        }
+       
+       public function mustBePosted() { return true; }
 
        protected function getAllowedParams() {
                return array (
index be1dced..4c294a4 100644 (file)
@@ -320,8 +320,11 @@ class ApiMain extends ApiBase {
                                return;
                        }
                }
-
+               
                if (!$this->mInternalMode) {
+                       // Ignore mustBePosted() for internal calls
+                       if($module->mustBePosted() && !$this->mRequest->wasPosted())
+                               $this->dieUsage("The {$this->mAction} module requires a POST request", 'mustbeposted');
 
                        // See if custom printer is used
                        $this->mPrinter = $module->getCustomPrinter();
index 77f21b3..0c219d3 100644 (file)
@@ -110,6 +110,8 @@ class ApiMove extends ApiBase {
                $this->getResult()->addValue(null, $this->getModuleName(), $r);
        }
        
+       public function mustBePosted() { return true; }
+       
        protected function getAllowedParams() {
                return array (
                        'from' => null,
index 04e2752..6a32434 100644 (file)
@@ -109,6 +109,8 @@ class ApiProtect extends ApiBase {
                $this->getResult()->addValue(null, $this->getModuleName(), $res);
        }
 
+       public function mustBePosted() { return true; }
+
        protected function getAllowedParams() {
                return array (
                        'title' => null,
index 9107edf..0f37ef9 100644 (file)
@@ -86,6 +86,8 @@ class ApiRollback extends ApiBase {
                $this->getResult()->addValue(null, $this->getModuleName(), $info);
        }
        
+       public function mustBePosted() { return true; }
+       
        protected function getAllowedParams() {
                return array (
                        'title' => null,
index 842267b..7aaa1d5 100644 (file)
@@ -82,6 +82,8 @@ class ApiUnblock extends ApiBase {
                $res['reason'] = $reason;
                $this->getResult()->addValue(null, $this->getModuleName(), $res);
        }
+       
+       public function mustBePosted() { return true; }
 
        protected function getAllowedParams() {
                return array (
index 06a0ca8..510b777 100644 (file)
@@ -81,6 +81,8 @@ class ApiUndelete extends ApiBase {
                $this->getResult()->addValue(null, $this->getModuleName(), $info);
        }
        
+       public function mustBePosted() { return true; }
+       
        protected function getAllowedParams() {
                return array (
                        'title' => null,