Localisation updates from http://translatewiki.net.
[lhc/web/wiklou.git] / includes / Message.php
index 3c5d5d7..3a87a00 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
  *         ->plain();
  * @endcode
  *
- * @note You cannot parse the text except in the content or interface
- * @note languages
+ * @note You can parse the text only in the content or interface languages
  *
  * @section message_compare_old Comparison with old wfMsg* functions:
  *
  * @see https://www.mediawiki.org/wiki/Localisation
  *
  * @since 1.17
- * @author Niklas Laxström
  */
 class Message {
        /**
@@ -295,6 +315,7 @@ class Message {
        public function setContext( IContextSource $context ) {
                $this->inLanguage( $context->getLanguage() );
                $this->title( $context->getTitle() );
+               $this->interface = true;
 
                return $this;
        }
@@ -341,6 +362,18 @@ class Message {
                return $this;
        }
 
+       /**
+        * Allows manipulating the interface message flag directly.
+        * Can be used to restore the flag after setting a language.
+        * @param $value bool
+        * @return Message: $this
+        * @since 1.20
+        */
+       public function setInterfaceMessageFlag( $value ) {
+               $this->interface = (bool) $value;
+               return $this;
+       }
+
        /**
         * Enable or disable database use.
         * @param $value Boolean
@@ -367,7 +400,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' );
@@ -549,19 +590,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
         *