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 #TODO: cache settings, etc?
76 public function getHtml( ParserOptions
$options ) {
78 $html .= "<pre class=\"mw-code\" dir=\"ltr\">\n";
79 $html .= htmlspecialchars( $this->getRawData() );
80 $html .= "\n</pre>\n";
86 public function getRawData( ) {
87 global $wgParser, $wgUser;
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 );
132 class JavaScriptContent
extends TextContent
{
133 public function __construct( $text, Title
$title, $revId = null ) {
134 parent
::__construct($text, $title, $revId, CONTENT_MODEL_JAVASCRIPT
);
137 public function getHtml( ParserOptions
$options ) {
139 $html .= "<pre class=\"mw-code mw-js\" dir=\"ltr\">\n";
140 $html .= htmlspecialchars( $this->getRawData() );
141 $html .= "\n</pre>\n";
148 class CssContent
extends TextContent
{
149 public function __construct( $text, Title
$title, $revId = null ) {
150 parent
::__construct($text, $title, $revId, CONTENT_MODEL_CSS
);
153 public function getHtml( ParserOptions
$options ) {
155 $html .= "<pre class=\"mw-code mw-css\" dir=\"ltr\">\n";
156 $html .= htmlspecialchars( $this->getRawData() );
157 $html .= "\n</pre>\n";
163 #TODO: MultipartMultipart < WikipageContent (Main + Links + X)
164 #TODO: LinksContent < LanguageLinksContent, CategoriesContent
165 #EXAMPLE: CoordinatesContent
166 #EXAMPLE: WikidataContent