From 846f4f58f50f3d9f28ba014d38ae72748158ef91 Mon Sep 17 00:00:00 2001 From: "James D. Forrester" Date: Tue, 17 Apr 2018 18:22:13 -0700 Subject: [PATCH] Remove $wgExperimentalHtmlIds and related code, deprecated in 1.30 Bug: T139744 Change-Id: Ia15d5ab6e7637fd40d5c3399822a3dbeb7b383b5 --- RELEASE-NOTES-1.32 | 2 + includes/DefaultSettings.php | 11 ------ includes/Setup.php | 6 --- includes/parser/Sanitizer.php | 37 +++---------------- resources/src/mediawiki/mediawiki.util.js | 7 ---- tests/parser/ParserTestRunner.php | 1 - .../phpunit/includes/parser/SanitizerTest.php | 15 -------- .../mediawiki/mediawiki.util.test.js | 22 ++--------- 8 files changed, 12 insertions(+), 89 deletions(-) diff --git a/RELEASE-NOTES-1.32 b/RELEASE-NOTES-1.32 index 6b3b1298ca..3df5e0b8b1 100644 --- a/RELEASE-NOTES-1.32 +++ b/RELEASE-NOTES-1.32 @@ -11,6 +11,8 @@ production. * The $wgSiteSupportPage setting, unused since 1.5, was removed. * $wgJpegQuality was added to allow configuring the quality of JPEG thumbnails (default 80). * The default quality of JPEG thumbnails generated by GD was reduced from 95 to 80. +* $wgExperimentalHtmlIds, deprecated since 1.30, has been removed. The 'html5-legacy' value for + $wgFragmentMode is no longer accepted. * … === New features in 1.32 === diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 4f4fa86e18..6ea3b9dc2b 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -3372,23 +3372,12 @@ $wgApiFrameOptions = 'DENY'; */ $wgDisableOutputCompression = false; -/** - * Abandoned experiment with HTML5-style ID escaping. Normalized IDs a bit - * too aggressively, breaking preexisting content (particularly Cite). - * See T29733, T29694, T29474. - * - * @deprecated since 1.30, use $wgFragmentMode - */ -$wgExperimentalHtmlIds = false; - /** * How should section IDs be encoded? * This array can contain 1 or 2 elements, each of them can be one of: * - 'html5' is modern HTML5 style encoding with minimal escaping. Displays Unicode * characters in most browsers' address bars. * - 'legacy' is old MediaWiki-style encoding, e.g. 啤酒 turns into .E5.95.A4.E9.85.92 - * - 'html5-legacy' corresponds to DEPRECATED $wgExperimentalHtmlIds mode. DO NOT use - * it for anything but migration off that mode (see below). * * The first element of this array specifies the primary mode of escaping IDs. This * is what users will see when they e.g. follow an [[#internal link]] to a section of diff --git a/includes/Setup.php b/includes/Setup.php index 6825c7b70f..5cc9a96aa3 100644 --- a/includes/Setup.php +++ b/includes/Setup.php @@ -361,12 +361,6 @@ foreach ( $wgForeignFileRepos as &$repo ) { } unset( $repo ); // no global pollution; destroy reference -// Convert this deprecated setting to modern system -if ( $wgExperimentalHtmlIds ) { - wfDeprecated( '$wgExperimentalHtmlIds', '1.30' ); - $wgFragmentMode = [ 'html5-legacy', 'html5' ]; -} - $rcMaxAgeDays = $wgRCMaxAge / ( 3600 * 24 ); if ( $wgRCFilterByAge ) { // Trim down $wgRCLinkDays so that it only lists links which are valid diff --git a/includes/parser/Sanitizer.php b/includes/parser/Sanitizer.php index b13e59787f..118442db0a 100644 --- a/includes/parser/Sanitizer.php +++ b/includes/parser/Sanitizer.php @@ -1180,13 +1180,12 @@ class Sanitizer { /** * Given a value, escape it so that it can be used in an id attribute and - * return it. This will use HTML5 validation if $wgExperimentalHtmlIds is - * true, allowing anything but ASCII whitespace. Otherwise it will use - * HTML 4 rules, which means a narrow subset of ASCII, with bad characters - * escaped with lots of dots. + * return it. This will use HTML5 validation, allowing anything but ASCII + * whitespace. + * + * To ensure we don't have to bother escaping anything, we also strip ', ". + * TODO: Is this the best tactic? * - * To ensure we don't have to bother escaping anything, we also strip ', ", - * & even if $wgExperimentalIds is true. TODO: Is this the best tactic? * We also strip # because it upsets IE, and % because it could be * ambiguous if it's part of something that looks like a percent escape * (which don't work reliably in fragments cross-browser). @@ -1204,28 +1203,12 @@ class Sanitizer { * @param string|array $options String or array of strings (default is array()): * 'noninitial': This is a non-initial fragment of an id, not a full id, * so don't pay attention if the first character isn't valid at the - * beginning of an id. Only matters if $wgExperimentalHtmlIds is - * false. - * 'legacy': Behave the way the old HTML 4-based ID escaping worked even - * if $wgExperimentalHtmlIds is used, so we can generate extra - * anchors and links won't break. + * beginning of an id. * @return string */ static function escapeId( $id, $options = [] ) { - global $wgExperimentalHtmlIds; $options = (array)$options; - if ( $wgExperimentalHtmlIds && !in_array( 'legacy', $options ) ) { - $id = preg_replace( '/[ \t\n\r\f_\'"&#%]+/', '_', $id ); - $id = trim( $id, '_' ); - if ( $id === '' ) { - // Must have been all whitespace to start with. - return '_'; - } else { - return $id; - } - } - // HTML4-style escaping static $replace = [ '%3A' => ':', @@ -1337,14 +1320,6 @@ class Sanitizer { $id = urlencode( str_replace( ' ', '_', $id ) ); $id = strtr( $id, $replace ); break; - case 'html5-legacy': - $id = preg_replace( '/[ \t\n\r\f_\'"&#%]+/', '_', $id ); - $id = trim( $id, '_' ); - if ( $id === '' ) { - // Must have been all whitespace to start with. - $id = '_'; - } - break; default: throw new InvalidArgumentException( "Invalid mode '$mode' passed to '" . __METHOD__ ); } diff --git a/resources/src/mediawiki/mediawiki.util.js b/resources/src/mediawiki/mediawiki.util.js index 9f6167a7c5..f0c74cedc4 100644 --- a/resources/src/mediawiki/mediawiki.util.js +++ b/resources/src/mediawiki/mediawiki.util.js @@ -32,13 +32,6 @@ switch ( mode ) { case 'html5': return str.replace( / /g, '_' ); - case 'html5-legacy': - str = str.replace( /[ \t\n\r\f_'"&#%]+/g, '_' ) - .replace( /^_+|_+$/, '' ); - if ( str === '' ) { - str = '_'; - } - return str; case 'legacy': return rawurlencode( str.replace( / /g, '_' ) ) .replace( /%3A/g, ':' ) diff --git a/tests/parser/ParserTestRunner.php b/tests/parser/ParserTestRunner.php index 91ddf24acb..77ef43e693 100644 --- a/tests/parser/ParserTestRunner.php +++ b/tests/parser/ParserTestRunner.php @@ -271,7 +271,6 @@ class ParserTestRunner { $setup['wgNoFollowLinks'] = true; $setup['wgNoFollowDomainExceptions'] = [ 'no-nofollow.org' ]; $setup['wgExternalLinkTarget'] = false; - $setup['wgExperimentalHtmlIds'] = false; $setup['wgLocaltimezone'] = 'UTC'; $setup['wgHtml5'] = true; $setup['wgDisableLangConversion'] = false; diff --git a/tests/phpunit/includes/parser/SanitizerTest.php b/tests/phpunit/includes/parser/SanitizerTest.php index 6590338d36..b5965c480c 100644 --- a/tests/phpunit/includes/parser/SanitizerTest.php +++ b/tests/phpunit/includes/parser/SanitizerTest.php @@ -457,7 +457,6 @@ class SanitizerTest extends MediaWikiTestCase { $legacyEncoded = 'foo_.D1.82.D0.B5.D1.81.D1.82_.23.25.21.27.28.29.5B.5D:.3C.3E' . '.26.26amp.3B.26amp.3Bamp.3B'; $html5Encoded = 'foo_тест_#%!\'()[]:<>&&&amp;'; - $html5Experimental = 'foo_тест_!_()[]:<>_amp;_amp;amp;'; // Settings: last element is $wgExternalInterwikiFragmentMode, the rest is $wgFragmentMode $legacy = [ 'legacy', 'legacy' ]; @@ -465,8 +464,6 @@ class SanitizerTest extends MediaWikiTestCase { $newLegacy = [ 'html5', 'legacy', 'legacy' ]; $new = [ 'html5', 'legacy' ]; $allNew = [ 'html5', 'html5' ]; - $experimentalLegacy = [ 'html5-legacy', 'legacy', 'legacy' ]; - $newExperimental = [ 'html5', 'html5-legacy', 'legacy' ]; return [ // Pure legacy: how MW worked before 2017 @@ -498,18 +495,6 @@ class SanitizerTest extends MediaWikiTestCase { [ 'Attribute', $allNew, $text, false, Sanitizer::ID_FALLBACK ], [ 'Link', $allNew, $text, $html5Encoded ], [ 'ExternalInterwiki', $allNew, $text, $html5Encoded ], - - // Someone flipped $wgExperimentalHtmlIds on - [ 'Attribute', $experimentalLegacy, $text, $html5Experimental, Sanitizer::ID_PRIMARY ], - [ 'Attribute', $experimentalLegacy, $text, $legacyEncoded, Sanitizer::ID_FALLBACK ], - [ 'Link', $experimentalLegacy, $text, $html5Experimental ], - [ 'ExternalInterwiki', $experimentalLegacy, $text, $legacyEncoded ], - - // Migration from $wgExperimentalHtmlIds to modern HTML5 - [ 'Attribute', $newExperimental, $text, $html5Encoded, Sanitizer::ID_PRIMARY ], - [ 'Attribute', $newExperimental, $text, $html5Experimental, Sanitizer::ID_FALLBACK ], - [ 'Link', $newExperimental, $text, $html5Encoded ], - [ 'ExternalInterwiki', $newExperimental, $text, $legacyEncoded ], ]; } diff --git a/tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js b/tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js index b8464e9907..550808808a 100644 --- a/tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js +++ b/tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js @@ -122,14 +122,11 @@ var text = 'foo тест_#%!\'()[]:<>', legacyEncoded = 'foo_.D1.82.D0.B5.D1.81.D1.82_.23.25.21.27.28.29.5B.5D:.3C.3E', html5Encoded = 'foo_тест_#%!\'()[]:<>', - html5Experimental = 'foo_тест_!_()[]:<>', // Settings: this is $wgFragmentMode legacy = [ 'legacy' ], legacyNew = [ 'legacy', 'html5' ], newLegacy = [ 'html5', 'legacy' ], - allNew = [ 'html5' ], - experimentalLegacy = [ 'html5-legacy', 'legacy' ], - newExperimental = [ 'html5', 'html5-legacy' ]; + allNew = [ 'html5' ]; // Test cases are kept in sync with SanitizerTest.php [ @@ -140,11 +137,7 @@ // New world: HTML5 links, legacy fallbacks [ newLegacy, text, html5Encoded ], // Distant future: no legacy fallbacks - [ allNew, text, html5Encoded ], - // Someone flipped $wgExperimentalHtmlIds on - [ experimentalLegacy, text, html5Experimental ], - // Migration from $wgExperimentalHtmlIds to modern HTML5 - [ newExperimental, text, html5Encoded ] + [ allNew, text, html5Encoded ] ].forEach( function ( testCase ) { mw.config.set( 'wgFragmentMode', testCase[ 0 ] ); @@ -157,14 +150,11 @@ var text = 'foo тест_#%!\'()[]:<>', legacyEncoded = 'foo_.D1.82.D0.B5.D1.81.D1.82_.23.25.21.27.28.29.5B.5D:.3C.3E', html5Encoded = 'foo_тест_#%!\'()[]:<>', - html5Experimental = 'foo_тест_!_()[]:<>', // Settings: this is wgFragmentMode legacy = [ 'legacy' ], legacyNew = [ 'legacy', 'html5' ], newLegacy = [ 'html5', 'legacy' ], - allNew = [ 'html5' ], - experimentalLegacy = [ 'html5-legacy', 'legacy' ], - newExperimental = [ 'html5', 'html5-legacy' ]; + allNew = [ 'html5' ]; [ // Pure legacy: how MW worked before 2017 @@ -174,11 +164,7 @@ // New world: HTML5 links, legacy fallbacks [ newLegacy, text, html5Encoded ], // Distant future: no legacy fallbacks - [ allNew, text, html5Encoded ], - // Someone flipped wgExperimentalHtmlIds on - [ experimentalLegacy, text, html5Experimental ], - // Migration from wgExperimentalHtmlIds to modern HTML5 - [ newExperimental, text, html5Encoded ] + [ allNew, text, html5Encoded ] ].forEach( function ( testCase ) { mw.config.set( 'wgFragmentMode', testCase[ 0 ] ); -- 2.20.1