Merge "(bug 7851) Implement mediawiki.page.patrol.ajax"
[lhc/web/wiklou.git] / includes / Message.php
index 9d09f00..5a4b810 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
@@ -420,6 +438,15 @@ class Message {
                        return '<' . $key . '>';
                }
 
+               # Replace $* with a list of parameters for &uselang=qqx.
+               if ( strpos( $string, '$*' ) !== false ) {
+                       $paramlist = '';
+                       if ( $this->parameters !== array() ) {
+                               $paramlist = ': $' . implode( ', $', range( 1, count( $this->parameters ) ) );
+                       }
+                       $string = str_replace( '$*', $paramlist, $string );
+               }
+
                # Replace parameters before text parsing
                $string = $this->replaceParameters( $string, 'before' );
 
@@ -591,7 +618,7 @@ class Message {
                } elseif ( !is_array( $param ) ) {
                        return array( 'before', $param );
                } else {
-                       throw new MWException( "Invalid message parameter" );
+                       throw new MWException( "Invalid message parameter: " . serialize( $param ) );
                }
        }
 
@@ -602,7 +629,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;
        }
 
        /**
@@ -618,6 +646,7 @@ class Message {
        /**
         * Wrapper for what ever method we use to get message contents
         * @since 1.17
+        * @throws MWException
         * @return string
         */
        protected function fetchMessage() {