Merge "Fix internal presentation of the dir="…" attribute"

This commit is contained in:
jenkins-bot 2019-11-22 13:26:49 +00:00 committed by Gerrit Code Review
commit 15985a7fa7
2 changed files with 18 additions and 21 deletions

View file

@ -244,8 +244,8 @@ class Cite {
) {
# The key here is the "name" attribute.
list( $key, $group, $follow, $dir, $extends ) = $this->refArg( $argv );
// empty string indicate invalid dir
if ( $dir === '' && $text !== '' ) {
if ( $dir === false && $text !== '' ) {
$text .= $this->errorReporter->wikitext( 'cite_error_ref_invalid_dir', $argv['dir'] );
}
# Split these into groups.
@ -415,13 +415,10 @@ class Cite {
$extends = 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'] ) ] );
$dir = strtolower( trim( $argv['dir'] ) );
if ( !in_array( $dir, [ 'ltr', 'rtl' ] ) ) {
$dir = false;
}
unset( $argv['dir'] );
}
@ -433,7 +430,7 @@ class Cite {
if ( isset( $argv['follow'] ) &&
( isset( $argv['name'] ) || isset( $argv[self::BOOK_REF_ATTRIBUTE] ) )
) {
return [ false, false, false, false, false ];
return [ false, false, false, null, false ];
}
if ( isset( $argv['name'] ) ) {
@ -458,7 +455,7 @@ class Cite {
if ( $argv !== [] ) {
// Unexpected invalid attribute.
return [ false, false, false, false, false ];
return [ false, false, false, null, false ];
}
return [ $key, $group, $follow, $dir, $extends ];
@ -835,7 +832,7 @@ class Cite {
$this->normalizeKey( self::getReferencesKey( $id ) ),
$this->normalizeKey( $backlinkId ),
$text,
$val['dir']
$val['dir'] ? Html::expandAttributes( [ 'class' => 'mw-cite-dir-' . $val['dir'] ] ) : ''
)->inContentLanguage()->plain();
}
@ -859,7 +856,7 @@ class Cite {
),
$this->listToText( $backlinks ),
$text,
$val['dir']
$val['dir'] ? Html::expandAttributes( [ 'class' => 'mw-cite-dir-' . $val['dir'] ] ) : ''
)->inContentLanguage()->plain();
}

View file

@ -35,27 +35,27 @@ class CiteTest extends \MediaWikiUnitTestCase {
[ [], [ null, null, false, null, null ] ],
// One attribute only
[ [ 'dir' => 'invalid' ], [ null, null, false, '', null ] ],
[ [ 'dir' => 'rtl' ], [ null, null, false, ' class="mw-cite-dir-rtl"', null ] ],
[ [ 'dir' => 'invalid' ], [ null, null, false, false, null ] ],
[ [ 'dir' => ' rtl ' ], [ null, null, false, 'rtl', null ] ],
[ [ 'follow' => ' f ' ], [ null, null, 'f', null, null ] ],
// FIXME: Unlike all other attributes, group isn't trimmed. Why?
[ [ 'group' => ' g ' ], [ null, ' g ', null, null, null ] ],
[ [ 'invalid' => 'i' ], [ false, false, false, false, false ] ],
[ [ 'invalid' => null ], [ false, false, false, false, false ] ],
[ [ 'invalid' => 'i' ], [ false, false, false, null, false ] ],
[ [ 'invalid' => null ], [ false, false, false, null, false ] ],
[ [ 'name' => ' n ' ], [ 'n', null, null, null, null ] ],
[ [ 'name' => null ], [ false, false, false, false, false ] ],
[ [ 'name' => null ], [ false, false, false, null, false ] ],
[ [ 'extends' => ' e ' ], [ null, null, null, null, 'e' ] ],
// Pairs
[ [ 'follow' => 'f', 'name' => 'n' ], [ false, false, false, false, false ] ],
[ [ 'follow' => null, 'name' => null ], [ false, false, false, false, false ] ],
[ [ 'follow' => 'f', 'extends' => 'e' ], [ false, false, false, false, false ] ],
[ [ 'follow' => 'f', 'name' => 'n' ], [ false, false, false, null, false ] ],
[ [ 'follow' => null, 'name' => null ], [ false, false, false, null, false ] ],
[ [ 'follow' => 'f', 'extends' => 'e' ], [ false, false, false, null, false ] ],
[ [ 'group' => 'g', 'name' => 'n' ], [ 'n', 'g', null, null, null ] ],
// Combinations of 3 or more attributes
[
[ 'group' => 'g', 'name' => 'n', 'extends' => 'e', 'dir' => 'rtl' ],
[ 'n', 'g', null, ' class="mw-cite-dir-rtl"', 'e' ]
[ 'n', 'g', null, 'rtl', 'e' ]
],
];
}