Rewrite TidySupport and add option --use-tidy-config
[lhc/web/wiklou.git] / includes / parser / MWTidy.php
index 807842b..a47e002 100644 (file)
@@ -45,12 +45,30 @@ class MWTidy {
        public static function tidy( $text ) {
                $driver = self::singleton();
                if ( !$driver ) {
-                       throw new MWException( __METHOD__.
+                       throw new MWException( __METHOD__ .
                                ': tidy is disabled, caller should have checked MWTidy::isEnabled()' );
                }
                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.
         *
@@ -61,7 +79,7 @@ class MWTidy {
        public static function checkErrors( $text, &$errorStr = null ) {
                $driver = self::singleton();
                if ( !$driver ) {
-                       throw new MWException( __METHOD__.
+                       throw new MWException( __METHOD__ .
                                ': tidy is disabled, caller should have checked MWTidy::isEnabled()' );
                }
                if ( $driver->supportsValidate() ) {
@@ -84,11 +102,11 @@ class MWTidy {
                                $config = $wgTidyConfig;
                        } elseif ( $wgUseTidy ) {
                                // b/c configuration
-                               $config = array(
+                               $config = [
                                        'tidyConfigFile' => $wgTidyConf,
                                        'debugComment' => $wgDebugTidy,
                                        'tidyBin' => $wgTidyBin,
-                                       'tidyCommandLine' => $wgTidyOpts );
+                                       'tidyCommandLine' => $wgTidyOpts ];
                                if ( $wgTidyInternal ) {
                                        if ( wfIsHHVM() ) {
                                                $config['driver'] = 'RaggettInternalHHVM';
@@ -114,6 +132,11 @@ class MWTidy {
                                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']}\"" );
                        }