<?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 {
/**
public function setContext( IContextSource $context ) {
$this->inLanguage( $context->getLanguage() );
$this->title( $context->getTitle() );
+ $this->interface = true;
return $this;
}
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
* @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 '<' . $key . '>';
+ }
# Replace parameters before text parsing
$string = $this->replaceParameters( $string, 'before' );
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 '<' . htmlspecialchars( is_array($this->key) ? $this->key[0] : $this->key ) . '>';
- } else {
- return $message;
- }
- }
-
/**
* Wrapper for what ever method we use to get message contents
*