Remove all methods of MWTidy except for MWTidy::tidy()

These methods were either @internal or deprecated in 1.35

Bug: T198214
Change-Id: Ica1d1fdfd2a23a2040eac90c71f6211a4513c916
This commit is contained in:
C. Scott Ananian 2020-08-12 18:04:35 -04:00 committed by C. Scott Ananian
parent a21774a721
commit 36da9ef204
6 changed files with 9 additions and 75 deletions

View file

@ -97,6 +97,8 @@ because of Phabricator reports.
has been removed.
* Sanitizer::escapeId(), deprecated in 1.30, has been removed.
* The ParserBeforeTidy hook, deprecated in 1.35, has been removed.
* All methods of MWTidy except for MW::tidy() have been removed. These
were either @internal or deprecated in 1.35.
* The support for IE8 has been dropped.
* Less mixin `.background-image-svg-quick()` from mediawiki.mixins.less,
deprecated since 1.35, has been removed.

View file

@ -4641,7 +4641,6 @@ $wgAllowImageTag = false;
* Setting this to null will use default settings.
*
* Keys include:
* - driver: formerly used to select a postprocessor; now ignored.
* - treeMutationTrace: a boolean to turn on Remex tracing
* - serializerTrace: a boolean to turn on Remex tracing
* - mungerTrace: a boolean to turn on Remex tracing
@ -4652,7 +4651,7 @@ $wgAllowImageTag = false;
* Overriding the default configuration is strongly discouraged in
* production.
*/
$wgTidyConfig = [ 'driver' => 'RemexHtml' ];
$wgTidyConfig = [];
/**
* Allow raw, unchecked HTML in "<html>...</html>" sections.

View file

@ -40,47 +40,10 @@ class MWTidy {
* @throws MWException
*/
public static function tidy( $text ) {
$driver = self::singleton();
return $driver->tidy( $text );
}
/**
* @return bool
* @deprecated since 1.35; tidy is always enabled
*/
public static function isEnabled() {
return true;
}
/**
* @return bool|\MediaWiki\Tidy\TidyDriverBase
* @deprecated since 1.35; use MWTidy::tidy()
*/
public static function singleton() {
global $wgTidyConfig;
if ( self::$instance === null ) {
self::$instance = self::factory( $wgTidyConfig );
global $wgTidyConfig;
self::$instance = new MediaWiki\Tidy\RemexDriver( $wgTidyConfig ?? [] );
}
return self::$instance;
}
/**
* Create a new Tidy driver object from configuration.
* @see $wgTidyConfig
* @param array|null $config Optional since 1.33
* @return bool|\MediaWiki\Tidy\TidyDriverBase
* @throws MWException
* @internal
*/
public static function factory( array $config = null ) {
return new MediaWiki\Tidy\RemexDriver( $config ?? [] );
}
/**
* Destroy the current singleton instance
* @internal
*/
public static function destroySingleton() {
self::$instance = null;
return self::$instance->tidy( $text );
}
}

View file

@ -27,10 +27,6 @@ class BenchmarkTidy extends Benchmarker {
public function __construct() {
parent::__construct();
$this->addOption( 'file', 'Path to file containing the input text', false, true );
$this->addOption( 'driver', 'The Tidy driver name, or false to use the configured instance',
false, true );
$this->addOption( 'tidy-config', 'JSON encoded value for the tidy configuration array',
false, true );
}
public function execute() {
@ -39,24 +35,11 @@ class BenchmarkTidy extends Benchmarker {
if ( $html === false ) {
$this->fatalError( "Unable to open input file" );
}
if ( $this->hasOption( 'driver' ) || $this->hasOption( 'tidy-config' ) ) {
$config = json_decode( $this->getOption( 'tidy-config', '{}' ), true );
if ( !is_array( $config ) ) {
$this->fatalError( "Invalid JSON tidy config" );
}
$config += [ 'driver' => $this->getOption( 'driver', 'RemexHtml' ) ];
$driver = MWTidy::factory( $config );
} else {
$driver = MWTidy::singleton();
if ( !$driver ) {
$this->fatalError( "Tidy disabled or not installed" );
}
}
$this->benchmark( $driver, $html );
$this->benchmark( $html );
}
private function benchmark( $driver, $html ) {
private function benchmark( $html ) {
$contLang = MediaWikiServices::getInstance()->getContentLanguage();
$times = [];
$innerCount = 10;
@ -64,7 +47,7 @@ class BenchmarkTidy extends Benchmarker {
for ( $j = 1; $j <= $outerCount; $j++ ) {
$t = microtime( true );
for ( $i = 0; $i < $innerCount; $i++ ) {
$driver->tidy( $html );
MWTidy::tidy( $html );
print $contLang->formatSize( memory_get_usage( true ) ) . "\n";
}
$t = ( ( microtime( true ) - $t ) / $innerCount ) * 1000;

View file

@ -31,17 +31,9 @@ class TextContentTest extends MediaWikiLangTestCase {
CONTENT_MODEL_CSS,
CONTENT_MODEL_JAVASCRIPT,
],
'wgTidyConfig' => [ 'driver' => 'RemexHtml' ],
'wgCapitalLinks' => true,
'wgHooks' => [], // bypass hook ContentGetParserOutput that force custom rendering
] );
MWTidy::destroySingleton();
}
protected function tearDown() : void {
MWTidy::destroySingleton();
parent::tearDown();
}
/**

View file

@ -7,11 +7,6 @@ use Wikimedia\TestingAccessWrapper;
*/
class SanitizerTest extends MediaWikiIntegrationTestCase {
protected function tearDown() : void {
MWTidy::destroySingleton();
parent::tearDown();
}
/**
* @covers Sanitizer::removeHTMLtags
* @dataProvider provideHtml5Tags