MediaWiki
master
|
00001 <?php 00002 00030 class MessageContent extends AbstractContent { 00031 00035 protected $mMessage; 00036 00041 public function __construct( $msg, $params = null ) { 00042 # XXX: messages may be wikitext, html or plain text! and maybe even something else entirely. 00043 parent::__construct( CONTENT_MODEL_WIKITEXT ); 00044 00045 if ( is_string( $msg ) ) { 00046 $this->mMessage = wfMessage( $msg ); 00047 } else { 00048 $this->mMessage = clone $msg; 00049 } 00050 00051 if ( $params ) { 00052 $this->mMessage = $this->mMessage->params( $params ); 00053 } 00054 } 00055 00061 public function getHtml() { 00062 return $this->mMessage->parse(); 00063 } 00064 00070 public function getWikitext() { 00071 return $this->mMessage->text(); 00072 } 00073 00079 public function getNativeData() { 00080 //NOTE: Message objects are mutable. Cloning here makes MessageContent immutable. 00081 return clone $this->mMessage; 00082 } 00083 00087 public function getTextForSearchIndex() { 00088 return $this->mMessage->plain(); 00089 } 00090 00094 public function getWikitextForTransclusion() { 00095 return $this->getWikitext(); 00096 } 00097 00101 public function getTextForSummary( $maxlength = 250 ) { 00102 return substr( $this->mMessage->plain(), 0, $maxlength ); 00103 } 00104 00110 public function getSize() { 00111 return strlen( $this->mMessage->plain() ); 00112 } 00113 00119 public function copy() { 00120 // MessageContent is immutable (because getNativeData() returns a clone of the Message object) 00121 return $this; 00122 } 00123 00129 public function isCountable( $hasLinks = null ) { 00130 return false; 00131 } 00132 00138 public function getParserOutput( 00139 Title $title, $revId = null, 00140 ParserOptions $options = null, $generateHtml = true 00141 ) { 00142 00143 if ( $generateHtml ) { 00144 $html = $this->getHtml(); 00145 } else { 00146 $html = ''; 00147 } 00148 00149 $po = new ParserOutput( $html ); 00150 return $po; 00151 } 00152 }