fixed several bugs (this is still a mess)
authorDaniel Kinzler <daniel.kinzler@wikimedia.de>
Tue, 6 Mar 2012 17:35:46 +0000 (17:35 +0000)
committerDaniel Kinzler <daniel.kinzler@wikimedia.de>
Wed, 4 Apr 2012 17:54:50 +0000 (19:54 +0200)
includes/Article.php
includes/AutoLoader.php
includes/Content.php
includes/ContentHandler.php
includes/Revision.php
includes/WikiPage.php

index 906f06f..628cc1c 100644 (file)
@@ -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__ );
index 9e9befd..46c62c2 100644 (file)
@@ -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',
index a8a0ba6..05ada53 100644 (file)
@@ -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;
index f586c94..eef232e 100644 (file)
@@ -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);
+    }
+
 }
index b40cd71..cdb0738 100644 (file)
@@ -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;
index e5462b5..d6b20e5 100644 (file)
@@ -431,6 +431,8 @@ class WikiPage extends Page {
 
     protected function getRawData() {
         $content = $this->getContent( Revision::RAW );
+        if ( !$content ) return null;
+
         return $content->getRawData();
     }