38 MediaWikiServices::getInstance()->getLanguageFactory()->
getLanguage(
'en' ),
55 $msg = ApiMessage::create( $error );
57 'message' => $msg->getKey(),
58 'params' => $msg->getParams(),
59 'code' => $msg->getApiCode(),
61 ApiResult::setIndexedTagName( $error[
'params'],
'param' );
71 'code' => $msg->getApiCode(),
72 'info' => $msg->text(),
73 ] + $msg->getApiData();
85 $ret = parent::formatException( $exception, $options );
86 return empty( $options[
'bc'] ) ? $ret : $ret[
'info'];
92 if ( $tag ===
'error' ) {
94 $existingError = $this->result->getResultData( [
'error' ] );
95 if ( !is_array( $existingError ) ||
96 !isset( $existingError[
'code'] ) || !isset( $existingError[
'info'] )
99 'code' => $msg->getApiCode(),
101 ] + $msg->getApiData();
102 $this->result->addValue(
null,
'error', $value,
103 ApiResult::OVERRIDE | ApiResult::ADD_ON_TOP | ApiResult::NO_SIZE_CHECK );
106 if ( $modulePath ===
null ) {
107 $moduleName =
'unknown';
109 $i = strrpos( $modulePath,
'+' );
110 $moduleName = $i ===
false ? $modulePath : substr( $modulePath, $i + 1 );
115 $path = [ $tag, $moduleName ];
116 $oldWarning = $this->result->getResultData( [ $tag, $moduleName, $tag ] );
117 if ( $oldWarning !==
null ) {
118 $warnPos = strpos( $oldWarning, $value );
120 if ( $warnPos !==
false && ( $warnPos === 0 || $oldWarning[$warnPos - 1] ===
"\n" ) ) {
122 $warnPos += strlen( $value );
123 if ( strlen( $oldWarning ) <= $warnPos || $oldWarning[$warnPos] ===
"\n" ) {
128 $value =
"$oldWarning\n$value";
130 $this->result->addContentValue(
$path, $tag, $value,
131 ApiResult::OVERRIDE | ApiResult::ADD_ON_TOP | ApiResult::NO_SIZE_CHECK );
This class represents the result of the API operations.
Generic operation result class Has warning/error list, boolean status and arbitrary value.
getErrors()
Get the list of errors.
getErrorsByType( $type)
Returns a list of status messages of the given type.
isGood()
Returns whether the operation completed and didn't have any error or warnings.