jenkins-bot has submitted this change and it was merged.
Change subject: Add lang and dir attributes to cite errors
......................................................................
Add lang and dir attributes to cite errors
This is needed when the error appears in an element with
a direction that is different from the UI language.
Change-Id: I583c9cc30f5bec24ab92e97ab938463ea0e45c15
---
M Cite_body.php
M citeParserTests.txt
M modules/ext.cite.styles.css
3 files changed, 50 insertions(+), 29 deletions(-)
Approvals:
Bartosz Dziewoński: Looks good to me, approved
jenkins-bot: Verified
diff --git a/Cite_body.php b/Cite_body.php
index 3cdabba..a36cae2 100644
--- a/Cite_body.php
+++ b/Cite_body.php
@@ -1275,12 +1275,14 @@
* @return string XHTML or wikitext ready for output
*/
function error( $key, $param = null, $parse = 'parse' ) {
- # We rely on the fact that PHP is okay with passing unused argu-
- # ments to functions. If $1 is not used in the message,
wfMessage will
- # just ignore the extra parameter.
# For ease of debugging and because errors are rare, we
# use the user language and split the parser cache.
$lang = $this->mParser->getOptions()->getUserLangObj();
+ $dir = $lang->getDir();
+
+ # We rely on the fact that PHP is okay with passing unused argu-
+ # ments to functions. If $1 is not used in the message,
wfMessage will
+ # just ignore the extra parameter.
$msg = wfMessage(
'cite_error',
wfMessage( $key, $param )->inLanguage( $lang )->plain()
@@ -1290,7 +1292,15 @@
$this->mParser->addTrackingCategory(
'cite-tracking-category-cite-error' );
- $ret = '<span class="error mw-ext-cite-error">' . $msg .
'</span>';
+ $ret = Html::rawElement(
+ 'span',
+ array(
+ 'class' => 'error mw-ext-cite-error',
+ 'lang' => $lang->getHtmlCode(),
+ 'dir' => $dir,
+ ),
+ $msg
+ );
if ( $parse === 'parse' ) {
$ret = $this->mParser->recursiveTagParse( $ret );
@@ -1308,12 +1318,14 @@
* @return string XHTML or wikitext ready for output
*/
function warning( $key, $param = null, $parse = 'parse' ) {
- # We rely on the fact that PHP is okay with passing unused argu-
- # ments to functions. If $1 is not used in the message,
wfMessage will
- # just ignore the extra parameter.
# For ease of debugging and because errors are rare, we
# use the user language and split the parser cache.
$lang = $this->mParser->getOptions()->getUserLangObj();
+ $dir = $lang->getDir();
+
+ # We rely on the fact that PHP is okay with passing unused argu-
+ # ments to functions. If $1 is not used in the message,
wfMessage will
+ # just ignore the extra parameter.
$msg = wfMessage(
'cite_warning',
wfMessage( $key, $param )->inLanguage( $lang )->plain()
@@ -1322,9 +1334,16 @@
->plain();
$key = preg_replace( '/^cite_warning_/', '', $key ) . '';
- $ret = '<span class="warning mw-ext-cite-warning
mw-ext-cite-warning-' .
- Sanitizer::escapeClass( $key ) .
- '">' . $msg . '</span>';
+ $ret = Html::rawElement(
+ 'span',
+ array(
+ 'class' => 'warning mw-ext-cite-warning
mw-ext-cite-warning-' .
+ Sanitizer::escapeClass( $key ),
+ 'lang' => $lang->getHtmlCode(),
+ 'dir' => $dir,
+ ),
+ $msg
+ );
if ( $parse === 'parse' ) {
$ret = $this->mParser->recursiveTagParse( $ret );
diff --git a/citeParserTests.txt b/citeParserTests.txt
index f401476..e1d66d4 100644
--- a/citeParserTests.txt
+++ b/citeParserTests.txt
@@ -210,7 +210,7 @@
</p><p><sup id="cite_ref-blank_1-1" class="reference"><a
href="#cite_note-blank-1">[1]</a></sup>
</p>
<ol class="references">
-<li id="cite_note-blank-1"><span class="mw-cite-backlink">↑ <sup><a
href="#cite_ref-blank_1-0">1.0</a></sup> <sup><a
href="#cite_ref-blank_1-1">1.1</a></sup></span> <span class="reference-text">0
<span class="error mw-ext-cite-error">Cite error: Invalid
<code><ref></code> tag; name "blank" defined multiple times with
different content</span></span>
+<li id="cite_note-blank-1"><span class="mw-cite-backlink">↑ <sup><a
href="#cite_ref-blank_1-0">1.0</a></sup> <sup><a
href="#cite_ref-blank_1-1">1.1</a></sup></span> <span class="reference-text">0
<span class="error mw-ext-cite-error" lang="en" dir="ltr">Cite error: Invalid
<code><ref></code> tag; name "blank" defined multiple times with
different content</span></span>
</li>
</ol>
@@ -229,7 +229,7 @@
</p><p><sup id="cite_ref-blank_1-1" class="reference"><a
href="#cite_note-blank-1">[1]</a></sup>
</p>
<ol class="references">
-<li id="cite_note-blank-1"><span class="mw-cite-backlink">↑ <sup><a
href="#cite_ref-blank_1-0">1.0</a></sup> <sup><a
href="#cite_ref-blank_1-1">1.1</a></sup></span> <span class="reference-text">1
<span class="error mw-ext-cite-error">Cite error: Invalid
<code><ref></code> tag; name "blank" defined multiple times with
different content</span></span>
+<li id="cite_note-blank-1"><span class="mw-cite-backlink">↑ <sup><a
href="#cite_ref-blank_1-0">1.0</a></sup> <sup><a
href="#cite_ref-blank_1-1">1.1</a></sup></span> <span class="reference-text">1
<span class="error mw-ext-cite-error" lang="en" dir="ltr">Cite error: Invalid
<code><ref></code> tag; name "blank" defined multiple times with
different content</span></span>
</li>
</ol>
@@ -276,22 +276,22 @@
<references />
!! result
-<p><span class="error mw-ext-cite-error">Cite error: Invalid
<code><ref></code> tag;
+<p><span class="error mw-ext-cite-error" lang="en" dir="ltr">Cite error:
Invalid <code><ref></code> tag;
name cannot be a simple integer. Use a descriptive title</span>
</p><p><sup id="cite_ref-1" class="reference"><a
href="#cite_note-1">[1]</a></sup>
-</p><p><span class="error mw-ext-cite-error">Cite error: The opening
<code><ref></code> tag is malformed or has a bad name</span>
+</p><p><span class="error mw-ext-cite-error" lang="en" dir="ltr">Cite error:
The opening <code><ref></code> tag is malformed or has a bad name</span>
</p><p><sup id="cite_ref-bar_2-0" class="reference"><a
href="#cite_note-bar-2">[2]</a></sup>
</p><p><sup id="cite_ref-blankwithnoreference_3-0" class="reference"><a
href="#cite_note-blankwithnoreference-3">[3]</a></sup>
-</p><p><span class="error mw-ext-cite-error">Cite error: Invalid
<code><references></code> tag;
+</p><p><span class="error mw-ext-cite-error" lang="en" dir="ltr">Cite error:
Invalid <code><references></code> tag;
parameter "group" is allowed only.
Use <code><references /></code>, or <code><references group="..."
/></code></span>
</p>
<ol class="references">
<li id="cite_note-1"><span class="mw-cite-backlink"><a
href="#cite_ref-1">↑</a></span> <span class="reference-text">Also zero, but
differently! (Normal ref)</span>
</li>
-<li id="cite_note-bar-2"><span class="mw-cite-backlink"><a
href="#cite_ref-bar_2-0">↑</a></span> <span class="error
mw-ext-cite-error">Cite error: Invalid <code><ref></code> tag;
+<li id="cite_note-bar-2"><span class="mw-cite-backlink"><a
href="#cite_ref-bar_2-0">↑</a></span> <span class="error mw-ext-cite-error"
lang="en" dir="ltr">Cite error: Invalid <code><ref></code> tag;
no text was provided for refs named <code>bar</code></span></li>
-<li id="cite_note-blankwithnoreference-3"><span class="mw-cite-backlink"><a
href="#cite_ref-blankwithnoreference_3-0">↑</a></span> <span class="error
mw-ext-cite-error">Cite error: Invalid <code><ref></code> tag;
+<li id="cite_note-blankwithnoreference-3"><span class="mw-cite-backlink"><a
href="#cite_ref-blankwithnoreference_3-0">↑</a></span> <span class="error
mw-ext-cite-error" lang="en" dir="ltr">Cite error: Invalid
<code><ref></code> tag;
no text was provided for refs named
<code>blankwithnoreference</code></span></li>
</ol>
@@ -399,12 +399,12 @@
<p><sup id="cite_ref-foo_1-0" class="reference"><a
href="#cite_note-foo-1">[2 1]</a></sup>
</p>
<ol class="references">
-<li id="cite_note-foo-1"><span class="mw-cite-backlink"><a
href="#cite_ref-foo_1-0">↑</a></span> <span class="error
mw-ext-cite-error">Cite error: Invalid <code><ref></code> tag;
+<li id="cite_note-foo-1"><span class="mw-cite-backlink"><a
href="#cite_ref-foo_1-0">↑</a></span> <span class="error mw-ext-cite-error"
lang="en" dir="ltr">Cite error: Invalid <code><ref></code> tag;
no text was provided for refs named <code>foo</code></span></li>
</ol>
-<p><span class="error mw-ext-cite-error">Cite error: <code><ref></code>
tag with name "unused" defined in <code><references></code> is not used
in prior text.</span><br />
-<span class="error mw-ext-cite-error">Cite error: <code><ref></code> tag
in <code><references></code> has conflicting group attribute
"1".</span><br />
-<span class="error mw-ext-cite-error">Cite error: <code><ref></code> tag
defined in <code><references></code> has no name attribute.</span>
+<p><span class="error mw-ext-cite-error" lang="en" dir="ltr">Cite error:
<code><ref></code> tag with name "unused" defined in
<code><references></code> is not used in prior text.</span><br />
+<span class="error mw-ext-cite-error" lang="en" dir="ltr">Cite error:
<code><ref></code> tag in <code><references></code> has conflicting
group attribute "1".</span><br />
+<span class="error mw-ext-cite-error" lang="en" dir="ltr">Cite error:
<code><ref></code> tag defined in <code><references></code> has no
name attribute.</span>
</p>
!! end
@@ -473,7 +473,7 @@
!! input
Bla.<ref></ref>
!! result
-<p>Bla.<span class="error mw-ext-cite-error">Cite error: Invalid
<code><ref></code> tag;
+<p>Bla.<span class="error mw-ext-cite-error" lang="en" dir="ltr">Cite error:
Invalid <code><ref></code> tag;
refs with no name must have content</span>
</p>
!! end
@@ -483,7 +483,7 @@
!! input
Bla.<ref name=""></ref>
!! result
-<p>Bla.<span class="error mw-ext-cite-error">Cite error: Invalid
<code><ref></code> tag;
+<p>Bla.<span class="error mw-ext-cite-error" lang="en" dir="ltr">Cite error:
Invalid <code><ref></code> tag;
refs with no name must have content</span>
</p>
!! end
@@ -494,7 +494,7 @@
Bla.<ref name="void"></ref>
!! result
Bla.<sup id="cite_ref-void_1-0" class="reference"><a
href="#cite_note-void-1">[1]</a></sup><ol class="references">
-<li id="cite_note-void-1"><span class="mw-cite-backlink"><a
href="#cite_ref-void_1-0">↑</a></span> <span class="error
mw-ext-cite-error">Cite error: Invalid <code><ref></code> tag;
+<li id="cite_note-void-1"><span class="mw-cite-backlink"><a
href="#cite_ref-void_1-0">↑</a></span> <span class="error mw-ext-cite-error"
lang="en" dir="ltr">Cite error: Invalid <code><ref></code> tag;
no text was provided for refs named <code>void</code></span></li>
</ol>
@@ -527,7 +527,7 @@
Page one.<ref name="the-name" follow="the-name">This ref is invalid.</ref>
<references />
!! result
-<p>Page one.<span class="error mw-ext-cite-error">Cite error: Invalid
<code><ref></code> tag;
+<p>Page one.<span class="error mw-ext-cite-error" lang="en" dir="ltr">Cite
error: Invalid <code><ref></code> tag;
invalid names, e.g. too many</span>
</p>
!! end
@@ -543,7 +543,7 @@
<sup id="cite_ref-a_1-1" class="reference"><a
href="#cite_note-a-1">[1]</a></sup>
</p>
<ol class="references">
-<li id="cite_note-a-1"><span class="mw-cite-backlink">↑ <sup><a
href="#cite_ref-a_1-0">1.0</a></sup> <sup><a
href="#cite_ref-a_1-1">1.1</a></sup></span> <span class="reference-text">abc
<span class="error mw-ext-cite-error">Cite error: Invalid
<code><ref></code> tag; name "a" defined multiple times with different
content</span></span>
+<li id="cite_note-a-1"><span class="mw-cite-backlink">↑ <sup><a
href="#cite_ref-a_1-0">1.0</a></sup> <sup><a
href="#cite_ref-a_1-1">1.1</a></sup></span> <span class="reference-text">abc
<span class="error mw-ext-cite-error" lang="en" dir="ltr">Cite error: Invalid
<code><ref></code> tag; name "a" defined multiple times with different
content</span></span>
</li>
</ol>
@@ -561,7 +561,7 @@
<p><sup id="cite_ref-a_1-0" class="reference"><a
href="#cite_note-a-1">[1]</a></sup>
</p>
<ol class="references">
-<li id="cite_note-a-1"><span class="mw-cite-backlink"><a
href="#cite_ref-a_1-0">↑</a></span> <span class="reference-text">abc <span
class="error mw-ext-cite-error">Cite error: Invalid <code><ref></code>
tag; name "a" defined multiple times with different content</span></span>
+<li id="cite_note-a-1"><span class="mw-cite-backlink"><a
href="#cite_ref-a_1-0">↑</a></span> <span class="reference-text">abc <span
class="error mw-ext-cite-error" lang="en" dir="ltr">Cite error: Invalid
<code><ref></code> tag; name "a" defined multiple times with different
content</span></span>
</li>
</ol>
@@ -578,7 +578,7 @@
<p><sup id="cite_ref-a_1-0" class="reference"><a
href="#cite_note-a-1">[1]</a></sup>
</p>
<ol class="references">
-<li id="cite_note-a-1"><span class="mw-cite-backlink"><a
href="#cite_ref-a_1-0">↑</a></span> <span class="reference-text">abc <span
class="error mw-ext-cite-error">Cite error: Invalid <code><ref></code>
tag; name "a" defined multiple times with different content</span></span>
+<li id="cite_note-a-1"><span class="mw-cite-backlink"><a
href="#cite_ref-a_1-0">↑</a></span> <span class="reference-text">abc <span
class="error mw-ext-cite-error" lang="en" dir="ltr">Cite error: Invalid
<code><ref></code> tag; name "a" defined multiple times with different
content</span></span>
</li>
</ol>
@@ -596,7 +596,7 @@
<p><sup id="cite_ref-a_1-0" class="reference"><a
href="#cite_note-a-1">[1]</a></sup>
</p>
<ol class="references">
-<li id="cite_note-a-1"><span class="mw-cite-backlink"><a
href="#cite_ref-a_1-0">↑</a></span> <span class="reference-text">abc <span
class="error mw-ext-cite-error">Cite error: Invalid <code><ref></code>
tag; name "a" defined multiple times with different content</span></span>
+<li id="cite_note-a-1"><span class="mw-cite-backlink"><a
href="#cite_ref-a_1-0">↑</a></span> <span class="reference-text">abc <span
class="error mw-ext-cite-error" lang="en" dir="ltr">Cite error: Invalid
<code><ref></code> tag; name "a" defined multiple times with different
content</span></span>
</li>
</ol>
diff --git a/modules/ext.cite.styles.css b/modules/ext.cite.styles.css
index a979ca2..f52be1b 100644
--- a/modules/ext.cite.styles.css
+++ b/modules/ext.cite.styles.css
@@ -27,4 +27,6 @@
/* Make cite errors "strong" */
.mw-ext-cite-error {
font-weight: bold;
+ /* For the case that the error is embedded in an element with a
different direction */
+ unicode-bidi: embed;
}
--
To view, visit https://gerrit.wikimedia.org/r/244508
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I583c9cc30f5bec24ab92e97ab938463ea0e45c15
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/extensions/Cite
Gerrit-Branch: master
Gerrit-Owner: Amire80 <[email protected]>
Gerrit-Reviewer: Bartosz Dziewoński <[email protected]>
Gerrit-Reviewer: Eranroz <[email protected]>
Gerrit-Reviewer: IKhitron <[email protected]>
Gerrit-Reviewer: Jackmcbarn <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits