mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite
synced 2024-09-23 18:29:15 +00:00
Merge "Support directionality for reference"
This commit is contained in:
commit
cfd18814be
|
@ -21,6 +21,7 @@
|
|||
"apierror-citestoragedisabled": "Cite extension reference storage is not enabled.",
|
||||
"cite-desc": "Adds <nowiki><ref[ name=id]></nowiki> and <nowiki><references/></nowiki> tags, for citations",
|
||||
"cite_error": "Cite error: $1",
|
||||
"cite_error_ref_invalid_dir": "Invalid <code><ref></code> tag; dir attribute \"$1\" is unknown. Must be ltr or rtl",
|
||||
"cite_error_ref_numeric_key": "Invalid <code><ref></code> tag;\nname cannot be a simple integer. Use a descriptive title",
|
||||
"cite_error_ref_no_key": "The opening <code><ref></code> tag is malformed or has a bad name",
|
||||
"cite_error_ref_too_many_keys": "Invalid <code><ref></code> tag;\ninvalid names, e.g. too many",
|
||||
|
@ -46,8 +47,8 @@
|
|||
"cite_references_link_suffix": "",
|
||||
"cite_reference_link": "<sup id=\"$1\" class=\"reference\">[[#$2|[$3]]]</sup>",
|
||||
"cite_references_no_link": "<p id=\"$1\">$2</p>",
|
||||
"cite_references_link_one": "<li id=\"$1\"><span class=\"mw-cite-backlink\">[[#$2|↑]]</span> $3</li>",
|
||||
"cite_references_link_many": "<li id=\"$1\"><span class=\"mw-cite-backlink\">↑ $2</span> $3</li>",
|
||||
"cite_references_link_one": "<li id=\"$1\"$4><span class=\"mw-cite-backlink\">[[#$2|↑]]</span> $3</li>",
|
||||
"cite_references_link_many": "<li id=\"$1\"$4><span class=\"mw-cite-backlink\">↑ $2</span> $3</li>",
|
||||
"cite_references_link_many_format": "<sup>[[#$1|$2]]</sup>",
|
||||
"cite_references_link_many_format_backlink_labels": "a b c d e f g h i j k l m n o p q r s t u v w x y z aa ab ac ad ae af ag ah ai aj ak al am an ao ap aq ar as at au av aw ax ay az ba bb bc bd be bf bg bh bi bj bk bl bm bn bo bp bq br bs bt bu bv bw bx by bz ca cb cc cd ce cf cg ch ci cj ck cl cm cn co cp cq cr cs ct cu cv cw cx cy cz da db dc dd de df dg dh di dj dk dl dm dn do dp dq dr ds dt du dv dw dx dy dz ea eb ec ed ee ef eg eh ei ej ek el em en eo ep eq er es et eu ev ew ex ey ez fa fb fc fd fe ff fg fh fi fj fk fl fm fn fo fp fq fr fs ft fu fv fw fx fy fz ga gb gc gd ge gf gg gh gi gj gk gl gm gn go gp gq gr gs gt gu gv gw gx gy gz ha hb hc hd he hf hg hh hi hj hk hl hm hn ho hp hq hr hs ht hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io ip iq ir is it iu iv iw ix iy iz ja jb jc jd je jf jg jh ji jj jk jl jm jn jo jp jq jr js jt ju jv jw jx jy jz ka kb kc kd ke kf kg kh ki kj kk kl km kn ko kp kq kr ks kt ku kv kw kx ky kz la lb lc ld le lf lg lh li lj lk ll lm ln lo lp lq lr ls lt lu lv lw lx ly lz ma mb mc md me mf mg mh mi mj mk ml mm mn mo mp mq mr ms mt mu mv mw mx my mz na nb nc nd ne nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu nv nw nx ny nz oa ob oc od oe of og oh oi oj ok ol om on oo op oq or os ot ou ov ow ox oy oz pa pb pc pd pe pf pg ph pi pj pk pl pm pn po pp pq pr ps pt pu pv pw px py pz qa qb qc qd qe qf qg qh qi qj qk ql qm qn qo qp qq qr qs qt qu qv qw qx qy qz ra rb rc rd re rf rg rh ri rj rk rl rm rn ro rp rq rr rs rt ru rv rw rx ry rz sa sb sc sd se sf sg sh si sj sk sl sm sn so sp sq sr ss st su sv sw sx sy sz ta tb tc td te tf tg th ti tj tk tl tm tn to tp tq tr ts tt tu tv tw tx ty tz ua ub uc ud ue uf ug uh ui uj uk ul um un uo up uq ur us ut uu uv uw ux uy uz va vb vc vd ve vf vg vh vi vj vk vl vm vn vo vp vq vr vs vt vu vv vw vx vy vz wa wb wc wd we wf wg wh wi wj wk wl wm wn wo wp wq wr ws wt wu wv ww wx wy wz xa xb xc xd xe xf xg xh xi xj xk xl xm xn xo xp xq xr xs xt xu xv xw xx xy xz ya yb yc yd ye yf yg yh yi yj yk yl ym yn yo yp yq yr ys yt yu yv yw yx yy yz za zb zc zd ze zf zg zh zi zj zk zl zm zn zo zp zq zr zs zt zu zv zw zx zy zz",
|
||||
"cite_references_link_many_sep": " ",
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
"apierror-citestoragedisabled": "{{doc-apierror}}",
|
||||
"cite-desc": "{{desc|name=Cite|url=https://www.mediawiki.org/wiki/Extension:Cite}}",
|
||||
"cite_error": "Cite extension.\n\nUsed when there are errors in ref or references tags.\n\nParameters:\n* $1 - an error message",
|
||||
"cite_error_ref_invalid_dir": "Cite extension. Error message shown when ref tag contain dir attribute with invalid value. $1 - invalid dir value",
|
||||
"cite_error_ref_numeric_key": "Cite extension. Error message shown if the name of a ref tag only contains digits. Examples that cause this error are <code><nowiki><ref name=\"123\" /></nowiki></code> or <code><nowiki><ref name=\"456\">input</ref></nowiki></code>",
|
||||
"cite_error_ref_no_key": "Cite extension. Error message shown when ref tags without any content (that is <code><nowiki><ref /></nowiki></code>) are used without a name.",
|
||||
"cite_error_ref_too_many_keys": "Cite extension. Error message shown when ref tags has parameters other than name and group. Examples that cause this error are <code><nowiki><ref name=\"name\" notname=\"value\" /></nowiki></code> or <code><nowiki><ref notname=\"value\" >input<ref></nowiki></code>",
|
||||
|
@ -47,8 +48,8 @@
|
|||
"cite_references_link_suffix": "{{ignored}}",
|
||||
"cite_reference_link": "{{optional}}\nParameters:\n* $1 - ref key\n* $2 - references key\n* $3 - link label",
|
||||
"cite_references_no_link": "{{notranslate}}\nParameters:\n* $1 - references key\n* $2 - reference text",
|
||||
"cite_references_link_one": "{{optional}}\nParameters:\n* $1 - references key\n* $2 - ref key\n* $3 - reference text",
|
||||
"cite_references_link_many": "{{optional}}\nParameters:\n* $1 - references key\n* $2 - list of links\n* $3 - reference text",
|
||||
"cite_references_link_one": "{{optional}}\nParameters:\n* $1 - references key\n* $2 - ref key\n* $3 - reference text\n* $4 - optional CSS class for direction",
|
||||
"cite_references_link_many": "{{optional}}\nParameters:\n* $1 - references key\n* $2 - list of links\n* $3 - reference text\n* $4 - optional CSS class for direction",
|
||||
"cite_references_link_many_format": "{{optional}}\nParameters:\n* $1 - ref key\n* $2 - ...\n* $3 - (Unused)...",
|
||||
"cite_references_link_many_format_backlink_labels": "{{Optional}}",
|
||||
"cite_references_link_many_sep": "{{optional}}",
|
||||
|
|
|
@ -248,8 +248,11 @@ class Cite {
|
|||
$this->mParser = $parser;
|
||||
|
||||
# The key here is the "name" attribute.
|
||||
list( $key, $group, $follow ) = $this->refArg( $argv );
|
||||
|
||||
list( $key, $group, $follow, $dir ) = $this->refArg( $argv );
|
||||
// empty string indicate invalid dir
|
||||
if ( $dir === '' && $str !== '' ) {
|
||||
$str .= $this->error( 'cite_error_ref_invalid_dir', $argv['dir'], 'noparse' );
|
||||
}
|
||||
# Split these into groups.
|
||||
if ( $group === null ) {
|
||||
if ( $this->mInReferences ) {
|
||||
|
@ -377,7 +380,7 @@ class Cite {
|
|||
# we'll figure that out later. Likewise it's definitely valid
|
||||
# if there's any content, regardless of key.
|
||||
|
||||
return $this->stack( $str, $key, $group, $follow, $argv );
|
||||
return $this->stack( $str, $key, $group, $follow, $argv, $dir );
|
||||
}
|
||||
|
||||
# Not clear how we could get here, but something is probably
|
||||
|
@ -391,6 +394,7 @@ class Cite {
|
|||
* "name" : Key of the reference.
|
||||
* "group" : Group to which it belongs. Needs to be passed to <references /> too.
|
||||
* "follow" : If the current reference is the continuation of another, key of that reference.
|
||||
* "dir" : set direction of text (ltr/rtl)
|
||||
*
|
||||
* @param string[] $argv The argument vector
|
||||
* @return mixed false on invalid input, a string on valid
|
||||
|
@ -401,14 +405,25 @@ class Cite {
|
|||
$group = null;
|
||||
$key = null;
|
||||
$follow = null;
|
||||
$dir = null;
|
||||
if ( isset( $argv['dir'] ) ) {
|
||||
// compare the dir attribute value against an explicit whitelist.
|
||||
$dir = '';
|
||||
$isValidDir = in_array( strtolower( $argv['dir'] ), [ 'ltr', 'rtl' ] );
|
||||
if ( $isValidDir ) {
|
||||
$dir = Html::expandAttributes( [ 'class' => 'mw-cite-dir-' . strtolower( $argv['dir'] ) ] );
|
||||
}
|
||||
|
||||
unset( $argv['dir'] );
|
||||
--$cnt;
|
||||
}
|
||||
if ( $cnt > 2 ) {
|
||||
// There should only be one key or follow parameter, and one group parameter
|
||||
// FIXME : this looks inconsistent, it should probably return a tuple
|
||||
return false;
|
||||
} elseif ( $cnt >= 1 ) {
|
||||
if ( isset( $argv['name'] ) && isset( $argv['follow'] ) ) {
|
||||
return [ false, false, false ];
|
||||
return [ false, false, false, false ];
|
||||
}
|
||||
if ( isset( $argv['name'] ) ) {
|
||||
// Key given.
|
||||
|
@ -430,14 +445,14 @@ class Cite {
|
|||
}
|
||||
|
||||
if ( $cnt === 0 ) {
|
||||
return [ $key, $group, $follow ];
|
||||
return [ $key, $group, $follow, $dir ];
|
||||
} else {
|
||||
// Invalid key
|
||||
return [ false, false, false ];
|
||||
return [ false, false, false, false ];
|
||||
}
|
||||
} else {
|
||||
// No key
|
||||
return [ null, $group, false ];
|
||||
return [ null, $group, false, $dir ];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -449,11 +464,12 @@ class Cite {
|
|||
* @param string $group
|
||||
* @param string|null $follow
|
||||
* @param string[] $call
|
||||
* @param $dir ref direction
|
||||
*
|
||||
* @throws Exception
|
||||
* @return string
|
||||
*/
|
||||
private function stack( $str, $key, $group, $follow, array $call ) {
|
||||
private function stack( $str, $key, $group, $follow, array $call, $dir ) {
|
||||
if ( !isset( $this->mRefs[$group] ) ) {
|
||||
$this->mRefs[$group] = [];
|
||||
}
|
||||
|
@ -476,7 +492,8 @@ class Cite {
|
|||
'count' => -1,
|
||||
'text' => $str,
|
||||
'key' => ++$this->mOutCnt,
|
||||
'follow' => $follow
|
||||
'follow' => $follow,
|
||||
'dir' => $dir
|
||||
] ] );
|
||||
array_splice( $this->mRefCallStack, $k, 0,
|
||||
[ [ 'new', $call, $str, $key, $group, $this->mOutCnt ] ] );
|
||||
|
@ -488,10 +505,12 @@ class Cite {
|
|||
if ( $key === null ) {
|
||||
// No key
|
||||
// $this->mRefs[$group][] = $str;
|
||||
|
||||
$this->mRefs[$group][] = [
|
||||
'count' => -1,
|
||||
'text' => $str,
|
||||
'key' => ++$this->mOutCnt
|
||||
'key' => ++$this->mOutCnt,
|
||||
'dir' => $dir
|
||||
];
|
||||
$this->mRefCallStack[] = [ 'new', $call, $str, $key, $group, $this->mOutCnt ];
|
||||
|
||||
|
@ -508,7 +527,8 @@ class Cite {
|
|||
'text' => $str,
|
||||
'count' => 0,
|
||||
'key' => ++$this->mOutCnt,
|
||||
'number' => ++$this->mGroupCnt[$group]
|
||||
'number' => ++$this->mGroupCnt[$group],
|
||||
'dir' => $dir
|
||||
];
|
||||
$this->mRefCallStack[] = [ 'new', $call, $str, $key, $group, $this->mOutCnt ];
|
||||
|
||||
|
@ -797,7 +817,8 @@ class Cite {
|
|||
$this->normalizeKey(
|
||||
$this->refKey( $key )
|
||||
),
|
||||
$this->referenceText( $key, $val )
|
||||
$this->referenceText( $key, $val ),
|
||||
$val['dir']
|
||||
)->inContentLanguage()->plain();
|
||||
}
|
||||
$text = $this->referenceText( $key, $val['text'] );
|
||||
|
@ -830,7 +851,8 @@ class Cite {
|
|||
# $this->refKey( $val['key'], $val['count'] )
|
||||
$this->refKey( $val['key'] )
|
||||
),
|
||||
$text
|
||||
$text,
|
||||
$val['dir']
|
||||
)->inContentLanguage()->plain();
|
||||
// Standalone named reference, I want to format this like an
|
||||
// anonymous reference because displaying "1. 1.1 Ref text" is
|
||||
|
@ -847,7 +869,8 @@ class Cite {
|
|||
# $this->refKey( $key, $val['count'] ),
|
||||
$this->refKey( $key, $val['key'] . "-" . $val['count'] )
|
||||
),
|
||||
$text
|
||||
$text,
|
||||
$val['dir']
|
||||
)->inContentLanguage()->plain();
|
||||
// Named references with >1 occurrences
|
||||
}
|
||||
|
@ -871,7 +894,8 @@ class Cite {
|
|||
self::getReferencesKey( $key . "-" . $val['key'] )
|
||||
),
|
||||
$list,
|
||||
$text
|
||||
$text,
|
||||
$val['dir']
|
||||
)->inContentLanguage()->plain();
|
||||
}
|
||||
|
||||
|
|
|
@ -17,3 +17,15 @@
|
|||
span[ rel='mw:referencedBy' ] a:before {
|
||||
content: counters( mw-ref-linkback, '٫', persian );
|
||||
}
|
||||
|
||||
/* @noflip */
|
||||
.mw-cite-dir-ltr {
|
||||
direction: ltr;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
/* @noflip */
|
||||
.mw-cite-dir-rtl {
|
||||
direction: rtl;
|
||||
text-align: right;
|
||||
}
|
||||
|
|
|
@ -42,3 +42,15 @@ sup.reference:target {
|
|||
/* For the case that the error is embedded in an element with a different direction */
|
||||
unicode-bidi: embed;
|
||||
}
|
||||
|
||||
/* @noflip */
|
||||
.mw-cite-dir-ltr .reference-text {
|
||||
direction: ltr;
|
||||
unicode-bidi: embed;
|
||||
}
|
||||
|
||||
/* @noflip */
|
||||
.mw-cite-dir-rtl .reference-text {
|
||||
direction: rtl;
|
||||
unicode-bidi: embed;
|
||||
}
|
||||
|
|
|
@ -1462,3 +1462,85 @@ CircularRef
|
|||
<p><sup about="#mwt4" class="mw-ref" id="cite_ref-1" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-1"},"attrs":{}}'><a href="./Main_Page#cite_note-1" style="counter-reset: mw-Ref 1;"><span class="mw-reflink-text">[1]</span></a></sup></p>
|
||||
<ol class="mw-references references" typeof="mw:Extension/references" about="#mwt6" data-mw='{"name":"references","attrs":{}}'><li about="#cite_note-1" id="cite_note-1"><a href="./Main_Page#cite_ref-1" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a> <span id="mw-reference-text-cite_note-1" class="mw-reference-text">Hi <span about="#mwt2" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"CircularRef","href":"./Template:CircularRef"},"params":{},"i":0}}]}'></span></span></li></ol>
|
||||
!! end
|
||||
|
||||
!! test
|
||||
bug 13673 <ref> with direction "rtl"
|
||||
!! input
|
||||
<ref dir="rtl">TEST</ref>
|
||||
|
||||
<references />
|
||||
!! result
|
||||
<p><sup id="cite_ref-1" class="reference"><a href="#cite_note-1">[1]</a></sup>
|
||||
</p>
|
||||
<div class="mw-references-wrap"><ol class="references">
|
||||
<li id="cite_note-1" class="mw-cite-dir-rtl"><span class="mw-cite-backlink"><a href="#cite_ref-1">↑</a></span> <span class="reference-text">TEST</span>
|
||||
</li>
|
||||
</ol></div>
|
||||
|
||||
!! end
|
||||
|
||||
!! test
|
||||
bug 13673 <ref> with direction "ltr"
|
||||
!! input
|
||||
<ref dir="ltr">TEST</ref>
|
||||
|
||||
<references />
|
||||
!! result
|
||||
<p><sup id="cite_ref-1" class="reference"><a href="#cite_note-1">[1]</a></sup>
|
||||
</p>
|
||||
<div class="mw-references-wrap"><ol class="references">
|
||||
<li id="cite_note-1" class="mw-cite-dir-ltr"><span class="mw-cite-backlink"><a href="#cite_ref-1">↑</a></span> <span class="reference-text">TEST</span>
|
||||
</li>
|
||||
</ol></div>
|
||||
|
||||
!! end
|
||||
|
||||
|
||||
!! test
|
||||
bug 13673 <ref> with direction "LTR", keeps upper case
|
||||
!! input
|
||||
<ref dir="LTR">TEST</ref>
|
||||
|
||||
<references />
|
||||
!! result
|
||||
<p><sup id="cite_ref-1" class="reference"><a href="#cite_note-1">[1]</a></sup>
|
||||
</p>
|
||||
<div class="mw-references-wrap"><ol class="references">
|
||||
<li id="cite_note-1" class="mw-cite-dir-ltr"><span class="mw-cite-backlink"><a href="#cite_ref-1">↑</a></span> <span class="reference-text">TEST</span>
|
||||
</li>
|
||||
</ol></div>
|
||||
|
||||
!! end
|
||||
|
||||
|
||||
!! test
|
||||
bug 13673 <ref> with direction "nonsense", strip invalid dir attribute and shows error
|
||||
!! input
|
||||
<ref dir="nonsense">TEST</ref>
|
||||
|
||||
<references />
|
||||
!! result
|
||||
<p><sup id="cite_ref-1" class="reference"><a href="#cite_note-1">[1]</a></sup>
|
||||
</p>
|
||||
<div class="mw-references-wrap"><ol class="references">
|
||||
<li id="cite_note-1"><span class="mw-cite-backlink"><a href="#cite_ref-1">↑</a></span> <span class="reference-text">TEST<span class="error mw-ext-cite-error" lang="en" dir="ltr">Cite error: Invalid <code><ref></code> tag; dir attribute "nonsense" is unknown. Must be ltr or rtl</span></span>
|
||||
</li>
|
||||
</ol></div>
|
||||
|
||||
!! end
|
||||
|
||||
|
||||
!! test
|
||||
Direction is supported when specifying name and group
|
||||
!! input
|
||||
<ref dir="ltr" name="a" group=note>TEST</ref>
|
||||
<references group=note/>
|
||||
!! result
|
||||
<p><sup id="cite_ref-a_1-0" class="reference"><a href="#cite_note-a-1">[note 1]</a></sup>
|
||||
</p>
|
||||
<div class="mw-references-wrap"><ol class="references">
|
||||
<li id="cite_note-a-1" class="mw-cite-dir-ltr"><span class="mw-cite-backlink"><a href="#cite_ref-a_1-0">↑</a></span> <span class="reference-text">TEST</span>
|
||||
</li>
|
||||
</ol></div>
|
||||
|
||||
!! end
|
||||
|
|
Loading…
Reference in a new issue