MediaWiki REL1_28
ApiErrorFormatter Class Reference

Formats errors and warnings for the API, and add them to the associated ApiResult. More...

Inheritance diagram for ApiErrorFormatter:
Collaboration diagram for ApiErrorFormatter:

Public Member Functions

 __construct (ApiResult $result, Language $lang, $format, $useDB=false)
 
 addError ( $moduleName, $msg, $code=null, $data=null)
 Add an error to the result.
 
 addMessagesFromStatus ( $moduleName, Status $status, $types=[ 'warning', 'error'])
 Add warnings and errors from a Status object to the result.
 
 addWarning ( $moduleName, $msg, $code=null, $data=null)
 Add a warning to the result.
 
 arrayFromStatus (Status $status, $type='error', $format=null)
 Format messages from a Status as an array.
 

Protected Member Functions

 addWarningOrError ( $tag, $moduleName, $msg)
 Actually add the warning or error to the result.
 
 getDummyTitle ()
 Fetch a dummy title to set on Messages.
 

Protected Attributes

 $format = 'none'
 
Language $lang
 
ApiResult $result
 
 $useDB = false
 

Static Private Attributes

static Title $dummyTitle = null
 Dummy title to silence warnings from MessageCache::parse()
 

Detailed Description

Formats errors and warnings for the API, and add them to the associated ApiResult.

Since
1.25

Definition at line 30 of file ApiErrorFormatter.php.

Constructor & Destructor Documentation

◆ __construct()

ApiErrorFormatter::__construct ( ApiResult  $result,
Language  $lang,
  $format,
  $useDB = false 
)
Parameters
ApiResult$resultInto which data will be added
Language$langUsed for i18n
string$format
  • text: Error message as wikitext
  • html: Error message as HTML
  • raw: Raw message key and parameters, no human-readable text
  • none: Code and data only, no human-readable text
bool$useDBWhether to use local translations for errors and warnings.

Definition at line 52 of file ApiErrorFormatter.php.

References $format, $lang, $result, $useDB, and format.

Member Function Documentation

◆ addError()

ApiErrorFormatter::addError (   $moduleName,
  $msg,
  $code = null,
  $data = null 
)

Add an error to the result.

Parameters
string$moduleName
MessageSpecifier | array | string$msgi18n message for the error
string$codeMachine-readable code for the warning. Defaults as for IApiMessage::getApiCode().
array$dataMachine-readable data for the warning, if any. Uses IApiMessage::getApiData() if $msg implements that interface.

Definition at line 96 of file ApiErrorFormatter.php.

References $code, addWarningOrError(), ApiMessage\create(), and getDummyTitle().

◆ addMessagesFromStatus()

ApiErrorFormatter::addMessagesFromStatus (   $moduleName,
Status  $status,
  $types = [ 'warning', 'error' ] 
)

Add warnings and errors from a Status object to the result.

Parameters
string$moduleName
Status$status
string[]$types'warning' and/or 'error'

Definition at line 110 of file ApiErrorFormatter.php.

References $args, $status, $tag, addWarningOrError(), array(), as, ApiMessage\create(), and getDummyTitle().

Referenced by arrayFromStatus().

◆ addWarning()

ApiErrorFormatter::addWarning (   $moduleName,
  $msg,
  $code = null,
  $data = null 
)

Add a warning to the result.

Parameters
string$moduleName
MessageSpecifier | array | string$msgi18n message for the warning
string$codeMachine-readable code for the warning. Defaults as for IApiMessage::getApiCode().
array$dataMachine-readable data for the warning, if any. Uses IApiMessage::getApiData() if $msg implements that interface.

Definition at line 79 of file ApiErrorFormatter.php.

References $code, addWarningOrError(), ApiMessage\create(), and getDummyTitle().

◆ addWarningOrError()

ApiErrorFormatter::addWarningOrError (   $tag,
  $moduleName,
  $msg 
)
protected

Actually add the warning or error to the result.

Parameters
string$tag'warning' or 'error'
string$moduleName
ApiMessage | ApiRawMessage$msg

Reimplemented in ApiErrorFormatter_BackCompat.

Definition at line 186 of file ApiErrorFormatter.php.

References $flags, $path, $tag, $value, ApiResult\ADD_ON_TOP, format, ApiResult\META_CONTENT, ApiResult\NO_SIZE_CHECK, and ApiResult\setIndexedTagName().

Referenced by addError(), addMessagesFromStatus(), and addWarning().

◆ arrayFromStatus()

ApiErrorFormatter::arrayFromStatus ( Status  $status,
  $type = 'error',
  $format = null 
)

Format messages from a Status as an array.

Parameters
Status$status
string$type'warning' or 'error'
string | null$format
Returns
array

Reimplemented in ApiErrorFormatter_BackCompat.

Definition at line 162 of file ApiErrorFormatter.php.

References $format, $status, $type, $useDB, addMessagesFromStatus(), and array().

◆ getDummyTitle()

ApiErrorFormatter::getDummyTitle ( )
protected

Fetch a dummy title to set on Messages.

Returns
Title

Definition at line 63 of file ApiErrorFormatter.php.

References $dummyTitle, and NS_SPECIAL.

Referenced by addError(), addMessagesFromStatus(), and addWarning().

Member Data Documentation

◆ $dummyTitle

Title ApiErrorFormatter::$dummyTitle = null
staticprivate

Dummy title to silence warnings from MessageCache::parse()

Definition at line 32 of file ApiErrorFormatter.php.

Referenced by getDummyTitle().

◆ $format

ApiErrorFormatter::$format = 'none'
protected

Definition at line 40 of file ApiErrorFormatter.php.

Referenced by __construct(), and arrayFromStatus().

◆ $lang

Language ApiErrorFormatter::$lang
protected

Definition at line 38 of file ApiErrorFormatter.php.

Referenced by __construct().

◆ $result

ApiResult ApiErrorFormatter::$result
protected

◆ $useDB

ApiErrorFormatter::$useDB = false
protected

Definition at line 39 of file ApiErrorFormatter.php.

Referenced by __construct(), and arrayFromStatus().


The documentation for this class was generated from the following file: