MediaWiki REL1_37
|
Generic operation result class Has warning/error list, boolean status and arbitrary value. More...
Public Member Functions | |
__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. | |
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. | |
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 |
Private Member Functions | |
addError (array $newError) | |
Add a new error to the error array ($this->errors) if that error is not already in the error array. | |
flattenParams (array $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 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.
@newable
Definition at line 43 of file StatusValue.php.
StatusValue::__toString | ( | ) |
Definition at line 363 of file StatusValue.php.
References flattenParams(), and isOK().
|
private |
Add a new error to the error array ($this->errors) if that error is not already in the error array.
Each error is passed as an array with the following fields:
If the new error is of type 'error' and it matches an existing error of type 'warning', the existing error is upgraded to type 'error'. An error provided as a MessageSpecifier will successfully match an error provided as the same string message key and array of parameters as separate array elements.
array | $newError |
Definition at line 193 of file StatusValue.php.
StatusValue::error | ( | $message, | |
$parameters | |||
) |
Add an error, do not set fatal flag This can be used for non-fatal errors.
string | MessageSpecifier | $message | Message key or object |
mixed | ...$parameters |
Definition at line 250 of file StatusValue.php.
References addError().
Referenced by MediaWiki\Storage\PageUpdater\checkAllRequiredRoles(), MediaWiki\Storage\PageUpdater\checkAllRolesAllowed(), MediaWiki\Storage\PageUpdater\checkAllRolesDerived(), MediaWiki\Storage\PageUpdater\checkNoRolesRequired(), and fatal().
StatusValue::fatal | ( | $message, | |
$parameters | |||
) |
Add an error and set OK to false, indicating that the operation as a whole was fatal.
string | MessageSpecifier | $message | Message key or object |
mixed | ...$parameters |
Definition at line 266 of file StatusValue.php.
References error().
Referenced by MediaWiki\Page\DeletePage\authorizeDeletion(), MediaWiki\Page\RollbackPage\authorizeRollback(), MediaWiki\Permissions\SimpleAuthority\checkPermission(), Article\fetchRevisionRecord(), MediaWiki\EditPage\Constraint\AutoSummaryMissingSummaryConstraint\getLegacyStatus(), MediaWiki\EditPage\Constraint\CreationPermissionConstraint\getLegacyStatus(), MediaWiki\EditPage\Constraint\DefaultTextConstraint\getLegacyStatus(), MediaWiki\EditPage\Constraint\MissingCommentConstraint\getLegacyStatus(), MediaWiki\EditPage\Constraint\NewSectionMissingSummaryConstraint\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(), Status\getMessage(), Status\getWikiText(), MediaWiki\Block\UnblockUser\unblock(), MediaWiki\Block\UnblockUser\unblockUnsafe(), MediaWiki\Block\BlockUtils\validateIPv4Range(), and MediaWiki\Block\BlockUtils\validateIPv6Range().
|
private |
array | $params | Message parameters |
Definition at line 417 of file StatusValue.php.
Referenced by __toString().
StatusValue::getErrors | ( | ) |
Get the list of errors.
Each error is a (message:string or MessageSpecifier,params:array) map
Definition at line 149 of file StatusValue.php.
Referenced by Status\__get(), ApiErrorFormatter\addMessagesFromStatus(), ApiErrorFormatter\arrayFromStatus(), ApiErrorFormatter_BackCompat\arrayFromStatus(), Status\getMessage(), and Status\getWikiText().
StatusValue::getErrorsByType | ( | $type | ) |
Returns a list of status messages of the given type.
Each entry is a map of:
string | $type |
Definition at line 301 of file StatusValue.php.
References $type.
Referenced by ApiErrorFormatter_BackCompat\arrayFromStatus(), and ApiBase\dieStatus().
|
protected |
Returns a list of status messages of the given type (or all if false)
string | bool | $type |
Definition at line 439 of file StatusValue.php.
References $type.
Referenced by Status\getErrorsArray(), and Status\getWarningsArray().
StatusValue::getValue | ( | ) |
Definition at line 138 of file StatusValue.php.
Referenced by Article\doOutputFromRenderStatus(), SearchEngine\maybePaginate(), ApiMove\moveSubpages(), MediaWiki\Auth\AbstractPasswordPrimaryAuthenticationProvider\setPasswordResetFlag(), and splitByErrorType().
StatusValue::hasMessage | ( | $message | ) |
Returns true if the specified message is present as a warning or error.
string | MessageSpecifier | $message | Message key or object to search for |
Definition at line 319 of file StatusValue.php.
Referenced by ApiBase\addBlockInfoToStatus(), and Article\doOutputFromRenderStatus().
StatusValue::isGood | ( | ) |
Returns whether the operation completed and didn't have any error or warnings.
Definition at line 122 of file StatusValue.php.
Referenced by ApiErrorFormatter\addMessagesFromStatus(), ApiErrorFormatter\arrayFromStatus(), ApiErrorFormatter_BackCompat\arrayFromStatus(), SpecialChangeEmail\attemptChange(), ApiBase\dieStatus(), LocalFileDeleteBatch\execute(), FindBadBlobs\handleStatus(), BotPassword\loginHook(), SpecialEmailUser\sendEmailForm(), MediaWiki\Auth\AbstractPasswordPrimaryAuthenticationProvider\setPasswordResetFlag(), HTMLForm\show(), and SpecialConfirmEmail\showRequestForm().
StatusValue::isOK | ( | ) |
Returns whether the operation completed.
Definition at line 131 of file StatusValue.php.
Referenced by ApiUsageException\__construct(), Status\__get(), __toString(), Article\doOutputFromRenderStatus(), ApiRevisionDelete\extractStatusInfo(), Status\getMessage(), Status\getWikiText(), FindBadBlobs\handleStatus(), 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 278 of file StatusValue.php.
References addError().
Referenced by LocalFileDeleteBatch\execute(), ScopedLock\factory(), MediaWiki\Storage\PageUpdater\makeNewRevision(), and FileOpBatch\runParallelBatches().
|
static |
Factory function for fatal errors.
string | MessageSpecifier | $message | Message key or object |
mixed | ...$parameters |
Definition at line 70 of file StatusValue.php.
|
static |
Factory function for good results.
mixed | null | $value |
Definition at line 82 of file StatusValue.php.
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.
Note, due to the lack of tools for comparing IStatusMessage objects, this function will not work when using such an object as the search parameter.
MessageSpecifier | string | $source | Message key or object to search for |
MessageSpecifier | string | $dest | Replacement message key or object |
Definition at line 347 of file StatusValue.php.
References $source.
Referenced by ApiBase\addBlockInfoToStatus().
StatusValue::setOK | ( | $ok | ) |
Change operation status.
bool | $ok |
Definition at line 159 of file StatusValue.php.
Referenced by 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 171 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 Status.
Definition at line 99 of file StatusValue.php.
References getValue(), and isOK().
StatusValue::warning | ( | $message, | |
$parameters | |||
) |
Add a new warning.
string | MessageSpecifier | $message | Message key or object |
mixed | ...$parameters |
Definition at line 234 of file StatusValue.php.
References addError().
|
protected |
Definition at line 49 of file StatusValue.php.
Referenced by Status\getErrorMessageArray(), and Status\getWikiText().
int StatusValue::$failCount = 0 |
Counter for batch operations.
Definition at line 61 of file StatusValue.php.
|
protected |
Definition at line 46 of file StatusValue.php.
bool [] StatusValue::$success = [] |
Map of (key => bool) to indicate success of each part of batch operations.
Definition at line 55 of file StatusValue.php.
int StatusValue::$successCount = 0 |
Counter for batch operations.
Definition at line 58 of file StatusValue.php.
mixed StatusValue::$value |
Definition at line 52 of file StatusValue.php.
Referenced by Status\__set().