4 * A content object represents page content, e.g. the text to show on a page.
7 abstract class Content
{
9 public function __construct( Title
$title, $revId, $modelName ) { #FIXME: really need revId? annoying! #FIXME: really $title? or just when parsing, every time?
10 $this->mModelName
= $modelName;
11 $this->mTitle
= $title;
12 $this->mRevId
= $revId;
15 public function getModelName() {
16 return $this->mModelName
;
19 public function getTitle() {
23 public function getRevId() {
27 public abstract function getSearchText( $obj );
29 public abstract function getWikitextForTransclusion( $obj );
31 public abstract function getParserOutput( ParserOptions
$options = NULL );
33 public abstract function getRawData( );
35 public function getHtml( ParserOptions
$options ) {
36 $po = $this->getParserOutput( $options );
37 return $po->getText();
40 public function getIndexUpdateJobs( ParserOptions
$options , $recursive = true ) {
41 $po = $this->getParserOutput( $options );
42 $update = new LinksUpdate( $this->mTitle
, $po, $recursive );
46 public function getRedirectChain() {
50 public function getSection( $section ) { #FIXME: should this return text? or a Content object? or what??
54 #XXX: is the native model for wikitext a string or the parser output? parse early or parse late?
57 class TextContent
extends Content
{
58 public function __construct( $text, Title
$title, $revId, $modelName ) {
59 parent
::__construct($title, $revId, $modelName);
64 public function getSearchText( $obj ) {
65 return $this->getRawData();
68 public function getWikitextForTransclusion( $obj ) {
69 return $this->getRawData();
73 public function getParserOutput( ParserOptions
$options = null ) {
74 # generic implementation, relying on $this->getHtml()
76 $html = $this->getHtml( $options );
77 $po = new ParserOutput( $html );
79 if ( $this->mTitle
) $po->setTitleText( $this->mTitle
->getText() );
81 #TODO: cache settings, etc?
86 public function getHtml( ParserOptions
$options ) {
88 $html .= "<pre class=\"mw-code\" dir=\"ltr\">\n";
89 $html .= htmlspecialchars( $this->getRawData() );
90 $html .= "\n</pre>\n";
96 public function getRawData( ) {
101 public function getRedirectChain() {
102 #XXX: really do this for all text, or just in WikitextContent
103 $text = $this->getRawData();
104 return Title
::newFromRedirectArray( $text );
108 class WikitextContent
extends TextContent
{
109 public function __construct( $text, Title
$title, $revId = null) {
110 parent
::__construct($text, $title, $revId, CONTENT_MODEL_WIKITEXT
);
112 $this->mDefaultParserOptions
= null;
115 public function getDefaultParserOptions() {
116 global $wgUser, $wgContLang;
118 if ( !$this->mDefaultParserOptions
) {
119 #TODO: use static member?!
120 $this->mDefaultParserOptions
= ParserOptions
::newFromUserAndLang( $wgUser, $wgContLang );
123 return $this->mDefaultParserOptions
;
126 public function getParserOutput( ParserOptions
$options = null ) {
129 #TODO: quick local cache: if $options is NULL, use ->mParserOutput!
130 #FIXME: need setParserOutput, so we can use stuff from the parser cache??
131 #FIXME: ...or we somehow need to know the parser cache key??
134 $options = $this->getDefaultParserOptions();
137 $po = $wgParser->parse( $this->mText
, $this->getTitle(), $options, true, true, $this->mRevId
);
142 public function getSection( $section ) {
145 $text = $this->getRawData();
146 return $wgParser->getSection( $text, $section, false );
151 class MessageContent
extends TextContent
{
152 public function __construct( $msg_key, $params = null, $options = null ) {
153 parent
::__construct(null, null, null, CONTENT_MODEL_WIKITEXT
);
155 $this->mMessageKey
= $msg_key;
157 $this->mParameters
= $params;
159 if ( !$options ) $options = array();
160 $this->mOptions
= $options;
162 $this->mHtmlOptions
= null;
166 public function getHtml( ParserOptions
$options ) {
167 $opt = array_merge( $this->mOptions
, array('parse') );
168 return wfMsgExt( $this->mMessageKey
, $this->mParameters
, $opt );
172 public function getRawData( ) {
173 $opt = array_diff( $this->mOptions
, array('parse', 'parseinline') );
175 return wfMsgExt( $this->mMessageKey
, $this->mParameters
, $opt );
181 class JavaScriptContent
extends TextContent
{
182 public function __construct( $text, Title
$title, $revId = null ) {
183 parent
::__construct($text, $title, $revId, CONTENT_MODEL_JAVASCRIPT
);
186 public function getHtml( ParserOptions
$options ) {
188 $html .= "<pre class=\"mw-code mw-js\" dir=\"ltr\">\n";
189 $html .= htmlspecialchars( $this->getRawData() );
190 $html .= "\n</pre>\n";
197 class CssContent
extends TextContent
{
198 public function __construct( $text, Title
$title, $revId = null ) {
199 parent
::__construct($text, $title, $revId, CONTENT_MODEL_CSS
);
202 public function getHtml( ParserOptions
$options ) {
204 $html .= "<pre class=\"mw-code mw-css\" dir=\"ltr\">\n";
205 $html .= htmlspecialchars( $this->getRawData() );
206 $html .= "\n</pre>\n";
212 #FIXME: special type for redirects?!
213 #FIXME: special type for message-based pseudo-content? with raw html?
215 #TODO: MultipartMultipart < WikipageContent (Main + Links + X)
216 #TODO: LinksContent < LanguageLinksContent, CategoriesContent
217 #EXAMPLE: CoordinatesContent
218 #EXAMPLE: WikidataContent