Localisation updates from http://translatewiki.net.
[lhc/web/wiklou.git] / includes / Message.php
index 87b53aa..976f144 100644 (file)
@@ -202,6 +202,11 @@ class Message {
         */
        protected $title = null;
 
+       /**
+        * Content object representing the message
+        */
+       protected $content = null;
+
        /**
         * @var string
         */
@@ -332,6 +337,7 @@ class Message {
         * turned off.
         * @since 1.17
         * @param $lang Mixed: language code or Language object.
+        * @throws MWException
         * @return Message: $this
         */
        public function inLanguage( $lang ) {
@@ -404,6 +410,18 @@ 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.
         * @since 1.17
@@ -588,7 +606,6 @@ class Message {
         * @since 1.18
         * @param $param String|Array: Parameter as defined in this class.
         * @return Tuple(type, value)
-        * @throws MWException
         */
        protected function extractParam( $param ) {
                if ( is_array( $param ) && isset( $param['raw'] ) ) {
@@ -600,7 +617,11 @@ class Message {
                } elseif ( !is_array( $param ) ) {
                        return array( 'before', $param );
                } else {
-                       throw new MWException( "Invalid message parameter" );
+                       trigger_error(
+                               "Invalid message parameter: " . htmlspecialchars( serialize( $param ) ),
+                               E_USER_WARNING
+                       );
+                       return array( 'before', '[INVALID]' );
                }
        }
 
@@ -611,7 +632,8 @@ class Message {
         * @return string Wikitext parsed into HTML
         */
        protected function parseText( $string ) {
-               return MessageCache::singleton()->parse( $string, $this->title, /*linestart*/true, $this->interface, $this->language )->getText();
+               $out = MessageCache::singleton()->parse( $string, $this->title, /*linestart*/true, $this->interface, $this->language );
+               return is_object( $out ) ? $out->getText() : $out;
        }
 
        /**
@@ -627,6 +649,7 @@ class Message {
        /**
         * Wrapper for what ever method we use to get message contents
         * @since 1.17
+        * @throws MWException
         * @return string
         */
        protected function fetchMessage() {
@@ -651,3 +674,45 @@ class Message {
        }
 
 }
+
+/**
+ * Variant of the Message class.
+ *
+ * Rather than treating the message key as a lookup
+ * value (which is passed to the MessageCache and
+ * translated as necessary), a RawMessage key is
+ * treated as the actual message.
+ *
+ * All other functionality (parsing, escaping, etc.)
+ * is preserved.
+ *
+ * @since 1.21
+ */
+class RawMessage extends Message {
+       /**
+        * Call the parent constructor, then store the key as
+        * the message.
+        *
+        * @param $key Message to use
+        * @param $params Parameters for the message
+        * @see Message::__construct
+        */
+       public function __construct( $key, $params = array() ) {
+               parent::__construct( $key, $params );
+               // The key is the message.
+               $this->message = $key;
+       }
+
+       /**
+        * Fetch the message (in this case, the key).
+        *
+        * @return string
+        */
+       public function fetchMessage() {
+               // Just in case the message is unset somewhere.
+               if( !isset( $this->message ) ) {
+                       $this->message = $this->key;
+               }
+               return $this->message;
+       }
+}