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 = null, $revId = null, $modelName = null ) { #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 # TODO: EditPage::mergeChanges( Content $a, Content $b )
58 # TODO: Wikipage::isCountable(Content $a)
59 # TODO: Title::newFromRedirectRecurse( $this->getRawText() );
61 # TODO: isCacheable( )
64 # TODO: WikiPage::getUndoText( Revision $undo, Revision $undoafter = null )
65 # TODO: WikiPage::replaceSection( $section, $text, $sectionTitle = '', $edittime = null )
66 # TODO: WikiPage::getAutosummary( $oldtext, $text, $flags )
68 # TODO: EditPage::getPreloadedText( $preload ) // $wgParser->getPreloadText
72 class TextContent
extends Content
{
73 public function __construct( $text, Title
$title = null, $revId = null, $modelName = null ) {
74 parent
::__construct($title, $revId, $modelName);
79 public function getSearchText( $obj ) {
80 return $this->getRawData();
83 public function getWikitextForTransclusion( $obj ) {
84 return $this->getRawData();
88 public function getParserOutput( ParserOptions
$options = null ) {
89 # generic implementation, relying on $this->getHtml()
91 $html = $this->getHtml( $options );
92 $po = new ParserOutput( $html );
94 if ( $this->mTitle
) $po->setTitleText( $this->mTitle
->getText() );
96 #TODO: cache settings, etc?
101 public function getHtml( ParserOptions
$options ) {
103 $html .= "<pre class=\"mw-code\" dir=\"ltr\">\n";
104 $html .= htmlspecialchars( $this->getRawData() );
105 $html .= "\n</pre>\n";
111 public function getRawData( ) {
112 $text = $this->mText
;
116 public function getRedirectChain() {
117 #XXX: really do this for all text, or just in WikitextContent
118 $text = $this->getRawData();
119 return Title
::newFromRedirectArray( $text );
123 class WikitextContent
extends TextContent
{
124 public function __construct( $text, Title
$title, $revId = null) {
125 parent
::__construct($text, $title, $revId, CONTENT_MODEL_WIKITEXT
);
127 $this->mDefaultParserOptions
= null;
130 public function getDefaultParserOptions() {
131 global $wgUser, $wgContLang;
133 if ( !$this->mDefaultParserOptions
) {
134 #TODO: use static member?!
135 $this->mDefaultParserOptions
= ParserOptions
::newFromUserAndLang( $wgUser, $wgContLang );
138 return $this->mDefaultParserOptions
;
141 public function getParserOutput( ParserOptions
$options = null ) {
144 #TODO: quick local cache: if $options is NULL, use ->mParserOutput!
145 #FIXME: need setParserOutput, so we can use stuff from the parser cache??
146 #FIXME: ...or we somehow need to know the parser cache key??
149 $options = $this->getDefaultParserOptions();
152 $po = $wgParser->parse( $this->mText
, $this->getTitle(), $options, true, true, $this->mRevId
);
157 public function getSection( $section ) {
160 $text = $this->getRawData();
161 return $wgParser->getSection( $text, $section, false );
166 class MessageContent
extends TextContent
{
167 public function __construct( $msg_key, $params = null, $options = null ) {
168 parent
::__construct(null, null, null, CONTENT_MODEL_WIKITEXT
);
170 $this->mMessageKey
= $msg_key;
172 $this->mParameters
= $params;
174 if ( !$options ) $options = array();
175 $this->mOptions
= $options;
177 $this->mHtmlOptions
= null;
181 public function getHtml( ParserOptions
$options ) {
182 $opt = array_merge( $this->mOptions
, array('parse') );
183 return wfMsgExt( $this->mMessageKey
, $this->mParameters
, $opt );
187 public function getRawData( ) {
188 $opt = array_diff( $this->mOptions
, array('parse', 'parseinline') );
190 return wfMsgExt( $this->mMessageKey
, $this->mParameters
, $opt );
196 class JavaScriptContent
extends TextContent
{
197 public function __construct( $text, Title
$title, $revId = null ) {
198 parent
::__construct($text, $title, $revId, CONTENT_MODEL_JAVASCRIPT
);
201 public function getHtml( ParserOptions
$options ) {
203 $html .= "<pre class=\"mw-code mw-js\" dir=\"ltr\">\n";
204 $html .= htmlspecialchars( $this->getRawData() );
205 $html .= "\n</pre>\n";
212 class CssContent
extends TextContent
{
213 public function __construct( $text, Title
$title, $revId = null ) {
214 parent
::__construct($text, $title, $revId, CONTENT_MODEL_CSS
);
217 public function getHtml( ParserOptions
$options ) {
219 $html .= "<pre class=\"mw-code mw-css\" dir=\"ltr\">\n";
220 $html .= htmlspecialchars( $this->getRawData() );
221 $html .= "\n</pre>\n";
227 #FIXME: special type for redirects?!
228 #FIXME: special type for message-based pseudo-content? with raw html?
230 #TODO: MultipartMultipart < WikipageContent (Main + Links + X)
231 #TODO: LinksContent < LanguageLinksContent, CategoriesContent
232 #EXAMPLE: CoordinatesContent
233 #EXAMPLE: WikidataContent