MediaWiki REL1_31
MWTidy.php
Go to the documentation of this file.
1<?php
33class MWTidy {
34 private static $instance;
35
46 public static function tidy( $text ) {
47 $driver = self::singleton();
48 if ( !$driver ) {
49 throw new MWException( __METHOD__ .
50 ': tidy is disabled, caller should have checked MWTidy::isEnabled()' );
51 }
52 return $driver->tidy( $text );
53 }
54
58 public static function isEnabled() {
59 return self::singleton() !== false;
60 }
61
65 public static function singleton() {
68
69 if ( self::$instance === null ) {
70 if ( $wgTidyConfig !== null ) {
71 $config = $wgTidyConfig;
72 } elseif ( $wgUseTidy ) {
73 // b/c configuration
74 $config = [
75 'tidyConfigFile' => $wgTidyConf,
76 'debugComment' => $wgDebugTidy,
77 'tidyBin' => $wgTidyBin,
78 'tidyCommandLine' => $wgTidyOpts ];
79 if ( $wgTidyInternal ) {
80 if ( wfIsHHVM() ) {
81 $config['driver'] = 'RaggettInternalHHVM';
82 } else {
83 $config['driver'] = 'RaggettInternalPHP';
84 }
85 } else {
86 $config['driver'] = 'RaggettExternal';
87 }
88 } else {
89 return false;
90 }
91 self::$instance = self::factory( $config );
92 }
93 return self::$instance;
94 }
95
103 public static function factory( array $config ) {
104 switch ( $config['driver'] ) {
105 case 'RaggettInternalHHVM':
107 break;
108 case 'RaggettInternalPHP':
110 break;
111 case 'RaggettExternal':
113 break;
114 case 'Html5Depurate':
116 break;
117 case 'Html5Internal':
119 break;
120 case 'RemexHtml':
121 $instance = new MediaWiki\Tidy\RemexDriver( $config );
122 break;
123 case 'disabled':
124 return false;
125 default:
126 throw new MWException( "Invalid tidy driver: \"{$config['driver']}\"" );
127 }
128 return $instance;
129 }
130
135 public static function setInstance( $instance ) {
136 self::$instance = $instance;
137 }
138
142 public static function destroySingleton() {
143 self::$instance = null;
144 }
145}
$wgTidyConf
The path to the tidy config file.
$wgTidyInternal
Set this to true to use the tidy extension.
$wgUseTidy
Set this to true to use the deprecated tidy configuration parameters.
$wgDebugTidy
Put tidy warnings in HTML comments Only works for internal tidy.
$wgTidyBin
The path to the tidy binary.
$wgTidyOpts
The command line options to the tidy binary.
$wgTidyConfig
Configuration for HTML postprocessing tool.
wfIsHHVM()
Check if we are running under HHVM.
MediaWiki exception.
Class to interact with HTML tidy.
Definition MWTidy.php:33
static $instance
Definition MWTidy.php:34
static singleton()
Definition MWTidy.php:65
static factory(array $config)
Create a new Tidy driver object from configuration.
Definition MWTidy.php:103
static setInstance( $instance)
Set the driver to be used.
Definition MWTidy.php:135
static destroySingleton()
Destroy the current singleton instance.
Definition MWTidy.php:142
static tidy( $text)
Interface with html tidy.
Definition MWTidy.php:46
static isEnabled()
Definition MWTidy.php:58