MediaWiki
REL1_22
|
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 00093 public function getTextForSearchIndex() { 00094 return $this->mMessage->plain(); 00095 } 00096 00100 public function getWikitextForTransclusion() { 00101 return $this->getWikitext(); 00102 } 00103 00107 public function getTextForSummary( $maxlength = 250 ) { 00108 return substr( $this->mMessage->plain(), 0, $maxlength ); 00109 } 00110 00116 public function getSize() { 00117 return strlen( $this->mMessage->plain() ); 00118 } 00119 00125 public function copy() { 00126 // MessageContent is immutable (because getNativeData() returns a clone of the Message object) 00127 return $this; 00128 } 00129 00135 public function isCountable( $hasLinks = null ) { 00136 return false; 00137 } 00138 00144 public function getParserOutput( 00145 Title $title, $revId = null, 00146 ParserOptions $options = null, $generateHtml = true 00147 ) { 00148 00149 if ( $generateHtml ) { 00150 $html = $this->getHtml(); 00151 } else { 00152 $html = ''; 00153 } 00154 00155 $po = new ParserOutput( $html ); 00156 return $po; 00157 } 00158 }