MediaWiki  1.27.3
MWTidy.php
Go to the documentation of this file.
1 <?php
33 class MWTidy {
34  private static $instance;
35 
45  public static function tidy( $text ) {
46  $driver = self::singleton();
47  if ( !$driver ) {
48  throw new MWException( __METHOD__ .
49  ': tidy is disabled, caller should have checked MWTidy::isEnabled()' );
50  }
51  return $driver->tidy( $text );
52  }
53 
63  public static function getModuleStyles() {
64  $driver = self::singleton();
65  if ( $driver && $driver instanceof MediaWiki\Tidy\RaggettBase ) {
66  return [ 'mediawiki.raggett' ];
67  } else {
68  return [];
69  }
70  }
71 
79  public static function checkErrors( $text, &$errorStr = null ) {
80  $driver = self::singleton();
81  if ( !$driver ) {
82  throw new MWException( __METHOD__ .
83  ': tidy is disabled, caller should have checked MWTidy::isEnabled()' );
84  }
85  if ( $driver->supportsValidate() ) {
86  return $driver->validate( $text, $errorStr );
87  } else {
88  throw new MWException( __METHOD__ . ": error text return from HHVM tidy is not supported" );
89  }
90  }
91 
92  public static function isEnabled() {
93  return self::singleton() !== false;
94  }
95 
96  protected static function singleton() {
97  global $wgUseTidy, $wgTidyInternal, $wgTidyConf, $wgDebugTidy, $wgTidyConfig,
98  $wgTidyBin, $wgTidyOpts;
99 
100  if ( self::$instance === null ) {
101  if ( $wgTidyConfig !== null ) {
102  $config = $wgTidyConfig;
103  } elseif ( $wgUseTidy ) {
104  // b/c configuration
105  $config = [
106  'tidyConfigFile' => $wgTidyConf,
107  'debugComment' => $wgDebugTidy,
108  'tidyBin' => $wgTidyBin,
109  'tidyCommandLine' => $wgTidyOpts ];
110  if ( $wgTidyInternal ) {
111  if ( wfIsHHVM() ) {
112  $config['driver'] = 'RaggettInternalHHVM';
113  } else {
114  $config['driver'] = 'RaggettInternalPHP';
115  }
116  } else {
117  $config['driver'] = 'RaggettExternal';
118  }
119  } else {
120  return false;
121  }
122  switch ( $config['driver'] ) {
123  case 'RaggettInternalHHVM':
124  self::$instance = new MediaWiki\Tidy\RaggettInternalHHVM( $config );
125  break;
126  case 'RaggettInternalPHP':
127  self::$instance = new MediaWiki\Tidy\RaggettInternalPHP( $config );
128  break;
129  case 'RaggettExternal':
130  self::$instance = new MediaWiki\Tidy\RaggettExternal( $config );
131  break;
132  case 'Html5Depurate':
133  self::$instance = new MediaWiki\Tidy\Html5Depurate( $config );
134  break;
135  default:
136  throw new MWException( "Invalid tidy driver: \"{$config['driver']}\"" );
137  }
138  }
139  return self::$instance;
140  }
141 
146  public static function setInstance( $instance ) {
147  self::$instance = $instance;
148  }
149 
153  public static function destroySingleton() {
154  self::$instance = null;
155  }
156 }
wfIsHHVM()
Check if we are running under HHVM.
static isEnabled()
Definition: MWTidy.php:92
static tidy($text)
Interface with html tidy.
Definition: MWTidy.php:45
static checkErrors($text, &$errorStr=null)
Check HTML for errors, used if $wgValidateAllHtml = true.
Definition: MWTidy.php:79
A helper class for throttling authentication attempts.
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:96
Class to interact with HTML tidy.
Definition: MWTidy.php:33
static destroySingleton()
Destroy the current singleton instance.
Definition: MWTidy.php:153
static getModuleStyles()
Get CSS modules needed if HTML from the current driver is to be displayed.
Definition: MWTidy.php:63
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:146