4 * Wrapper allowing us to handle a system message as a Content object. Note that this is generally *not* used
5 * to represent content from the MediaWiki namespace, and that there is no MessageContentHandler. MessageContent
6 * is just intended as glue for wrapping a message programatically.
10 class MessageContent
extends AbstractContent
{
18 * @param Message|String $msg A Message object, or a message key
19 * @param array|null $params An optional array of message parameters
21 public function __construct( $msg, $params = null ) {
22 # XXX: messages may be wikitext, html or plain text! and maybe even something else entirely.
23 parent
::__construct( CONTENT_MODEL_WIKITEXT
);
25 if ( is_string( $msg ) ) {
26 $this->mMessage
= wfMessage( $msg );
28 $this->mMessage
= clone $msg;
32 $this->mMessage
= $this->mMessage
->params( $params );
37 * Returns the message as rendered HTML
39 * @return string The message text, parsed into html
41 public function getHtml() {
42 return $this->mMessage
->parse();
46 * Returns the message as rendered HTML
48 * @return string The message text, parsed into html
50 public function getWikitext() {
51 return $this->mMessage
->text();
55 * Returns the message object, with any parameters already substituted.
57 * @return Message The message object.
59 public function getNativeData() {
60 //NOTE: Message objects are mutable. Cloning here makes MessageContent immutable.
61 return clone $this->mMessage
;
65 * @see Content::getTextForSearchIndex
67 public function getTextForSearchIndex() {
68 return $this->mMessage
->plain();
72 * @see Content::getWikitextForTransclusion
74 public function getWikitextForTransclusion() {
75 return $this->getWikitext();
79 * @see Content::getTextForSummary
81 public function getTextForSummary( $maxlength = 250 ) {
82 return substr( $this->mMessage
->plain(), 0, $maxlength );
86 * @see Content::getSize
90 public function getSize() {
91 return strlen( $this->mMessage
->plain() );
97 * @return Content. A copy of this object
99 public function copy() {
100 // MessageContent is immutable (because getNativeData() returns a clone of the Message object)
105 * @see Content::isCountable
109 public function isCountable( $hasLinks = null ) {
114 * @see Content::getParserOutput
116 * @return ParserOutput
118 public function getParserOutput(
119 Title
$title, $revId = null,
120 ParserOptions
$options = null, $generateHtml = true
123 if ( $generateHtml ) {
124 $html = $this->getHtml();
129 $po = new ParserOutput( $html );