*
* Self-documentation: code to allow api to document its own state.
*
- * @addtogroup API
+ * @ingroup API
*/
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);
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) . "'" : '';
$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];
'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"),
'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"),
'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"),
'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"),
);
/**