From: Tim Starling Date: Wed, 14 Oct 2015 03:16:44 +0000 (-0400) Subject: Client-side migration for empty li preservation X-Git-Tag: 1.31.0-rc.0~9187 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22articles%22%2C%22id_article=%24id_article%22%29%20.%20%22?a=commitdiff_plain;h=eb40eb0f1834bd480f15cc9e14dd9c31bfe42e25;p=lhc%2Fweb%2Fwiklou.git Client-side migration for empty li preservation It is desirable in terms of user-friendly syntax to display an empty list item if the user adds one to the source. However, we suspect that this change will break the rendering of existing templates. So, preserve the empty
  • element, but style it with display:none so that there is no user-visible change. Changes can then be observed with a user script, then eventually the CSS can be removed so that the desired behaviour will be user visible. This is imagined as a staged deployment of T89331, i.e. it is better to resolve differences with Html5Depurate one at a time instead of deploying it all at once. The CSS module is specified in parser/MWTidy.php since the tidy driver hierarchy is not meant to be so closely tied to the MW environment. Bug: T49673 Change-Id: Ifb44b782c617240e3de73dcdf76c8737c7307d94 --- diff --git a/includes/parser/MWTidy.php b/includes/parser/MWTidy.php index 3a2bb177e6..746e15be3e 100644 --- a/includes/parser/MWTidy.php +++ b/includes/parser/MWTidy.php @@ -51,6 +51,24 @@ 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 array( 'mediawiki.raggett' ); + } else { + return array(); + } + } + /** * Check HTML for errors, used if $wgValidateAllHtml = true. * diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index 9060756a82..cfbf0b46cd 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -1340,6 +1340,7 @@ 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 3f549d0750..4759023fbf 100644 --- a/includes/tidy/RaggettWrapper.php +++ b/includes/tidy/RaggettWrapper.php @@ -51,6 +51,11 @@ class RaggettWrapper { // we can trick Tidy into not stripping them out by including them in tidy's new-empty-tags config $wrappedtext = preg_replace( '!<(link|meta)([^>]*?)(/{0,1}>)!', '([ \r\n\t\f]*)
  • !", + '
  • \1
  • ', $wrappedtext ); + // Wrap the whole thing in a doctype and body for Tidy. $wrappedtext = '' . @@ -79,6 +84,9 @@ class RaggettWrapper { // Revert back to <{link,meta}> $text = preg_replace( '!]*?)(/{0,1}>)!', '<$1$2$3', $text ); + // Remove datafld + $text = str_replace( '
  • mTokens->replace( $text ); diff --git a/resources/Resources.php b/resources/Resources.php index 59ce155497..b1b1541b6a 100644 --- a/resources/Resources.php +++ b/resources/Resources.php @@ -1318,6 +1318,9 @@ return array( 'scripts' => 'resources/src/mediawiki/mediawiki.experiments.js', 'targets' => array( 'desktop', 'mobile' ), ), + 'mediawiki.raggett' => array( + 'styles' => 'resources/src/mediawiki/mediawiki.raggett.css' + ), /* MediaWiki Action */ diff --git a/resources/src/mediawiki/mediawiki.raggett.css b/resources/src/mediawiki/mediawiki.raggett.css new file mode 100644 index 0000000000..1e1e973ca7 --- /dev/null +++ b/resources/src/mediawiki/mediawiki.raggett.css @@ -0,0 +1,3 @@ +.mw-empty-li { + display: none; +} diff --git a/tests/parser/parserTests.txt b/tests/parser/parserTests.txt index f245826d3d..4e6c591695 100644 --- a/tests/parser/parserTests.txt +++ b/tests/parser/parserTests.txt @@ -26405,3 +26405,19 @@ B foobar !! end + +!! test +Empty LI (T49673) +!! wikitext +* a +* +* +* b +!! html/php+tidy +
      +
    • a
    • +
    • +
    • +
    • b
    • +
    +!! end