MediaWiki  1.27.2
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. More...
 
 addMessagesFromStatus ($moduleName, Status $status, $types=[ 'warning', 'error'])
 Add warnings and errors from a Status object to the result. More...
 
 addWarning ($moduleName, $msg, $code=null, $data=null)
 Add a warning to the result. More...
 
 arrayFromStatus (Status $status, $type= 'error', $format=null)
 Format messages from a Status as an array. More...
 

Protected Member Functions

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

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() More...
 

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

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

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().

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, $tag, addWarningOrError(), array(), as, ApiMessage\create(), getDummyTitle(), and Status\isGood().

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().

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

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().

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

Definition at line 162 of file ApiErrorFormatter.php.

References $format, $type, array(), format, ApiResult\getResultData(), and Status\isGood().

ApiErrorFormatter::getDummyTitle ( )
protected

Fetch a dummy title to set on Messages.

Returns
Title

Definition at line 63 of file ApiErrorFormatter.php.

References Title\makeTitle(), and NS_SPECIAL.

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

Member Data Documentation

Title ApiErrorFormatter::$dummyTitle = null
staticprivate

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

Definition at line 32 of file ApiErrorFormatter.php.

ApiErrorFormatter::$format = 'none'
protected

Definition at line 40 of file ApiErrorFormatter.php.

Referenced by __construct(), and arrayFromStatus().

Language ApiErrorFormatter::$lang
protected

Definition at line 38 of file ApiErrorFormatter.php.

Referenced by __construct().

ApiResult ApiErrorFormatter::$result
protected
ApiErrorFormatter::$useDB = false
protected

Definition at line 39 of file ApiErrorFormatter.php.

Referenced by __construct().


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