// Main module has getResult() method overriden
// Safety - avoid infinite loop:
if ($this->isMain())
- ApiBase :: dieDebug(__METHOD__ .
- ' base method was called on main module. ');
+ ApiBase :: dieDebug(__METHOD__, 'base method was called on main module. ');
return $this->getMain()->getResult();
}
$multi = false;
$type = gettype($paramSettings);
} else {
- $default = isset ($paramSettings[self::PARAM_DFLT]) ? $paramSettings[self::PARAM_DFLT] : null;
- $multi = isset ($paramSettings[self::PARAM_ISMULTI]) ? $paramSettings[self::PARAM_ISMULTI] : false;
- $type = isset ($paramSettings[self::PARAM_TYPE]) ? $paramSettings[self::PARAM_TYPE] : null;
+ $default = isset ($paramSettings[self :: PARAM_DFLT]) ? $paramSettings[self :: PARAM_DFLT] : null;
+ $multi = isset ($paramSettings[self :: PARAM_ISMULTI]) ? $paramSettings[self :: PARAM_ISMULTI] : false;
+ $type = isset ($paramSettings[self :: PARAM_TYPE]) ? $paramSettings[self :: PARAM_TYPE] : null;
// When type is not given, and no choices, the type is the same as $default
if (!isset ($type)) {
if ($type == 'boolean') {
if (isset ($default) && $default !== false) {
// Having a default value of anything other than 'false' is pointless
- ApiBase :: dieDebug("Boolean param $paramName's default is set to '$default'");
+ ApiBase :: dieDebug(__METHOD__, "Boolean param $paramName's default is set to '$default'");
}
$value = $wgRequest->getCheck($paramName);
$value = is_array($value) ? array_map('intval', $value) : intval($value);
break;
case 'limit' :
- if (!isset ($paramSettings[self::PARAM_MAX1]) || !isset ($paramSettings[self::PARAM_MAX2]))
- ApiBase :: dieDebug("MAX1 or MAX2 are not defined for the limit $paramName");
+ if (!isset ($paramSettings[self :: PARAM_MAX1]) || !isset ($paramSettings[self :: PARAM_MAX2]))
+ ApiBase :: dieDebug(__METHOD__, "MAX1 or MAX2 are not defined for the limit $paramName");
if ($multi)
- ApiBase :: dieDebug("Multi-values not supported for $paramName");
- $min = isset ($paramSettings[self::PARAM_MIN]) ? $paramSettings[self::PARAM_MIN] : 0;
+ ApiBase :: dieDebug(__METHOD__, "Multi-values not supported for $paramName");
+ $min = isset ($paramSettings[self :: PARAM_MIN]) ? $paramSettings[self :: PARAM_MIN] : 0;
$value = intval($value);
- $this->validateLimit($paramName, $value, $min, $paramSettings[self::PARAM_MAX1], $paramSettings[self::PARAM_MAX2]);
+ $this->validateLimit($paramName, $value, $min, $paramSettings[self :: PARAM_MAX1], $paramSettings[self :: PARAM_MAX2]);
break;
case 'boolean' :
if ($multi)
- ApiBase :: dieDebug("Multi-values not supported for $paramName");
+ ApiBase :: dieDebug(__METHOD__, "Multi-values not supported for $paramName");
break;
case 'timestamp' :
if ($multi)
- ApiBase :: dieDebug("Multi-values not supported for $paramName");
- $value = $this->prepareTimestamp($value); // Adds quotes around timestamp
+ ApiBase :: dieDebug(__METHOD__, "Multi-values not supported for $paramName");
+ if (!preg_match('/^[0-9]{14}$/', $value))
+ $this->dieUsage("Invalid value '$value' for timestamp parameter $paramName", "badtimestamp_{$valueName}");
break;
default :
- ApiBase :: dieDebug("Param $paramName's type is unknown - $type");
+ ApiBase :: dieDebug(__METHOD__, "Param $paramName's type is unknown - $type");
}
}
return $allowMultiple ? $valuesList : $valuesList[0];
}
- /**
- * Validate the proper format of the timestamp string (14 digits), and add quotes to it.
- */
- function prepareTimestamp($value) {
- if (preg_match('/^[0-9]{14}$/', $value)) {
- return $this->db->addQuotes($value);
- } else {
- $this->dieUsage('Incorrect timestamp format', 'badtimestamp');
- }
- }
-
/**
* Validate the value against the minimum and user/bot maximum limits. Prints usage info on failure.
*/
if ($value > $botMax) {
$this->dieUsage("$varname may not be over $botMax (set to $value) for bots", $varname);
}
- } else {
- if ($value > $max) {
- $this->dieUsage("$varname may not be over $max (set to $value) for users", $varname);
- }
+ }
+ elseif ($value > $max) {
+ $this->dieUsage("$varname may not be over $max (set to $value) for users", $varname);
}
}
/**
* Internal code errors should be reported with this method
*/
- protected static function dieDebug($message) {
- wfDebugDieBacktrace("Internal error: $message");
+ protected static function dieDebug($method, $message) {
+ wfDebugDieBacktrace("Internal error in $method: $message");
}
/**
*/
public function profileIn() {
if ($this->mTimeIn !== 0)
- ApiBase :: dieDebug(__METHOD__ . ' called twice without calling profileOut()');
+ ApiBase :: dieDebug(__METHOD__, 'called twice without calling profileOut()');
$this->mTimeIn = microtime(true);
}
*/
public function profileOut() {
if ($this->mTimeIn === 0)
- ApiBase :: dieDebug(__METHOD__ . ' called without calling profileIn() first');
+ ApiBase :: dieDebug(__METHOD__, 'called without calling profileIn() first');
if ($this->mDBTimeIn !== 0)
- ApiBase :: dieDebug(__METHOD__ . ' must be called after database profiling is done with profileDBOut()');
+ ApiBase :: dieDebug(__METHOD__, 'must be called after database profiling is done with profileDBOut()');
$this->mModuleTime += microtime(true) - $this->mTimeIn;
$this->mTimeIn = 0;
*/
public function getProfileTime() {
if ($this->mTimeIn !== 0)
- ApiBase :: dieDebug(__METHOD__ . ' called without calling profileOut() first');
+ ApiBase :: dieDebug(__METHOD__, 'called without calling profileOut() first');
return $this->mModuleTime;
}
*/
public function profileDBIn() {
if ($this->mTimeIn === 0)
- ApiBase :: dieDebug(__METHOD__ . ' must be called while profiling the entire module with profileIn()');
+ ApiBase :: dieDebug(__METHOD__, 'must be called while profiling the entire module with profileIn()');
if ($this->mDBTimeIn !== 0)
- ApiBase :: dieDebug(__METHOD__ . ' called twice without calling profileDBOut()');
+ ApiBase :: dieDebug(__METHOD__, 'called twice without calling profileDBOut()');
$this->mDBTimeIn = microtime(true);
}
*/
public function profileDBOut() {
if ($this->mTimeIn === 0)
- ApiBase :: dieDebug(__METHOD__ . ' must be called while profiling the entire module with profileIn()');
+ ApiBase :: dieDebug(__METHOD__, 'must be called while profiling the entire module with profileIn()');
if ($this->mDBTimeIn === 0)
- ApiBase :: dieDebug(__METHOD__ . ' called without calling profileDBIn() first');
+ ApiBase :: dieDebug(__METHOD__, 'called without calling profileDBIn() first');
$time = microtime(true) - $this->mDBTimeIn;
$this->mDBTimeIn = 0;
*/
public function getProfileDBTime() {
if ($this->mDBTimeIn !== 0)
- ApiBase :: dieDebug(__METHOD__ . ' called without calling profileDBOut() first');
+ ApiBase :: dieDebug(__METHOD__, 'called without calling profileDBOut() first');
return $this->mDBTime;
}
}