MediaWiki  1.23.6
Status Class Reference

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

Inheritance diagram for Status:

Public Member Functions

 __wakeup ()
 Sanitize the callback parameter on wakeup, to avoid arbitrary execution. More...
 
 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...
 
 getErrorsArray ()
 Get the list of errors (but not warnings) More...
 
 getErrorsByType ( $type)
 Returns a list of status messages of the given type, with message and params left untouched, like a sane version of getStatusArray. More...
 
 getHTML ( $shortContext=false, $longContext=false)
 Get the error message as HTML. More...
 
 getMessage ( $shortContext=false, $longContext=false)
 Get the error list as a Message object. More...
 
 getValue ()
 
 getWarningsArray ()
 Get the list of warnings (but not errors) More...
 
 getWikiText ( $shortContext=false, $longContext=false)
 Get the error list as a wikitext formatted list. More...
 
 hasMessage ( $msg)
 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...
 
 setResult ( $ok, $value=null)
 Change operation result. More...
 
 warning ( $message)
 Add a new warning. More...
 

Static Public Member Functions

static newFatal ( $message)
 Factory function for fatal errors. More...
 
static newGood ( $value=null)
 Factory function for good results. More...
 

Public Attributes

callable $cleanCallback = false
 
array $errors = array()
 
int $failCount = 0
 
bool $ok = true
 
array $success = array()
 Array to indicate which items of the batch operations were successful. More...
 
int $successCount = 0
 Counters for batch operations. More...
 
mixed $value
 

Protected Member Functions

 cleanParams ( $params)
 
 getErrorMessage ( $error)
 Return the message for a single error. More...
 
 getErrorMessageArray ( $errors)
 Return an array with the wikitext for each item in the array. More...
 
 getStatusArray ( $type)
 Returns a list of status messages of the given type. More...
 

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

◆ __wakeup()

Status::__wakeup ( )

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

Definition at line 158 of file Status.php.

Referenced by StatusTest\testWakeUpSanitizesCallback().

◆ cleanParams()

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

Definition at line 166 of file Status.php.

References $params, array(), and as.

Referenced by getErrorMessage().

◆ error()

Status::error (   $message)

Add an error, do not set fatal flag This can be used for non-fatal errors.

Parameters
string | Message$messagemessage name or object

Definition at line 132 of file Status.php.

References $params, array(), and errors.

Referenced by StatusTest\testGetErrorsByType(), and StatusTest\testReplaceMessage().

◆ fatal()

Status::fatal (   $message)

Add an error and set OK to false, indicating that the operation as a whole was fatal.

Parameters
string | Message$messagemessage name or object

Definition at line 146 of file Status.php.

References $params, array(), and errors.

Referenced by getMessage(), FSFileBackend\getResponseCopy(), FSFileBackend\getResponseCreate(), FSFileBackend\getResponseDelete(), FSFileBackend\getResponseMove(), FSFileBackend\getResponseStore(), and getWikiText().

◆ getErrorMessage()

Status::getErrorMessage (   $error)
protected

Return the message for a single error.

Parameters
$errorMixed With an array & two values keyed by 'message' and 'params', use those keys-value pairs. Otherwise, if its an array, just use the first value as the message and the remaining items as the params.
Returns
String

Definition at line 278 of file Status.php.

References $error, cleanParams(), and wfMessage().

Referenced by getMessage(), and getWikiText().

◆ getErrorMessageArray()

Status::getErrorMessageArray (   $errors)
protected

Return an array with the wikitext for each item in the array.

Parameters
$errorsArray
Returns
Array

Definition at line 315 of file Status.php.

References $errors, and array().

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.

Definition at line 341 of file Status.php.

References getStatusArray().

Referenced by WebInstaller\showStatusMessage().

◆ getErrorsByType()

Status::getErrorsByType (   $type)

Returns a list of status messages of the given type, with message and params left untouched, like a sane version of getStatusArray.

Parameters
$typeString
Returns
Array

Definition at line 388 of file Status.php.

References $error, $type, array(), as, and errors.

Referenced by StatusTest\testGetErrorsByType().

◆ getHTML()

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

Get the error message as HTML.

This is done by parsing the wikitext error message.

Parameters
string$shortContexta short enclosing context message name, to be used when there is a single error
string$longContexta long enclosing context message name, for a list
Returns
String

Definition at line 304 of file Status.php.

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

Referenced by StatusTest\testGetHtml().

◆ getMessage()

Status::getMessage (   $shortContext = false,
  $longContext = false 
)

Get the error list as a Message object.

Parameters
string | string[]$shortContextA short enclosing context message name (or an array of message names), to be used when there is a single error.
string | string[]$longContextA long enclosing context message name (or an array of message names), for a list.
Returns
Message

Definition at line 227 of file Status.php.

References $s, errors, fatal(), getErrorMessage(), getErrorMessageArray(), and wfMessage().

Referenced by StatusTest\testGetMessage().

◆ getStatusArray()

Status::getStatusArray (   $type)
protected

Returns a list of status messages of the given type.

Parameters
$typeString
Returns
Array

Definition at line 360 of file Status.php.

References $error, $type, array(), as, and errors.

Referenced by getErrorsArray(), and getWarningsArray().

◆ getValue()

Status::getValue ( )
Returns
mixed

Definition at line 441 of file Status.php.

References $value.

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

Definition at line 351 of file Status.php.

References getStatusArray().

Referenced by WebInstaller\showStatusMessage(), and StatusTest\testGetStatusArrayWithNonObjectMessages().

◆ getWikiText()

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

Get the error list as a wikitext formatted list.

Parameters
string$shortContexta short enclosing context message name, to be used when there is a single error
string$longContexta long enclosing context message name, for a list
Returns
String

Definition at line 185 of file Status.php.

References $error, $errors, $s, as, errors, fatal(), getErrorMessage(), getErrorMessageArray(), and wfMessage().

Referenced by getHTML(), and StatusTest\testGetWikiText().

◆ hasMessage()

Status::hasMessage (   $msg)

Returns true if the specified message is present as a warning or error.

Note, due to the lack of tools for comparing Message objects, this function will not work when using a Message object as a parameter.

Parameters
string$msgmessage name
Returns
Boolean

Definition at line 407 of file Status.php.

References $error, as, and errors.

◆ isGood()

Status::isGood ( )

Returns whether the operation completed and didn't have any error or warnings.

Returns
Boolean

Definition at line 100 of file Status.php.

References $errors.

Referenced by SpecialEmailUser\execute(), LocalFileDeleteBatch\execute(), and HTMLForm\show().

◆ isOK()

Status::isOK ( )

Returns whether the operation completed.

Returns
Boolean

Definition at line 109 of file Status.php.

References $ok.

◆ merge()

Status::merge (   $other,
  $overwriteValue = false 
)

Merge another status object into this one.

Parameters
Status$otherOther Status object
bool$overwriteValueWhether to override the "value" member

Definition at line 325 of file Status.php.

References errors.

Referenced by ScopedLock\factory(), and FileOpBatch\runParallelBatches().

◆ newFatal()

static Status::newFatal (   $message)
static

Factory function for fatal errors.

Parameters
string | Message$messagemessage name or object
Returns
Status

Reimplemented in FileRepoStatus.

Definition at line 63 of file Status.php.

References $params, and array().

Referenced by MWHttpRequest\__construct(), UploadFromChunks\addChunk(), LoginForm\addNewAccountInternal(), User\addToDatabase(), FileOp\attempt(), FileBackend\clean(), ImportReporter\close(), UploadBase\convertVerifyErrorToStatus(), FileBackendStore\createInternal(), Installer\createSysop(), SqliteInstaller\dataDirOKmaybeCreate(), SpecialRedirect\dispatch(), FileDeleteForm\doDelete(), WikiPage\doEditContent(), Installer\doEnvironmentChecks(), SwiftFileBackend\doExecuteOpHandlesInternal(), SpecialImport\doImport(), FileBackend\doOperations(), FileBackend\doQuickOperations(), WatchAction\doUnwatch(), WikiPage\doUpdateRestrictions(), WatchAction\doWatch(), PoolCounterWork\execute(), ZipDirectoryReader\execute(), UploadFromUrl\fetchFile(), UserrightsPage\fetchUser(), PoolCounterRedis\getConnection(), LoginForm\mailPasswordInternal(), User\newFatalPermissionDeniedStatus(), ImportStreamSource\newFromFile(), ImportStreamSource\newFromInterwiki(), ImportStreamSource\newFromUpload(), ImportStreamSource\newFromURL(), SpecialUnlockdb\onSubmit(), SpecialLockdb\onSubmit(), UploadFromUrl\performUpload(), DatabaseInstaller\populateInterwikiTable(), FileOp\precheck(), FileBackend\prepare(), AbstractContent\prepareSave(), FileBackend\publish(), UploadFromUrl\reallyFetchFile(), PoolCounterRedis\release(), AssembleUploadChunksJob\run(), PublishStashedFileJob\run(), FileBackend\secure(), UserMailer\send(), UserMailer\sendWithPear(), User\setEmailWithConfirmation(), SqliteInstaller\setupDatabase(), PostgresInstaller\setupPLpgSQL(), PostgresInstaller\setupSchema(), PostgresInstaller\setupUser(), RevDel_List\setVisibility(), FileBackendStore\storeInternal(), PostgresInstaller\submitConnectForm(), OracleInstaller\submitConnectForm(), MysqlInstaller\submitConnectForm(), MssqlInstaller\submitConnectForm(), PostgresInstaller\submitSettingsForm(), MssqlInstaller\submitSettingsForm(), MysqlInstaller\submitSettingsForm(), DatabaseInstaller\submitWebUserBox(), StatusTest\testNewFatalWithMessage(), StatusTest\testNewFatalWithString(), SpecialUploadStash\tryClearStashedUploads(), Preferences\tryFormSubmit(), PageArchive\undeleteRevisions(), and PoolCounterRedis\waitForSlotOrNotif().

◆ newGood()

static Status::newGood (   $value = null)
static

Factory function for good results.

Parameters
$valueMixed
Returns
Status

Definition at line 77 of file Status.php.

References $value.

Referenced by MWHttpRequest\__construct(), FileBackendMultiWrite\accessibilityCheck(), PoolCounter_Stub\acquireForAnyone(), PoolCounter_Stub\acquireForMe(), SwiftFileBackend\addMissingMetadata(), User\addToDatabase(), FileOpBatch\attempt(), FileOp\attempt(), User\checkPasswordValidity(), SqliteInstaller\checkPrerequisites(), DatabaseInstaller\checkPrerequisites(), ImportReporter\close(), FSLockManager\closeLockHandles(), PostgresInstaller\commitChanges(), FileBackendStore\concatenate(), FileBackendMultiWrite\consistencyCheck(), SwiftFileBackend\createContainer(), Installer\createMainpage(), Installer\createSysop(), SqliteInstaller\dataDirOKmaybeCreate(), SwiftFileBackend\deleteContainer(), FileBackendStore\describeInternal(), FileOp\doAttempt(), CreateFileOp\doAttempt(), StoreFileOp\doAttempt(), CopyFileOp\doAttempt(), MoveFileOp\doAttempt(), FileBackendMultiWrite\doClean(), FileBackendStore\doClean(), FSFileBackend\doCleanInternal(), SwiftFileBackend\doCleanInternal(), FileBackendStore\doCleanInternal(), FileBackendStore\doConcatenate(), MemoryFileBackend\doCopyInternal(), FSFileBackend\doCopyInternal(), SwiftFileBackend\doCopyInternal(), MemoryFileBackend\doCreateInternal(), FSFileBackend\doCreateInternal(), SwiftFileBackend\doCreateInternal(), WikiPage\doDeleteArticleReal(), MemoryFileBackend\doDeleteInternal(), FSFileBackend\doDeleteInternal(), SwiftFileBackend\doDeleteInternal(), FileBackendStore\doDescribeInternal(), SwiftFileBackend\doDescribeInternal(), WikiPage\doEditContent(), Installer\doEnvironmentChecks(), FSFileBackend\doExecuteOpHandlesInternal(), SwiftFileBackend\doExecuteOpHandlesInternal(), MemcLockManager\doFreeLocksOnServer(), Installer\doGenerateKeys(), MemcLockManager\doGetLocksOnServer(), MySqlLockManager\doGetLocksOnServer(), PostgreSqlLockManager\doGetLocksOnServer(), FSLockManager\doLock(), NullLockManager\doLock(), QuorumLockManager\doLockByType(), LockManager\doLockByType(), QuorumLockManager\doLockingRequestBucket(), DBFileJournal\doLogChangeBatch(), NullFileJournal\doLogChangeBatch(), FSFileBackend\doMoveInternal(), SwiftFileBackend\doMoveInternal(), FileBackend\doOperations(), FileBackendMultiWrite\doOperationsInternal(), FileBackendStore\doOperationsInternal(), RevDel_RevisionList\doPostCommitUpdates(), RevDel_List\doPostCommitUpdates(), RevDel_ArchiveList\doPostCommitUpdates(), RevDel_FileList\doPostCommitUpdates(), FileOp\doPrecheck(), CreateFileOp\doPrecheck(), StoreFileOp\doPrecheck(), CopyFileOp\doPrecheck(), MoveFileOp\doPrecheck(), DeleteFileOp\doPrecheck(), DescribeFileOp\doPrecheck(), RevDel_RevisionList\doPreCommitUpdates(), RevDel_List\doPreCommitUpdates(), RevDel_ArchiveList\doPreCommitUpdates(), RevDel_FileList\doPreCommitUpdates(), FileBackendStore\doPrepare(), FileBackendMultiWrite\doPrepare(), FSFileBackend\doPrepareInternal(), FileBackendStore\doPrepareInternal(), SwiftFileBackend\doPrepareInternal(), FileBackendMultiWrite\doPublish(), FileBackendStore\doPublish(), FSFileBackend\doPublishInternal(), FileBackendStore\doPublishInternal(), SwiftFileBackend\doPublishInternal(), DBFileJournal\doPurgeOldLogs(), NullFileJournal\doPurgeOldLogs(), FileBackend\doQuickOperations(), FileBackendMultiWrite\doQuickOperationsInternal(), FileBackendStore\doQuickOperationsInternal(), FileBackendStore\doSecure(), FileBackendMultiWrite\doSecure(), FSFileBackend\doSecureInternal(), FileBackendStore\doSecureInternal(), SwiftFileBackend\doSecureInternal(), FSLockManager\doSingleLock(), FSLockManager\doSingleUnlock(), MemoryFileBackend\doStoreInternal(), FSFileBackend\doStoreInternal(), SwiftFileBackend\doStoreInternal(), MemoryFileBackend\doStreamFile(), FileBackendStore\doStreamFile(), SwiftFileBackend\doStreamFile(), FileBackendTest\doTestLockCalls(), FSLockManager\doUnlock(), NullLockManager\doUnlock(), QuorumLockManager\doUnlockByType(), LockManager\doUnlockByType(), QuorumLockManager\doUnlockingRequestBucket(), WatchAction\doUnwatch(), WikiPage\doUpdateRestrictions(), WatchAction\doWatch(), WatchAction\doWatchOrUnwatch(), ZipDirectoryReader\execute(), UploadFromUrl\fetchFile(), UploadBase\fetchFile(), UserrightsPage\fetchUser(), MemcLockManager\freeLocksOnServer(), DBLockManager\freeLocksOnServer(), RedisLockManager\freeLocksOnServer(), ApiUpload\getChunkResult(), PoolCounterRedis\getConnection(), DatabaseInstaller\getConnection(), RedisLockManager\getLocksOnServer(), MemcLockManager\getLocksOnServer(), DBLockManager\getLocksOnServer(), PostgresInstaller\getPgConnection(), Installer\includeExtensions(), LoginForm\initUser(), LockManager\lockByType(), FileJournal\logChangeBatch(), ImportStreamSource\newFromFile(), ImportStreamSource\newFromURL(), FileBackendStore\nullInternal(), SwiftFileBackend\objectListing(), SpecialUnlockdb\onSubmit(), SpecialLockdb\onSubmit(), MysqlInstaller\openConnection(), OracleInstaller\openConnection(), SqliteInstaller\openConnection(), MssqlInstaller\openConnection(), PostgresInstaller\openConnectionToAnyDB(), PostgresInstaller\openConnectionWithParams(), OracleInstaller\openSYSDBAConnection(), ApiUpload\performUpload(), DatabaseInstaller\populateInterwikiTable(), Installer\populateSiteStats(), FileOp\precheckDestExistence(), AbstractContent\prepareSave(), FSLockManager\pruneKeyLockFiles(), PoolCounterRedis\release(), PoolCounter_Stub\release(), RedisLockManager\releaseAllLocks(), MemcLockManager\releaseAllLocks(), MySqlLockManager\releaseAllLocks(), PostgreSqlLockManager\releaseAllLocks(), FileBackendMultiWrite\resyncFiles(), AssembleUploadChunksJob\run(), PublishStashedFileJob\run(), UserMailer\send(), UserMailer\sendWithPear(), SwiftFileBackend\setContainerAccess(), User\setEmailWithConfirmation(), WikiImporter\setTargetRootPage(), OracleInstaller\setupDatabase(), PostgresInstaller\setupDatabase(), PostgresInstaller\setupPLpgSQL(), PostgresInstaller\setupSchema(), OracleInstaller\setupUser(), MssqlInstaller\setupUser(), MysqlInstaller\setupUser(), PostgresInstaller\setupUser(), RevDel_List\setVisibility(), FileBackendStore\streamFile(), PostgresInstaller\submitConnectForm(), OracleInstaller\submitConnectForm(), MysqlInstaller\submitConnectForm(), MssqlInstaller\submitConnectForm(), OracleInstaller\submitInstallUserBox(), DatabaseInstaller\submitInstallUserBox(), DatabaseInstaller\submitSettingsForm(), PostgresInstaller\submitSettingsForm(), MssqlInstaller\submitSettingsForm(), MysqlInstaller\submitSettingsForm(), DatabaseInstaller\submitWebUserBox(), SyncFileBackend\syncFileBatch(), StatusTest\testNewGood(), SpecialUploadStash\tryClearStashedUploads(), Preferences\tryUISubmit(), PageArchive\undeleteRevisions(), SpecialBlock\validateTarget(), MediaHandler\verifyUpload(), and PoolCounterRedis\waitForSlotOrNotif().

◆ replaceMessage()

Status::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 Message objects, this function will not work when using a Message object as the search parameter.

Parameters
Message | string$sourceMessage key or object to search for
Message | string$destReplacement message key or object
Returns
bool Return true if the replacement was done, false otherwise.

Definition at line 427 of file Status.php.

References $error, $source, as, and errors.

Referenced by StatusTest\testReplaceMessage().

◆ setResult()

Status::setResult (   $ok,
  $value = null 
)

Change operation result.

Parameters
bool$okWhether the operation completed
mixed$value

Definition at line 89 of file Status.php.

References $ok, and $value.

◆ warning()

Status::warning (   $message)

Add a new warning.

Parameters
string | Message$messagemessage name or object

Definition at line 118 of file Status.php.

References $params, array(), and errors.

Referenced by StatusTest\provideGetMessage(), StatusTest\testGetErrorsByType(), and StatusTest\testGetStatusArrayWithNonObjectMessages().

Member Data Documentation

◆ $cleanCallback

callable Status::$cleanCallback = false

Definition at line 55 of file Status.php.

◆ $errors

array Status::$errors = array()

Definition at line 53 of file Status.php.

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

◆ $failCount

int Status::$failCount = 0

Definition at line 48 of file Status.php.

◆ $ok

bool Status::$ok = true

Definition at line 41 of file Status.php.

Referenced by isOK(), and setResult().

◆ $success

array Status::$success = array()

Array to indicate which items of the batch operations were successful.

Definition at line 51 of file Status.php.

◆ $successCount

int Status::$successCount = 0

Counters for batch operations.

Definition at line 46 of file Status.php.

◆ $value

mixed Status::$value

Definition at line 43 of file Status.php.

Referenced by getValue(), FileRepoStatus\newGood(), newGood(), and setResult().


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