// Set a warning if a deprecated parameter has been passed
if ( $deprecated && $value !== false ) {
$this->setWarning( "The $encParamName parameter has been deprecated." );
+
+ $feature = $encParamName;
+ $m = $this;
+ while ( !$m->isMain() ) {
+ $p = $m->getParent();
+ $name = $m->getModuleName();
+ $param = $p->encodeParamName( $p->getModuleManager()->getModuleGroup( $name ) );
+ $feature = "{$param}={$name}&{$feature}";
+ $m = $p;
+ }
+ $this->logFeatureUsage( $feature );
}
} elseif ( $required ) {
$this->dieUsageMsg( array( 'missingparam', $paramName ) );
* @param int $botMax Maximum value for sysops/bots
* @param bool $enforceLimits Whether to enforce (die) if value is outside limits
*/
- protected function validateLimit( $paramName, &$value, $min, $max, $botMax = null, $enforceLimits = false ) {
+ protected function validateLimit( $paramName, &$value, $min, $max, $botMax = null,
+ $enforceLimits = false
+ ) {
if ( !is_null( $min ) && $value < $min ) {
$msg = $this->encodeParamName( $paramName ) . " may not be less than $min (set to $value)";
$this->warnOrDie( $msg, $enforceLimits );
* @param string $errorCode Brief, arbitrary, stable string to allow easy
* automated identification of the error, e.g., 'unknown_action'
* @param int $httpRespCode HTTP response code
- * @param array $extradata Data to add to the "<error>" element; array in ApiResult format
- * @throws UsageException
+ * @param array|null $extradata Data to add to the "<error>" element; array in ApiResult format
+ * @throws UsageException always
*/
public function dieUsage( $description, $errorCode, $httpRespCode = 0, $extradata = null ) {
throw new UsageException(
*
* @since 1.23
* @param Status $status
+ * @param array|null &$extraData Set if extra data from IApiMessage is available (since 1.27)
* @return array Array of code and error string
* @throws MWException
*/
- public function getErrorFromStatus( $status ) {
+ public function getErrorFromStatus( $status, &$extraData = null ) {
if ( $status->isGood() ) {
throw new MWException( 'Successful status passed to ApiBase::dieStatus' );
}
// error messages.
if ( $errors[0] instanceof Message ) {
$msg = $errors[0];
- $code = $msg->getKey();
+ if ( $msg instanceof IApiMessage ) {
+ $extraData = $msg->getApiData();
+ $code = $msg->getApiCode();
+ } else {
+ $code = $msg->getKey();
+ }
} else {
$code = array_shift( $errors[0] );
$msg = wfMessage( $code, $errors[0] );
*
* @since 1.22
* @param Status $status
- * @throws MWException
+ * @throws UsageException always
*/
public function dieStatus( $status ) {
-
- list( $code, $msg ) = $this->getErrorFromStatus( $status );
- $this->dieUsage( $msg, $code );
+ $extraData = null;
+ list( $code, $msg ) = $this->getErrorFromStatus( $status, $extraData );
+ $this->dieUsage( $msg, $code, 0, $extraData );
}
// @codingStandardsIgnoreStart Allow long lines. Cannot split these.
/**
* Helper function for readonly errors
+ *
+ * @throws UsageException always
*/
public function dieReadOnly() {
$parsed = $this->parseMsg( array( 'readonlytext' ) );
/**
* Output the error message related to a certain array
* @param array|string $error Element of a getUserPermissionsErrors()-style array
+ * @throws UsageException always
*/
public function dieUsageMsg( $error ) {
# most of the time we send a 1 element, so we might as well send it as
$error = array( $error );
}
$parsed = $this->parseMsg( $error );
- $this->dieUsage( $parsed['info'], $parsed['code'] );
+ $extraData = isset( $parsed['data'] ) ? $parsed['data'] : null;
+ $this->dieUsage( $parsed['info'], $parsed['code'], 0, $extraData );
}
/**
* Will only set a warning instead of failing if the global $wgDebugAPI
* is set to true. Otherwise behaves exactly as dieUsageMsg().
* @param array|string $error Element of a getUserPermissionsErrors()-style array
+ * @throws UsageException
* @since 1.21
*/
public function dieUsageMsgOrDebug( $error ) {
* Die with the $prefix.'badcontinue' error. This call is common enough to
* make it into the base method.
* @param bool $condition Will only die if this value is true
+ * @throws UsageException
* @since 1.21
*/
protected function dieContinueUsageIf( $condition ) {
$key = array_shift( $error );
}
+ if ( $key instanceof IApiMessage ) {
+ return array(
+ 'code' => $key->getApiCode(),
+ 'info' => $key->inLanguage( 'en' )->useDatabase( false )->text(),
+ 'data' => $key->getApiData()
+ );
+ }
+
if ( isset( self::$messageMap[$key] ) ) {
return array(
'code' => wfMsgReplaceArgs( self::$messageMap[$key]['code'], $error ),
* Internal code errors should be reported with this method
* @param string $method Method or function name
* @param string $message Error message
- * @throws MWException
+ * @throws MWException always
*/
protected static function dieDebug( $method, $message ) {
throw new MWException( "Internal error in $method: $message" );
$desc = implode( $paramPrefix, $desc );
}
- //handle shorthand
+ // handle shorthand
if ( !is_array( $paramSettings ) ) {
$paramSettings = array(
self::PARAM_DFLT => $paramSettings,
);
}
- //handle missing type
+ // handle missing type
if ( !isset( $paramSettings[ApiBase::PARAM_TYPE] ) ) {
$dflt = isset( $paramSettings[ApiBase::PARAM_DFLT] )
? $paramSettings[ApiBase::PARAM_DFLT]
/**
* @deprecated since 1.25, always returns empty string
- * @param DatabaseBase|bool $db
+ * @param IDatabase|bool $db
* @return string
*/
public function getModuleProfileName( $db = false ) {