MediaWiki  1.28.3
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  protected 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 'disabled':
142  return false;
143  default:
144  throw new MWException( "Invalid tidy driver: \"{$config['driver']}\"" );
145  }
146  return $instance;
147  }
148 
153  public static function setInstance( $instance ) {
154  self::$instance = $instance;
155  }
156 
160  public static function destroySingleton() {
161  self::$instance = null;
162  }
163 }
the array() calling protocol came about after MediaWiki 1.4rc1.
wfIsHHVM()
Check if we are running under HHVM.
static factory(array $config)
Create a new Tidy driver object from configuration.
Definition: MWTidy.php:124
static isEnabled()
Definition: MWTidy.php:79
static tidy($text)
Interface with html tidy.
Definition: MWTidy.php:46
static checkErrors($text, &$errorStr=null)
Check HTML for errors, used if $wgValidateAllHtml = true.
Definition: MWTidy.php:63
when a variable name is used in a it is silently declared as a new local masking the global
Definition: design.txt:93
static singleton()
Definition: MWTidy.php:86
Class to interact with HTML tidy.
Definition: MWTidy.php:33
static destroySingleton()
Destroy the current singleton instance.
Definition: MWTidy.php:160
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
static $instance
Definition: MWTidy.php:34
static setInstance($instance)
Set the driver to be used.
Definition: MWTidy.php:153