MediaWiki  REL1_31
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 
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':
112  $instance = new MediaWiki\Tidy\RaggettExternal( $config );
113  break;
114  case 'Html5Depurate':
115  $instance = new MediaWiki\Tidy\Html5Depurate( $config );
116  break;
117  case 'Html5Internal':
118  $instance = new MediaWiki\Tidy\Html5Internal( $config );
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 }
MediaWiki\Tidy\RaggettInternalHHVM
Definition: RaggettInternalHHVM.php:5
array
the array() calling protocol came about after MediaWiki 1.4rc1.
MediaWiki\Tidy\RaggettInternalPHP
Definition: RaggettInternalPHP.php:5
MWTidy\factory
static factory(array $config)
Create a new Tidy driver object from configuration.
Definition: MWTidy.php:103
$wgDebugTidy
$wgDebugTidy
Put tidy warnings in HTML comments Only works for internal tidy.
Definition: DefaultSettings.php:4333
MWTidy\isEnabled
static isEnabled()
Definition: MWTidy.php:58
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:37
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:95
MWTidy\setInstance
static setInstance( $instance)
Set the driver to be used.
Definition: MWTidy.php:135
$wgTidyConf
$wgTidyConf
The path to the tidy config file.
Definition: DefaultSettings.php:4315
$wgTidyInternal
$wgTidyInternal
Set this to true to use the tidy extension.
Definition: DefaultSettings.php:4327
$wgUseTidy
$wgUseTidy
Set this to true to use the deprecated tidy configuration parameters.
Definition: DefaultSettings.php:4303
MediaWiki\Tidy\Html5Internal
Definition: Html5Internal.php:5
$wgTidyOpts
$wgTidyOpts
The command line options to the tidy binary.
Definition: DefaultSettings.php:4321
$wgTidyConfig
$wgTidyConfig
Configuration for HTML postprocessing tool.
Definition: DefaultSettings.php:4297
MWTidy\singleton
static singleton()
Definition: MWTidy.php:65
MediaWiki\Tidy\Html5Depurate
Definition: Html5Depurate.php:8
$wgTidyBin
$wgTidyBin
The path to the tidy binary.
Definition: DefaultSettings.php:4309
wfIsHHVM
wfIsHHVM()
Check if we are running under HHVM.
Definition: GlobalFunctions.php:2032
MWTidy\destroySingleton
static destroySingleton()
Destroy the current singleton instance.
Definition: MWTidy.php:142
MWTidy\tidy
static tidy( $text)
Interface with html tidy.
Definition: MWTidy.php:46