From b8c3140723d0eb8df0c888ea95976608112c21c7 Mon Sep 17 00:00:00 2001 From: daniel Date: Wed, 17 Jul 2013 19:11:56 +0200 Subject: [PATCH] Return messages in a consistent form from Status objects Also fixes Message::getKey() to always return a string. Rationale: Some code, like RollbackAction, assumes that Status::getErrorArray will return an array of the form ( messagekey, param... ), but this was not the case when a Message object was passed to the Status. This change makes sure Status::getErrorArray will always return arrays of the expected form. This is especially important since the messages in the Status object may be provided by extensions. In order to convert Message objects to arrays of message keys and parameters, Message::getKey() needed to be fixed to return a single key always. Bug: 49338 Change-Id: I0deaa9888e9d86726a8e41ca606c571f56190c91 --- includes/Message.php | 8 +++++++- includes/Status.php | 8 +++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/includes/Message.php b/includes/Message.php index de0b17eeb7..74b4021ba8 100644 --- a/includes/Message.php +++ b/includes/Message.php @@ -234,7 +234,13 @@ class Message { * @return string */ public function getKey() { - return $this->key; + if ( is_array( $this->key ) ) { + // May happen if some kind of fallback is applied. + // For now, just use the first key. We really need a better solution. + return $this->key[0]; + } else { + return $this->key; + } } /** diff --git a/includes/Status.php b/includes/Status.php index f0253df483..7ec1b0f68c 100644 --- a/includes/Status.php +++ b/includes/Status.php @@ -269,7 +269,8 @@ class Status { /** * Get the list of errors (but not warnings) * - * @return Array + * @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() { return $this->getStatusArray( "error" ); @@ -278,7 +279,8 @@ class Status { /** * Get the list of warnings (but not errors) * - * @return Array + * @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() { return $this->getStatusArray( "warning" ); @@ -295,7 +297,7 @@ class Status { foreach ( $this->errors as $error ) { if ( $error['type'] === $type ) { if ( $error['message'] instanceof Message ) { - $result[] = $error['message']; + $result[] = array_merge( array( $error['message']->getKey() ), $error['message']->getParams() ); } elseif ( $error['params'] ) { $result[] = array_merge( array( $error['message'] ), $error['params'] ); } else { -- 2.20.1