Merge "HTMLForm: Support hide-if for HTMLCheckMatrix"
[lhc/web/wiklou.git] / includes / Message.php
index 4df0d80..93a37cb 100644 (file)
@@ -540,6 +540,30 @@ class Message {
                return $this;
        }
 
+       /**
+        * Add parameters that are plaintext and will be passed through without
+        * the content being evaluated.  Plaintext parameters are not valid as
+        * arguments to parser functions. This differs from self::rawParams in
+        * that the Message class handles escaping to match the output format.
+        *
+        * @since 1.25
+        *
+        * @param string|string[] $param,... plaintext parameters, or a single argument that is
+        * an array of plaintext parameters.
+        *
+        * @return Message $this
+        */
+       public function plaintextParams( /*...*/ ) {
+               $params = func_get_args();
+               if ( isset( $params[0] ) && is_array( $params[0] ) ) {
+                       $params = $params[0];
+               }
+               foreach ( $params as $param ) {
+                       $this->parameters[] = self::plaintextParam( $param );
+               }
+               return $this;
+       }
+
        /**
         * Set the language and the title from a context object
         *
@@ -674,11 +698,10 @@ class Message {
                $string = $this->fetchMessage();
 
                if ( $string === false ) {
-                       $key = htmlspecialchars( $this->key );
-                       if ( $this->format === 'plain' ) {
-                               return '<' . $key . '>';
+                       if ( $this->format === 'plain' || $this->format === 'text' ) {
+                               return '<' . $this->key . '>';
                        }
-                       return '&lt;' . $key . '&gt;';
+                       return '&lt;' . htmlspecialchars( $this->key ) . '&gt;';
                }
 
                # Replace $* with a list of parameters for &uselang=qqx.
@@ -735,10 +758,10 @@ class Message {
                                // Doh! Cause a fatal error after all?
                        }
 
-                       if ( $this->format === 'plain' ) {
+                       if ( $this->format === 'plain' || $this->format === 'text' ) {
                                return '<' . $this->key . '>';
                        }
-                       return '&lt;' . $this->key . '&gt;';
+                       return '&lt;' . htmlspecialchars( $this->key ) . '&gt;';
                }
        }
 
@@ -916,6 +939,17 @@ class Message {
                return array( 'bitrate' => $bitrate );
        }
 
+       /**
+        * @since 1.25
+        *
+        * @param string $plaintext
+        *
+        * @return string[] Array with a single "plaintext" key.
+        */
+       public static function plaintextParam( $plaintext ) {
+               return array( 'plaintext' => $plaintext );
+       }
+
        /**
         * Substitutes any parameters into the message text.
         *
@@ -965,6 +999,8 @@ class Message {
                                return array( 'before', $this->language->formatSize( $param['size'] ) );
                        } elseif ( isset( $param['bitrate'] ) ) {
                                return array( 'before', $this->language->formatBitrate( $param['bitrate'] ) );
+                       } elseif ( isset( $param['plaintext'] ) ) {
+                               return array( 'after', $this->formatPlaintext( $param['plaintext'] ) );
                        } else {
                                $warning = 'Invalid parameter for message "' . $this->getKey() . '": ' .
                                        htmlspecialchars( serialize( $param ) );
@@ -1050,6 +1086,31 @@ class Message {
                return $this->message;
        }
 
+       /**
+        * Formats a message parameter wrapped with 'plaintext'. Ensures that
+        * the entire string is displayed unchanged when displayed in the output
+        * format.
+        *
+        * @since 1.25
+        *
+        * @param string $plaintext String to ensure plaintext output of
+        *
+        * @return string Input plaintext encoded for output to $this->format
+        */
+       protected function formatPlaintext( $plaintext ) {
+               switch ( $this->format ) {
+               case 'text':
+               case 'plain':
+                       return $plaintext;
+
+               case 'parse':
+               case 'block-parse':
+               case 'escaped':
+               default:
+                       return htmlspecialchars( $plaintext, ENT_QUOTES );
+
+               }
+       }
 }
 
 /**