Merge "Capitalized dir="RTL" should not trigger any error"

This commit is contained in:
jenkins-bot 2024-01-04 11:14:47 +00:00 committed by Gerrit Code Review
commit be755491cc
6 changed files with 13 additions and 9 deletions

View file

@ -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'

View file

@ -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

View file

@ -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 );
}

View file

@ -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

View file

@ -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' ],

View file

@ -259,7 +259,7 @@ class ValidatorTest extends \MediaWikiIntegrationTestCase {
'name' => 'n',
'extends' => null,
'follow' => null,
'dir' => 'RTL',
'dir' => 'rtl',
'expected' => null,
],
'Bad dir' => [