Fix Bug 30681 - Wrong escaping for inexistent messages.
authorSanthosh Thottingal <santhosh.thottingal@gmail.com>
Wed, 28 Mar 2012 05:55:45 +0000 (11:25 +0530)
committerSanthosh Thottingal <santhosh.thottingal@gmail.com>
Wed, 28 Mar 2012 06:02:04 +0000 (11:32 +0530)
- If the message does not exist, do an early return from the toString method, instead of going through replaceParameter and format comparisons.
- Avoid getMessageText method.
- If the format is plain, do not escape the angle brackets.

Change-Id: I4561ee75d991ef8df3399ab17e5d75cb81f63f8f

includes/Message.php

index 7357ed7..96ce7a9 100644 (file)
@@ -379,7 +379,15 @@ class Message {
         * @return String: HTML
         */
        public function toString() {
-               $string = $this->getMessageText();
+               $string = $this->fetchMessage();
+
+               if ( $string === false ) {
+                       $key =  htmlspecialchars( is_array( $this->key ) ? $this->key[0] : $this->key );
+                       if ( $this->format === 'plain' ) {
+                               return '<' . $key . '>';
+                       }
+                       return '&lt;' . $key . '&gt;';
+               }
 
                # Replace parameters before text parsing
                $string = $this->replaceParameters( $string, 'before' );
@@ -561,19 +569,6 @@ class Message {
                return MessageCache::singleton()->transform( $string, $this->interface, $this->language, $this->title );
        }
 
-       /**
-        * Returns the textual value for the message.
-        * @return Message contents or placeholder
-        */
-       protected function getMessageText() {
-               $message = $this->fetchMessage();
-               if ( $message === false ) {
-                       return '&lt;' . htmlspecialchars( is_array($this->key) ? $this->key[0] : $this->key ) . '&gt;';
-               } else {
-                       return $message;
-               }
-       }
-
        /**
         * Wrapper for what ever method we use to get message contents
         *