Merge branch 'Wikidata' of ssh://gerrit.wikimedia.org:29418/mediawiki/core into Wikidata
[lhc/web/wiklou.git] / includes / Content.php
index 30e8400..abf8282 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,16 +47,74 @@ 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;
     }
 
     public function equals( Content $that ) {
-        if ( empty( $that ) ) return false;
-        if ( $that === $this ) return true;
-        if ( $that->getModelName() !== $this->getModelName() ) return false;
+        if ( empty( $that ) ){ // FIXME: empty on an object?
+                       return false;
+               }
+
+        if ( $that === $this ) {
+                       return true;
+               }
 
-        return $this->getNativeData() == $that->getNativeData();
+        if ( $that->getModelName() !== $this->getModelName() ) {
+                       return false;
+               }
+
+        return $this->getNativeData() === $that->getNativeData();
     }
 
     /**
@@ -242,8 +260,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;
     }
@@ -337,6 +356,7 @@ abstract class TextContent extends Content {
 }
 
 class WikitextContent extends TextContent {
+
     public function __construct( $text ) {
         parent::__construct($text, CONTENT_MODEL_WIKITEXT);
 
@@ -398,8 +418,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();
@@ -552,7 +570,13 @@ class MessageContent extends TextContent {
 
         $this->mParameters = $params;
 
-        if ( !$options ) $options = array();
+        if ( is_null( $options ) ) {
+                       $options = array();
+               }
+               elseif ( is_string( $options ) ) {
+                       $options = array( $options );
+               }
+
         $this->mOptions = $options;
 
         $this->mHtmlOptions = null;