*
*/
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.
*/
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;
}
* 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;
}
}
class WikitextContent extends TextContent {
+
public function __construct( $text ) {
parent::__construct($text, CONTENT_MODEL_WIKITEXT);
* @return string Complete article text, or null if error
*/
public function replaceSection( $section, Content $with, $sectionTitle = '' ) {
- global $wgParser;
-
wfProfileIn( __METHOD__ );
$myModelName = $this->getModelName();
* 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;
}
}
- /**
- * @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
*
$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.