Merge "registration: Support 'ServiceWiringFiles' in extension.json"
[lhc/web/wiklou.git] / includes / Status.php
index f8370e4..a6348b7 100644 (file)
@@ -105,6 +105,26 @@ class Status {
                return new self( $sv );
        }
 
+       /**
+        * 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:
+        * array(
+        *      0 => object(Status) # the Status with error messages, only
+        *      1 => object(Status) # The Status with warning messages, only
+        * )
+        *
+        * @return array
+        */
+       public function splitByErrorType() {
+               list( $errorsOnlyStatusValue, $warningsOnlyStatusValue ) = $this->sv->splitByErrorType();
+               $errorsOnlyStatus = new Status( $errorsOnlyStatusValue );
+               $warningsOnlyStatus = new Status( $warningsOnlyStatusValue );
+               $errorsOnlyStatus->cleanCallback = $warningsOnlyStatus->cleanCallback = $this->cleanCallback;
+
+               return [ $errorsOnlyStatus, $warningsOnlyStatus ];
+       }
+
        /**
         * Change operation result
         *
@@ -118,6 +138,7 @@ class Status {
        /**
         * Returns the wrapped StatusValue object
         * @return StatusValue
+        * @since 1.27
         */
        public function getStatusValue() {
                return $this->sv;
@@ -250,12 +271,22 @@ class Status {
        }
 
        /**
-        * Get the error list as a Message object
+        * Get a bullet list of the errors as a Message object.
         *
-        * @param string|string[] $shortContext A short enclosing context message name (or an array of
-        * message names), to be used when there is a single error.
-        * @param string|string[] $longContext A long enclosing context message name (or an array of
-        * message names), for a list.
+        * $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.
+        *
+        * @param string|string[] $shortContext A message name or an array of message names.
+        * @param string|string[] $longContext A message name or an array of message names.
         * @param string|Language $lang Language to use for processing messages
         * @return Message
         */
@@ -286,10 +317,6 @@ class Status {
                        $msgs = $this->getErrorMessageArray( $rawErrors, $lang );
                        $msgCount = count( $msgs );
 
-                       if ( $shortContext ) {
-                               $msgCount++;
-                       }
-
                        $s = new RawMessage( '* $' . implode( "\n* \$", range( 1, $msgCount ) ) );
                        $s->params( $msgs )->parse();
 
@@ -307,6 +334,7 @@ class Status {
 
        /**
         * Return the message for a single error.
+        *
         * @param mixed $error 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
@@ -378,7 +406,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.
-        * @deprecated 1.25
+        * @deprecated since 1.25
         */
        public function getErrorsArray() {
                return $this->getStatusArray( 'error' );
@@ -389,7 +417,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.
-        * @deprecated 1.25
+        * @deprecated since 1.25
         */
        public function getWarningsArray() {
                return $this->getStatusArray( 'warning' );