mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite
synced 2024-11-23 14:36:51 +00:00
Merge "Capitalized dir="RTL" should not trigger any error"
This commit is contained in:
commit
be755491cc
11
src/Cite.php
11
src/Cite.php
|
@ -193,11 +193,16 @@ class Cite {
|
|||
* parsed or default values. Missing attributes will be `null`.
|
||||
*/
|
||||
private function parseArguments( array $argv, array $allowedAttributes ): StatusValue {
|
||||
$maxCount = count( $allowedAttributes );
|
||||
$expected = count( $allowedAttributes );
|
||||
$allValues = array_merge( array_fill_keys( $allowedAttributes, null ), $argv );
|
||||
$status = StatusValue::newGood( array_slice( $allValues, 0, $maxCount ) );
|
||||
if ( isset( $allValues['dir'] ) ) {
|
||||
// @phan-suppress-next-line PhanTypeMismatchArgumentNullableInternal False positive
|
||||
$allValues['dir'] = strtolower( $allValues['dir'] );
|
||||
}
|
||||
|
||||
if ( count( $allValues ) > $maxCount ) {
|
||||
$status = StatusValue::newGood( array_slice( $allValues, 0, $expected ) );
|
||||
|
||||
if ( count( $allValues ) > $expected ) {
|
||||
// A <ref> must have a name (can be null), but <references> can't have one
|
||||
$status->fatal( in_array( 'name', $allowedAttributes, true )
|
||||
? 'cite_error_ref_too_many_keys'
|
||||
|
|
|
@ -154,11 +154,10 @@ class ReferencesFormatter {
|
|||
$extraAttributes = '';
|
||||
|
||||
if ( isset( $val['dir'] ) ) {
|
||||
$dir = strtolower( $val['dir'] );
|
||||
// The following classes are generated here:
|
||||
// * mw-cite-dir-ltr
|
||||
// * mw-cite-dir-rtl
|
||||
$extraAttributes = Html::expandAttributes( [ 'class' => 'mw-cite-dir-' . $dir ] );
|
||||
$extraAttributes = Html::expandAttributes( [ 'class' => 'mw-cite-dir-' . $val['dir'] ] );
|
||||
}
|
||||
|
||||
// Special case for an incomplete follow="…". This is valid e.g. in the Page:… namespace on
|
||||
|
|
|
@ -76,7 +76,7 @@ class Validator {
|
|||
return StatusValue::newFatal( 'cite_error_ref_follow_conflicts' );
|
||||
}
|
||||
|
||||
if ( $dir !== null && !in_array( strtolower( $dir ), [ 'ltr', 'rtl' ], true ) ) {
|
||||
if ( $dir !== null && $dir !== 'rtl' && $dir !== 'ltr' ) {
|
||||
return StatusValue::newFatal( 'cite_error_ref_invalid_dir', $dir );
|
||||
}
|
||||
|
||||
|
|
|
@ -1324,7 +1324,7 @@ T202593: Conflicting dir attributes with the full ref first
|
|||
!! test
|
||||
T202593: Identical dir attributes are pointless, but should not generate an error
|
||||
!! wikitext
|
||||
<ref name="a" dir="rtl" />
|
||||
<ref name="a" dir="RTL" />
|
||||
<ref name="a" dir="rtl">abc</ref>
|
||||
<references />
|
||||
!! html/php
|
||||
|
|
|
@ -58,7 +58,7 @@ class CiteTest extends \MediaWikiIntegrationTestCase {
|
|||
'attributes' => [ 'dir' => 'invalid' ],
|
||||
'expectedValue' => [ 'invalid', null, null, null, null ] ],
|
||||
[
|
||||
'attributes' => [ 'dir' => 'rtl' ],
|
||||
'attributes' => [ 'dir' => 'RTL' ],
|
||||
'expectedValue' => [ 'rtl', null, null, null, null ] ],
|
||||
[
|
||||
'attributes' => [ 'follow' => 'f' ],
|
||||
|
|
|
@ -259,7 +259,7 @@ class ValidatorTest extends \MediaWikiIntegrationTestCase {
|
|||
'name' => 'n',
|
||||
'extends' => null,
|
||||
'follow' => null,
|
||||
'dir' => 'RTL',
|
||||
'dir' => 'rtl',
|
||||
'expected' => null,
|
||||
],
|
||||
'Bad dir' => [
|
||||
|
|
Loading…
Reference in a new issue