MediaWiki  REL1_24
MessageContent.php
Go to the documentation of this file.
00001 <?php
00036 class MessageContent extends AbstractContent {
00037 
00041     protected $mMessage;
00042 
00047     public function __construct( $msg, $params = null ) {
00048         # XXX: messages may be wikitext, html or plain text! and maybe even something else entirely.
00049         parent::__construct( CONTENT_MODEL_WIKITEXT );
00050 
00051         if ( is_string( $msg ) ) {
00052             $this->mMessage = wfMessage( $msg );
00053         } else {
00054             $this->mMessage = clone $msg;
00055         }
00056 
00057         if ( $params ) {
00058             $this->mMessage = $this->mMessage->params( $params );
00059         }
00060     }
00061 
00067     public function getHtml() {
00068         return $this->mMessage->parse();
00069     }
00070 
00076     public function getWikitext() {
00077         return $this->mMessage->text();
00078     }
00079 
00085     public function getNativeData() {
00086         //NOTE: Message objects are mutable. Cloning here makes MessageContent immutable.
00087         return clone $this->mMessage;
00088     }
00089 
00095     public function getTextForSearchIndex() {
00096         return $this->mMessage->plain();
00097     }
00098 
00104     public function getWikitextForTransclusion() {
00105         return $this->getWikitext();
00106     }
00107 
00115     public function getTextForSummary( $maxlength = 250 ) {
00116         return substr( $this->mMessage->plain(), 0, $maxlength );
00117     }
00118 
00124     public function getSize() {
00125         return strlen( $this->mMessage->plain() );
00126     }
00127 
00133     public function copy() {
00134         // MessageContent is immutable (because getNativeData() returns a clone of the Message object)
00135         return $this;
00136     }
00137 
00145     public function isCountable( $hasLinks = null ) {
00146         return false;
00147     }
00148 
00159     public function getParserOutput( Title $title, $revId = null,
00160         ParserOptions $options = null, $generateHtml = true ) {
00161         if ( $generateHtml ) {
00162             $html = $this->getHtml();
00163         } else {
00164             $html = '';
00165         }
00166 
00167         $po = new ParserOutput( $html );
00168         // Message objects are in the user language.
00169         $po->recordOption( 'userlang' );
00170 
00171         return $po;
00172     }
00173 
00174 }