MediaWiki REL1_35
|
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. | |
addMessagesFromStatus ( $modulePath, StatusValue $status, $types=[ 'warning', 'error'], array $filter=[]) | |
Add warnings and errors from a StatusValue object to the result. | |
addWarning ( $modulePath, $msg, $code=null, $data=null) | |
Add a warning to the result. | |
arrayFromStatus (StatusValue $status, $type='error', $format=null) | |
Format messages from a StatusValue as an array. | |
formatException (Throwable $exception, array $options=[]) | |
Format a throwable as an array. | |
formatMessage ( $msg, $format=null) | |
Format a message as an array. | |
getFormat () | |
Fetch the format for this formatter. | |
getLanguage () | |
Fetch the Language for this formatter. | |
getMessageFromException (Throwable $exception, array $options=[]) | |
Get an ApiMessage from a throwable. | |
newWithFormat ( $format) | |
Return a formatter like this one but with a different format. | |
Static Public Member Functions | |
static | isValidApiCode ( $code) |
Test whether a code is a valid API error code. | |
static | stripMarkup ( $text) |
Turn wikitext into something resembling plaintext. | |
Protected Member Functions | |
addWarningOrError ( $tag, $modulePath, $msg) | |
Actually add the warning or error to the result. | |
formatMessageInternal ( $msg, $format) | |
Format a message as an array. | |
getDummyTitle () | |
Fetch a dummy title to set on Messages. | |
Protected Attributes | |
$format = 'none' | |
Language | $lang |
ApiResult | $result |
$useDB = false | |
Private Member Functions | |
formatRawMessage (MessageSpecifier $msg) | |
Format a Message object for raw format. | |
Static Private Attributes | |
static Title | $dummyTitle = null |
Dummy title to silence warnings from MessageCache::parse() | |
Formats errors and warnings for the API, and add them to the associated ApiResult.
-file-suppress PhanUndeclaredMethod Undeclared methods in IApiMessage
Definition at line 31 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 55 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 144 of file ApiErrorFormatter.php.
References addWarningOrError(), 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.33) |
Definition at line 159 of file ApiErrorFormatter.php.
References addWarningOrError(), getDummyTitle(), StatusValue\getErrors(), and StatusValue\isGood().
Referenced by arrayFromStatus().
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 129 of file ApiErrorFormatter.php.
References addWarningOrError(), 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 375 of file ApiErrorFormatter.php.
References $path, and formatMessageInternal().
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 267 of file ApiErrorFormatter.php.
References $format, $result, $type, $useDB, addMessagesFromStatus(), StatusValue\getErrors(), ApiResult\getResultData(), and StatusValue\isGood().
ApiErrorFormatter::formatException | ( | Throwable | $exception, |
array | $options = [] |
||
) |
Format a throwable as an array.
Throwable | $exception | |
array | $options | See self::getMessageFromException(), plus
|
Reimplemented in ApiErrorFormatter_BackCompat.
Definition at line 238 of file ApiErrorFormatter.php.
References formatMessage(), and getMessageFromException().
ApiErrorFormatter::formatMessage | ( | $msg, | |
$format = null |
|||
) |
Format a message as an array.
Definition at line 252 of file ApiErrorFormatter.php.
References $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 329 of file ApiErrorFormatter.php.
References $format, formatRawMessage(), and stripMarkup().
Referenced by addWarningOrError(), and formatMessage().
|
private |
Format a Message object for raw format.
MessageSpecifier | $msg |
Definition at line 306 of file ApiErrorFormatter.php.
References formatRawMessage(), MessageSpecifier\getKey(), and MessageSpecifier\getParams().
Referenced by formatMessageInternal(), and formatRawMessage().
|
protected |
Fetch a dummy title to set on Messages.
Definition at line 115 of file ApiErrorFormatter.php.
References $dummyTitle, 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 98 of file ApiErrorFormatter.php.
References $format.
ApiErrorFormatter::getLanguage | ( | ) |
Fetch the Language for this formatter.
Definition at line 107 of file ApiErrorFormatter.php.
References $lang.
Referenced by ApiErrorFormatter_BackCompat\__construct().
ApiErrorFormatter::getMessageFromException | ( | Throwable | $exception, |
array | $options = [] |
||
) |
Get an ApiMessage from a throwable.
Throwable | $exception | |
array | $options |
|
Definition at line 201 of file ApiErrorFormatter.php.
References getDummyTitle(), Message\newFromSpecifier(), and wfEscapeWikiText().
Referenced by formatException().
|
static |
Test whether a code is a valid API error code.
A valid code contains only ASCII letters, numbers, underscore, and hyphen and is not the empty string.
For backwards compatibility, any code beginning 'internal_api_error_' is also allowed.
string | $code |
Definition at line 74 of file ApiErrorFormatter.php.
Referenced by setApiCode(), and ApiMain\substituteResultWithError().
ApiErrorFormatter::newWithFormat | ( | $format | ) |
Return a formatter like this one but with a different format.
string | $format | New format. |
Definition at line 89 of file ApiErrorFormatter.php.
|
static |
Turn wikitext into something resembling plaintext.
string | $text |
Definition at line 291 of file ApiErrorFormatter.php.
Referenced by ApiUsageException\__construct(), ApiUsageException\__toString(), ApiErrorFormatter_BackCompat\addWarningOrError(), ApiLogin\formatMessage(), and formatMessageInternal().
|
staticprivate |
Dummy title to silence warnings from MessageCache::parse()
Definition at line 33 of file ApiErrorFormatter.php.
Referenced by getDummyTitle().
|
protected |
Definition at line 41 of file ApiErrorFormatter.php.
Referenced by __construct(), arrayFromStatus(), formatMessage(), formatMessageInternal(), getFormat(), and newWithFormat().
|
protected |
Definition at line 39 of file ApiErrorFormatter.php.
Referenced by __construct(), getLanguage(), and newWithFormat().
|
protected |
Definition at line 36 of file ApiErrorFormatter.php.
Referenced by ApiErrorFormatter_BackCompat\__construct(), __construct(), arrayFromStatus(), ApiErrorFormatter_BackCompat\arrayFromStatus(), and newWithFormat().
|
protected |
Definition at line 40 of file ApiErrorFormatter.php.
Referenced by __construct(), arrayFromStatus(), and newWithFormat().