3 * Wrapper content object allowing to handle a system message as a Content object.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
25 * @author Daniel Kinzler
29 * Wrapper allowing us to handle a system message as a Content object.
30 * Note that this is generally *not* used to represent content from the
31 * MediaWiki namespace, and that there is no MessageContentHandler.
32 * MessageContent is just intended as glue for wrapping a message programatically.
36 class MessageContent
extends AbstractContent
{
44 * @param Message|String $msg A Message object, or a message key
45 * @param array|null $params An optional array of message parameters
47 public function __construct( $msg, $params = null ) {
48 # XXX: messages may be wikitext, html or plain text! and maybe even something else entirely.
49 parent
::__construct( CONTENT_MODEL_WIKITEXT
);
51 if ( is_string( $msg ) ) {
52 $this->mMessage
= wfMessage( $msg );
54 $this->mMessage
= clone $msg;
58 $this->mMessage
= $this->mMessage
->params( $params );
63 * Returns the message as rendered HTML
65 * @return string The message text, parsed into html
67 public function getHtml() {
68 return $this->mMessage
->parse();
72 * Returns the message as rendered HTML
74 * @return string The message text, parsed into html
76 public function getWikitext() {
77 return $this->mMessage
->text();
81 * Returns the message object, with any parameters already substituted.
83 * @return Message The message object.
85 public function getNativeData() {
86 //NOTE: Message objects are mutable. Cloning here makes MessageContent immutable.
87 return clone $this->mMessage
;
91 * @see Content::getTextForSearchIndex
93 public function getTextForSearchIndex() {
94 return $this->mMessage
->plain();
98 * @see Content::getWikitextForTransclusion
100 public function getWikitextForTransclusion() {
101 return $this->getWikitext();
105 * @see Content::getTextForSummary
107 public function getTextForSummary( $maxlength = 250 ) {
108 return substr( $this->mMessage
->plain(), 0, $maxlength );
112 * @see Content::getSize
116 public function getSize() {
117 return strlen( $this->mMessage
->plain() );
123 * @return Content. A copy of this object
125 public function copy() {
126 // MessageContent is immutable (because getNativeData() returns a clone of the Message object)
131 * @see Content::isCountable
135 public function isCountable( $hasLinks = null ) {
140 * @see Content::getParserOutput
142 * @return ParserOutput
144 public function getParserOutput(
145 Title
$title, $revId = null,
146 ParserOptions
$options = null, $generateHtml = true
149 if ( $generateHtml ) {
150 $html = $this->getHtml();
155 $po = new ParserOutput( $html );