merged master
[lhc/web/wiklou.git] / includes / Message.php
index 7357ed7..86d3609 100644 (file)
@@ -1,4 +1,26 @@
 <?php
+/**
+ * Fetching and processing of interface messages.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ * @author Niklas Laxström
+ */
+
 /**
  * The Message class provides methods which fullfil two basic services:
  *  - fetching interface messages
  * @see https://www.mediawiki.org/wiki/Localisation
  *
  * @since 1.17
- * @author Niklas Laxström
  */
 class Message {
        /**
@@ -181,6 +202,11 @@ class Message {
         */
        protected $title = null;
 
+       /**
+        * Content object representing the message
+        */
+       protected $content = null;
+
        /**
         * @var string
         */
@@ -374,12 +400,32 @@ class Message {
                return $this;
        }
 
+       /**
+        * Returns the message as a Content object.
+        * @return Content
+        */
+       public function content() {
+               if ( !$this->content ) {
+                       $this->content = new MessageContent( $this->key );
+               }
+
+               return $this->content;
+       }
+
        /**
         * Returns the message parsed from wikitext to HTML.
         * @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 +607,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
         *