MediaWiki  1.34.4
StatusValue Class Reference

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

Inheritance diagram for StatusValue:

Public Member Functions

 __toString ()
 
 error ( $message,... $parameters)
 Add an error, do not set fatal flag This can be used for non-fatal errors. More...
 
 fatal ( $message,... $parameters)
 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,... $parameters)
 Add a new warning. More...
 

Static Public Member Functions

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

Public Attributes

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 Attributes

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

Since
1.25

Definition at line 42 of file StatusValue.php.

Member Function Documentation

◆ __toString()

StatusValue::__toString ( )
Returns
string

Definition at line 305 of file StatusValue.php.

References isOK().

◆ error()

StatusValue::error (   $message,
  $parameters 
)

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

Parameters
string | MessageSpecifier$messageMessage key or object
mixed...$parameters

Definition at line 193 of file StatusValue.php.

Referenced by MediaWiki\Storage\PageUpdater\checkAllRequiredRoles(), MediaWiki\Storage\PageUpdater\checkAllRolesAllowed(), and MediaWiki\Storage\PageUpdater\checkNoRolesRequired().

◆ fatal()

StatusValue::fatal (   $message,
  $parameters 
)

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

Parameters
string | MessageSpecifier$messageMessage key or object
mixed...$parameters

Definition at line 208 of file StatusValue.php.

Referenced by MediaWiki\Storage\PageUpdater\doCreate(), MediaWiki\Storage\PageUpdater\doModify(), SpamBlacklistHooks\filterMergedContent(), Status\getMessage(), Status\getWikiText(), TitleBlacklistHooks\onMovePageCheckPermissions(), and EditPage\runPostMergeFilters().

◆ getErrors()

StatusValue::getErrors ( )

◆ getErrorsByType()

StatusValue::getErrorsByType (   $type)

Returns a list of status messages of the given type.

Each entry is a map of:

  • message: string message key or MessageSpecifier
  • params: array list of parameters
Parameters
string$type
Returns
array[]

Definition at line 243 of file StatusValue.php.

References $type.

Referenced by ApiErrorFormatter_BackCompat\arrayFromStatus(), and ApiBase\dieStatus().

◆ getValue()

StatusValue::getValue ( )

◆ hasMessage()

StatusValue::hasMessage (   $message)

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

Parameters
string | MessageSpecifier$messageMessage key or object to search for
Returns
bool

Definition at line 261 of file StatusValue.php.

Referenced by ApiBase\addBlockInfoToStatus().

◆ isGood()

◆ isOK()

◆ merge()

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

Merge another status object into this one.

Parameters
StatusValue$other
bool$overwriteValueWhether to override the "value" member

Definition at line 223 of file StatusValue.php.

Referenced by LocalFileDeleteBatch\execute(), ScopedLock\factory(), MediaWiki\Storage\PageUpdater\makeNewRevision(), GadgetHooks\onEditFilterMergedContent(), FileOpBatch\runParallelBatches(), SpecialSearch\showResults(), and ScribuntoHooks\validateScript().

◆ newFatal()

static StatusValue::newFatal (   $message,
  $parameters 
)
static

Factory function for fatal errors.

Parameters
string | MessageSpecifier$messageMessage key or object
mixed...$parameters
Returns
static

Definition at line 69 of file StatusValue.php.

Referenced by MWHttpRequest\__construct(), UploadFromChunks\addChunk(), User\addToDatabase(), FileOp\attempt(), SpecialChangeEmail\attemptChange(), MediaWiki\Auth\AuthManager\autoCreateUser(), ChangeTags\canActivateTag(), ChangeTags\canAddTagsAccompanyingChange(), MediaWiki\Auth\AuthManager\canCreateAccount(), ChangeTags\canCreateTag(), ChangeTags\canDeactivateTag(), ChangeTags\canDeleteTag(), ChangeTags\canUpdateTags(), SpecialPageLanguage\changePageLanguage(), MediaWiki\Auth\AuthManager\checkAccountCreatePermissions(), SqliteInstaller\checkDataDir(), ImportReporter\close(), SimpleCaptcha\confirmEmailUser(), UploadBase\convertVerifyErrorToStatus(), SqliteInstaller\createDataDir(), Installer\createSysop(), ApiDelete\delete(), ApiDelete\deleteFile(), SpecialRedirect\dispatchFile(), SpecialRedirect\dispatchLog(), SpecialRedirect\dispatchPage(), SpecialRedirect\dispatchRevision(), SpecialRedirect\dispatchUser(), FileDeleteForm\doDelete(), Installer\doEnvironmentChecks(), SpecialImport\doImport(), WatchAction\doUnwatch(), WikiPage\doUpdateRestrictions(), WatchAction\doWatch(), ApiEmailUser\execute(), ApiImageRotate\execute(), SpecialLinkAccounts\execute(), SpecialUnlinkAccounts\execute(), SpecialChangeCredentials\execute(), PoolCounterWork\execute(), ZipDirectoryReader\execute(), PasswordReset\execute(), CliInstaller\execute(), LoginSignupSpecialPage\execute(), UploadFromUrl\fetchFile(), Article\fetchRevisionRecord(), UserrightsPage\fetchUser(), PoolCounterRedis\getConnection(), Installer\getExtensionInfo(), MediaWiki\Auth\LocalPasswordPrimaryAuthenticationProvider\getPasswordResetData(), WebInstallerExistingWiki\handleExistingUpgrade(), ApiUpload\handleStashException(), EasyDeflate\inflate(), PasswordReset\isAllowed(), ChangeTags\isTagNameValid(), ApiAuthManagerHelper\logAuthenticationResult(), BotPassword\login(), CaptchaPreAuthenticationProvider\makeError(), SqliteInstaller\makeStubDBFile(), DatabaseInstaller\meetsMinimumRequirement(), MovePage\moveFile(), MovePage\moveSubpagesInternal(), FileRepo\newFatal(), User\newFatalPermissionDeniedStatus(), ImportStreamSource\newFromFile(), ImportStreamSource\newFromInterwiki(), ImportStreamSource\newFromUpload(), ImportStreamSource\newFromURL(), FileBackend\newStatus(), ApiUsageException\newWithMessage(), SpecialNewSection\onFormSubmit(), SpecialUnlockdb\onSubmit(), SpecialLockdb\onSubmit(), SpecialRandomInCategory\onSubmit(), RevertAction\onSubmit(), SpecialPageLanguage\onSubmit(), SpecialChangeContentModel\onSubmit(), McrUndoAction\onSubmit(), SpecialExpandTemplates\onSubmitInput(), FormatJson\parse(), ApiUpload\performStash(), UploadBase\performUpload(), DatabaseInstaller\populateInterwikiTable(), MediaWiki\Auth\UserDataAuthenticationRequest\populateUser(), FileOp\precheck(), PoolCounter\precheckAcquire(), AbstractContent\prepareSave(), Installer\readExtension(), UploadFromUrl\reallyFetchFile(), LocalFile\recordUpload2(), PoolCounterRedis\release(), LocalFileMoveBatch\removeNonexistentFiles(), LocalFileRestoreBatch\removeNonexistentFiles(), LocalFileDeleteBatch\removeNonexistentFiles(), ChangeTags\restrictedTagError(), AssembleUploadChunksJob\run(), PublishStashedFileJob\run(), SpecialBotPasswords\save(), MediaWiki\Preferences\DefaultPreferencesFactory\saveFormData(), MediaWiki\Storage\PageUpdater\saveRevision(), UserrightsPage\saveUserGroups(), UserMailer\send(), SpecialEmailUser\sendEmailForm(), UserMailer\sendInternal(), UserMailer\sendWithPear(), User\setEmailWithConfirmation(), SqliteInstaller\setupDatabase(), PostgresInstaller\setupPLpgSQL(), PostgresInstaller\setupSchema(), PostgresInstaller\setupUser(), RevDelList\setVisibility(), MediaTransformOutput\streamFileWithStatus(), WebInstallerDBConnect\submit(), SpecialEmailUser\submit(), SpecialEditTags\submit(), SpecialConfirmEmail\submitSend(), PostgresInstaller\submitSettingsForm(), MysqlInstaller\submitSettingsForm(), DatabaseInstaller\submitWebUserBox(), SpecialLinkAccounts\success(), SpamBlacklistPreAuthenticationProvider\testForAccountCreation(), MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProvider\testForAccountCreation(), MediaWiki\Auth\CheckBlocksSecondaryAuthenticationProvider\testUserForCreation(), TitleBlacklistHooks\testUserName(), ScribuntoException\toStatus(), SpecialUploadStash\tryClearStashedUploads(), UploadFromChunks\tryStashFile(), UploadBase\tryStashFile(), AuthManagerSpecialPage\trySubmit(), PageArchive\undeleteRevisions(), ChangeTags\updateTagsWithChecks(), GadgetDefinitionValidator\validate(), and PoolCounterRedis\waitForSlotOrNotif().

◆ newGood()

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

Factory function for good results.

Parameters
mixed | null$value
Returns
static

Definition at line 81 of file StatusValue.php.

References $value.

Referenced by MWHttpRequest\__construct(), PoolCounterNull\acquireForAnyone(), PoolCounterNull\acquireForMe(), RevDelList\acquireItemLocks(), ChangeTags\activateTagWithChecks(), ChangeTags\addTagsAccompanyingChangeWithChecks(), User\addToDatabase(), MediaWiki\Auth\AuthManager\allowsAuthenticationDataChange(), FileOpBatch\attempt(), FileOp\attempt(), MediaWiki\Auth\AuthManager\autoCreateUser(), ChangeTags\canActivateTag(), ChangeTags\canAddTagsAccompanyingChange(), MediaWiki\Auth\AuthManager\canCreateAccount(), ChangeTags\canCreateTag(), ChangeTags\canDeactivateTag(), ChangeTags\canDeleteTag(), ChangeTags\canUpdateTags(), User\changeAuthenticationData(), SpecialPageLanguage\changePageLanguage(), MWRestrictions\check(), MediaWiki\Auth\AuthManager\checkAccountCreatePermissions(), SqliteInstaller\checkDataDir(), PasswordPolicyChecks\checkMaximalPasswordLength(), PasswordPolicyChecks\checkMinimalPasswordLength(), PasswordPolicyChecks\checkMinimumPasswordLengthToLogin(), PasswordPolicyChecks\checkPasswordCannotMatchBlacklist(), PasswordPolicyChecks\checkPasswordCannotMatchUsername(), PasswordPolicyChecks\checkPasswordNotInLargeBlacklist(), User\checkPasswordValidity(), UserPasswordPolicy\checkPolicies(), PasswordPolicyChecks\checkPopularPasswordBlacklist(), DatabaseInstaller\checkPrerequisites(), LocalRepo\cleanupDeletedBatch(), ImportReporter\close(), FSLockManager\closeLockHandles(), QuorumLockManager\collectPledgeQuorum(), PostgresInstaller\commitChanges(), MediaWiki\Auth\ConfirmLinkSecondaryAuthenticationProvider\continueLinkAttempt(), SqliteInstaller\createDataDir(), Installer\createMainpage(), Installer\createSysop(), ChangeTags\createTagWithChecks(), ChangeTags\deactivateTagWithChecks(), ChangeTags\deleteTagEverywhere(), ApiUpload\dieRecoverableError(), ApiBase\dieStatus(), ApiUpload\dieStatusWithCode(), SpecialRedirect\dispatchFile(), SpecialRedirect\dispatchLog(), SpecialRedirect\dispatchPage(), SpecialRedirect\dispatchRevision(), SpecialRedirect\dispatchUser(), CreateFileOp\doAttempt(), StoreFileOp\doAttempt(), CopyFileOp\doAttempt(), MoveFileOp\doAttempt(), FileOp\doAttempt(), MediaWiki\Storage\PageUpdater\doCreate(), WikiPage\doDeleteArticleBatched(), WikiPage\doDeleteArticleReal(), Installer\doEnvironmentChecks(), Installer\doGenerateKeys(), PostgreSqlLockManager\doGetLocksOnServer(), MySqlLockManager\doGetLocksOnServer(), NullLockManager\doLock(), FSLockManager\doLock(), QuorumLockManager\doLockByType(), LockManager\doLockByType(), NullFileJournal\doLogChangeBatch(), DBFileJournal\doLogChangeBatch(), MediaWiki\Storage\PageUpdater\doModify(), RevDelArchiveList\doPostCommitUpdates(), RevDelFileList\doPostCommitUpdates(), RevDelRevisionList\doPostCommitUpdates(), RevDelList\doPostCommitUpdates(), DescribeFileOp\doPrecheck(), DeleteFileOp\doPrecheck(), CreateFileOp\doPrecheck(), CopyFileOp\doPrecheck(), MoveFileOp\doPrecheck(), StoreFileOp\doPrecheck(), FileOp\doPrecheck(), RevDelArchiveList\doPreCommitUpdates(), RevDelFileList\doPreCommitUpdates(), RevDelRevisionList\doPreCommitUpdates(), RevDelList\doPreCommitUpdates(), NullFileJournal\doPurgeOldLogs(), DBFileJournal\doPurgeOldLogs(), SearchEngine\doSearchArchiveTitle(), FSLockManager\doSingleLock(), FSLockManager\doSingleUnlock(), NullLockManager\doUnlock(), FSLockManager\doUnlock(), QuorumLockManager\doUnlockByType(), LockManager\doUnlockByType(), WatchAction\doUnwatch(), WikiPage\doUpdateRestrictions(), WatchAction\doWatch(), WatchAction\doWatchOrUnwatch(), ApiBase\errorArrayToStatus(), SpecialUnlinkAccounts\execute(), ZipDirectoryReader\execute(), PasswordReset\execute(), CliInstaller\execute(), UploadBase\fetchFile(), Article\fetchRevisionRecord(), UserrightsPage\fetchUser(), Installer\findExtensionsByType(), DBLockManager\freeLocksOnServer(), MemcLockManager\freeLocksOnServer(), RedisLockManager\freeLocksOnServer(), MediaWiki\Storage\SqlBlobStore\getBlobBatch(), ApiUpload\getChunkResult(), PoolCounterRedis\getConnection(), DatabaseInstaller\getConnection(), Installer\getExtensionInfo(), RedisLockManager\getLocksOnServer(), MemcLockManager\getLocksOnServer(), DBLockManager\getLocksOnServer(), PostgresInstaller\getPgConnection(), SpecialUnlinkAccounts\handleFormSubmit(), SpecialChangeCredentials\handleFormSubmit(), AuthManagerSpecialPage\handleFormSubmit(), WebInstallerExistingWiki\importVariables(), Installer\includeExtensions(), EasyDeflate\inflate(), EditPage\internalAttemptSave(), PasswordReset\isAllowed(), ChangeTags\isTagNameValid(), RevDelItem\lock(), ApiAuthManagerHelper\logAuthenticationResult(), FileJournal\logChangeBatch(), BotPassword\login(), LoginSignupSpecialPage\mainLoginForm(), SqliteInstaller\makeStubDBFile(), DatabaseInstaller\meetsMinimumRequirement(), MovePage\moveSubpagesInternal(), MovePage\moveUnsafe(), ImportStreamSource\newFromFile(), ImportStreamSource\newFromURL(), FileRepo\newGood(), FileBackend\newStatus(), SpecialUnlockdb\onSubmit(), SpecialLockdb\onSubmit(), SpecialInterwiki\onSubmit(), SpecialBotPasswords\onSubmit(), McrUndoAction\onSubmit(), SpecialExpandTemplates\onSubmitInput(), MysqlInstaller\openConnection(), SqliteInstaller\openConnection(), PostgresInstaller\openConnectionToAnyDB(), PostgresInstaller\openConnectionWithParams(), FormatJson\parse(), ApiUpload\performUpload(), DatabaseInstaller\populateInterwikiTable(), Installer\populateSiteStats(), MediaWiki\Auth\UserDataAuthenticationRequest\populateUser(), FileOp\precheck(), PoolCounter\precheckAcquire(), FileOp\precheckDestExistence(), AbstractContent\prepareSave(), MediaWiki\Auth\LocalPasswordPrimaryAuthenticationProvider\providerAllowsAuthenticationDataChange(), MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProvider\providerAllowsAuthenticationDataChange(), FSLockManager\pruneKeyLockFiles(), Installer\readExtension(), LocalFile\recordUpload2(), PoolCounterNull\release(), PoolCounterRedis\release(), PostgreSqlLockManager\releaseAllLocks(), MySqlLockManager\releaseAllLocks(), MemcLockManager\releaseAllLocks(), RedisLockManager\releaseAllLocks(), RevDelList\releaseItemLocks(), QuorumLockManager\releasePledges(), LocalFileMoveBatch\removeNonexistentFiles(), LocalFileRestoreBatch\removeNonexistentFiles(), LocalFileDeleteBatch\removeNonexistentFiles(), AssembleUploadChunksJob\run(), PublishStashedFileJob\run(), ApiQueryRevisions\run(), SpecialBotPasswords\save(), MediaWiki\Storage\PageUpdater\saveRevision(), UserrightsPage\saveUserGroups(), UserMailer\send(), UserMailer\sendInternal(), UserMailer\sendWithPear(), User\setEmailWithConfirmation(), WikiImporter\setTargetRootPage(), SqliteInstaller\setupDatabase(), PostgresInstaller\setupDatabase(), PostgresInstaller\setupPLpgSQL(), PostgresInstaller\setupSchema(), MysqlInstaller\setupUser(), PostgresInstaller\setupUser(), RevDelList\setVisibility(), SpecialInterwiki\showForm(), LocalRepo\skipWriteOperationIfSha1(), MediaTransformOutput\streamFileWithStatus(), SpecialEmailUser\submit(), PostgresInstaller\submitConnectForm(), MysqlInstaller\submitConnectForm(), MediaWiki\Preferences\DefaultPreferencesFactory\submitForm(), DatabaseInstaller\submitInstallUserBox(), SpecialConfirmEmail\submitSend(), DatabaseInstaller\submitSettingsForm(), PostgresInstaller\submitSettingsForm(), MysqlInstaller\submitSettingsForm(), DatabaseInstaller\submitWebUserBox(), SyncFileBackend\syncFileBatch(), SpamBlacklistPreAuthenticationProvider\testForAccountCreation(), CaptchaPreAuthenticationProvider\testForAccountCreation(), MediaWiki\Auth\LocalPasswordPrimaryAuthenticationProvider\testForAccountCreation(), MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProvider\testForAccountCreation(), CaptchaPreAuthenticationProvider\testForAuthentication(), TitleBlacklistPreAuthenticationProvider\testUserForCreation(), MediaWiki\Auth\CheckBlocksSecondaryAuthenticationProvider\testUserForCreation(), TitleBlacklistHooks\testUserName(), SpecialUploadStash\tryClearStashedUploads(), UploadBase\tryStashFile(), AuthManagerSpecialPage\trySubmit(), HTMLForm\trySubmit(), PageArchive\undeleteRevisions(), RevDelItem\unlock(), ChangeTags\updateTagsWithChecks(), GadgetDefinitionValidator\validate(), HTMLRestrictionsField\validate(), Scribunto_LuaModule\validate(), SpecialBlock\validateTarget(), MediaHandler\verifyUpload(), and PoolCounterRedis\waitForSlotOrNotif().

◆ replaceMessage()

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.

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

Definition at line 289 of file StatusValue.php.

References $source.

Referenced by ApiBase\addBlockInfoToStatus().

◆ setOK()

StatusValue::setOK (   $ok)

Change operation status.

Parameters
bool$ok

Definition at line 157 of file StatusValue.php.

References $ok.

Referenced by Status\__set(), and ApiBase\dieStatus().

◆ setResult()

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

Change operation result.

Parameters
bool$okWhether the operation completed
mixed | null$value

Definition at line 167 of file StatusValue.php.

References $ok, and $value.

◆ splitByErrorType()

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 ]

Returns
static[]

Reimplemented in Status.

Definition at line 98 of file StatusValue.php.

◆ warning()

StatusValue::warning (   $message,
  $parameters 
)

Add a new warning.

Parameters
string | MessageSpecifier$messageMessage key or object
mixed...$parameters

Definition at line 178 of file StatusValue.php.

Referenced by MediaWiki\Storage\PageUpdater\doModify().

Member Data Documentation

◆ $errors

array [] StatusValue::$errors = []
protected

Definition at line 48 of file StatusValue.php.

Referenced by Status\getErrorMessageArray(), getErrors(), Status\getWikiText(), and isGood().

◆ $failCount

int StatusValue::$failCount = 0

Counter for batch operations.

Definition at line 60 of file StatusValue.php.

◆ $ok

bool StatusValue::$ok = true
protected

Definition at line 45 of file StatusValue.php.

Referenced by isOK(), setOK(), and setResult().

◆ $success

bool [] StatusValue::$success = []

Map of (key => bool) to indicate success of each part of batch operations.

Definition at line 54 of file StatusValue.php.

◆ $successCount

int StatusValue::$successCount = 0

Counter for batch operations.

Definition at line 57 of file StatusValue.php.

◆ $value

mixed StatusValue::$value

Definition at line 51 of file StatusValue.php.

Referenced by Status\__set(), getValue(), newGood(), and setResult().


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