3 * HTML validation and correction
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
25 * Class to interact with and configure Remex tidy
30 private static $instance;
33 * Interface with Remex tidy.
34 * If tidy isn't able to correct the markup, the original will be
35 * returned in all its glory with a warning comment appended.
37 * @param string $text HTML input fragment. This should not contain a
38 * <body> or <html> tag.
39 * @return string Corrected HTML output
42 public static function tidy( $text ) {
43 $driver = self
::singleton();
45 throw new MWException( __METHOD__
.
46 ': tidy is disabled, caller should have checked MWTidy::isEnabled()' );
48 return $driver->tidy( $text );
54 public static function isEnabled() {
55 return self
::singleton() !== false;
59 * @return bool|\MediaWiki\Tidy\TidyDriverBase
61 public static function singleton() {
63 if ( self
::$instance === null ) {
64 self
::$instance = self
::factory( $wgTidyConfig );
66 return self
::$instance;
70 * Create a new Tidy driver object from configuration.
72 * @param array|null $config Optional since 1.33
73 * @return bool|\MediaWiki\Tidy\TidyDriverBase
76 public static function factory( array $config = null ) {
77 return new MediaWiki\Tidy\
RemexDriver( $config ??
[] );
81 * Set the driver to be used. This is for testing.
82 * @param MediaWiki\Tidy\TidyDriverBase|false|null $instance
83 * @deprecated Since 1.33
85 public static function setInstance( $instance ) {
86 wfDeprecated( __METHOD__
, '1.33' );
87 self
::$instance = $instance;
91 * Destroy the current singleton instance
93 public static function destroySingleton() {
94 self
::$instance = null;