https://www.mediawiki.org/wiki/Special:Code/MediaWiki/113156

Revision: 113156
Author:   daniel
Date:     2012-03-06 17:35:46 +0000 (Tue, 06 Mar 2012)
Log Message:
-----------
fixed several bugs (this is still a mess)

Modified Paths:
--------------
    branches/Wikidata/phase3/includes/Article.php
    branches/Wikidata/phase3/includes/AutoLoader.php
    branches/Wikidata/phase3/includes/Content.php
    branches/Wikidata/phase3/includes/ContentHandler.php
    branches/Wikidata/phase3/includes/Revision.php
    branches/Wikidata/phase3/includes/WikiPage.php

Modified: branches/Wikidata/phase3/includes/Article.php
===================================================================
--- branches/Wikidata/phase3/includes/Article.php       2012-03-06 17:35:35 UTC 
(rev 113155)
+++ branches/Wikidata/phase3/includes/Article.php       2012-03-06 17:35:46 UTC 
(rev 113156)
@@ -374,6 +374,7 @@
             }
 
             $this->mRevision = $this->mPage->getRevision();
+
             if ( !$this->mRevision ) {
                 wfDebug( __METHOD__ . " failed to retrieve current page, 
rev_id " . $this->mPage->getLatest() . "\n" );
                 wfProfileOut( __METHOD__ );

Modified: branches/Wikidata/phase3/includes/AutoLoader.php
===================================================================
--- branches/Wikidata/phase3/includes/AutoLoader.php    2012-03-06 17:35:35 UTC 
(rev 113155)
+++ branches/Wikidata/phase3/includes/AutoLoader.php    2012-03-06 17:35:46 UTC 
(rev 113156)
@@ -252,6 +252,18 @@
        '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',

Modified: branches/Wikidata/phase3/includes/Content.php
===================================================================
--- branches/Wikidata/phase3/includes/Content.php       2012-03-06 17:35:35 UTC 
(rev 113155)
+++ branches/Wikidata/phase3/includes/Content.php       2012-03-06 17:35:46 UTC 
(rev 113156)
@@ -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 @@
 }
 
 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;

Modified: branches/Wikidata/phase3/includes/ContentHandler.php
===================================================================
--- branches/Wikidata/phase3/includes/ContentHandler.php        2012-03-06 
17:35:35 UTC (rev 113155)
+++ branches/Wikidata/phase3/includes/ContentHandler.php        2012-03-06 
17:35:46 UTC (rev 113156)
@@ -114,7 +114,7 @@
         return $wgContentHandlers[$modelName];
     }
 
-
+    # 
----------------------------------------------------------------------------------------------------------
     public function __construct( $modelName, $formats ) {
         $this->mModelName = $modelName;
         $this->mSupportedFormats = $formats;
@@ -137,21 +137,13 @@
         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 ); #TODO...
 
-    public abstract function doPreSaveTransform( $title, $obj );
-
-    # TODO: getPreloadText()
-    # TODO: preprocess()
-
-    /** 
+    /**
      * Return an Article object suitable for viewing the given object
      * 
      * @param type $title
@@ -159,7 +151,7 @@
      * @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 @@
      * @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 @@
     }
     **/
     
-    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 @@
     #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 {
 
-abstract class JavaScriptContentHandler extends WikitextHandler {
+    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);
+    }
+
 }
 
-abstract class CssContentHandler extends WikitextHandler {
+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);
+    }
+
 }
+
+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);
+    }
+
+}

Modified: branches/Wikidata/phase3/includes/Revision.php
===================================================================
--- branches/Wikidata/phase3/includes/Revision.php      2012-03-06 17:35:35 UTC 
(rev 113155)
+++ branches/Wikidata/phase3/includes/Revision.php      2012-03-06 17:35:46 UTC 
(rev 113156)
@@ -849,8 +849,8 @@
 
     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;

Modified: branches/Wikidata/phase3/includes/WikiPage.php
===================================================================
--- branches/Wikidata/phase3/includes/WikiPage.php      2012-03-06 17:35:35 UTC 
(rev 113155)
+++ branches/Wikidata/phase3/includes/WikiPage.php      2012-03-06 17:35:46 UTC 
(rev 113156)
@@ -431,6 +431,8 @@
 
     protected function getRawData() {
         $content = $this->getContent( Revision::RAW );
+        if ( !$content ) return null;
+
         return $content->getRawData();
     }
 


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to