* $button = Xml::button( wfMessage( 'submit' )->text() );
* </pre>
* Messages can have parameters:
- * wfMessage( 'welcome-to' )->params( $wgSitename )->text();
+ * wfMessage( 'welcome-to' )->params( $wgSitename )->text();
* {{GRAMMAR}} and friends work correctly
* wfMessage( 'are-friends', $user, $friend );
* wfMessage( 'bad-message' )->rawParams( '<script>...</script>' )->escaped();
* $escaped = wfMessage( 'key' )->rawParams( 'apple' )->escaped();
* </pre>
*
- * TODO:
+ * @todo
* - test, can we have tests?
- * - sort out the details marked with fixme
*
* @since 1.17
* @author Niklas Laxström
* means the current interface language, false content language.
*/
protected $interface = true;
-
+
/**
* In which language to get this message. Overrides the $interface
* variable.
* @var Language
*/
protected $language = null;
-
+
/**
* The message key.
*/
*/
protected $title = null;
+ /**
+ * @var string
+ */
+ protected $message;
+
/**
* Constructor.
* @param $key: message key, or array of message keys to try and use the first non-empty message for
}
return $this;
}
-
+
/**
* Add parameters that are numeric and will be passed through
* Language::formatNum before substitution
}
return $this;
}
-
+
/**
* Request the message in any language that is supported.
* As a side effect interface message status is unconditionally
* @return Message: $this
*/
public function inLanguage( $lang ) {
- if ( $lang instanceof Language || $lang instanceof StubContLang || $lang instanceof StubUserLang ) {
+ if ( $lang instanceof Language || $lang instanceof StubUserLang ) {
$this->language = $lang;
} elseif ( is_string( $lang ) ) {
if( $this->language->getCode() != $lang ) {
} else {
$type = gettype( $lang );
throw new MWException( __METHOD__ . " must be "
- . "passed a String or Language object; $type given"
+ . "passed a String or Language object; $type given"
);
}
$this->interface = false;
}
/**
- * Request the message in the wiki's content language.
+ * Request the message in the wiki's content language,
+ * unless it is disabled for this message.
+ * @see $wgForceUIMsgAsContentMsg
* @return Message: $this
*/
public function inContentLanguage() {
+ global $wgForceUIMsgAsContentMsg;
+ if ( in_array( $this->key, (array)$wgForceUIMsgAsContentMsg ) ) {
+ return $this;
+ }
+
global $wgContLang;
$this->interface = false;
$this->language = $wgContLang;
*/
public function toString() {
$string = $this->getMessageText();
-
+
# Replace parameters before text parsing
$string = $this->replaceParameters( $string, 'before' );
-
+
# Maybe transform using the full parser
if( $this->format === 'parse' ) {
$string = $this->parseText( $string );
} elseif( $this->format === 'text' ){
$string = $this->transformText( $string );
} elseif( $this->format === 'escaped' ){
- # FIXME: Sanitizer method here?
$string = $this->transformText( $string );
- $string = htmlspecialchars( $string );
+ $string = htmlspecialchars( $string, ENT_QUOTES, 'UTF-8', false );
}
-
+
# Raw parameter replacement
$string = $this->replaceParameters( $string, 'after' );
-
+
return $string;
}
public function __toString() {
return $this->toString();
}
-
+
/**
* Fully parse the text from wikitext to HTML
* @return String parsed HTML
/**
* Check whether a message does not exist, or is an empty string
* @return Bool: true if is is and false if not
- * @todo Merge with isDisabled()?
+ * @todo FIXME: Merge with isDisabled()?
*/
public function isBlank() {
$message = $this->fetchMessage();
* @return string Wikitext parsed into HTML
*/
protected function parseText( $string ) {
- return MessageCache::singleton()->parse( $string, /*linestart*/true, $this->interface, $this->language );
+ return MessageCache::singleton()->parse( $string, $this->title, /*linestart*/true, $this->interface, $this->language )->getText();
}
/**