From d3d682fb45189c7437b6344c40b6024557bc06e0 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Wed, 13 Jul 2016 12:01:59 +1000 Subject: [PATCH] Hide marked empty elements by default (stage 1) We originally imagined rolling out the display of empty elements simultaneously with the Html5Depurate, but now we have added support for marking empty elements to Html5Depurate and plan on having some sort of longer migration period. So, move the relevant CSS to content.css, and remove the concept of CSS dependant on tidy driver. Add a body class which will allow the effect to be toggled in a gadget or extension. Actual toggling in the CSS will be in the stage 2 patch, to be deployed after the varnish cache and parser cache have expired. I originally imagined that there would be a gadget that overrides the rule with an !important selector, but that method does not allow you to recover the original display property, which is often overridden by the style attribute or site CSS to be "inline". Also, in RaggettWrapper, switch to the new class mw-empty-elt, following Html5Depurate, instead of mw-empty-li. The old class will be removed in the stage 2 patch. Change-Id: Ic0f432c43a006629ca5a1a7c2dda3552ceb4dc4f --- includes/OutputPage.php | 5 +++++ includes/parser/MWTidy.php | 18 ------------------ includes/parser/Parser.php | 1 - includes/tidy/RaggettWrapper.php | 2 +- resources/src/mediawiki.skinning/content.css | 6 ++++++ resources/src/mediawiki/mediawiki.raggett.css | 4 ---- tests/parser/parserTests.txt | 4 ++-- 7 files changed, 14 insertions(+), 26 deletions(-) diff --git a/includes/OutputPage.php b/includes/OutputPage.php index c667fb9363..7d5e1af512 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -2688,6 +2688,11 @@ class OutputPage extends ContextSource { $bodyClasses[] = 'capitalize-all-nouns'; } + // Parser feature migration class + // The idea is that this will eventually be removed, after the wikitext + // which requires it is cleaned up. + $bodyClasses[] = 'mw-hide-empty-elt'; + $bodyClasses[] = $sk->getPageClasses( $this->getTitle() ); $bodyClasses[] = 'skin-' . Sanitizer::escapeClass( $sk->getSkinName() ); $bodyClasses[] = diff --git a/includes/parser/MWTidy.php b/includes/parser/MWTidy.php index a47e002b96..32d8373176 100644 --- a/includes/parser/MWTidy.php +++ b/includes/parser/MWTidy.php @@ -51,24 +51,6 @@ class MWTidy { return $driver->tidy( $text ); } - /** - * Get CSS modules needed if HTML from the current driver is to be displayed. - * - * This is just a migration tool to allow some changes expected as part of - * Tidy replacement (T89331) to be exposed on the client side via user - * scripts, without actually replacing tidy. See T49673. - * - * @return array - */ - public static function getModuleStyles() { - $driver = self::singleton(); - if ( $driver && $driver instanceof MediaWiki\Tidy\RaggettBase ) { - return [ 'mediawiki.raggett' ]; - } else { - return []; - } - } - /** * Check HTML for errors, used if $wgValidateAllHtml = true. * diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index 19d68c274f..a765450f4e 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -1357,7 +1357,6 @@ class Parser { if ( MWTidy::isEnabled() && $this->mOptions->getTidy() ) { $text = MWTidy::tidy( $text ); - $this->mOutput->addModuleStyles( MWTidy::getModuleStyles() ); } else { # attempt to sanitize at least some nesting problems # (bug #2702 and quite a few others) diff --git a/includes/tidy/RaggettWrapper.php b/includes/tidy/RaggettWrapper.php index ab19142cc4..56d5ce76fd 100644 --- a/includes/tidy/RaggettWrapper.php +++ b/includes/tidy/RaggettWrapper.php @@ -54,7 +54,7 @@ class RaggettWrapper { // Preserve empty li elements (T49673) by abusing Tidy's datafld hack // The whitespace class is as in TY_(InitMap) $wrappedtext = preg_replace( "!
  • ([ \r\n\t\f]*)
  • !", - '
  • \1
  • ', $wrappedtext ); + '
  • \1
  • ', $wrappedtext ); // Wrap the whole thing in a doctype and body for Tidy. $wrappedtext = '
  • a
  • -
  • -
  • +
  • +
  • b
  • !! end -- 2.20.1