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 ) {
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 #XXX: is the native model for wikitext a string or the parser output? parse early or parse late?
49 class TextContent
extends Content
{
50 public function __construct( $text, Title
$title, $revId, $modelName ) {
51 parent
::__construct($title, $revId, $modelName);
56 public function getSearchText( $obj ) {
57 return $this->getRawData();
60 public function getWikitextForTransclusion( $obj ) {
61 return $this->getRawData();
65 public function getParserOutput( ParserOptions
$options = null ) {
66 # generic implementation, relying on $this->getHtml()
68 $html = $this->getHtml( $options );
69 $po = new ParserOutput( $html );
71 if ( $this->mTitle
) $po->setTitleText( $this->mTitle
->getText() );
73 #TODO: cache settings, etc?
78 public function getHtml( ParserOptions
$options ) {
80 $html .= "<pre class=\"mw-code\" dir=\"ltr\">\n";
81 $html .= htmlspecialchars( $this->getRawData() );
82 $html .= "\n</pre>\n";
88 public function getRawData( ) {
95 class WikitextContent
extends TextContent
{
96 public function __construct( $text, Title
$title, $revId = null) {
97 parent
::__construct($text, $title, $revId, CONTENT_MODEL_WIKITEXT
);
99 $this->mDefaultParserOptions
= null;
102 public function getDefaultParserOptions() {
103 global $wgUser, $wgContLang;
105 if ( !$this->mDefaultParserOptions
) {
106 #TODO: use static member?!
107 $this->mDefaultParserOptions
= ParserOptions
::newFromUserAndLang( $wgUser, $wgContLang );
110 return $this->mDefaultParserOptions
;
113 public function getParserOutput( ParserOptions
$options = null ) {
116 #TODO: quick local cache: if $options is NULL, use ->mParserOutput!
117 #FIXME: need setParserOutput, so we can use stuff from the parser cache??
118 #FIXME: ...or we somehow need to know the parser cache key??
121 $options = $this->getDefaultParserOptions();
124 $po = $wgParser->parse( $this->mText
, $this->getTitle(), $options );
131 class MessageContent
extends TextContent
{
132 public function __construct( $msg_key, $params = null, $options = null ) {
133 parent
::__construct(null, null, null, CONTENT_MODEL_WIKITEXT
);
135 $this->mMessageKey
= $msg_key;
137 $this->mParameters
= $params;
139 if ( !$options ) $options = array();
140 $this->mOptions
= $options;
142 $this->mHtmlOptions
= null;
146 public function getHtml( ParserOptions
$options ) {
147 $opt = array_merge( $this->mOptions
, array('parse') );
148 return wfMsgExt( $this->mMessageKey
, $this->mParameters
, $opt );
152 public function getRawData( ) {
153 $opt = array_diff( $this->mOptions
, array('parse', 'parseinline') );
155 return wfMsgExt( $this->mMessageKey
, $this->mParameters
, $opt );
161 class JavaScriptContent
extends TextContent
{
162 public function __construct( $text, Title
$title, $revId = null ) {
163 parent
::__construct($text, $title, $revId, CONTENT_MODEL_JAVASCRIPT
);
166 public function getHtml( ParserOptions
$options ) {
168 $html .= "<pre class=\"mw-code mw-js\" dir=\"ltr\">\n";
169 $html .= htmlspecialchars( $this->getRawData() );
170 $html .= "\n</pre>\n";
177 class CssContent
extends TextContent
{
178 public function __construct( $text, Title
$title, $revId = null ) {
179 parent
::__construct($text, $title, $revId, CONTENT_MODEL_CSS
);
182 public function getHtml( ParserOptions
$options ) {
184 $html .= "<pre class=\"mw-code mw-css\" dir=\"ltr\">\n";
185 $html .= htmlspecialchars( $this->getRawData() );
186 $html .= "\n</pre>\n";
192 #FIXME: special type for redirects?!
193 #FIXME: special type for message-based pseudo-content? with raw html?
195 #TODO: MultipartMultipart < WikipageContent (Main + Links + X)
196 #TODO: LinksContent < LanguageLinksContent, CategoriesContent
197 #EXAMPLE: CoordinatesContent
198 #EXAMPLE: WikidataContent