X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FStatus.php;h=5f5ca7497fea069047fc1a81c580be16c0196e2b;hb=18068472265bffbce73e68073ad5007dd7d70d7f;hp=928f8ebd618b3b7eed41a3ebcced2c2c05847872;hpb=966fb8da62a9439476ada380dfc3c1a2672446ec;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/Status.php b/includes/Status.php index 928f8ebd61..5f5ca7497f 100644 --- a/includes/Status.php +++ b/includes/Status.php @@ -38,16 +38,28 @@ * so that a lack of error-handling will be explicit. */ class Status { - var $ok = true; - var $value; + /** @var bool */ + public $ok = true; + + /** @var mixed */ + public $value; /** Counters for batch operations */ - public $successCount = 0, $failCount = 0; + /** @var int */ + public $successCount = 0; + + /** @var int */ + public $failCount = 0; + /** Array to indicate which items of the batch operations were successful */ + /** @var array */ public $success = array(); - /*semi-private*/ var $errors = array(); - /*semi-private*/ var $cleanCallback = false; + /** @var array */ + public $errors = array(); + + /** @var callable */ + public $cleanCallback = false; /** * Factory function for fatal errors @@ -81,7 +93,7 @@ class Status { * @param $ok Boolean: whether the operation completed * @param $value Mixed */ - function setResult( $ok, $value = null ) { + public function setResult( $ok, $value = null ) { $this->ok = $ok; $this->value = $value; } @@ -92,7 +104,7 @@ class Status { * * @return Boolean */ - function isGood() { + public function isGood() { return $this->ok && !$this->errors; } @@ -101,7 +113,7 @@ class Status { * * @return Boolean */ - function isOK() { + public function isOK() { return $this->ok; } @@ -110,7 +122,7 @@ class Status { * * @param string|Message $message message name or object */ - function warning( $message /*, parameters... */ ) { + public function warning( $message /*, parameters... */ ) { $params = array_slice( func_get_args(), 1 ); $this->errors[] = array( 'type' => 'warning', @@ -124,7 +136,7 @@ class Status { * * @param string|Message $message message name or object */ - function error( $message /*, parameters... */ ) { + public function error( $message /*, parameters... */ ) { $params = array_slice( func_get_args(), 1 ); $this->errors[] = array( 'type' => 'error', @@ -138,7 +150,7 @@ class Status { * * @param string|Message $message message name or object */ - function fatal( $message /*, parameters... */ ) { + public function fatal( $message /*, parameters... */ ) { $params = array_slice( func_get_args(), 1 ); $this->errors[] = array( 'type' => 'error', @@ -150,7 +162,7 @@ class Status { /** * Sanitize the callback parameter on wakeup, to avoid arbitrary execution. */ - function __wakeup() { + public function __wakeup() { $this->cleanCallback = false; } @@ -177,7 +189,7 @@ class Status { * @param string $longContext a long enclosing context message name, for a list * @return String */ - function getWikiText( $shortContext = false, $longContext = false ) { + public function getWikiText( $shortContext = false, $longContext = false ) { if ( count( $this->errors ) == 0 ) { if ( $this->ok ) { $this->fatal( 'internalerror_info', @@ -217,7 +229,7 @@ class Status { * @param string $longContext a long enclosing context message name, for a list * @return Message */ - function getMessage( $shortContext = false, $longContext = false ) { + public function getMessage( $shortContext = false, $longContext = false ) { if ( count( $this->errors ) == 0 ) { if ( $this->ok ) { $this->fatal( 'internalerror_info', @@ -237,7 +249,7 @@ class Status { $s = wfMessage( $longContext, $wrapper ); } } else { - $msgs = $this->getErrorMessageArray( $this->errors ); + $msgs = $this->getErrorMessageArray( $this->errors ); $msgCount = count( $msgs ); if ( $shortContext ) { @@ -314,7 +326,7 @@ class Status { * @param $other Status Other Status object * @param $overwriteValue Boolean: whether to override the "value" member */ - function merge( $other, $overwriteValue = false ) { + public function merge( $other, $overwriteValue = false ) { $this->errors = array_merge( $this->errors, $other->errors ); $this->ok = $this->ok && $other->ok; if ( $overwriteValue ) { @@ -330,7 +342,7 @@ class Status { * @return 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. */ - function getErrorsArray() { + public function getErrorsArray() { return $this->getStatusArray( "error" ); } @@ -340,14 +352,13 @@ class Status { * @return 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. */ - function getWarningsArray() { + public function getWarningsArray() { return $this->getStatusArray( "warning" ); } /** * Returns a list of status messages of the given type * @param $type String - * * @return Array */ protected function getStatusArray( $type ) { @@ -355,7 +366,10 @@ class Status { foreach ( $this->errors as $error ) { if ( $error['type'] === $type ) { if ( $error['message'] instanceof Message ) { - $result[] = array_merge( array( $error['message']->getKey() ), $error['message']->getParams() ); + $result[] = array_merge( + array( $error['message']->getKey() ), + $error['message']->getParams() + ); } elseif ( $error['params'] ) { $result[] = array_merge( array( $error['message'] ), $error['params'] ); } else { @@ -363,6 +377,7 @@ class Status { } } } + return $result; } @@ -393,7 +408,7 @@ class Status { * @param string $msg message name * @return Boolean */ - function hasMessage( $msg ) { + public function hasMessage( $msg ) { foreach ( $this->errors as $error ) { if ( $error['message'] === $msg ) { return true; @@ -413,7 +428,7 @@ class Status { * @param $dest Message|String: Replacement message key or object * @return bool Return true if the replacement was done, false otherwise. */ - function replaceMessage( $source, $dest ) { + public function replaceMessage( $source, $dest ) { $replaced = false; foreach ( $this->errors as $index => $error ) { if ( $error['message'] === $source ) {