MediaWiki  1.29.2
MWTidy.php
Go to the documentation of this file.
1 <?php
33 class 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() {
87  global $wgUseTidy, $wgTidyInternal, $wgTidyConf, $wgDebugTidy, $wgTidyConfig,
88  $wgTidyBin, $wgTidyOpts;
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':
133  $instance = new MediaWiki\Tidy\RaggettExternal( $config );
134  break;
135  case 'Html5Depurate':
136  $instance = new MediaWiki\Tidy\Html5Depurate( $config );
137  break;
138  case 'Html5Internal':
139  $instance = new MediaWiki\Tidy\Html5Internal( $config );
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 }
MediaWiki\Tidy\RaggettInternalHHVM
Definition: RaggettInternalHHVM.php:5
MediaWiki\Tidy\RaggettInternalPHP
Definition: RaggettInternalPHP.php:5
MWTidy\factory
static factory(array $config)
Create a new Tidy driver object from configuration.
Definition: MWTidy.php:124
MWTidy\isEnabled
static isEnabled()
Definition: MWTidy.php:79
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
MWException
MediaWiki exception.
Definition: MWException.php:26
MediaWiki\Tidy\RemexDriver
Definition: RemexDriver.php:11
MWTidy\$instance
static $instance
Definition: MWTidy.php:34
MediaWiki\Tidy\RaggettExternal
Definition: RaggettExternal.php:5
MWTidy
Class to interact with HTML tidy.
Definition: MWTidy.php:33
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
MWTidy\setInstance
static setInstance( $instance)
Set the driver to be used.
Definition: MWTidy.php:156
MediaWiki\Tidy\Html5Internal
Definition: Html5Internal.php:5
MWTidy\singleton
static singleton()
Definition: MWTidy.php:86
MediaWiki\Tidy\Html5Depurate
Definition: Html5Depurate.php:8
MWTidy\checkErrors
static checkErrors( $text, &$errorStr=null)
Check HTML for errors, used if $wgValidateAllHtml = true.
Definition: MWTidy.php:63
wfIsHHVM
wfIsHHVM()
Check if we are running under HHVM.
Definition: GlobalFunctions.php:2046
MWTidy\destroySingleton
static destroySingleton()
Destroy the current singleton instance.
Definition: MWTidy.php:163
array
the array() calling protocol came about after MediaWiki 1.4rc1.
MWTidy\tidy
static tidy( $text)
Interface with html tidy.
Definition: MWTidy.php:46