38 MediaWikiServices::getInstance()->getLanguageFactory()->
getLanguage(
'en' ),
55 $msg = ApiMessage::create( $msg );
57 'message' => $msg->getKey(),
58 'params' => $msg->getParams(),
59 'code' => $msg->getApiCode(),
62 ApiResult::setIndexedTagName( $error[
'params'],
'param' );
65 ApiResult::setIndexedTagName(
$result, $type );
72 'code' => $msg->getApiCode(),
73 'info' => $msg->text(),
74 ] + $msg->getApiData();
86 $ret = parent::formatException( $exception, $options );
87 return empty( $options[
'bc'] ) ? $ret : $ret[
'info'];
93 if ( $tag ===
'error' ) {
95 $existingError = $this->result->getResultData( [
'error' ] );
96 if ( !is_array( $existingError ) ||
97 !isset( $existingError[
'code'] ) || !isset( $existingError[
'info'] )
100 'code' => $msg->getApiCode(),
102 ] + $msg->getApiData();
103 $this->result->addValue(
null,
'error', $value,
104 ApiResult::OVERRIDE | ApiResult::ADD_ON_TOP | ApiResult::NO_SIZE_CHECK );
107 if ( $modulePath ===
null ) {
108 $moduleName =
'unknown';
110 $i = strrpos( $modulePath,
'+' );
111 $moduleName = $i ===
false ? $modulePath : substr( $modulePath, $i + 1 );
116 $path = [ $tag, $moduleName ];
117 $oldWarning = $this->result->getResultData( [ $tag, $moduleName, $tag ] );
118 if ( $oldWarning !==
null ) {
119 $warnPos = strpos( $oldWarning, $value );
121 if ( $warnPos !==
false && ( $warnPos === 0 || $oldWarning[$warnPos - 1] ===
"\n" ) ) {
123 $warnPos += strlen( $value );
124 if ( strlen( $oldWarning ) <= $warnPos || $oldWarning[$warnPos] ===
"\n" ) {
129 $value =
"$oldWarning\n$value";
131 $this->result->addContentValue(
$path, $tag, $value,
132 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.
getMessages(?string $type=null)
Returns a list of error messages, optionally only those of the given type.
isGood()
Returns whether the operation completed and didn't have any error or warnings.