MediaWiki  master
Status Class Reference

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

Inheritance diagram for Status:
Collaboration diagram for Status:

Public Member Functions

 __get ( $name)
 Backwards compatibility logic. More...
 
 __set ( $name, $value)
 Change operation result Backwards compatibility logic. More...
 
 __sleep ()
 Don't save the callback when serializing, because Closures can't be serialized and we're going to clear it in __wakeup anyway. More...
 
 __wakeup ()
 Sanitize the callback parameter on wakeup, to avoid arbitrary execution. More...
 
 getErrorsArray ()
 Get the list of errors (but not warnings) More...
 
 getHTML ( $shortContext=false, $longContext=false, $lang=null)
 Get the error message as HTML. More...
 
 getMessage ( $shortContext=false, $longContext=false, $lang=null)
 Get a bullet list of the errors as a Message object. More...
 
 getStatusValue ()
 Returns the wrapped StatusValue object. More...
 
 getWarningsArray ()
 Get the list of warnings (but not errors) More...
 
 getWikiText ( $shortContext=false, $longContext=false, $lang=null)
 Get the error list as a wikitext formatted list. More...
 
 splitByErrorType ()
 Splits this Status object into two new Status objects, one which contains only the error messages, and one that contains the warnings, only. More...
 
- Public Member Functions inherited from StatusValue
 __toString ()
 
 error ( $message)
 Add an error, do not set fatal flag This can be used for non-fatal errors. More...
 
 fatal ( $message)
 Add an error and set OK to false, indicating that the operation as a whole was fatal. More...
 
 getErrors ()
 Get the list of errors. More...
 
 getErrorsByType ( $type)
 Returns a list of status messages of the given type. More...
 
 getValue ()
 
 hasMessage ( $message)
 Returns true if the specified message is present as a warning or error. More...
 
 isGood ()
 Returns whether the operation completed and didn't have any error or warnings. More...
 
 isOK ()
 Returns whether the operation completed. More...
 
 merge ( $other, $overwriteValue=false)
 Merge another status object into this one. More...
 
 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. More...
 
 setOK ( $ok)
 Change operation status. More...
 
 setResult ( $ok, $value=null)
 Change operation result. More...
 
 splitByErrorType ()
 Splits this StatusValue object into two new StatusValue objects, one which contains only the error messages, and one that contains the warnings, only. More...
 
 warning ( $message)
 Add a new warning. More...
 

Static Public Member Functions

static wrap ( $sv)
 Succinct helper method to wrap a StatusValue. More...
 
- Static Public Member Functions inherited from StatusValue
static newFatal ( $message)
 Factory function for fatal errors. More...
 
static newGood ( $value=null)
 Factory function for good results. More...
 

Public Attributes

callable false $cleanCallback = false
 
- Public Attributes inherited from StatusValue
int $failCount = 0
 Counter for batch operations. More...
 
bool [] $success = []
 Map of (key => bool) to indicate success of each part of batch operations. More...
 
int $successCount = 0
 Counter for batch operations. More...
 
mixed $value
 

Protected Member Functions

 cleanParams (array $params)
 
 getErrorMessage ( $error, $lang=null)
 Return the message for a single error. More...
 
 getErrorMessageArray ( $errors, $lang=null)
 Return an array with a Message object for each error. More...
 
 getStatusArray ( $type=false)
 Returns a list of status messages of the given type (or all if false) More...
 
 languageFromParam ( $lang)
 

Additional Inherited Members

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

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.

Definition at line 40 of file Status.php.

Member Function Documentation

◆ __get()

Status::__get (   $name)

Backwards compatibility logic.

Parameters
string$name
Returns
mixed
Exceptions
RuntimeException

Definition at line 78 of file Status.php.

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

◆ __set()

Status::__set (   $name,
  $value 
)

Change operation result Backwards compatibility logic.

Parameters
string$name
mixed$value
Exceptions
RuntimeException

Definition at line 97 of file Status.php.

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

◆ __sleep()

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.

Returns
array

Definition at line 391 of file Status.php.

References $keys.

◆ __wakeup()

Status::__wakeup ( )

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

Definition at line 399 of file Status.php.

◆ cleanParams()

Status::cleanParams ( array  $params)
protected
Parameters
array$params
Returns
array

Definition at line 140 of file Status.php.

References $params, and as.

Referenced by getErrorMessage().

◆ getErrorMessage()

Status::getErrorMessage (   $error,
  $lang = null 
)
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.

Parameters
array | string$errorCode string or (key: code string, params: string[]) map
string | Language | null$langLanguage to use for processing messages
Returns
Message

Definition at line 283 of file Status.php.

References $lang, cleanParams(), languageFromParam(), and wfMessage().

Referenced by getErrorMessageArray(), getMessage(), and getWikiText().

◆ getErrorMessageArray()

Status::getErrorMessageArray (   $errors,
  $lang = null 
)
protected

Return an array with a Message object for each error.

Parameters
array$errors
string | Language | null$langLanguage to use for processing messages
Returns
Message[]

Definition at line 328 of file Status.php.

References $e, StatusValue\$errors, $lang, getErrorMessage(), languageFromParam(), and use.

Referenced by getMessage(), and getWikiText().

◆ getErrorsArray()

Status::getErrorsArray ( )

Get the list of errors (but not warnings)

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.
Deprecated:
since 1.25

Definition at line 342 of file Status.php.

References getStatusArray().

Referenced by CliInstaller\showStatusMessage(), and WebInstaller\showStatusMessage().

◆ getHTML()

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

Get the error message as HTML.

This is done by parsing the wikitext error message

Parameters
string | bool$shortContextA short enclosing context message name, to be used when there is a single error
string | bool$longContextA long enclosing context message name, for a list
string | Language | null$langLanguage to use for processing messages
Returns
string

Definition at line 313 of file Status.php.

References $lang, $out, getWikiText(), languageFromParam(), null, and MessageCache\singleton().

Referenced by StatusTest\testGetHtml().

◆ getMessage()

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.

Parameters
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 | null$langLanguage to use for processing messages
Returns
Message

Definition at line 231 of file Status.php.

References $lang, $s, StatusValue\fatal(), getErrorMessage(), getErrorMessageArray(), StatusValue\getErrors(), StatusValue\isOK(), languageFromParam(), and wfMessage().

Referenced by LocalFileLockError\__construct(), BotPassword\loginHook(), MediaWiki\Auth\AbstractPasswordPrimaryAuthenticationProvider\setPasswordResetFlag(), and StatusTest\testGetMessage().

◆ getStatusArray()

Status::getStatusArray (   $type = false)
protected

Returns a list of status messages of the given type (or all if false)

Note
this handles RawMessage poorly
Parameters
string | bool$type
Returns
array

Definition at line 365 of file Status.php.

References $type, as, and StatusValue\getErrors().

Referenced by getErrorsArray(), and getWarningsArray().

◆ getStatusValue()

Status::getStatusValue ( )

Returns the wrapped StatusValue object.

Returns
StatusValue
Since
1.27

Definition at line 132 of file Status.php.

◆ getWarningsArray()

Status::getWarningsArray ( )

Get the list of warnings (but not errors)

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.
Deprecated:
since 1.25

Definition at line 353 of file Status.php.

References getStatusArray().

Referenced by CliInstaller\showStatusMessage(), and WebInstaller\showStatusMessage().

◆ getWikiText()

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

Get the error list as a wikitext formatted list.

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

Definition at line 175 of file Status.php.

References StatusValue\$errors, $lang, $s, as, StatusValue\fatal(), getErrorMessage(), getErrorMessageArray(), StatusValue\getErrors(), StatusValue\isOK(), languageFromParam(), and wfMessage().

Referenced by EditPage\formatStatusErrors(), getHTML(), EditPage\handleStatus(), and StatusTest\testGetWikiText().

◆ languageFromParam()

Status::languageFromParam (   $lang)
protected
Parameters
string | Language | null | StubUserLang$langLanguage to use for processing messages, or null to default to the user language.
Returns
Language|StubUserLang

Definition at line 156 of file Status.php.

References $lang, Language\factory(), RequestContext\getMain(), and null.

Referenced by getErrorMessage(), getErrorMessageArray(), getHTML(), getMessage(), and getWikiText().

◆ splitByErrorType()

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[]

Definition at line 119 of file Status.php.

References $cleanCallback, and list.

◆ wrap()

static Status::wrap (   $sv)
static

Succinct helper method to wrap a StatusValue.

This is is useful when formatting StatusValue objects:

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

Definition at line 55 of file Status.php.

Referenced by LocalFile\acquireFileLock(), MediaWiki\Auth\AuthManager\allowsAuthenticationDataChange(), MediaWiki\Auth\AuthManager\autoCreateUser(), MediaWiki\Auth\AuthManager\beginAccountCreation(), MediaWiki\Auth\AuthManager\beginAccountLink(), MediaWiki\Auth\AuthManager\beginAuthentication(), MediaWiki\Auth\AuthManager\canCreateAccount(), SpecialPasswordReset\checkExecutePermissions(), MediaWiki\Auth\AuthManager\continueAccountCreation(), MediaWiki\Auth\AuthManager\continueAuthentication(), CopyFileBackend\copyFileBatch(), CopyFileBackend\delFileBatch(), AuthManagerSpecialPage\displayForm(), ApiResetPassword\execute(), CurlHttpRequest\execute(), PhpHttpRequest\execute(), GuzzleHttpRequest\execute(), MultiHttpClientTest\getHttpRequest(), ApiUsageException\getMessageObject(), ThumbnailRenderJob\hitThumbUrl(), SpecialPasswordReset\onSubmit(), MediaWiki\Auth\AuthManagerTest\provideAllowsAuthenticationDataChange(), MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProviderTest\provideProviderAllowsAuthenticationDataChange(), MediaWiki\Auth\LocalPasswordPrimaryAuthenticationProviderTest\provideProviderAllowsAuthenticationDataChange(), LocalFile\releaseFileLock(), MediaWiki\Http\HttpRequestFactory\request(), LoginSignupSpecialPage\showSuccessPage(), MediaTransformOutput\streamFileWithStatus(), and AuthManagerSpecialPage\trySubmit().

Member Data Documentation

◆ $cleanCallback

callable false Status::$cleanCallback = false

Definition at line 42 of file Status.php.

Referenced by splitByErrorType().


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