MediaWiki master
|
Generic operation result class Has warning/error list, boolean status and arbitrary value. More...
Inherits Stringable.
Inherited by MediaWiki\Permissions\PermissionStatus, and MediaWiki\Status\Status.
Public Member Functions | |
__toString () | |
Returns a string representation of the status for debugging. | |
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. | |
getMessages (?string $type=null) | |
Returns a list of error messages, optionally only those of the given type. | |
getValue () | |
hasMessage ( $message) | |
Returns true if the specified message is present as a warning or error. | |
hasMessagesExcept (... $messages) | |
Returns true if any other message than the specified ones 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. | |
splitByErrorType () | |
Splits this StatusValue object into two new StatusValue objects, one which contains only the error messages, and one that contains the warnings, only. | |
warning ( $message,... $parameters) | |
Add a new warning. | |
Static Public Member Functions | |
static | newFatal ( $message,... $parameters) |
Factory function for fatal errors. | |
static | newGood ( $value=null) |
Factory function for good results. | |
Public Attributes | |
int | $failCount = 0 |
Counter for batch operations. | |
mixed | $statusData |
arbitrary extra data about the operation | |
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 | |
getStatusArray ( $type=false) | |
Returns a list of status messages of the given type (or all if false) | |
Protected Attributes | |
array[] | $errors = [] |
bool | $ok = true |
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 StatusValue 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.
The use of Message objects should be avoided when serializability is needed.
Definition at line 49 of file StatusValue.php.
StatusValue::__toString | ( | ) |
Returns a string representation of the status for debugging.
This is fairly verbose and may change without notice.
Definition at line 491 of file StatusValue.php.
References $params.
StatusValue::error | ( | $message, | |
$parameters ) |
Add an error, do not set fatal flag This can be used for non-fatal errors.
string | MessageSpecifier | MessageValue | $message | Message key or object |
mixed | ...$parameters |
Definition at line 269 of file StatusValue.php.
Referenced by fatal().
StatusValue::fatal | ( | $message, | |
$parameters ) |
Add an error and set OK to false, indicating that the operation as a whole was fatal.
string | MessageSpecifier | MessageValue | $message | Message key or object |
mixed | ...$parameters |
Definition at line 287 of file StatusValue.php.
References error().
Referenced by MediaWiki\Page\RollbackPage\authorizeRollback(), ApiBase\dieStatus(), Article\fetchRevisionRecord(), MediaWiki\EditPage\Constraint\DefaultTextConstraint\getLegacyStatus(), MediaWiki\EditPage\Constraint\ExistingSectionEditConstraint\getLegacyStatus(), MediaWiki\EditPage\Constraint\MissingCommentConstraint\getLegacyStatus(), MediaWiki\EditPage\Constraint\NewSectionMissingSubjectConstraint\getLegacyStatus(), MediaWiki\EditPage\Constraint\ReadOnlyConstraint\getLegacyStatus(), MediaWiki\EditPage\Constraint\SelfRedirectConstraint\getLegacyStatus(), MediaWiki\EditPage\Constraint\SimpleAntiSpamConstraint\getLegacyStatus(), MediaWiki\EditPage\Constraint\UnicodeConstraint\getLegacyStatus(), MediaWiki\EditPage\Constraint\UserRateLimitConstraint\getLegacyStatus(), MediaWiki\Status\StatusFormatter\getMessage(), MediaWiki\Status\StatusFormatter\getWikiText(), MediaWiki\Installer\PostgresInstaller\openConnectionToAnyDB(), MediaWiki\Block\UnblockUser\unblock(), MediaWiki\Block\UnblockUser\unblockUnsafe(), and MediaWiki\Settings\Config\ConfigSchemaAggregator\validateConfig().
StatusValue::getErrors | ( | ) |
Get the list of errors.
Each error is a (message:string or MessageSpecifier,params:array) map
->getMessages()
instead Definition at line 168 of file StatusValue.php.
Referenced by MediaWiki\Status\Status\__get(), MediaWiki\Status\StatusFormatter\getMessage(), and MediaWiki\Status\StatusFormatter\getWikiText().
StatusValue::getErrorsByType | ( | $type | ) |
Returns a list of status messages of the given type.
Each entry is a map of:
->getMessages( $type )
instead string | $type |
Definition at line 331 of file StatusValue.php.
StatusValue::getMessages | ( | ?string | $type = null | ) |
Returns a list of error messages, optionally only those of the given type.
?string | $type | If provided, only return messages of the type 'warning' or 'error' |
Definition at line 350 of file StatusValue.php.
References $params.
Referenced by ApiBase\addBlockInfoToStatus(), ApiErrorFormatter\addMessagesFromStatus(), ApiErrorFormatter\arrayFromStatus(), ApiErrorFormatter_BackCompat\arrayFromStatus(), ApiBase\dieStatus(), MediaWiki\Installer\CliInstaller\showStatusMessage(), and MediaWiki\Installer\WebInstaller\showStatusMessage().
|
protected |
Returns a list of status messages of the given type (or all if false)
string | bool | $type |
Definition at line 570 of file StatusValue.php.
StatusValue::getValue | ( | ) |
Definition at line 155 of file StatusValue.php.
Referenced by ApiMove\moveSubpages(), MediaWiki\Auth\AbstractPasswordPrimaryAuthenticationProvider\setPasswordResetFlag(), and splitByErrorType().
StatusValue::hasMessage | ( | $message | ) |
Returns true if the specified message is present as a warning or error.
Any message using the same key will be found (ignoring the message parameters).
string | $message | Message key to search for (this parameter used to allow MessageSpecifier|MessageValue too, deprecated since 1.43) |
Definition at line 377 of file StatusValue.php.
References MessageSpecifier\getKey(), and wfDeprecatedMsg().
Referenced by ApiBase\dieStatus().
StatusValue::hasMessagesExcept | ( | $messages | ) |
Returns true if any other message than the specified ones is present as a warning or error.
Any messages using the same keys will be found (ignoring the message parameters).
string | ...$messages Message keys to search for (this parameter used to allow MessageSpecifier|MessageValue too, deprecated since 1.43) |
Definition at line 407 of file StatusValue.php.
References wfDeprecatedMsg().
StatusValue::isGood | ( | ) |
Returns whether the operation completed and didn't have any error or warnings.
Definition at line 139 of file StatusValue.php.
Referenced by ApiErrorFormatter\addMessagesFromStatus(), ApiErrorFormatter\arrayFromStatus(), ApiErrorFormatter_BackCompat\arrayFromStatus(), MediaWiki\Auth\AuthManager\beginAccountLink(), ApiBase\dieStatus(), MediaWiki\SpecialPage\FormSpecialPage\execute(), MediaWiki\Specials\SpecialEditWatchlist\executeViewEditWatchlist(), MediaWiki\SpecialPage\ContributionsSpecialPage\getForm(), MediaWiki\Specials\SpecialEmailUser\sendEmailForm(), MediaWiki\Auth\AbstractPasswordPrimaryAuthenticationProvider\setPasswordResetFlag(), MediaWiki\HTMLForm\HTMLForm\show(), and LogEventsList\showOptions().
StatusValue::isOK | ( | ) |
Returns whether the operation completed.
Definition at line 148 of file StatusValue.php.
Referenced by ApiUsageException\__construct(), MediaWiki\Status\Status\__get(), MediaWiki\Status\StatusFormatter\getMessage(), MediaWiki\Status\StatusFormatter\getWikiText(), and splitByErrorType().
StatusValue::merge | ( | $other, | |
$overwriteValue = false ) |
Merge another status object into this one.
StatusValue | $other | |
bool | $overwriteValue | Whether to override the "value" member |
Definition at line 299 of file StatusValue.php.
Referenced by ScopedLock\factory(), and FileOpBatch\runParallelBatches().
|
static |
Factory function for fatal errors.
string | MessageSpecifier | $message | Message key or object |
mixed | ...$parameters |
Definition at line 87 of file StatusValue.php.
Referenced by MediaWiki\User\TempUser\TempUserCreator\create().
|
static |
Factory function for good results.
mixed | null | $value |
Definition at line 99 of file StatusValue.php.
Referenced by LocalFileDeleteBatch\execute().
StatusValue::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.
When using a string as the $source
parameter, any message using the same key will be replaced (regardless of whether it was stored as string or as MessageSpecifier, and ignoring the message parameters).
When using a MessageValue as the $source
parameter, this function does not work. This is a bug, but it's impractical to fix. Therefore, passing a MessageValue is deprecated (since 1.43).
When using a MessageSpecifier as the $source
parameter, the message will only be replaced when the same MessageSpecifier object was stored in the StatusValue (compared with ===
). Since the only reliable way to obtain one is to use getErrors(), which is deprecated, passing a MessageSpecifier is deprecated as well (since 1.43).
string | $source | Message key to search for (this parameter used to allow MessageSpecifier|MessageValue too, deprecated since 1.43) |
MessageSpecifier | MessageValue | string | $dest | Replacement message key or object |
Definition at line 455 of file StatusValue.php.
References $params, $source, MessageSpecifier\getKey(), and wfDeprecatedMsg().
Referenced by ApiBase\addBlockInfoToStatus(), and ApiBase\dieStatus().
StatusValue::setOK | ( | $ok | ) |
Change operation status.
bool | $ok |
Definition at line 178 of file StatusValue.php.
Referenced by MediaWiki\Status\Status\__set(), and ApiBase\dieStatus().
StatusValue::setResult | ( | $ok, | |
$value = null ) |
Change operation result.
bool | $ok | Whether the operation completed |
mixed | null | $value |
Definition at line 190 of file StatusValue.php.
Referenced by MediaWiki\EditPage\Constraint\AccidentalRecreationConstraint\getLegacyStatus(), MediaWiki\EditPage\Constraint\ContentModelChangeConstraint\getLegacyStatus(), MediaWiki\EditPage\Constraint\EditRightConstraint\getLegacyStatus(), MediaWiki\EditPage\Constraint\ImageRedirectConstraint\getLegacyStatus(), MediaWiki\EditPage\Constraint\PageSizeConstraint\getLegacyStatus(), and MediaWiki\EditPage\Constraint\UserBlockConstraint\getLegacyStatus().
StatusValue::splitByErrorType | ( | ) |
Splits this StatusValue object into two new StatusValue objects, one which contains only the error messages, and one that contains the warnings, only.
The returned array is defined as: [ 0 => object(StatusValue) # the StatusValue with error messages, only 1 => object(StatusValue) # The StatusValue with warning messages, only ]
Reimplemented in MediaWiki\Status\Status.
Definition at line 116 of file StatusValue.php.
References getValue(), and isOK().
StatusValue::warning | ( | $message, | |
$parameters ) |
Add a new warning.
string | MessageSpecifier | MessageValue | $message | Message key or object |
mixed | ...$parameters |
Definition at line 251 of file StatusValue.php.
|
protected |
self::getErrors()
(get full list), self::splitByErrorType()
(get errors/warnings), or self::fatal()
, self::error()
or self::warning()
(add error/warning). Definition at line 63 of file StatusValue.php.
int StatusValue::$failCount = 0 |
Counter for batch operations.
Definition at line 75 of file StatusValue.php.
|
protected |
self::isOK()
or self::setOK()
. Definition at line 55 of file StatusValue.php.
mixed StatusValue::$statusData |
arbitrary extra data about the operation
Definition at line 78 of file StatusValue.php.
bool [] StatusValue::$success = [] |
Map of (key => bool) to indicate success of each part of batch operations.
Definition at line 69 of file StatusValue.php.
int StatusValue::$successCount = 0 |
Counter for batch operations.
Definition at line 72 of file StatusValue.php.
mixed StatusValue::$value |
Definition at line 66 of file StatusValue.php.
Referenced by MediaWiki\Status\Status\__set().