MediaWiki
1.32.5
|
Formats errors and warnings for the API, and add them to the associated ApiResult. More...
Public Member Functions | |
__construct (ApiResult $result, Language $lang, $format, $useDB=false) | |
addError ( $modulePath, $msg, $code=null, $data=null) | |
Add an error to the result. More... | |
addMessagesFromStatus ( $modulePath, StatusValue $status, $types=[ 'warning', 'error'], array $filter=[]) | |
Add warnings and errors from a StatusValue object to the result. More... | |
addWarning ( $modulePath, $msg, $code=null, $data=null) | |
Add a warning to the result. More... | |
arrayFromStatus (StatusValue $status, $type='error', $format=null) | |
Format messages from a StatusValue as an array. More... | |
formatException ( $exception, array $options=[]) | |
Format an exception as an array. More... | |
formatMessage ( $msg, $format=null) | |
Format a message as an array. More... | |
getFormat () | |
Fetch the format for this formatter. More... | |
getLanguage () | |
Fetch the Language for this formatter. More... | |
getMessageFromException ( $exception, array $options=[]) | |
Get an ApiMessage from an exception. More... | |
newWithFormat ( $format) | |
Return a formatter like this one but with a different format. More... | |
Static Public Member Functions | |
static | stripMarkup ( $text) |
Turn wikitext into something resembling plaintext. More... | |
Protected Member Functions | |
addWarningOrError ( $tag, $modulePath, $msg) | |
Actually add the warning or error to the result. More... | |
formatMessageInternal ( $msg, $format) | |
Format a message as an array. More... | |
getDummyTitle () | |
Fetch a dummy title to set on Messages. More... | |
Protected Attributes | |
$format = 'none' | |
Language | $lang |
ApiResult | $result |
$useDB = false | |
Private Member Functions | |
formatRawMessage (MessageSpecifier $msg) | |
Format a Message object for raw format. More... | |
Static Private Attributes | |
static Title | $dummyTitle = null |
Dummy title to silence warnings from MessageCache::parse() More... | |
Formats errors and warnings for the API, and add them to the associated ApiResult.
Definition at line 30 of file ApiErrorFormatter.php.
ApiResult | $result | Into which data will be added |
Language | $lang | Used for i18n |
string | $format |
|
bool | $useDB | Whether to use local translations for errors and warnings. |
Definition at line 54 of file ApiErrorFormatter.php.
ApiErrorFormatter::addError | ( | $modulePath, | |
$msg, | |||
$code = null , |
|||
$data = null |
|||
) |
Add an error to the result.
string | null | $modulePath | |
Message | array | string | $msg | Warning message. See ApiMessage::create(). |
string | null | $code | See ApiMessage::create(). |
array | null | $data | See ApiMessage::create(). |
Definition at line 123 of file ApiErrorFormatter.php.
References $code, addWarningOrError(), ApiMessage\create(), and getDummyTitle().
ApiErrorFormatter::addMessagesFromStatus | ( | $modulePath, | |
StatusValue | $status, | ||
$types = [ 'warning' , |
|||
'error'] | , | ||
array | $filter = [] |
||
) |
Add warnings and errors from a StatusValue object to the result.
string | null | $modulePath | |
StatusValue | $status | |
string[] | string | $types | 'warning' and/or 'error' |
string[] | $filter | Messages to filter out (since 1.32) |
Definition at line 138 of file ApiErrorFormatter.php.
References addWarningOrError(), array(), as, ApiMessage\create(), getDummyTitle(), and true.
ApiErrorFormatter::addWarning | ( | $modulePath, | |
$msg, | |||
$code = null , |
|||
$data = null |
|||
) |
Add a warning to the result.
string | null | $modulePath | |
Message | array | string | $msg | Warning message. See ApiMessage::create(). |
string | null | $code | See ApiMessage::create(). |
array | null | $data | See ApiMessage::create(). |
Definition at line 108 of file ApiErrorFormatter.php.
References $code, addWarningOrError(), ApiMessage\create(), and getDummyTitle().
|
protected |
Actually add the warning or error to the result.
string | $tag | 'warning' or 'error' |
string | null | $modulePath | |
ApiMessage | ApiRawMessage | $msg |
Reimplemented in ApiErrorFormatter_BackCompat.
Definition at line 352 of file ApiErrorFormatter.php.
References $path, $value, ApiResult\ADD_ON_TOP, format, formatMessageInternal(), and ApiResult\NO_SIZE_CHECK.
Referenced by addError(), addMessagesFromStatus(), and addWarning().
ApiErrorFormatter::arrayFromStatus | ( | StatusValue | $status, |
$type = 'error' , |
|||
$format = null |
|||
) |
Format messages from a StatusValue as an array.
StatusValue | $status | |
string | $type | 'warning' or 'error' |
string | null | $format |
Reimplemented in ApiErrorFormatter_BackCompat.
Definition at line 244 of file ApiErrorFormatter.php.
ApiErrorFormatter::formatException | ( | $exception, | |
array | $options = [] |
||
) |
Format an exception as an array.
Exception | Throwable | $exception | |
array | $options | See self::getMessageFromException(), plus
|
Reimplemented in ApiErrorFormatter_BackCompat.
Definition at line 216 of file ApiErrorFormatter.php.
References $options, formatMessage(), and getMessageFromException().
ApiErrorFormatter::formatMessage | ( | $msg, | |
$format = null |
|||
) |
Format a message as an array.
Message | array | string | $msg | Message. See ApiMessage::create(). |
string | null | $format |
Definition at line 229 of file ApiErrorFormatter.php.
References $format, ApiMessage\create(), format, formatMessageInternal(), and getDummyTitle().
Referenced by formatException().
|
protected |
Format a message as an array.
ApiMessage | ApiRawMessage | $msg | |
string | null | $format |
Reimplemented in ApiErrorFormatter_BackCompat.
Definition at line 306 of file ApiErrorFormatter.php.
References $format, $value, formatRawMessage(), ApiResult\META_CONTENT, ApiResult\META_TYPE, and stripMarkup().
Referenced by addWarningOrError(), and formatMessage().
|
private |
Format a Message object for raw format.
MessageSpecifier | $msg |
Definition at line 283 of file ApiErrorFormatter.php.
References $ret, as, MessageSpecifier\getKey(), MessageSpecifier\getParams(), and ApiResult\setIndexedTagName().
Referenced by formatMessageInternal().
|
protected |
Fetch a dummy title to set on Messages.
Definition at line 94 of file ApiErrorFormatter.php.
References $dummyTitle, Title\makeTitle(), and NS_SPECIAL.
Referenced by addError(), addMessagesFromStatus(), addWarning(), formatMessage(), and getMessageFromException().
ApiErrorFormatter::getFormat | ( | ) |
Fetch the format for this formatter.
Reimplemented in ApiErrorFormatter_BackCompat.
Definition at line 77 of file ApiErrorFormatter.php.
References $format.
ApiErrorFormatter::getLanguage | ( | ) |
Fetch the Language for this formatter.
Definition at line 86 of file ApiErrorFormatter.php.
References $lang.
ApiErrorFormatter::getMessageFromException | ( | $exception, | |
array | $options = [] |
||
) |
Get an ApiMessage from an exception.
Exception | Throwable | $exception | |
array | $options |
|
Definition at line 180 of file ApiErrorFormatter.php.
References $options, $params, ApiMessage\create(), getDummyTitle(), and wfEscapeWikiText().
Referenced by formatException().
ApiErrorFormatter::newWithFormat | ( | $format | ) |
Return a formatter like this one but with a different format.
string | $format | New format. |
Definition at line 68 of file ApiErrorFormatter.php.
|
static |
Turn wikitext into something resembling plaintext.
string | $text |
Definition at line 268 of file ApiErrorFormatter.php.
References $ret.
Referenced by ApiUsageException\__construct(), ApiUsageException\__toString(), ApiErrorFormatter_BackCompat\addWarningOrError(), ApiLogin\formatMessage(), formatMessageInternal(), ApiLoginTest\testBotPasswordThrottled(), ApiLoginTest\testDeprecatedUserLogin(), ApiLoginTest\testGoodPass(), and ApiLoginTest\testUnsupportedAuthResponseType().
|
staticprivate |
Dummy title to silence warnings from MessageCache::parse()
Definition at line 32 of file ApiErrorFormatter.php.
Referenced by getDummyTitle().
|
protected |
Definition at line 40 of file ApiErrorFormatter.php.
Referenced by __construct(), arrayFromStatus(), formatMessage(), formatMessageInternal(), getFormat(), and newWithFormat().
|
protected |
Definition at line 38 of file ApiErrorFormatter.php.
Referenced by __construct(), getLanguage(), and newWithFormat().
|
protected |
Definition at line 35 of file ApiErrorFormatter.php.
Referenced by __construct(), ApiErrorFormatter_BackCompat\arrayFromStatus(), and newWithFormat().
|
protected |
Definition at line 39 of file ApiErrorFormatter.php.
Referenced by __construct(), and newWithFormat().