MaxSem has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/375099 )
Change subject: Don't percent-encode HTML5 IDs
......................................................................
Don't percent-encode HTML5 IDs
During the TechCom meeting, it was decided this is the better way.
Change-Id: I6c3ec1c407225b4e925b7373bf52208e2f6b6c4a
---
M includes/Linker.php
M includes/Sanitizer.php
M includes/compat/Timestamp.php
M resources/src/mediawiki/mediawiki.util.js
M tests/parser/parserTests.txt
M tests/phpunit/includes/SanitizerTest.php
M tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js
7 files changed, 36 insertions(+), 54 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/99/375099/1
diff --git a/includes/Linker.php b/includes/Linker.php
index aedb704..415ceab 100644
--- a/includes/Linker.php
+++ b/includes/Linker.php
@@ -1539,10 +1539,16 @@
if ( $sectionIndex !== false ) {
$classes .= " tocsection-$sectionIndex";
}
- return "\n<li class=\"$classes\"><a href=\"#" .
- $anchor . '"><span class="tocnumber">' .
- $tocnumber . '</span> <span class="toctext">' .
- $tocline . '</span></a>';
+
+ // \n<li class="classes"><a href="#$anchor"><span
class="tocnumber">
+ // $tocnumber</span> <span class="toctext">$tocline</span></a>
+ return "\n" . Html::openElement( 'li', [ 'class' => $classes ] )
+ . Html::rawElement( 'a',
+ [ 'href' => "#$anchor" ],
+ Html::rawElement( 'span', [ 'class' =>
'tocnumber' ], $tocnumber )
+ . ' '
+ . Html::rawElement( 'span', [ 'class'
=> 'toctext' ], $tocline )
+ );
}
/**
diff --git a/includes/Sanitizer.php b/includes/Sanitizer.php
index ed09701..7d17cd1 100644
--- a/includes/Sanitizer.php
+++ b/includes/Sanitizer.php
@@ -1284,7 +1284,6 @@
$mode = $wgFragmentMode[self::ID_PRIMARY];
$id = self::escapeIdInternal( $id, $mode );
- $id = self::urlEscapeId( $id, $mode );
return $id;
}
@@ -1302,23 +1301,6 @@
global $wgExternalInterwikiFragmentMode;
$id = self::escapeIdInternal( $id,
$wgExternalInterwikiFragmentMode );
- $id = self::urlEscapeId( $id, $wgExternalInterwikiFragmentMode
);
-
- return $id;
- }
-
- /**
- * Helper for escapeIdFor*() functions. URL-escapes the ID if needed.
- *
- * @param string $id String to escape
- * @param string $mode One of modes from $wgFragmentMode
- * @return string
- */
- private static function urlEscapeId( $id, $mode ) {
- if ( $mode === 'html5' ) {
- $id = urlencode( $id );
- $id = str_replace( '%3A', ':', $id );
- }
return $id;
}
diff --git a/includes/compat/Timestamp.php b/includes/compat/Timestamp.php
index bd25432..f26d56b 100644
--- a/includes/compat/Timestamp.php
+++ b/includes/compat/Timestamp.php
@@ -15,4 +15,4 @@
* @deprecated since 1.29
* @since 1.20
*/
-class_alias( Wikimedia\Timestamp\TimestampException::class, 'Timestamp' .
'Exception' );
+class_alias( Wikimedia\Timestamp\TimestampException::class, 'Timestam' .
'pException' );
diff --git a/resources/src/mediawiki/mediawiki.util.js
b/resources/src/mediawiki/mediawiki.util.js
index 34f7eba..fb34a89 100644
--- a/resources/src/mediawiki/mediawiki.util.js
+++ b/resources/src/mediawiki/mediawiki.util.js
@@ -90,14 +90,9 @@
* @return {string} Encoded string
*/
escapeIdForLink: function ( str ) {
- var mode = mw.config.get( 'wgFragmentMode' )[ 0 ],
- id = escapeIdInternal( str, mode );
+ var mode = mw.config.get( 'wgFragmentMode' )[ 0 ];
- if ( mode === 'html5' ) {
- id = encodeURIComponent( id ).replace( /%3A/g,
':' );
- }
-
- return id;
+ return escapeIdInternal( str, mode );
},
/**
diff --git a/tests/parser/parserTests.txt b/tests/parser/parserTests.txt
index 0205165..4592061 100644
--- a/tests/parser/parserTests.txt
+++ b/tests/parser/parserTests.txt
@@ -28449,10 +28449,10 @@
<ul>
<li class="toclevel-1 tocsection-1"><a href="#Foo_bar"><span
class="tocnumber">1</span> <span class="toctext">Foo bar</span></a></li>
<li class="toclevel-1 tocsection-2"><a href="#foo_Bar_2"><span
class="tocnumber">2</span> <span class="toctext">foo Bar</span></a></li>
-<li class="toclevel-1 tocsection-3"><a href="#%D0%A2%D0%B5%D1%81%D1%82"><span
class="tocnumber">3</span> <span class="toctext">Тест</span></a></li>
-<li class="toclevel-1 tocsection-4"><a
href="#%D0%A2%D0%B5%D1%81%D1%82_2"><span class="tocnumber">4</span> <span
class="toctext">Тест</span></a></li>
-<li class="toclevel-1 tocsection-5"><a href="#%D1%82%D0%B5%D1%81%D1%82"><span
class="tocnumber">5</span> <span class="toctext">тест</span></a></li>
-<li class="toclevel-1 tocsection-6"><a
href="#Hey_%3C_%23_%22_%3E_%25_:_%27"><span class="tocnumber">6</span> <span
class="toctext">Hey < # " > % : '</span></a></li>
+<li class="toclevel-1 tocsection-3"><a href="#Тест"><span
class="tocnumber">3</span> <span class="toctext">Тест</span></a></li>
+<li class="toclevel-1 tocsection-4"><a href="#Тест_2"><span
class="tocnumber">4</span> <span class="toctext">Тест</span></a></li>
+<li class="toclevel-1 tocsection-5"><a href="#тест"><span
class="tocnumber">5</span> <span class="toctext">тест</span></a></li>
+<li class="toclevel-1 tocsection-6"><a
href="#Hey_<_#_"_>_%_:_'"><span class="tocnumber">6</span> <span
class="toctext">Hey < # " > % : '</span></a></li>
</ul>
</div>
@@ -28462,9 +28462,9 @@
<h2><span id=".D0.A2.D0.B5.D1.81.D1.82_2"></span><span class="mw-headline"
id="Тест_2">Тест</span><span class="mw-editsection"><span
class="mw-editsection-bracket">[</span><a
href="/index.php?title=Parser_test&action=edit&section=4" title="Edit
section: Тест">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<h2><span id=".D1.82.D0.B5.D1.81.D1.82"></span><span class="mw-headline"
id="тест">тест</span><span class="mw-editsection"><span
class="mw-editsection-bracket">[</span><a
href="/index.php?title=Parser_test&action=edit&section=5" title="Edit
section: тест">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<h2><span id="Hey_.3C_.23_.22_.3E_.25_:_.27"></span><span class="mw-headline"
id="Hey_<_#_"_>_%_:_'">Hey < # " > % : '</span><span
class="mw-editsection"><span class="mw-editsection-bracket">[</span><a
href="/index.php?title=Parser_test&action=edit&section=6" title="Edit
section: Hey < # " > % : '">edit</a><span
class="mw-editsection-bracket">]</span></span></h2>
-<p><a href="#Foo_bar">#Foo bar</a> <a href="#foo_Bar">#foo Bar</a> <a
href="#%D0%A2%D0%B5%D1%81%D1%82">#Тест</a> <a
href="#%D1%82%D0%B5%D1%81%D1%82">#тест</a> <a
href="#Hey_%3C_%23_%22_%3E_%25_:_%27">#Hey < # " > % : '</a>
-</p><p>%F0%9F%92%A9 <span id="%F0%9F%92%A9"></span>
-</p><p><a href="#%E5%95%A4%E9%85%92">#啤酒</a> <a
href="#%E5%95%A4%E9%85%92">#啤酒</a>
+<p><a href="#Foo_bar">#Foo bar</a> <a href="#foo_Bar">#foo Bar</a> <a
href="#Тест">#Тест</a> <a href="#тест">#тест</a> <a
href="#Hey_<_#_"_>_%_:_'">#Hey < # " > % : '</a>
+</p><p>💩 <span id="💩"></span>
+</p><p><a href="#啤酒">#啤酒</a> <a href="#啤酒">#啤酒</a>
</p>
!! end
@@ -28543,10 +28543,10 @@
<ul>
<li class="toclevel-1 tocsection-1"><a href="#Foo_bar"><span
class="tocnumber">1</span> <span class="toctext">Foo bar</span></a></li>
<li class="toclevel-1 tocsection-2"><a href="#foo_Bar_2"><span
class="tocnumber">2</span> <span class="toctext">foo Bar</span></a></li>
-<li class="toclevel-1 tocsection-3"><a href="#%D0%A2%D0%B5%D1%81%D1%82"><span
class="tocnumber">3</span> <span class="toctext">Тест</span></a></li>
-<li class="toclevel-1 tocsection-4"><a
href="#%D0%A2%D0%B5%D1%81%D1%82_2"><span class="tocnumber">4</span> <span
class="toctext">Тест</span></a></li>
-<li class="toclevel-1 tocsection-5"><a href="#%D1%82%D0%B5%D1%81%D1%82"><span
class="tocnumber">5</span> <span class="toctext">тест</span></a></li>
-<li class="toclevel-1 tocsection-6"><a
href="#Hey_%3C_%23_%22_%3E_%25_:_%27"><span class="tocnumber">6</span> <span
class="toctext">Hey < # " > % : '</span></a></li>
+<li class="toclevel-1 tocsection-3"><a href="#Тест"><span
class="tocnumber">3</span> <span class="toctext">Тест</span></a></li>
+<li class="toclevel-1 tocsection-4"><a href="#Тест_2"><span
class="tocnumber">4</span> <span class="toctext">Тест</span></a></li>
+<li class="toclevel-1 tocsection-5"><a href="#тест"><span
class="tocnumber">5</span> <span class="toctext">тест</span></a></li>
+<li class="toclevel-1 tocsection-6"><a
href="#Hey_<_#_"_>_%_:_'"><span class="tocnumber">6</span> <span
class="toctext">Hey < # " > % : '</span></a></li>
</ul>
</div>
@@ -28556,8 +28556,8 @@
<h2><span class="mw-headline" id="Тест_2">Тест</span><span
class="mw-editsection"><span class="mw-editsection-bracket">[</span><a
href="/index.php?title=Parser_test&action=edit&section=4" title="Edit
section: Тест">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<h2><span class="mw-headline" id="тест">тест</span><span
class="mw-editsection"><span class="mw-editsection-bracket">[</span><a
href="/index.php?title=Parser_test&action=edit&section=5" title="Edit
section: тест">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<h2><span class="mw-headline" id="Hey_<_#_"_>_%_:_'">Hey < # "
> % : '</span><span class="mw-editsection"><span
class="mw-editsection-bracket">[</span><a
href="/index.php?title=Parser_test&action=edit&section=6" title="Edit
section: Hey < # " > % : '">edit</a><span
class="mw-editsection-bracket">]</span></span></h2>
-<p><a href="#Foo_bar">#Foo bar</a> <a href="#foo_Bar">#foo Bar</a> <a
href="#%D0%A2%D0%B5%D1%81%D1%82">#Тест</a> <a
href="#%D1%82%D0%B5%D1%81%D1%82">#тест</a> <a
href="#Hey_%3C_%23_%22_%3E_%25_:_%27">#Hey < # " > % : '</a>
-</p><p>%F0%9F%92%A9 <span id="%F0%9F%92%A9"></span>
-</p><p><a href="#%E5%95%A4%E9%85%92">#啤酒</a> <a
href="#%E5%95%A4%E9%85%92">#啤酒</a>
+<p><a href="#Foo_bar">#Foo bar</a> <a href="#foo_Bar">#foo Bar</a> <a
href="#Тест">#Тест</a> <a href="#тест">#тест</a> <a
href="#Hey_<_#_"_>_%_:_'">#Hey < # " > % : '</a>
+</p><p>💩 <span id="💩"></span>
+</p><p><a href="#啤酒">#啤酒</a> <a href="#啤酒">#啤酒</a>
</p>
!! end
diff --git a/tests/phpunit/includes/SanitizerTest.php
b/tests/phpunit/includes/SanitizerTest.php
index d506623..7472fb9 100644
--- a/tests/phpunit/includes/SanitizerTest.php
+++ b/tests/phpunit/includes/SanitizerTest.php
@@ -456,7 +456,6 @@
$text = 'foo тест_#%!\'()[]:<>';
$legacyEncoded =
'foo_.D1.82.D0.B5.D1.81.D1.82_.23.25.21.27.28.29.5B.5D:.3C.3E';
$html5Encoded = 'foo_тест_#%!\'()[]:<>';
- $html5Escaped =
'foo_%D1%82%D0%B5%D1%81%D1%82_%23%25%21%27%28%29%5B%5D:%3C%3E';
$html5Experimental = 'foo_тест_!_()[]:<>';
// Settings: last element is $wgExternalInterwikiFragmentMode,
the rest is $wgFragmentMode
@@ -484,20 +483,20 @@
// New world: HTML5 links, legacy fallbacks
[ 'Attribute', $newLegacy, $text, $html5Encoded,
Sanitizer::ID_PRIMARY ],
[ 'Attribute', $newLegacy, $text, $legacyEncoded,
Sanitizer::ID_FALLBACK ],
- [ 'Link', $newLegacy, $text, $html5Escaped ],
+ [ 'Link', $newLegacy, $text, $html5Encoded ],
[ 'ExternalInterwiki', $newLegacy, $text,
$legacyEncoded ],
// Distant future: no legacy fallbacks, but still
linking to leagacy wikis
[ 'Attribute', $new, $text, $html5Encoded,
Sanitizer::ID_PRIMARY ],
[ 'Attribute', $new, $text, false,
Sanitizer::ID_FALLBACK ],
- [ 'Link', $new, $text, $html5Escaped ],
+ [ 'Link', $new, $text, $html5Encoded ],
[ 'ExternalInterwiki', $new, $text, $legacyEncoded ],
// Just before the heat death of universe: external
interwikis are also HTML5 \m/
[ 'Attribute', $allNew, $text, $html5Encoded,
Sanitizer::ID_PRIMARY ],
[ 'Attribute', $allNew, $text, false,
Sanitizer::ID_FALLBACK ],
- [ 'Link', $allNew, $text, $html5Escaped ],
- [ 'ExternalInterwiki', $allNew, $text, $html5Escaped ],
+ [ 'Link', $allNew, $text, $html5Encoded ],
+ [ 'ExternalInterwiki', $allNew, $text, $html5Encoded ],
// Someone flipped $wgExperimentalHtmlIds on
[ 'Attribute', $experimentalLegacy, $text,
$html5Experimental, Sanitizer::ID_PRIMARY ],
@@ -508,7 +507,7 @@
// Migration from $wgExperimentalHtmlIds to modern HTML5
[ 'Attribute', $newExperimental, $text, $html5Encoded,
Sanitizer::ID_PRIMARY ],
[ 'Attribute', $newExperimental, $text,
$html5Experimental, Sanitizer::ID_FALLBACK ],
- [ 'Link', $newExperimental, $text, $html5Escaped ],
+ [ '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 2efe9cd..bb27626 100644
--- a/tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js
+++ b/tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js
@@ -156,7 +156,7 @@
// Test cases are kept in sync with SanitizerTest.php
var text = 'foo тест_#%!\'()[]:<>',
legacyEncoded =
'foo_.D1.82.D0.B5.D1.81.D1.82_.23.25.21.27.28.29.5B.5D:.3C.3E',
- html5Escaped =
'foo_%D1%82%D0%B5%D1%81%D1%82_%23%25!\'()%5B%5D:%3C%3E',
+ html5Encoded = 'foo_тест_#%!\'()[]:<>',
html5Experimental = 'foo_тест_!_()[]:<>',
// Settings: this is wgFragmentMode
legacy = [ 'legacy' ],
@@ -172,13 +172,13 @@
// Transition to a new world: legacy links with HTML5
fallback
[ legacyNew, text, legacyEncoded ],
// New world: HTML5 links, legacy fallbacks
- [ newLegacy, text, html5Escaped ],
+ [ newLegacy, text, html5Encoded ],
// Distant future: no legacy fallbacks
- [ allNew, text, html5Escaped ],
+ [ allNew, text, html5Encoded ],
// Someone flipped wgExperimentalHtmlIds on
[ experimentalLegacy, text, html5Experimental ],
// Migration from wgExperimentalHtmlIds to modern HTML5
- [ newExperimental, text, html5Escaped ]
+ [ newExperimental, text, html5Encoded ]
], function ( index, testCase ) {
mw.config.set( 'wgFragmentMode', testCase[ 0 ] );
--
To view, visit https://gerrit.wikimedia.org/r/375099
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I6c3ec1c407225b4e925b7373bf52208e2f6b6c4a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: MaxSem <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits