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 ) {
131 ->inLanguage( $this->lang )
133 ->useDatabase( $this->useDB );
144 public function addError( $modulePath, $msg, $code =
null, $data =
null ) {
146 ->inLanguage( $this->lang )
148 ->useDatabase( $this->useDB );
166 $types = (array)$types;
167 foreach ( $status->
getErrors() as $error ) {
168 if ( !in_array( $error[
'type'], $types,
true ) ) {
172 if ( $error[
'type'] ===
'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 );
225 ->inLanguage( $this->lang )
227 ->useDatabase( $this->useDB );
242 $options[
'format'] ??
null
254 ->inLanguage( $this->lang )
256 ->useDatabase( $this->useDB );
293 $ret = preg_replace(
'!</?(var|kbd|samp|code)>!',
'"', $text );
296 $ret = Sanitizer::stripAllTags( $ret );
314 foreach ( $ret[
'params'] as $i => $param ) {
330 $value = [
'code' => $msg->getApiCode() ];
341 'text' => $msg->text(),
348 'html' => $msg->parse(),
360 $data = $msg->getApiData();
362 $value[
'data'] = $msg->getApiData() + [
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 ) ) {
385 if ( $existing ===
null ) {
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,...
static create( $msg, $code=null, array $data=null)
Create an IApiMessage for the message.
This class represents the result of the API operations.
const META_TYPE
Key for the 'type' metadata item.
const NO_SIZE_CHECK
For addValue() and similar functions, do not check size while adding a value Don't use this unless yo...
const META_CONTENT
Key for the 'content' metadata item.
const ADD_ON_TOP
For addValue(), setValue() and similar functions, if the value does not exist, add it as the first el...
getResultData( $path=[], $transforms=[])
Get the result data array.
static setIndexedTagName(array &$arr, $tag)
Set the tag name for numeric-keyed values in XML format.
Internationalisation code.
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.