75 return is_string( $code ) && (
76 preg_match(
'/^[a-zA-Z0-9_-]+$/', $code ) ||
78 preg_match(
'/^internal_api_error_[^\0\r\n]+$/', $code )
116 if ( self::$dummyTitle ===
null ) {
117 self::$dummyTitle = Title::makeTitle(
NS_SPECIAL,
'Badtitle/' . __METHOD__ );
129 public function addWarning( $modulePath, $msg, $code =
null, $data =
null ) {
130 $msg = ApiMessage::create( $msg, $code, $data )
131 ->inLanguage( $this->lang )
133 ->useDatabase( $this->useDB );
144 public function addError( $modulePath, $msg, $code =
null, $data =
null ) {
145 $msg = ApiMessage::create( $msg, $code, $data )
146 ->inLanguage( $this->lang )
148 ->useDatabase( $this->useDB );
160 $modulePath,
StatusValue $status, $types = [
'warning',
'error' ], array $filter = []
166 $types = (array)$types;
167 foreach ( $status->
getErrors() as $error ) {
168 if ( !in_array( $error[
'type'], $types,
true ) ) {
172 if ( $error[
'type'] ===
'error' ) {
179 $msg = ApiMessage::create( $error )
180 ->inLanguage( $this->lang )
182 ->useDatabase( $this->useDB );
183 if ( !in_array( $msg->getKey(), $filter,
true ) ) {
202 $options += [
'code' =>
null,
'data' => [] ];
205 $msg = $exception->getMessageObject();
211 if ( isset( $options[
'wrap'] ) ) {
212 $msg = $options[
'wrap'];
215 if ( !isset( $options[
'code'] ) ) {
216 $class = preg_replace(
'#^Wikimedia\\\Rdbms\\\#',
'', get_class( $exception ) );
217 $options[
'code'] =
'internal_api_error_' . $class;
218 $options[
'data'][
'errorclass'] = get_class( $exception );
223 return ApiMessage::create( $msg, $options[
'code'], $options[
'data'] )
225 ->inLanguage( $this->lang )
227 ->useDatabase( $this->useDB );
242 $options[
'format'] ??
null
253 $msg = ApiMessage::create( $msg )
254 ->inLanguage( $this->lang )
256 ->useDatabase( $this->useDB );
293 $ret = preg_replace(
'!</?(var|kbd|samp|code)>!',
'"', $text );
296 $ret = Sanitizer::stripAllTags( $ret );
311 ApiResult::setIndexedTagName( $ret[
'params'],
'param' );
314 foreach ( $ret[
'params'] as $i => $param ) {
330 $value = [
'code' => $msg->getApiCode() ];
335 ApiResult::META_CONTENT =>
'text',
341 'text' => $msg->text(),
342 ApiResult::META_CONTENT =>
'text',
348 'html' => $msg->parse(),
349 ApiResult::META_CONTENT =>
'html',
360 $data = $msg->getApiData();
362 $value[
'data'] = $msg->getApiData() + [
363 ApiResult::META_TYPE =>
'assoc',
377 if ( $modulePath !==
null ) {
378 $value += [
'module' => $modulePath ];
381 $path = [ $tag .
's' ];
382 $existing = $this->result->getResultData(
$path );
383 if ( $existing ===
null || !in_array( $value, $existing ) ) {
384 $flags = ApiResult::NO_SIZE_CHECK;
385 if ( $existing ===
null ) {
386 $flags |= ApiResult::ADD_ON_TOP;
388 $this->result->addValue(
$path,
null, $value, $flags );
389 $this->result->addIndexedTagName(
$path, $tag );
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
This class represents the result of the API operations.
getResultData( $path=[], $transforms=[])
Get the result data array.
Internationalisation code See https://www.mediawiki.org/wiki/Special:MyLanguage/Localisation for more...
static newFromSpecifier( $value)
Transform a MessageSpecifier or a primitive value used interchangeably with specifiers (a message key...
Variant of the Message class.
Generic operation result class Has warning/error list, boolean status and arbitrary value.
getErrors()
Get the list of errors.
isGood()
Returns whether the operation completed and didn't have any error or warnings.
Represents a title within MediaWiki.
Interface for MediaWiki-localized exceptions.
getParams()
Returns the message parameters.
getKey()
Returns the message key.