MediaWiki REL1_31
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
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':
113 break;
114 case 'Html5Depurate':
116 break;
117 case 'Html5Internal':
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}
$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:65
static factory(array $config)
Create a new Tidy driver object from configuration.
Definition MWTidy.php:103
static setInstance( $instance)
Set the driver to be used.
Definition MWTidy.php:135
static destroySingleton()
Destroy the current singleton instance.
Definition MWTidy.php:142
static tidy( $text)
Interface with html tidy.
Definition MWTidy.php:46
static isEnabled()
Definition MWTidy.php:58
when a variable name is used in a it is silently declared as a new local masking the global
Definition design.txt:95
the array() calling protocol came about after MediaWiki 1.4rc1.
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