minor cleanup, added todos and attempted (but aborted) refactoring to make stuff...
authorjeroendedauw <jeroendedauw@gmail.com>
Thu, 12 Apr 2012 14:01:33 +0000 (16:01 +0200)
committerjeroendedauw <jeroendedauw@gmail.com>
Thu, 12 Apr 2012 14:01:33 +0000 (16:01 +0200)
Change-Id: I3f57ee2c28861462cf46fc3af13c4ab0cb6aa960

includes/Content.php
includes/ContentHandler.php

index 913eb06..aed9bba 100644 (file)
@@ -7,48 +7,8 @@
  *
  */
 abstract class Content {
-    
-    public function __construct( $modelName = null ) {
-        $this->mModelName = $modelName;
-    }
-
-    public function getModelName() {
-        return $this->mModelName;
-    }
-
-    protected function checkModelName( $modelName ) {
-        if ( $modelName !== $this->mModelName ) {
-            throw new MWException( "Bad content model: expected " . $this->mModelName . " but got found " . $modelName );
-        }
-    }
-
-    public function getContentHandler() {
-        return ContentHandler::getForContent( $this );
-    }
-
-    public function getDefaultFormat() {
-        return $this->getContentHandler()->getDefaultFormat();
-    }
-
-    public function getSupportedFormats() {
-        return $this->getContentHandler()->getSupportedFormats();
-    }
 
-    public function isSupportedFormat( $format ) {
-        if ( !$format ) return true; # this means "use the default"
-
-        return $this->getContentHandler()->isSupportedFormat( $format );
-    }
-
-    protected function checkFormat( $format ) {
-        if ( !$this->isSupportedFormat( $format ) ) {
-            throw new MWException( "Format $format is not supported for content model " . $this->getModelName() );
-        }
-    }
-
-    public function serialize( $format = null ) {
-        return $this->getContentHandler()->serialize( $this, $format );
-    }
+       // TODO: create actual fields and document them
 
     /**
      * @return String a string representing the content in a way useful for building a full text search index.
@@ -87,6 +47,54 @@ abstract class Content {
      */
     public abstract function getSize( );
 
+       /**
+        * TODO: do we really need to pass a $modelName here?
+        * Seems odd and makes lots of stuff hard (ie having a newEmpty static method in TextContent)
+        *
+        * @param $modelName
+        */
+       public function __construct( $modelName = null ) {
+               $this->mModelName = $modelName;
+       }
+
+       public function getModelName() {
+               return $this->mModelName;
+       }
+
+       protected function checkModelName( $modelName ) {
+               if ( $modelName !== $this->mModelName ) {
+                       throw new MWException( "Bad content model: expected " . $this->mModelName . " but got found " . $modelName );
+               }
+       }
+
+       public function getContentHandler() {
+               return ContentHandler::getForContent( $this );
+       }
+
+       public function getDefaultFormat() {
+               return $this->getContentHandler()->getDefaultFormat();
+       }
+
+       public function getSupportedFormats() {
+               return $this->getContentHandler()->getSupportedFormats();
+       }
+
+       public function isSupportedFormat( $format ) {
+               if ( !$format ) return true; # this means "use the default"
+
+               return $this->getContentHandler()->isSupportedFormat( $format );
+       }
+
+       protected function checkFormat( $format ) {
+               if ( !$this->isSupportedFormat( $format ) ) {
+                       throw new MWException( "Format $format is not supported for content model " . $this->getModelName() );
+               }
+       }
+
+       public function serialize( $format = null ) {
+               return $this->getContentHandler()->serialize( $this, $format );
+       }
+
     public function isEmpty() {
         return $this->getSize() == 0;
     }
@@ -238,8 +246,9 @@ abstract class Content {
  * Content object implementation for representing flat text. The
  */
 abstract class TextContent extends Content {
+
     public function __construct( $text, $modelName = null ) {
-        parent::__construct($modelName);
+        parent::__construct( $modelName );
 
         $this->mText = $text;
     }
@@ -331,6 +340,7 @@ abstract class TextContent extends Content {
 }
 
 class WikitextContent extends TextContent {
+
     public function __construct( $text ) {
         parent::__construct($text, CONTENT_MODEL_WIKITEXT);
 
@@ -392,8 +402,6 @@ class WikitextContent extends TextContent {
      * @return string Complete article text, or null if error
      */
     public function replaceSection( $section, Content $with, $sectionTitle = '' ) {
-        global $wgParser;
-
         wfProfileIn( __METHOD__ );
 
         $myModelName = $this->getModelName();
index 699e2fd..1a55788 100644 (file)
@@ -14,10 +14,34 @@ class MWContentSerializationException extends MWException {
  * same as their serialized form. Examples would be JavaScript and CSS code. As of now,
  * this also applies to wikitext (mediawiki's default content type), but wikitext
  * content may be represented by a DOM or AST structure in the future.
- *  
+ *
+ * TODO: add documentation
  */
 abstract class ContentHandler {
 
+       /**
+        * @abstract
+        * @param Content $content
+        * @param null $format
+        * @return String
+        */
+       public abstract function serialize( Content $content, $format = null );
+
+       /**
+        * TODO: calling unserialize on a ContentHandler returns a Content?!! Something looks wrong here...
+        *
+        * @abstract
+        * @param $blob String
+        * @param null $format
+        * @return Content
+        */
+       public abstract function unserialize( $blob, $format = null );
+
+       /**
+        * FIXME: bad method name: suggests it empties the content of an instance rather then creating a new empty one
+        */
+       public abstract function emptyContent();
+
     public static function getContentText( Content $content = null ) {
         global $wgContentHandlerTextFallback;
 
@@ -194,24 +218,6 @@ abstract class ContentHandler {
         }
     }
 
-    /**
-     * @abstract
-     * @param Content $content
-     * @param null $format
-     * @return String
-     */
-    public abstract function serialize( Content $content, $format = null );
-
-    /**
-     * @abstract
-     * @param $blob String
-     * @param null $format
-     * @return Content
-     */
-    public abstract function unserialize( $blob, $format = null );
-
-    public abstract function emptyContent();
-
     /**
      * Return an Article object suitable for viewing the given object
      *
@@ -271,9 +277,22 @@ abstract class ContentHandler {
 
         $this->checkModelName( $context->getTitle()->getModelName() );
 
-        return new DifferenceEngine( $context, $old, $new, $rcid, $refreshCache, $unhide );
+               $diffEngineClass = $this->getDiffEngineClass();
+
+        return new $diffEngineClass( $context, $old, $new, $rcid, $refreshCache, $unhide );
     }
 
+       /**
+        * Returns the name of the diff engine to use.
+        *
+        * @since 0.1
+        *
+        * @return string
+        */
+       protected function getDiffEngineClass() {
+               return 'DifferenceEngine';
+       }
+
     /**
      * attempts to merge differences between three versions.
      * Returns a new Content object for a clean merge and false for failure or a conflict.