Add release note for Ieec65c90
[mediawiki.git] / includes / content / MessageContent.php
blobd38355d107a063894f85ec768b7861373e53c0ac
1 <?php
3 /**
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
23 * @since 1.21
25 * @file
26 * @ingroup Content
28 * @author Daniel Kinzler
30 class MessageContent extends AbstractContent {
32 /**
33 * @var Message
35 protected $mMessage;
37 /**
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 );
47 } else {
48 $this->mMessage = clone $msg;
51 if ( $params ) {
52 $this->mMessage = $this->mMessage->params( $params );
56 /**
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();
65 /**
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();
74 /**
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;
84 /**
85 * @see Content::getTextForSearchIndex
87 public function getTextForSearchIndex() {
88 return $this->mMessage->plain();
91 /**
92 * @see Content::getWikitextForTransclusion
94 public function getWikitextForTransclusion() {
95 return $this->getWikitext();
98 /**
99 * @see Content::getTextForSummary
101 public function getTextForSummary( $maxlength = 250 ) {
102 return substr( $this->mMessage->plain(), 0, $maxlength );
106 * @see Content::getSize
108 * @return int
110 public function getSize() {
111 return strlen( $this->mMessage->plain() );
115 * @see Content::copy
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)
121 return $this;
125 * @see Content::isCountable
127 * @return bool false
129 public function isCountable( $hasLinks = null ) {
130 return false;
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();
145 } else {
146 $html = '';
149 $po = new ParserOutput( $html );
150 return $po;