Use class instead of id for scribunto errors

This avoids having multiple HTML elements with the same `id` attribute
when certain Scribunto errors reoccur more than once on the same page.

Bug: T375539
Change-Id: I123a0f0046a616f63506f096651ae917bbc65cc5
This commit is contained in:
C. Scott Ananian 2024-09-24 12:50:38 -04:00
parent ba5588a2b9
commit 248e886dc0
3 changed files with 11 additions and 7 deletions

View file

@ -223,7 +223,7 @@ class Hooks implements
$parserError = htmlspecialchars( $e->getMessage() );
// #iferror-compatible error element
return "<strong class=\"error\"><span class=\"scribunto-error\" id=\"$id\">" .
return "<strong class=\"error\"><span class=\"scribunto-error $id\">" .
$parserError . "</span></strong>";
}
}

View file

@ -1,11 +1,15 @@
( () => {
mw.hook( 'wikipage.content' ).add( () => {
const regex = /^mw-scribunto-error-(\w+)/;
const regex = /\bmw-scribunto-error-(\w+)\b/;
let popup;
$( '.scribunto-error' ).each( ( index, span ) => {
const matches = regex.exec( span.id );
let matches = regex.exec( span.className );
if ( matches === null ) {
// T375539: backward-compatibility with old cached HTML
matches = regex.exec( span.id );
}
if ( matches === null ) {
mw.log( 'mw.scribunto.errors: regex mismatch!' );
return;

View file

@ -272,10 +272,10 @@ extension=ScribuntoErrors-5e10d413
cat=Pages_with_script_errors sort=
extension[ScribuntoErrors-5e10d413]="<p>Script error: No such module \"foo\".</p><p>No further details are available.</p>"
!! html/php
<p><strong class="error"><span class="scribunto-error" id="mw-scribunto-error-5e10d413">Script error: No such module &quot;foo&quot;.</span></strong>
<p><strong class="error"><span class="scribunto-error mw-scribunto-error-5e10d413">Script error: No such module &quot;foo&quot;.</span></strong>
</p>
!! html/parsoid
<p><strong class="error" about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#invoke:foo","function":"invoke"},"params":{"1":{"wt":"bar"}},"i":0}}]}'><span class="scribunto-error" id="mw-scribunto-error-5e10d413">Script error: No such module <span typeof="mw:Entity">"</span>foo<span typeof="mw:Entity">"</span>.</span></strong></p>
<p><strong class="error" about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#invoke:foo","function":"invoke"},"params":{"1":{"wt":"bar"}},"i":0}}]}'><span class="scribunto-error mw-scribunto-error-5e10d413">Script error: No such module <span typeof="mw:Entity">"</span>foo<span typeof="mw:Entity">"</span>.</span></strong></p>
!! end
!! test
@ -290,10 +290,10 @@ extension=ScribuntoErrors-d64a22ba
cat=Pages_with_script_errors sort=
extension[ScribuntoErrors-d64a22ba]="<p>Script error: The function \"blah\" does not exist.</p><p>No further details are available.</p>"
!! html/php
<p><strong class="error"><span class="scribunto-error" id="mw-scribunto-error-d64a22ba">Script error: The function &quot;blah&quot; does not exist.</span></strong>
<p><strong class="error"><span class="scribunto-error mw-scribunto-error-d64a22ba">Script error: The function &quot;blah&quot; does not exist.</span></strong>
</p>
!! html/parsoid
<p><strong class="error" about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#invoke:test","function":"invoke"},"params":{"1":{"wt":"blah"}},"i":0}}]}'><span class="scribunto-error" id="mw-scribunto-error-d64a22ba">Script error: The function <span typeof="mw:Entity">"</span>blah<span typeof="mw:Entity">"</span> does not exist.</span></strong></p>
<p><strong class="error" about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#invoke:test","function":"invoke"},"params":{"1":{"wt":"blah"}},"i":0}}]}'><span class="scribunto-error mw-scribunto-error-d64a22ba">Script error: The function <span typeof="mw:Entity">"</span>blah<span typeof="mw:Entity">"</span> does not exist.</span></strong></p>
!! end
!! test