X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiBase.php;h=9f66869b00210cab0264c047147ce5cadaac0a13;hb=b63b22fc4716287ac91d77ed0655ceb7a4b46f8b;hp=d8bea668a500a5a2615df7c9c4610096ab7d5840;hpb=79d5225c0e864482269e2315f47b899697681e52;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiBase.php b/includes/api/ApiBase.php index d8bea668a5..9f66869b00 100644 --- a/includes/api/ApiBase.php +++ b/includes/api/ApiBase.php @@ -34,7 +34,7 @@ * * Self-documentation: code to allow api to document its own state. * - * @addtogroup API + * @ingroup API */ abstract class ApiBase { @@ -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,16 +515,33 @@ abstract class ApiBase { protected function parseMultiValue($valueName, $value, $allowMultiple, $allowedValues) { if( trim($value) === "" ) return array(); - $valuesList = explode('|', $value); + $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) . "'" : ''; $this->dieUsage("Only one $possibleValues is allowed for parameter '$valueName'", "multival_$valueName"); } if (is_array($allowedValues)) { - $unknownValues = array_diff($valuesList, $allowedValues); - if ($unknownValues) { - $this->dieUsage('Unrecognised value' . (count($unknownValues) > 1 ? "s" : "") . " for parameter '$valueName'", "unknown_$valueName"); + # Check for unknown values + $unknown = array_diff($valuesList, $allowedValues); + if(!empty($unknown)) + { + if($allowMultiple) + { + $s = count($unknown) > 1 ? "s" : ""; + $vals = implode(", ", $unknown); + $this->setWarning("Unrecognized value$s for parameter '$valueName': $vals"); + } + else + $this->dieUsage("Unrecognized value for parameter '$valueName': {$valuesList[0]}", "unknown_$valueName"); } + # Now throw them out + $valuesList = array_intersect($valuesList, $allowedValues); } return $allowMultiple ? $valuesList : $valuesList[0]; @@ -572,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"), @@ -598,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"), @@ -626,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"), @@ -638,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"), ); /**