MediaWiki fundraising/REL1_35
|
Generic operation result class Has warning/error list, boolean status and arbitrary value. More...
Public Member Functions | |
__get ( $name) | |
Backwards compatibility logic. | |
__set ( $name, $value) | |
Change operation result Backwards compatibility logic. | |
__sleep () | |
Don't save the callback when serializing, because Closures can't be serialized and we're going to clear it in __wakeup anyway. | |
__wakeup () | |
Sanitize the callback parameter on wakeup, to avoid arbitrary execution. | |
getErrorsArray () | |
Get the list of errors (but not warnings) | |
getHTML ( $shortContext=false, $longContext=false, $lang=null) | |
Get the error message as HTML. | |
getMessage ( $shortContext=false, $longContext=false, $lang=null) | |
Get a bullet list of the errors as a Message object. | |
getStatusValue () | |
Returns the wrapped StatusValue object. | |
getWarningsArray () | |
Get the list of warnings (but not errors) | |
getWikiText ( $shortContext=false, $longContext=false, $lang=null) | |
Get the error list as a wikitext formatted list. | |
setMessageLocalizer (MessageLocalizer $messageLocalizer) | |
Makes this Status object use the given localizer instead of the global one. | |
splitByErrorType () | |
Splits this Status object into two new Status objects, one which contains only the error messages, and one that contains the warnings, only. | |
Public Member Functions inherited from StatusValue | |
__toString () | |
error ( $message,... $parameters) | |
Add an error, do not set fatal flag This can be used for non-fatal errors. | |
fatal ( $message,... $parameters) | |
Add an error and set OK to false, indicating that the operation as a whole was fatal. | |
getErrors () | |
Get the list of errors. | |
getErrorsByType ( $type) | |
Returns a list of status messages of the given type. | |
getValue () | |
hasMessage ( $message) | |
Returns true if the specified message is present as a warning or error. | |
isGood () | |
Returns whether the operation completed and didn't have any error or warnings. | |
isOK () | |
Returns whether the operation completed. | |
merge ( $other, $overwriteValue=false) | |
Merge another status object into this one. | |
replaceMessage ( $source, $dest) | |
If the specified source message exists, replace it with the specified destination message, but keep the same parameters as in the original error. | |
setOK ( $ok) | |
Change operation status. | |
setResult ( $ok, $value=null) | |
Change operation result. | |
warning ( $message,... $parameters) | |
Add a new warning. | |
Static Public Member Functions | |
static | wrap ( $sv) |
Succinct helper method to wrap a StatusValue. | |
Static Public Member Functions inherited from StatusValue | |
static | newFatal ( $message,... $parameters) |
Factory function for fatal errors. | |
static | newGood ( $value=null) |
Factory function for good results. | |
Public Attributes | |
callable false | $cleanCallback = false |
Public Attributes inherited from StatusValue | |
int | $failCount = 0 |
Counter for batch operations. | |
bool[] | $success = [] |
Map of (key => bool) to indicate success of each part of batch operations. | |
int | $successCount = 0 |
Counter for batch operations. | |
mixed | $value |
Protected Member Functions | |
cleanParams (array $params) | |
getErrorMessage ( $error, $lang=null) | |
Return the message for a single error. | |
getErrorMessageArray ( $errors, $lang=null) | |
Return an array with a Message object for each error. | |
getStatusArray ( $type=false) | |
Returns a list of status messages of the given type (or all if false) | |
Protected Attributes | |
MessageLocalizer null | $messageLocalizer |
Protected Attributes inherited from StatusValue | |
array[] | $errors = [] |
bool | $ok = true |
Private Member Functions | |
msg ( $key,... $params) | |
msgInLang ( $key, $lang,... $params) | |
Generic operation result class Has warning/error list, boolean status and arbitrary value.
"Good" means the operation was completed with no warnings or errors.
"OK" means the operation was partially or wholly completed.
An operation which is not OK should have errors so that the user can be informed as to what went wrong. Calling the fatal() function sets an error message and simultaneously switches off the OK flag.
The recommended pattern for Status objects is to return a Status object unconditionally, i.e. both on success and on failure – so that the developer of the calling code is reminded that the function can fail, and so that a lack of error-handling will be explicit.
@newable
Definition at line 44 of file Status.php.
Status::__get | ( | $name | ) |
Backwards compatibility logic.
string | $name |
RuntimeException |
Definition at line 85 of file Status.php.
References StatusValue\getErrors(), and StatusValue\isOK().
Status::__set | ( | $name, | |
$value ) |
Change operation result Backwards compatibility logic.
string | $name | |
mixed | $value |
RuntimeException |
Definition at line 104 of file Status.php.
References StatusValue\$value, and StatusValue\setOK().
Status::__sleep | ( | ) |
Don't save the callback when serializing, because Closures can't be serialized and we're going to clear it in __wakeup anyway.
Don't save the localizer, because it can be pretty much anything. Restoring it is the caller's responsibility (otherwise it will just fall back to the global request context).
Definition at line 406 of file Status.php.
References $keys.
Status::__wakeup | ( | ) |
Sanitize the callback parameter on wakeup, to avoid arbitrary execution.
Definition at line 414 of file Status.php.
|
protected |
array | $params |
Definition at line 169 of file Status.php.
Referenced by getErrorMessage().
|
protected |
Return the message for a single error.
The code string can be used a message key with per-language versions. If $error is an array, the "params" field is a list of parameters for the message.
array | string | $error | Code string or (key: code string, params: string[]) map |
string | Language | null | $lang | Language to use for processing messages |
Definition at line 293 of file Status.php.
References $lang, cleanParams(), msg(), and wfEscapeWikiText().
Referenced by getErrorMessageArray(), getMessage(), and getWikiText().
|
protected |
Return an array with a Message object for each error.
Definition at line 342 of file Status.php.
References StatusValue\$errors, $lang, and getErrorMessage().
Referenced by getMessage(), and getWikiText().
Status::getErrorsArray | ( | ) |
Get the list of errors (but not warnings)
Definition at line 355 of file Status.php.
References getStatusArray().
Referenced by WikiEditorHooks\editPageAttemptSaveAfter(), CliInstaller\showStatusMessage(), and WebInstaller\showStatusMessage().
Status::getHTML | ( | $shortContext = false, | |
$longContext = false, | |||
$lang = null ) |
Get the error message as HTML.
This is done by parsing the wikitext error message
string | bool | $shortContext | A short enclosing context message name, to be used when there is a single error |
string | bool | $longContext | A long enclosing context message name, for a list |
string | Language | null | $lang | Language to use for processing messages |
Definition at line 327 of file Status.php.
References $lang, ParserOutput\getText(), and getWikiText().
Status::getMessage | ( | $shortContext = false, | |
$longContext = false, | |||
$lang = null ) |
Get a bullet list of the errors as a Message object.
$shortContext and $longContext can be used to wrap the error list in some text. $shortContext will be preferred when there is a single error; $longContext will be preferred when there are multiple ones. In either case, $1 will be replaced with the list of errors.
$shortContext is assumed to use $1 as an inline parameter: if there is a single item, it will not be made into a list; if there are multiple items, newlines will be inserted around the list. $longContext is assumed to use $1 as a standalone parameter; it will always receive a list.
If both parameters are missing, and there is only one error, no bullet will be added.
string | string[] | bool | $shortContext | A message name or an array of message names. |
string | string[] | bool | $longContext | A message name or an array of message names. |
string | Language | StubUserLang | null | $lang | Language to use for processing messages |
Definition at line 243 of file Status.php.
References $lang, $s, StatusValue\fatal(), getErrorMessage(), getErrorMessageArray(), StatusValue\getErrors(), StatusValue\isOK(), and msgInLang().
Referenced by LocalFileLockError\__construct(), BotPassword\loginHook(), and MediaWiki\Auth\AbstractPasswordPrimaryAuthenticationProvider\setPasswordResetFlag().
|
protected |
Returns a list of status messages of the given type (or all if false)
string | bool | $type |
Definition at line 378 of file Status.php.
References $type, and StatusValue\getErrors().
Referenced by getErrorsArray(), and getWarningsArray().
Status::getStatusValue | ( | ) |
Returns the wrapped StatusValue object.
Definition at line 161 of file Status.php.
Status::getWarningsArray | ( | ) |
Get the list of warnings (but not errors)
Definition at line 366 of file Status.php.
References getStatusArray().
Referenced by CliInstaller\showStatusMessage(), and WebInstaller\showStatusMessage().
Status::getWikiText | ( | $shortContext = false, | |
$longContext = false, | |||
$lang = null ) |
Get the error list as a wikitext formatted list.
string | bool | $shortContext | A short enclosing context message name, to be used when there is a single error |
string | bool | $longContext | A long enclosing context message name, for a list |
string | Language | StubUserLang | null | $lang | Language to use for processing messages |
Definition at line 189 of file Status.php.
References StatusValue\$errors, $lang, $s, StatusValue\fatal(), getErrorMessage(), getErrorMessageArray(), StatusValue\getErrors(), StatusValue\isOK(), and msgInLang().
Referenced by EditPage\formatStatusErrors(), getHTML(), and EditPage\handleStatus().
|
private |
string | MessageSpecifier | $key | |
string|string[] | ...$params |
Definition at line 424 of file Status.php.
Referenced by getErrorMessage().
|
private |
string | MessageSpecifier | $key | |
string | Language | StubUserLang | null | $lang | |
mixed | ...$params |
Definition at line 438 of file Status.php.
References $lang, and Message\inLanguage().
Referenced by getMessage(), and getWikiText().
Status::setMessageLocalizer | ( | MessageLocalizer | $messageLocalizer | ) |
Makes this Status object use the given localizer instead of the global one.
If it is an IContextSource or a ResourceLoaderContext, it will also be used to determine the interface language.
MessageLocalizer | $messageLocalizer |
Definition at line 125 of file Status.php.
Status::splitByErrorType | ( | ) |
Splits this Status object into two new Status objects, one which contains only the error messages, and one that contains the warnings, only.
The returned array is defined as: [ 0 => object(Status) # The Status with error messages, only 1 => object(Status) # The Status with warning messages, only ]
Reimplemented from StatusValue.
Definition at line 140 of file Status.php.
|
static |
Succinct helper method to wrap a StatusValue.
This is is useful when formatting StatusValue objects:
StatusValue | Status | $sv |
Definition at line 62 of file Status.php.
callable false Status::$cleanCallback = false |
Definition at line 46 of file Status.php.
|
protected |
Definition at line 49 of file Status.php.