Moved ContentHandler deriving classes into their own files for better discoverability...
authorjeroendedauw <jeroendedauw@gmail.com>
Tue, 16 Oct 2012 18:20:43 +0000 (20:20 +0200)
committerjeroendedauw <jeroendedauw@gmail.com>
Tue, 16 Oct 2012 18:20:43 +0000 (20:20 +0200)
Change-Id: I37db53e1d1420e61d3af4566322bcdba85ec778b

includes/AutoLoader.php
includes/content/ContentHandler.php
includes/content/CssContentHandler.php [new file with mode: 0644]
includes/content/JavaScriptContentHandler.php [new file with mode: 0644]
includes/content/TextContentHandler.php [new file with mode: 0644]
includes/content/WikitextContentHandler.php [new file with mode: 0644]

index 182104d..1cf6634 100644 (file)
@@ -294,14 +294,14 @@ $wgAutoloadLocalClasses = array(
        'AbstractContent' => 'includes/content/AbstractContent.php',
        'ContentHandler' => 'includes/content/ContentHandler.php',
        'Content' => 'includes/content/Content.php',
-       'CssContentHandler' => 'includes/content/ContentHandler.php',
+       'CssContentHandler' => 'includes/content/CssContentHandler.php',
        'CssContent' => 'includes/content/CssContent.php',
-       'JavaScriptContentHandler' => 'includes/content/ContentHandler.php',
+       'JavaScriptContentHandler' => 'includes/content/JavaScriptContentHandler.php',
        'JavaScriptContent' => 'includes/content/JavaScriptContent.php',
        'MessageContent' => 'includes/content/MessageContent.php',
-       'TextContentHandler' => 'includes/content/ContentHandler.php',
+       'TextContentHandler' => 'includes/content/TextContentHandler.php',
        'TextContent' => 'includes/content/TextContent.php',
-       'WikitextContentHandler' => 'includes/content/ContentHandler.php',
+       'WikitextContentHandler' => 'includes/content/WikitextContentHandler.php',
        'WikitextContent' => 'includes/content/WikitextContent.php',
 
        # includes/actions
index 4bb4e40..bf21021 100644 (file)
@@ -1081,239 +1081,3 @@ abstract class ContentHandler {
        }
 }
 
-/**
- * @since 1.21
- */
-class TextContentHandler extends ContentHandler {
-
-       public function __construct( $modelId = CONTENT_MODEL_TEXT, $formats = array( CONTENT_FORMAT_TEXT ) ) {
-               parent::__construct( $modelId, $formats );
-       }
-
-       /**
-        * Returns the content's text as-is.
-        *
-        * @param $content Content
-        * @param $format string|null
-        * @return mixed
-        */
-       public function serializeContent( Content $content, $format = null ) {
-               $this->checkFormat( $format );
-               return $content->getNativeData();
-       }
-
-       /**
-        * Attempts to merge differences between three versions. Returns a new
-        * Content object for a clean merge and false for failure or a conflict.
-        *
-        * All three Content objects passed as parameters must have the same
-        * content model.
-        *
-        * This text-based implementation uses wfMerge().
-        *
-        * @param $oldContent \Content|string  String
-        * @param $myContent \Content|string   String
-        * @param $yourContent \Content|string String
-        *
-        * @return Content|Bool
-        */
-       public function merge3( Content $oldContent, Content $myContent, Content $yourContent ) {
-               $this->checkModelID( $oldContent->getModel() );
-               $this->checkModelID( $myContent->getModel() );
-               $this->checkModelID( $yourContent->getModel() );
-
-               $format = $this->getDefaultFormat();
-
-               $old = $this->serializeContent( $oldContent, $format );
-               $mine = $this->serializeContent( $myContent, $format );
-               $yours = $this->serializeContent( $yourContent, $format );
-
-               $ok = wfMerge( $old, $mine, $yours, $result );
-
-               if ( !$ok ) {
-                       return false;
-               }
-
-               if ( !$result ) {
-                       return $this->makeEmptyContent();
-               }
-
-               $mergedContent = $this->unserializeContent( $result, $format );
-               return $mergedContent;
-       }
-
-       /**
-        * Unserializes a Content object of the type supported by this ContentHandler.
-        *
-        * @since 1.21
-        *
-        * @param $text   string serialized form of the content
-        * @param $format null|String the format used for serialization
-        *
-        * @return Content the TextContent object wrapping $text
-        */
-       public function unserializeContent( $text, $format = null ) {
-               $this->checkFormat( $format );
-
-               return new TextContent( $text );
-       }
-
-       /**
-        * Creates an empty TextContent object.
-        *
-        * @since 1.21
-        *
-        * @return Content
-        */
-       public function makeEmptyContent() {
-               return new TextContent( '' );
-       }
-}
-
-/**
- * @since 1.21
- */
-class WikitextContentHandler extends TextContentHandler {
-
-       public function __construct( $modelId = CONTENT_MODEL_WIKITEXT ) {
-               parent::__construct( $modelId, array( CONTENT_FORMAT_WIKITEXT ) );
-       }
-
-       public function unserializeContent( $text, $format = null ) {
-               $this->checkFormat( $format );
-
-               return new WikitextContent( $text );
-       }
-
-       /**
-        * @see ContentHandler::makeEmptyContent
-        *
-        * @return Content
-        */
-       public function makeEmptyContent() {
-               return new WikitextContent( '' );
-       }
-
-
-       /**
-        * Returns a WikitextContent object representing a redirect to the given destination page.
-        *
-        * @see ContentHandler::makeRedirectContent
-        *
-        * @param Title $destination the page to redirect to.
-        *
-        * @return Content
-        */
-       public function makeRedirectContent( Title $destination ) {
-               $mwRedir = MagicWord::get( 'redirect' );
-               $redirectText = $mwRedir->getSynonym( 0 ) . ' [[' . $destination->getPrefixedText() . "]]\n";
-
-               return new WikitextContent( $redirectText );
-       }
-
-       /**
-        * Returns true because wikitext supports sections.
-        *
-        * @return boolean whether sections are supported.
-        */
-       public function supportsSections() {
-               return true;
-       }
-
-       /**
-        * Returns true, because wikitext supports caching using the
-        * ParserCache mechanism.
-        *
-        * @since 1.21
-        * @return bool
-        */
-       public function isParserCacheSupported() {
-               return true;
-       }
-}
-
-# XXX: make ScriptContentHandler base class, do highlighting stuff there?
-
-/**
- * @since 1.21
- */
-class JavaScriptContentHandler extends TextContentHandler {
-
-       public function __construct( $modelId = CONTENT_MODEL_JAVASCRIPT ) {
-               parent::__construct( $modelId, array( CONTENT_FORMAT_JAVASCRIPT ) );
-       }
-
-       public function unserializeContent( $text, $format = null ) {
-               $this->checkFormat( $format );
-
-               return new JavaScriptContent( $text );
-       }
-
-       public function makeEmptyContent() {
-               return new JavaScriptContent( '' );
-       }
-
-       /**
-        * Returns the english language, because JS is english, and should be handled as such.
-        *
-        * @return Language wfGetLangObj( 'en' )
-        *
-        * @see ContentHandler::getPageLanguage()
-        */
-       public function getPageLanguage( Title $title, Content $content = null ) {
-               return wfGetLangObj( 'en' );
-       }
-
-       /**
-        * Returns the english language, because CSS is english, and should be handled as such.
-        *
-        * @return Language wfGetLangObj( 'en' )
-        *
-        * @see ContentHandler::getPageViewLanguage()
-        */
-       public function getPageViewLanguage( Title $title, Content $content = null ) {
-               return wfGetLangObj( 'en' );
-       }
-}
-
-/**
- * @since 1.21
- */
-class CssContentHandler extends TextContentHandler {
-
-       public function __construct( $modelId = CONTENT_MODEL_CSS ) {
-               parent::__construct( $modelId, array( CONTENT_FORMAT_CSS ) );
-       }
-
-       public function unserializeContent( $text, $format = null ) {
-               $this->checkFormat( $format );
-
-               return new CssContent( $text );
-       }
-
-       public function makeEmptyContent() {
-               return new CssContent( '' );
-       }
-
-       /**
-        * Returns the english language, because CSS is english, and should be handled as such.
-        *
-        * @return Language wfGetLangObj( 'en' )
-        *
-        * @see ContentHandler::getPageLanguage()
-        */
-       public function getPageLanguage( Title $title, Content $content = null ) {
-               return wfGetLangObj( 'en' );
-       }
-
-       /**
-        * Returns the english language, because CSS is english, and should be handled as such.
-        *
-        * @return Language wfGetLangObj( 'en' )
-        *
-        * @see ContentHandler::getPageViewLanguage()
-        */
-       public function getPageViewLanguage( Title $title, Content $content = null ) {
-               return wfGetLangObj( 'en' );
-       }
-}
diff --git a/includes/content/CssContentHandler.php b/includes/content/CssContentHandler.php
new file mode 100644 (file)
index 0000000..e2199c4
--- /dev/null
@@ -0,0 +1,43 @@
+<?php
+
+/**
+ * @since 1.21
+ */
+class CssContentHandler extends TextContentHandler {
+
+       public function __construct( $modelId = CONTENT_MODEL_CSS ) {
+               parent::__construct( $modelId, array( CONTENT_FORMAT_CSS ) );
+       }
+
+       public function unserializeContent( $text, $format = null ) {
+               $this->checkFormat( $format );
+
+               return new CssContent( $text );
+       }
+
+       public function makeEmptyContent() {
+               return new CssContent( '' );
+       }
+
+       /**
+        * Returns the english language, because CSS is english, and should be handled as such.
+        *
+        * @return Language wfGetLangObj( 'en' )
+        *
+        * @see ContentHandler::getPageLanguage()
+        */
+       public function getPageLanguage( Title $title, Content $content = null ) {
+               return wfGetLangObj( 'en' );
+       }
+
+       /**
+        * Returns the english language, because CSS is english, and should be handled as such.
+        *
+        * @return Language wfGetLangObj( 'en' )
+        *
+        * @see ContentHandler::getPageViewLanguage()
+        */
+       public function getPageViewLanguage( Title $title, Content $content = null ) {
+               return wfGetLangObj( 'en' );
+       }
+}
\ No newline at end of file
diff --git a/includes/content/JavaScriptContentHandler.php b/includes/content/JavaScriptContentHandler.php
new file mode 100644 (file)
index 0000000..8b080bf
--- /dev/null
@@ -0,0 +1,45 @@
+<?php
+
+# XXX: make ScriptContentHandler base class, do highlighting stuff there?
+
+/**
+ * @since 1.21
+ */
+class JavaScriptContentHandler extends TextContentHandler {
+
+       public function __construct( $modelId = CONTENT_MODEL_JAVASCRIPT ) {
+               parent::__construct( $modelId, array( CONTENT_FORMAT_JAVASCRIPT ) );
+       }
+
+       public function unserializeContent( $text, $format = null ) {
+               $this->checkFormat( $format );
+
+               return new JavaScriptContent( $text );
+       }
+
+       public function makeEmptyContent() {
+               return new JavaScriptContent( '' );
+       }
+
+       /**
+        * Returns the english language, because JS is english, and should be handled as such.
+        *
+        * @return Language wfGetLangObj( 'en' )
+        *
+        * @see ContentHandler::getPageLanguage()
+        */
+       public function getPageLanguage( Title $title, Content $content = null ) {
+               return wfGetLangObj( 'en' );
+       }
+
+       /**
+        * Returns the english language, because CSS is english, and should be handled as such.
+        *
+        * @return Language wfGetLangObj( 'en' )
+        *
+        * @see ContentHandler::getPageViewLanguage()
+        */
+       public function getPageViewLanguage( Title $title, Content $content = null ) {
+               return wfGetLangObj( 'en' );
+       }
+}
\ No newline at end of file
diff --git a/includes/content/TextContentHandler.php b/includes/content/TextContentHandler.php
new file mode 100644 (file)
index 0000000..9dff67e
--- /dev/null
@@ -0,0 +1,90 @@
+<?php
+
+/**
+ * @since 1.21
+ */
+class TextContentHandler extends ContentHandler {
+
+       public function __construct( $modelId = CONTENT_MODEL_TEXT, $formats = array( CONTENT_FORMAT_TEXT ) ) {
+               parent::__construct( $modelId, $formats );
+       }
+
+       /**
+        * Returns the content's text as-is.
+        *
+        * @param $content Content
+        * @param $format string|null
+        * @return mixed
+        */
+       public function serializeContent( Content $content, $format = null ) {
+               $this->checkFormat( $format );
+               return $content->getNativeData();
+       }
+
+       /**
+        * Attempts to merge differences between three versions. Returns a new
+        * Content object for a clean merge and false for failure or a conflict.
+        *
+        * All three Content objects passed as parameters must have the same
+        * content model.
+        *
+        * This text-based implementation uses wfMerge().
+        *
+        * @param $oldContent \Content|string  String
+        * @param $myContent \Content|string   String
+        * @param $yourContent \Content|string String
+        *
+        * @return Content|Bool
+        */
+       public function merge3( Content $oldContent, Content $myContent, Content $yourContent ) {
+               $this->checkModelID( $oldContent->getModel() );
+               $this->checkModelID( $myContent->getModel() );
+               $this->checkModelID( $yourContent->getModel() );
+
+               $format = $this->getDefaultFormat();
+
+               $old = $this->serializeContent( $oldContent, $format );
+               $mine = $this->serializeContent( $myContent, $format );
+               $yours = $this->serializeContent( $yourContent, $format );
+
+               $ok = wfMerge( $old, $mine, $yours, $result );
+
+               if ( !$ok ) {
+                       return false;
+               }
+
+               if ( !$result ) {
+                       return $this->makeEmptyContent();
+               }
+
+               $mergedContent = $this->unserializeContent( $result, $format );
+               return $mergedContent;
+       }
+
+       /**
+        * Unserializes a Content object of the type supported by this ContentHandler.
+        *
+        * @since 1.21
+        *
+        * @param $text   string serialized form of the content
+        * @param $format null|String the format used for serialization
+        *
+        * @return Content the TextContent object wrapping $text
+        */
+       public function unserializeContent( $text, $format = null ) {
+               $this->checkFormat( $format );
+
+               return new TextContent( $text );
+       }
+
+       /**
+        * Creates an empty TextContent object.
+        *
+        * @since 1.21
+        *
+        * @return Content
+        */
+       public function makeEmptyContent() {
+               return new TextContent( '' );
+       }
+}
\ No newline at end of file
diff --git a/includes/content/WikitextContentHandler.php b/includes/content/WikitextContentHandler.php
new file mode 100644 (file)
index 0000000..c6ac2ba
--- /dev/null
@@ -0,0 +1,63 @@
+<?php
+
+/**
+ * @since 1.21
+ */
+class WikitextContentHandler extends TextContentHandler {
+
+       public function __construct( $modelId = CONTENT_MODEL_WIKITEXT ) {
+               parent::__construct( $modelId, array( CONTENT_FORMAT_WIKITEXT ) );
+       }
+
+       public function unserializeContent( $text, $format = null ) {
+               $this->checkFormat( $format );
+
+               return new WikitextContent( $text );
+       }
+
+       /**
+        * @see ContentHandler::makeEmptyContent
+        *
+        * @return Content
+        */
+       public function makeEmptyContent() {
+               return new WikitextContent( '' );
+       }
+
+
+       /**
+        * Returns a WikitextContent object representing a redirect to the given destination page.
+        *
+        * @see ContentHandler::makeRedirectContent
+        *
+        * @param Title $destination the page to redirect to.
+        *
+        * @return Content
+        */
+       public function makeRedirectContent( Title $destination ) {
+               $mwRedir = MagicWord::get( 'redirect' );
+               $redirectText = $mwRedir->getSynonym( 0 ) . ' [[' . $destination->getPrefixedText() . "]]\n";
+
+               return new WikitextContent( $redirectText );
+       }
+
+       /**
+        * Returns true because wikitext supports sections.
+        *
+        * @return boolean whether sections are supported.
+        */
+       public function supportsSections() {
+               return true;
+       }
+
+       /**
+        * Returns true, because wikitext supports caching using the
+        * ParserCache mechanism.
+        *
+        * @since 1.21
+        * @return bool
+        */
+       public function isParserCacheSupported() {
+               return true;
+       }
+}
\ No newline at end of file