|
MediaWiki master
|
Generic operation result class Has warning/error list, boolean status and arbitrary value. More...
Inherits Stringable.
Inherited by MediaWiki\PageEdit\PageEditStatus, MediaWiki\PageEdit\PageEditStatus, MediaWiki\Permissions\PermissionStatus, MediaWiki\Permissions\PermissionStatus, MediaWiki\Status\Status, MediaWiki\Status\Status, MediaWiki\Upload\UploadVerificationStatus, and MediaWiki\Upload\UploadVerificationStatus.

Public Member Functions | |
| __construct () | |
| __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 (string $message) | |
| Returns true if the specified message is present as a warning or error. | |
| hasMessagesExcept (string ... $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 (string $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 | cast (StatusValue $sv) |
| Succinct helper method to wrap a StatusValue in some other specific subclass. | |
| 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. | |
| T | $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 functions returning StatusValue objects is to return a StatusValue unconditionally, both on success and on failure (similarly to Option, Maybe, Promise etc. objects in other languages) – 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.
This class accepts any MessageSpecifier objects. The use of Message objects should be avoided when serializability is needed. Use MessageValue in that case instead.
Definition at line 41 of file StatusValue.php.
| StatusValue::__construct | ( | ) |
Reimplemented in MediaWiki\Status\Status.
Definition at line 75 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 493 of file StatusValue.php.
|
static |
Succinct helper method to wrap a StatusValue in some other specific subclass.
One place where this is useful is when formatting StatusValue objects:
Also, several code paths in MediaWiki core use Status::wrap() to turn a returned StatusValue into a Status (e.g. ()); in such cases, cast() can be used to "restore" the original type. $form = HTMLForm::factory( 'ooui', [ ... ], $this->getContext() ) ->setSubmitCallback( function ( array $data, HTMLForm $form ) { return CustomStatusValue::newGood( $data ); ); $result = $form->tryAuthorizedSubmit(); // $result is a generic Status if ( $result && $result->isGood() ) { $result = CustomStatusValue::cast( $result ); // $result is a CustomStatusValue again } To support this pattern, StatusValue subclasses should not add any new properties: all data should be stored in the standard fields, chiefly self::$value and self::$statusData. (Making them associative arrays can help to keep the data extensible.)
| StatusValue | $sv |
Definition at line 133 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 |
| MessageParam|MessageSpecifier|string|int|float|list<MessageParam|MessageSpecifier|string|int|float> | ...$parameters See Message::params() |
Definition at line 317 of file StatusValue.php.
Referenced by MediaWiki\Auth\AuthManager\autoCreateUser(), MediaWiki\Password\PasswordPolicyChecks\checkMinimalPasswordLength(), and MediaWiki\Password\PasswordPolicyChecks\checkPasswordNotInCommonList().
| 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 |
| MessageParam|MessageSpecifier|string|int|float|list<MessageParam|MessageSpecifier|string|int|float> | ...$parameters See Message::params() |
Definition at line 335 of file StatusValue.php.
Referenced by MediaWiki\Exception\PermissionsError\__construct(), MediaWiki\Page\RollbackPage\authorizeRollback(), MediaWiki\EditPage\Constraint\EditFilterMergedContentHookConstraint\checkConstraint(), MediaWiki\Password\PasswordPolicyChecks\checkMaximalPasswordLength(), MediaWiki\Password\PasswordPolicyChecks\checkMinimumPasswordLengthToLogin(), MediaWiki\Status\StatusFormatter\getMessage(), MediaWiki\Status\StatusFormatter\getWikiText(), 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 213 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 379 of file StatusValue.php.
| StatusValue::getMessages | ( | ?string | $type = null | ) |
Returns a list of error messages, optionally only those of the given type.
If the warning() or error() method was called with a MessageSpecifier object, this method is guaranteed to return the same object.
| ?string | $type | If provided, only return messages of the type 'warning' or 'error' |
Definition at line 401 of file StatusValue.php.
Referenced by MediaWiki\Exception\PermissionsError\__construct(), MediaWiki\Api\ApiErrorFormatter\addMessagesFromStatus(), MediaWiki\Api\ApiErrorFormatter\arrayFromStatus(), MediaWiki\Api\ApiErrorFormatter_BackCompat\arrayFromStatus(), MediaWiki\Specials\SpecialEmailUser\getTarget(), MediaWiki\Output\OutputPage\showPermissionStatus(), 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 571 of file StatusValue.php.
| StatusValue::getValue | ( | ) |
Definition at line 200 of file StatusValue.php.
Referenced by MediaWiki\Api\ApiMove\moveSubpages(), and MediaWiki\Auth\AbstractPasswordPrimaryAuthenticationProvider\setPasswordResetFlag().
| StatusValue::hasMessage | ( | string | $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 |
Definition at line 426 of file StatusValue.php.
References Wikimedia\Message\MessageSpecifier\getKey().
Referenced by MediaWiki\Specials\SpecialEmailUser\execute().
| StatusValue::hasMessagesExcept | ( | string ... | $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 |
Definition at line 445 of file StatusValue.php.
| StatusValue::isGood | ( | ) |
Returns whether the operation completed and didn't have any error or warnings.
Definition at line 184 of file StatusValue.php.
Referenced by MediaWiki\Exception\PermissionsError\__construct(), MediaWiki\Api\ApiErrorFormatter\addMessagesFromStatus(), MediaWiki\Api\ApiErrorFormatter\arrayFromStatus(), MediaWiki\Api\ApiErrorFormatter_BackCompat\arrayFromStatus(), MediaWiki\Auth\AuthManager\autoCreateUser(), MediaWiki\Auth\AuthManager\beginAccountLink(), MediaWiki\SpecialPage\FormSpecialPage\execute(), MediaWiki\Specials\SpecialEmailUser\execute(), MediaWiki\SpecialPage\ContributionsSpecialPage\getForm(), MediaWiki\Specials\SpecialEmailUser\getTarget(), MediaWiki\Auth\AbstractPasswordPrimaryAuthenticationProvider\setPasswordResetFlag(), MediaWiki\HTMLForm\HTMLForm\show(), MediaWiki\Logging\LogEventsList\showOptions(), and MediaWiki\Output\OutputPage\showPermissionStatus().
| StatusValue::isOK | ( | ) |
Returns whether the operation completed.
Definition at line 193 of file StatusValue.php.
Referenced by MediaWiki\Status\Status\__get(), MediaWiki\Auth\AuthManager\autoCreateUser(), MediaWiki\Auth\AuthManager\beginAccountLink(), MediaWiki\Auth\AuthManager\continueAccountLink(), MediaWiki\Status\StatusFormatter\getMessage(), and MediaWiki\Status\StatusFormatter\getWikiText().
| 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 347 of file StatusValue.php.
Referenced by MediaWiki\RevisionDelete\RevDelList\acquireItemLocks(), MediaWiki\Auth\AuthManager\beginAccountLink(), MediaWiki\Auth\AuthManager\continueAccountLink(), Wikimedia\LockManager\ScopedLock\factory(), MediaWiki\RevisionDelete\RevDelList\releaseItemLocks(), and Wikimedia\FileBackend\FileOpBatch\runParallelBatches().
|
static |
Factory function for fatal errors.
| string | MessageSpecifier | $message | Message key or object |
| MessageParam|MessageSpecifier|string|int|float|list<MessageParam|MessageSpecifier|string|int|float> | ...$parameters See Message::params() |
Definition at line 86 of file StatusValue.php.
Referenced by MediaWiki\User\TempUser\TempUserCreator\create().
|
static |
Factory function for good results.
| mixed | null | $value |
Definition at line 97 of file StatusValue.php.
Referenced by MediaWiki\FileRepo\File\LocalFileDeleteBatch\execute().
| StatusValue::replaceMessage | ( | string | $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.
Any message using the same key will be replaced (ignoring the message parameters).
| string | $source | Message key to search for |
| MessageSpecifier | string | $dest | Replacement message key or object |
Definition at line 468 of file StatusValue.php.
References $source, and Wikimedia\Message\MessageSpecifier\getKey().
| StatusValue::setOK | ( | $ok | ) |
Change operation status.
| bool | $ok |
Definition at line 223 of file StatusValue.php.
Referenced by MediaWiki\Status\Status\__set(), MediaWiki\EditPage\Constraint\ImageRedirectConstraint\checkConstraint(), and MediaWiki\EditPage\Constraint\NewSectionMissingSubjectConstraint\checkConstraint().
| StatusValue::setResult | ( | $ok, | |
| $value = null ) |
Change operation result.
| bool | $ok | Whether the operation completed |
| T | $value | If $ok is true, this should be a value of the template type T. Otherwise it may be null or omitted. |
Definition at line 237 of file StatusValue.php.
| 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 161 of file StatusValue.php.
| StatusValue::warning | ( | $message, | |
| $parameters ) |
Add a new warning.
| string | MessageSpecifier | $message | Message key or object |
| MessageParam|MessageSpecifier|string|int|float|list<MessageParam|MessageSpecifier|string|int|float> | ...$parameters See Message::params() |
Definition at line 299 of file StatusValue.php.
Referenced by MediaWiki\Auth\AuthManager\autoCreateUser().
|
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 55 of file StatusValue.php.
| int StatusValue::$failCount = 0 |
Counter for batch operations.
Definition at line 67 of file StatusValue.php.
|
protected |
self::isOK() or self::setOK(). Definition at line 47 of file StatusValue.php.
| mixed StatusValue::$statusData |
arbitrary extra data about the operation
Definition at line 70 of file StatusValue.php.
| bool [] StatusValue::$success = [] |
Map of (key => bool) to indicate success of each part of batch operations.
Definition at line 61 of file StatusValue.php.
| int StatusValue::$successCount = 0 |
Counter for batch operations.
Definition at line 64 of file StatusValue.php.
| T StatusValue::$value |
Definition at line 58 of file StatusValue.php.
Referenced by MediaWiki\Status\Status\__set().