MediaWiki REL1_32
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 wfDeprecated( '$wgUseTidy', '1.26' );
75 $config = [
76 'tidyConfigFile' => $wgTidyConf,
77 'debugComment' => $wgDebugTidy,
78 'tidyBin' => $wgTidyBin,
79 'tidyCommandLine' => $wgTidyOpts ];
80 if ( $wgTidyInternal ) {
81 if ( wfIsHHVM() ) {
82 $config['driver'] = 'RaggettInternalHHVM';
83 } else {
84 $config['driver'] = 'RaggettInternalPHP';
85 }
86 } else {
87 $config['driver'] = 'RaggettExternal';
88 }
89 } else {
90 wfDeprecated( '$wgTidyConfig = null and $wgUseTidy = false', '1.26' );
91 return false;
92 }
93 self::$instance = self::factory( $config );
94 }
95 return self::$instance;
96 }
97
105 public static function factory( array $config ) {
106 switch ( $config['driver'] ) {
107 case 'RaggettInternalHHVM':
109 break;
110 case 'RaggettInternalPHP':
112 break;
113 case 'RaggettExternal':
115 break;
116 case 'RemexHtml':
117 $instance = new MediaWiki\Tidy\RemexDriver( $config );
118 break;
119 case 'disabled':
120 wfDeprecated( '"disabled" tidy driver', '1.32' );
121 return false;
122 default:
123 throw new MWException( "Invalid tidy driver: \"{$config['driver']}\"" );
124 }
125 return $instance;
126 }
127
132 public static function setInstance( $instance ) {
133 self::$instance = $instance;
134 }
135
139 public static function destroySingleton() {
140 self::$instance = null;
141 }
142}
$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.
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
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:105
static setInstance( $instance)
Set the driver to be used.
Definition MWTidy.php:132
static destroySingleton()
Destroy the current singleton instance.
Definition MWTidy.php:139
static tidy( $text)
Interface with html tidy.
Definition MWTidy.php:46
static isEnabled()
Definition MWTidy.php:58
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
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))