MediaWiki master
MediaWiki\Status\Status Class Reference

Generic operation result class Has warning/error list, boolean status and arbitrary value. More...

Inherits StatusValue.

Inherited by MediaWiki\Installer\ConnectionStatus, MediaWiki\Storage\PageUpdateStatus, and MediaWiki\User\TempUser\CreateStatus.

Collaboration diagram for MediaWiki\Status\Status:

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.
 
 getPsr3MessageAndContext (array $context=[])
 Try to convert the status to a PSR-3 friendly format.
 
 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 ()
 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.
 
 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.
 
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 Attributes

MessageLocalizer null $messageLocalizer
 
- Protected Attributes inherited from StatusValue
array[] $errors = []
 
bool $ok = true
 

Additional Inherited Members

- Protected Member Functions inherited from StatusValue
 getStatusArray ( $type=false)
 Returns a list of status messages of the given type (or all if false)
 

Detailed Description

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.

Stability: newable

Definition at line 54 of file Status.php.

Member Function Documentation

◆ __get()

MediaWiki\Status\Status::__get ( $name)

Backwards compatibility logic.

Parameters
string$name
Returns
mixed
Exceptions
RuntimeException

Definition at line 98 of file Status.php.

References StatusValue\getErrors(), and StatusValue\isOK().

◆ __set()

MediaWiki\Status\Status::__set ( $name,
$value )

Change operation result Backwards compatibility logic.

Parameters
string$name
mixed$value
Exceptions
RuntimeException

Definition at line 117 of file Status.php.

References StatusValue\$value, and StatusValue\setOK().

◆ __sleep()

MediaWiki\Status\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). Same for the formatter, which is likely to contain a localizer.

Returns
array

Definition at line 339 of file Status.php.

◆ __wakeup()

MediaWiki\Status\Status::__wakeup ( )

Sanitize the callback parameter on wakeup, to avoid arbitrary execution.

Definition at line 347 of file Status.php.

◆ getErrorsArray()

MediaWiki\Status\Status::getErrorsArray ( )

Get the list of errors (but not warnings)

Deprecated
since 1.43 Use ‘->getMessages( 'error’ )` instead
Returns
array[] A list in which each entry is an array with a message key as its first element. The remaining array elements are the message parameters.

Definition at line 315 of file Status.php.

◆ getHTML()

MediaWiki\Status\Status::getHTML ( $shortContext = false,
$longContext = false,
$lang = null )

Get the error message as HTML.

This is done by parsing the wikitext error message

All message parameters that were provided as strings will be escaped with wfEscapeWikiText. This is mostly a historical accident and often undesirable (T368821).

  • To avoid this behavior when producing the Status, pass MessageSpecifier objects to methods such as $status->fatal(), instead of separate key and params parameters.
  • To avoid this behavior when consuming the Status, use the $status->getMessages() method instead, and display each message separately (or combine then with Message::listParams()).

    Deprecated
    since 1.42, use StatusFormatter instead.
Parameters
string | false$shortContextA short enclosing context message name, to be used when there is a single error
string | false$longContextA long enclosing context message name, for a list
string | Language | StubUserLang | null$langLanguage to use for processing messages
Returns
string

Definition at line 298 of file Status.php.

◆ getMessage()

MediaWiki\Status\Status::getMessage ( $shortContext = false,
$longContext = false,
$lang = null )

Get a bullet list of the errors as a Message object.

All message parameters that were provided as strings will be escaped with wfEscapeWikiText. This is mostly a historical accident and often undesirable (T368821).

  • To avoid this behavior when producing the Status, pass MessageSpecifier objects to methods such as $status->fatal(), instead of separate key and params parameters.
  • To avoid this behavior when consuming the Status, use the $status->getMessages() method instead, and display each message separately (or combine then with Message::listParams()).

$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.

Deprecated
since 1.42, use StatusFormatter instead.
Parameters
string | string[] | false$shortContextA message name or an array of message names.
string | string[] | false$longContextA message name or an array of message names.
string | Language | StubUserLang | null$langLanguage to use for processing messages
Returns
Message

Definition at line 256 of file Status.php.

Referenced by LocalFileLockError\__construct(), and MediaWiki\Auth\AbstractPasswordPrimaryAuthenticationProvider\setPasswordResetFlag().

◆ getPsr3MessageAndContext()

MediaWiki\Status\Status::getPsr3MessageAndContext ( array $context = [])

Try to convert the status to a PSR-3 friendly format.

The output will be similar to getWikiText( false, false, 'en' ), but message parameters will be extracted into the context array with parameter names 'parameter1' etc. when possible. A predefined context array may be passed for convenience.

Deprecated
since 1.42, use StatusFormatter instead.
Returns
array A pair of (message, context) suitable for passing to a PSR-3 logger.

Definition at line 276 of file Status.php.

◆ getStatusValue()

MediaWiki\Status\Status::getStatusValue ( )

Returns the wrapped StatusValue object.

Returns
StatusValue
Since
1.27

Definition at line 196 of file Status.php.

◆ getWarningsArray()

MediaWiki\Status\Status::getWarningsArray ( )

Get the list of warnings (but not errors)

Deprecated
since 1.43 Use ‘->getMessages( 'warning’ )` instead
Returns
array[] A list in which each entry is an array with a message key as its first element. The remaining array elements are the message parameters.

Definition at line 327 of file Status.php.

◆ getWikiText()

MediaWiki\Status\Status::getWikiText ( $shortContext = false,
$longContext = false,
$lang = null )

Get the error list as a wikitext formatted list.

All message parameters that were provided as strings will be escaped with wfEscapeWikiText. This is mostly a historical accident and often undesirable (T368821).

  • To avoid this behavior when producing the Status, pass MessageSpecifier objects to methods such as $status->fatal(), instead of separate key and params parameters.
  • To avoid this behavior when consuming the Status, use the $status->getMessages() method instead, and display each message separately (or combine then with Message::listParams()).

    Deprecated
    since 1.42, use StatusFormatter instead.
Parameters
string | false$shortContextA short enclosing context message name, to be used when there is a single error
string | false$longContextA long enclosing context message name, for a list
string | Language | StubUserLang | null$langLanguage to use for processing messages
Returns
string

Definition at line 218 of file Status.php.

Referenced by MediaWiki\Auth\AuthManager\autoCreateUser().

◆ setMessageLocalizer()

MediaWiki\Status\Status::setMessageLocalizer ( MessageLocalizer $messageLocalizer)

Makes this Status object use the given localizer instead of the global one.

If it is an IContextSource or a ResourceLoader Context, it will also be used to determine the interface language.

Note
This setting does not survive serialization. That's usually for the best (there's no guarantee we'll still have the same localization settings after unserialization); it is the caller's responsibility to set the localizer again if needed.
Parameters
MessageLocalizer$messageLocalizer
Deprecated
since 1.42, use FormatterFactory::getStatusFormatter instead.

Definition at line 137 of file Status.php.

References MediaWiki\Status\Status\$messageLocalizer.

◆ splitByErrorType()

MediaWiki\Status\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 ]

Returns
Status[]

Reimplemented from StatusValue.

Definition at line 170 of file Status.php.

◆ wrap()

static MediaWiki\Status\Status::wrap ( $sv)
static

Succinct helper method to wrap a StatusValue.

This is useful when formatting StatusValue objects:

$this->getOutput()->addHtml( Status::wrap( $sv )->getHTML() );
Parameters
StatusValue | Status$sv
Returns
Status

Definition at line 74 of file Status.php.

Member Data Documentation

◆ $cleanCallback

callable false MediaWiki\Status\Status::$cleanCallback = false

Definition at line 56 of file Status.php.

◆ $messageLocalizer

MessageLocalizer null MediaWiki\Status\Status::$messageLocalizer
protected

Definition at line 59 of file Status.php.

Referenced by MediaWiki\Status\Status\setMessageLocalizer().


The documentation for this class was generated from the following file: