MediaWiki REL1_30
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
63 public static function checkErrors( $text, &$errorStr = null ) {
64 $driver = self::singleton();
65 if ( !$driver ) {
66 throw new MWException( __METHOD__ .
67 ': tidy is disabled, caller should have checked MWTidy::isEnabled()' );
68 }
69 if ( $driver->supportsValidate() ) {
70 return $driver->validate( $text, $errorStr );
71 } else {
72 throw new MWException( __METHOD__ . ": error text return from HHVM tidy is not supported" );
73 }
74 }
75
79 public static function isEnabled() {
80 return self::singleton() !== false;
81 }
82
86 public static function singleton() {
89
90 if ( self::$instance === null ) {
91 if ( $wgTidyConfig !== null ) {
92 $config = $wgTidyConfig;
93 } elseif ( $wgUseTidy ) {
94 // b/c configuration
95 $config = [
96 'tidyConfigFile' => $wgTidyConf,
97 'debugComment' => $wgDebugTidy,
98 'tidyBin' => $wgTidyBin,
99 'tidyCommandLine' => $wgTidyOpts ];
100 if ( $wgTidyInternal ) {
101 if ( wfIsHHVM() ) {
102 $config['driver'] = 'RaggettInternalHHVM';
103 } else {
104 $config['driver'] = 'RaggettInternalPHP';
105 }
106 } else {
107 $config['driver'] = 'RaggettExternal';
108 }
109 } else {
110 return false;
111 }
112 self::$instance = self::factory( $config );
113 }
114 return self::$instance;
115 }
116
124 public static function factory( array $config ) {
125 switch ( $config['driver'] ) {
126 case 'RaggettInternalHHVM':
128 break;
129 case 'RaggettInternalPHP':
131 break;
132 case 'RaggettExternal':
134 break;
135 case 'Html5Depurate':
137 break;
138 case 'Html5Internal':
140 break;
141 case 'RemexHtml':
142 $instance = new MediaWiki\Tidy\RemexDriver( $config );
143 break;
144 case 'disabled':
145 return false;
146 default:
147 throw new MWException( "Invalid tidy driver: \"{$config['driver']}\"" );
148 }
149 return $instance;
150 }
151
156 public static function setInstance( $instance ) {
157 self::$instance = $instance;
158 }
159
163 public static function destroySingleton() {
164 self::$instance = null;
165 }
166}
$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:86
static factory(array $config)
Create a new Tidy driver object from configuration.
Definition MWTidy.php:124
static setInstance( $instance)
Set the driver to be used.
Definition MWTidy.php:156
static destroySingleton()
Destroy the current singleton instance.
Definition MWTidy.php:163
static checkErrors( $text, &$errorStr=null)
Check HTML for errors, used if $wgValidateAllHtml = true.
Definition MWTidy.php:63
static tidy( $text)
Interface with html tidy.
Definition MWTidy.php:46
static isEnabled()
Definition MWTidy.php:79