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.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 * http://www.gnu.org/copyleft/gpl.html
28 * @author Daniel Kinzler
30 class MessageContent
extends AbstractContent
{
38 * @param Message|String $msg A Message object, or a message key
39 * @param array|null $params An optional array of message parameters
41 public function __construct( $msg, $params = null ) {
42 # XXX: messages may be wikitext, html or plain text! and maybe even something else entirely.
43 parent
::__construct( CONTENT_MODEL_WIKITEXT
);
45 if ( is_string( $msg ) ) {
46 $this->mMessage
= wfMessage( $msg );
48 $this->mMessage
= clone $msg;
52 $this->mMessage
= $this->mMessage
->params( $params );
57 * Returns the message as rendered HTML
59 * @return string The message text, parsed into html
61 public function getHtml() {
62 return $this->mMessage
->parse();
66 * Returns the message as rendered HTML
68 * @return string The message text, parsed into html
70 public function getWikitext() {
71 return $this->mMessage
->text();
75 * Returns the message object, with any parameters already substituted.
77 * @return Message The message object.
79 public function getNativeData() {
80 //NOTE: Message objects are mutable. Cloning here makes MessageContent immutable.
81 return clone $this->mMessage
;
85 * @see Content::getTextForSearchIndex
87 public function getTextForSearchIndex() {
88 return $this->mMessage
->plain();
92 * @see Content::getWikitextForTransclusion
94 public function getWikitextForTransclusion() {
95 return $this->getWikitext();
99 * @see Content::getTextForSummary
101 public function getTextForSummary( $maxlength = 250 ) {
102 return substr( $this->mMessage
->plain(), 0, $maxlength );
106 * @see Content::getSize
110 public function getSize() {
111 return strlen( $this->mMessage
->plain() );
117 * @return Content. A copy of this object
119 public function copy() {
120 // MessageContent is immutable (because getNativeData() returns a clone of the Message object)
125 * @see Content::isCountable
129 public function isCountable( $hasLinks = null ) {
134 * @see Content::getParserOutput
136 * @return ParserOutput
138 public function getParserOutput(
139 Title
$title, $revId = null,
140 ParserOptions
$options = null, $generateHtml = true
143 if ( $generateHtml ) {
144 $html = $this->getHtml();
149 $po = new ParserOutput( $html );