From 951633e51ffcfdf9b145e68a1a447bd2356744ac Mon Sep 17 00:00:00 2001 From: Daniel Kinzler Date: Tue, 6 Mar 2012 17:35:46 +0000 Subject: [PATCH] fixed several bugs (this is still a mess) --- includes/Article.php | 1 + includes/AutoLoader.php | 12 +++++++ includes/Content.php | 4 +-- includes/ContentHandler.php | 69 +++++++++++++++++++++++++++---------- includes/Revision.php | 4 +-- includes/WikiPage.php | 2 ++ 6 files changed, 69 insertions(+), 23 deletions(-) diff --git a/includes/Article.php b/includes/Article.php index 906f06fdfc..628cc1c35d 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -374,6 +374,7 @@ class Article extends Page { } $this->mRevision = $this->mPage->getRevision(); + if ( !$this->mRevision ) { wfDebug( __METHOD__ . " failed to retrieve current page, rev_id " . $this->mPage->getLatest() . "\n" ); wfProfileOut( __METHOD__ ); diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php index 9e9befde89..46c62c2636 100644 --- a/includes/AutoLoader.php +++ b/includes/AutoLoader.php @@ -252,6 +252,18 @@ $wgAutoloadLocalClasses = array( 'ZhClient' => 'includes/ZhClient.php', 'ZipDirectoryReader' => 'includes/ZipDirectoryReader.php', + # content handler + 'Content' => 'includes/Content.php', + 'ContentHandler' => 'includes/ContentHandler.php', + 'CssContent' => 'includes/Content.php', + 'CssContentHandler' => 'includes/ContentHandler.php', + 'JavaScriptContent' => 'includes/Content.php', + 'JavaScriptContentHandler' => 'includes/ContentHandler.php', + 'MessageContent' => 'includes/Content.php', + 'TextContent' => 'includes/Content.php', + 'WikitextContent' => 'includes/Content.php', + 'WikitextContentHandler' => 'includes/ContentHandler.php', + # includes/actions 'CreditsAction' => 'includes/actions/CreditsAction.php', 'DeleteAction' => 'includes/actions/DeleteAction.php', diff --git a/includes/Content.php b/includes/Content.php index a8a0ba6462..05ada53312 100644 --- a/includes/Content.php +++ b/includes/Content.php @@ -6,7 +6,7 @@ */ abstract class Content { - public function __construct( Title $title, $revId, $modelName ) { #FIXME: really need revId? annoying! #FIXME: really $title? or just when parsing, every time? + public function __construct( Title $title = null, $revId = null, $modelName = null ) { #FIXME: really need revId? annoying! #FIXME: really $title? or just when parsing, every time? $this->mModelName = $modelName; $this->mTitle = $title; $this->mRevId = $revId; @@ -55,7 +55,7 @@ abstract class Content { } class TextContent extends Content { - public function __construct( $text, Title $title, $revId, $modelName ) { + public function __construct( $text, Title $title = null, $revId = null, $modelName = null ) { parent::__construct($title, $revId, $modelName); $this->mText = $text; diff --git a/includes/ContentHandler.php b/includes/ContentHandler.php index f586c94db9..eef232eec6 100644 --- a/includes/ContentHandler.php +++ b/includes/ContentHandler.php @@ -114,7 +114,7 @@ abstract class ContentHandler { return $wgContentHandlers[$modelName]; } - + # ---------------------------------------------------------------------------------------------------------- public function __construct( $modelName, $formats ) { $this->mModelName = $modelName; $this->mSupportedFormats = $formats; @@ -137,21 +137,13 @@ abstract class ContentHandler { return $this->mSupportedFormats[0]; } - public abstract function serialize( $obj, Title $title, $format = null ); - # for wikitext, do nothing (in the future: serialise ast/dom) - # for wikidata: serialize arrays to json + public abstract function serialize( Content $content, Title $title, $format = null ); public abstract function unserialize( $blob, Title $title, $format = null ); #FIXME: ...and revId? - # for wikitext, do nothing (in the future: parse into ast/dom) - # for wikidata: serialize arrays to json - - public abstract function doPreSaveTransform( $title, $obj ); + # public abstract function doPreSaveTransform( $title, $obj ); #TODO... - # TODO: getPreloadText() - # TODO: preprocess() - - /** + /** * Return an Article object suitable for viewing the given object * * @param type $title @@ -159,7 +151,7 @@ abstract class ContentHandler { * @return \Article * @todo Article is being refactored into an action class, keep track of that */ - public function createArticle( $title, $obj ) { + public function createArticle( Title $title, $obj ) { #TODO: use this! $article = new Article($title); return $article; } @@ -172,7 +164,7 @@ abstract class ContentHandler { * @param type $article * @return \EditPage */ - public function createEditPage( $title, $obj, $article ) { + public function createEditPage( Title $title, $obj, Article $article ) { #TODO: use this! $editPage = new EditPage($article); return $editPage; } @@ -182,12 +174,12 @@ abstract class ContentHandler { } **/ - public function getDiffEngine( $article ) { + public function getDiffEngine( Article $article ) { $de = new DifferenceEngine( $article->getContext() ); return $de; } - public function getIndexUpdateJobs( $title, $parserOutput, $recursive = true ) { + public function getIndexUpdateJobs( Title $title, ParserOutput $parserOutput, $recursive = true ) { # for wikitext, create a LinksUpdate object # for wikidata: serialize arrays to json $update = new LinksUpdate( $title, $parserOutput, $recursive ); @@ -197,11 +189,50 @@ abstract class ContentHandler { #XXX: is the native model for wikitext a string or the parser output? parse early or parse late? } -abstract class WikitextContentHandler extends ContentHandler { + +abstract class TextContentHandler extends ContentHandler { + + public function __construct( $modelName, $formats ) { + super::__construct( $modelName, $formats ); + } + + public function serialize( Content $content, Title $title, $format = null ) { + return $content->getRawData(); + } + } +class WikitextContentHandler extends TextContentHandler { + + public function __construct( $modelName = CONTENT_MODEL_WIKITEXT ) { + super::__construct( $modelName, array( 'application/x-wikitext' ) ); #FIXME: mime + } + + public function unserialize( $text, Title $title, $format = null ) { + return new WikitextContent($text, $title); + } + +} + +class JavaScriptContentHandler extends TextContentHandler { + + public function __construct( $modelName = CONTENT_MODEL_WIKITEXT ) { + super::__construct( $modelName, array( 'text/javascript' ) ); + } + + public function unserialize( $text, Title $title, $format = null ) { + return new JavaScriptContent($text, $title); + } -abstract class JavaScriptContentHandler extends WikitextHandler { } -abstract class CssContentHandler extends WikitextHandler { +class CssContentHandler extends TextContentHandler { + + public function __construct( $modelName = CONTENT_MODEL_WIKITEXT ) { + super::__construct( $modelName, array( 'text/css' ) ); + } + + public function unserialize( $text, Title $title, $format = null ) { + return new CssContent($text, $title); + } + } diff --git a/includes/Revision.php b/includes/Revision.php index b40cd71dab..cdb0738970 100644 --- a/includes/Revision.php +++ b/includes/Revision.php @@ -849,8 +849,8 @@ class Revision { public function getContentModelName() { if ( !$this->mContentModelName ) { - $title = $this->getTitle(); #XXX: never null? - $this->mContentModelName = $title->getContentModelName(); + $title = $this->getTitle(); + $this->mContentModelName = ( $title ? $title->getContentModelName() : CONTENT_MODEL_WIKITEXT ); } return $this->mContentModelName; diff --git a/includes/WikiPage.php b/includes/WikiPage.php index e5462b54d7..d6b20e5063 100644 --- a/includes/WikiPage.php +++ b/includes/WikiPage.php @@ -431,6 +431,8 @@ class WikiPage extends Page { protected function getRawData() { $content = $this->getContent( Revision::RAW ); + if ( !$content ) return null; + return $content->getRawData(); } -- 2.20.1