Patch from MaxSem re bug 15162 - handle throttling in the login API
[lhc/web/wiklou.git] / includes / api / ApiBase.php
index 978e056..9f66869 100644 (file)
@@ -155,6 +155,13 @@ abstract class ApiBase {
         * notice any changes in API.
         */
        public function setWarning($warning) {
+               # If there is a warning already, append it to the existing one
+               $data =& $this->getResult()->getData();
+               if(isset($data['warnings'][$this->getModuleName()]))
+               {
+                       $warning = "{$data['warnings'][$this->getModuleName()]['*']}\n$warning";
+                       unset($data['warnings'][$this->getModuleName()]);
+               }
                $msg = array();
                ApiResult :: setContent($msg, $warning);
                $this->getResult()->addValue('warnings', $this->getModuleName(), $msg);
@@ -508,10 +515,12 @@ abstract class ApiBase {
        protected function parseMultiValue($valueName, $value, $allowMultiple, $allowedValues) {
                if( trim($value) === "" )
                        return array();
-               $sizeLimit = $this->mMainModule->canApiHighLimits() ? 501 : 51;
-               $valuesList = explode('|', $value,$sizeLimit);
-               if( count($valuesList) == $sizeLimit ) {
+               $sizeLimit = $this->mMainModule->canApiHighLimits() ? self::LIMIT_SML2 : self::LIMIT_SML1;
+               $valuesList = explode('|', $value, $sizeLimit + 1);
+               if( count($valuesList) == $sizeLimit + 1 ) {
                        $junk = array_pop($valuesList); // kill last jumbled param
+                       // Set a warning too
+                       $this->setWarning("Too many values supplied for parameter '$valueName': the limit is $sizeLimit");
                }
                if (!$allowMultiple && count($valuesList) != 1) {
                        $possibleValues = is_array($allowedValues) ? "of '" . implode("', '", $allowedValues) . "'" : '';
@@ -587,8 +596,6 @@ abstract class ApiBase {
                'protectedpagetext' => array('code' => 'protectedpage', 'info' => "The ``\$1'' right is required to edit this page"),
                'protect-cantedit' => array('code' => 'cantedit', 'info' => "You can't protect this page because you can't edit it"),
                'badaccess-group0' => array('code' => 'permissiondenied', 'info' => "Permission denied"), // Generic permission denied message
-               'badaccess-group1' => array('code' => 'permissiondenied', 'info' => "Permission denied"), // Can't use the parameter 'cause it's wikilinked
-               'badaccess-group2' => array('code' => 'permissiondenied', 'info' => "Permission denied"),
                'badaccess-groups' => array('code' => 'permissiondenied', 'info' => "Permission denied"),
                'titleprotected' => array('code' => 'protectedtitle', 'info' => "This title has been protected from creation"),
                'nocreate-loggedin' => array('code' => 'cantcreate', 'info' => "You don't have permission to create new pages"),
@@ -613,6 +620,8 @@ abstract class ApiBase {
                'protectedpage' => array('code' => 'protectedpage', 'info' => "You don't have permission to perform this move"),
                'hookaborted' => array('code' => 'hookaborted', 'info' => "The modification you tried to make was aborted by an extension hook"),
                'cantmove-titleprotected' => array('code' => 'protectedtitle', 'info' => "The destination article has been protected from creation"),
+               'imagenocrossnamespace' => array('code' => 'nonfilenamespace', 'info' => "Can't move a file to a non-file namespace"),
+               'imagetypemismatch' => array('code' => 'filetypemismatch', 'info' => "The new file extension doesn't match its type"),
                // 'badarticleerror' => shouldn't happen
                // 'badtitletext' => shouldn't happen
                'ip_range_invalid' => array('code' => 'invalidrange', 'info' => "Invalid IP range"),
@@ -641,6 +650,7 @@ abstract class ApiBase {
                'cannotundelete' => array('code' => 'cantundelete', 'info' => "Couldn't undelete: the requested revisions may not exist, or may have been undeleted already"),
                'permdenied-undelete' => array('code' => 'permissiondenied', 'info' => "You don't have permission to restore deleted revisions"),
                'createonly-exists' => array('code' => 'articleexists', 'info' => "The article you tried to create has been created already"),
+               'nocreate-missing' => array('code' => 'missingtitle', 'info' => "The article you tried to edit doesn't exist"),
 
                // ApiEditPage messages
                'noimageredirect-anon' => array('code' => 'noimageredirect-anon', 'info' => "Anonymous users can't create image redirects"),
@@ -653,6 +663,8 @@ abstract class ApiBase {
                'wasdeleted' => array('code' => 'pagedeleted', 'info' => "The page has been deleted since you fetched its timestamp"),
                'blankpage' => array('code' => 'emptypage', 'info' => "Creating new, empty pages is not allowed"),
                'editconflict' => array('code' => 'editconflict', 'info' => "Edit conflict detected"),
+               'hashcheckfailed' => array('code' => 'badmd5', 'info' => "The supplied MD5 hash was incorrect"),
+               'missingtext' => array('code' => 'notext', 'info' => "One of the text, appendtext and prependtext parameters must be set"),
        );
 
        /**