X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=includes%2Fparser%2FMWTidy.php;h=5e5461587b9d0648802d9a088a981314760abaa3;hb=9c5dae53155a950edb1e712bbda59fa8732fddd8;hp=bdf3efba56ad0bd70a78a5a7dc996e4e7ee2dd4b;hpb=fc1ca75323b5f424a9f8d28d42d85a311ed2f721;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/parser/MWTidy.php b/includes/parser/MWTidy.php index bdf3efba56..5e5461587b 100644 --- a/includes/parser/MWTidy.php +++ b/includes/parser/MWTidy.php @@ -41,6 +41,7 @@ class MWTidy { * @param string $text HTML input fragment. This should not contain a * or tag. * @return string Corrected HTML output + * @throws MWException */ public static function tidy( $text ) { $driver = self::singleton(); @@ -51,30 +52,13 @@ class MWTidy { return $driver->tidy( $text ); } - /** - * Get CSS modules needed if HTML from the current driver is to be displayed. - * - * This is just a migration tool to allow some changes expected as part of - * Tidy replacement (T89331) to be exposed on the client side via user - * scripts, without actually replacing tidy. See T49673. - * - * @return array - */ - public static function getModuleStyles() { - $driver = self::singleton(); - if ( $driver && $driver instanceof MediaWiki\Tidy\RaggettBase ) { - return [ 'mediawiki.raggett' ]; - } else { - return []; - } - } - /** * Check HTML for errors, used if $wgValidateAllHtml = true. * * @param string $text * @param string &$errorStr Return the error string * @return bool Whether the HTML is valid + * @throws MWException */ public static function checkErrors( $text, &$errorStr = null ) { $driver = self::singleton(); @@ -89,10 +73,16 @@ class MWTidy { } } + /** + * @return bool + */ public static function isEnabled() { return self::singleton() !== false; } + /** + * @return bool|\MediaWiki\Tidy\TidyDriverBase + */ protected static function singleton() { global $wgUseTidy, $wgTidyInternal, $wgTidyConf, $wgDebugTidy, $wgTidyConfig, $wgTidyBin, $wgTidyOpts; @@ -119,29 +109,46 @@ 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; - 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 bool|\MediaWiki\Tidy\TidyDriverBase + * @throws MWException + */ + 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 + * @param MediaWiki\Tidy\TidyDriverBase|false|null $instance */ public static function setInstance( $instance ) { self::$instance = $instance;