From: Tim Starling Date: Tue, 26 Jul 2016 05:10:42 +0000 (+1000) Subject: Add MWTidy::factory() X-Git-Tag: 1.31.0-rc.0~6264^2 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/pie.php?a=commitdiff_plain;h=7a5fbec82dd797070b3271db6145b2175c731d5e;p=lhc%2Fweb%2Fwiklou.git Add MWTidy::factory() A convenient factory function to eliminate code duplication in ParserMigration's MigrationEditPage::tidyParserOutput(). Change-Id: I058912885025e7a9402912236c65c44e32ef036e --- diff --git a/includes/parser/MWTidy.php b/includes/parser/MWTidy.php index 32d8373176..46ea77395a 100644 --- a/includes/parser/MWTidy.php +++ b/includes/parser/MWTidy.php @@ -101,31 +101,42 @@ class MWTidy { } else { return false; } - switch ( $config['driver'] ) { - case 'RaggettInternalHHVM': - self::$instance = new MediaWiki\Tidy\RaggettInternalHHVM( $config ); - break; - case 'RaggettInternalPHP': - self::$instance = new MediaWiki\Tidy\RaggettInternalPHP( $config ); - break; - case 'RaggettExternal': - self::$instance = new MediaWiki\Tidy\RaggettExternal( $config ); - break; - case 'Html5Depurate': - self::$instance = new MediaWiki\Tidy\Html5Depurate( $config ); - break; - case 'Html5Internal': - self::$instance = new MediaWiki\Tidy\Html5Internal( $config ); - break; - case 'disabled': - return false; - default: - throw new MWException( "Invalid tidy driver: \"{$config['driver']}\"" ); - } + self::$instance = self::factory( $config ); } return self::$instance; } + /** + * Create a new Tidy driver object from configuration. + * @see $wgTidyConfig + * @param array $config + * @return TidyDriverBase + */ + public static function factory( array $config ) { + switch ( $config['driver'] ) { + case 'RaggettInternalHHVM': + $instance = new MediaWiki\Tidy\RaggettInternalHHVM( $config ); + break; + case 'RaggettInternalPHP': + $instance = new MediaWiki\Tidy\RaggettInternalPHP( $config ); + break; + case 'RaggettExternal': + $instance = new MediaWiki\Tidy\RaggettExternal( $config ); + break; + case 'Html5Depurate': + $instance = new MediaWiki\Tidy\Html5Depurate( $config ); + break; + case 'Html5Internal': + $instance = new MediaWiki\Tidy\Html5Internal( $config ); + break; + case 'disabled': + return false; + default: + throw new MWException( "Invalid tidy driver: \"{$config['driver']}\"" ); + } + return $instance; + } + /** * Set the driver to be used. This is for testing. * @param TidyDriverBase|false|null $instance