refArg parses and returns the refines attribute

Incremental patch which extracts the refines attribute from the tag.
Doing this now to allow the calling function to have responsibility
for doing something with the attribute value.

Bug: T237531
Change-Id: I59bb409bedd8e6ed06268e705e02e8ffb45b1f0e
This commit is contained in:
Adam Wight 2019-11-08 12:30:12 +01:00
parent 468b7e05e8
commit 5ac57def59
2 changed files with 22 additions and 22 deletions

View file

@ -233,7 +233,7 @@ class Cite {
$this->mParser = $parser;
# The key here is the "name" attribute.
list( $key, $group, $follow, $dir ) = $this->refArg( $argv );
list( $key, $group, $follow, $dir, $refines ) = $this->refArg( $argv );
// empty string indicate invalid dir
if ( $dir === '' && $text !== '' ) {
$text .= $this->plainError( 'cite_error_ref_invalid_dir', $argv['dir'] );
@ -397,6 +397,7 @@ class Cite {
$key = null;
$follow = null;
$dir = null;
$refines = null;
if ( isset( $argv['dir'] ) ) {
// compare the dir attribute value against an explicit whitelist.
@ -411,11 +412,11 @@ class Cite {
if ( $argv === [] ) {
// No key
return [ null, null, false, $dir ];
return [ null, null, false, $dir, null ];
}
if ( isset( $argv['name'] ) && isset( $argv['follow'] ) ) {
return [ false, false, false, false ];
return [ false, false, false, false, false ];
}
if ( isset( $argv['name'] ) ) {
@ -434,17 +435,16 @@ class Cite {
unset( $argv['group'] );
}
if ( $wgCiteBookReferencing && isset( $argv[self::REFINES_ATTRIBUTE] ) ) {
// TODO: Extract the name and return it.
// $refines = trim( $argv[self::REFINES_ATTRIBUTE] );
$refines = trim( $argv[self::REFINES_ATTRIBUTE] );
unset( $argv[self::REFINES_ATTRIBUTE] );
}
if ( $argv !== [] ) {
// Unexpected invalid attribute.
return [ false, false, false, false ];
return [ false, false, false, false, false ];
}
return [ $key, $group, $follow, $dir ];
return [ $key, $group, $follow, $dir, $refines ];
}
/**

View file

@ -28,28 +28,28 @@ class CiteTest extends MediaWikiTestCase {
public function provideRefAttributes() {
return [
[ [], [ null, null, false, null ] ],
[ [], [ null, null, false, null, null ] ],
// One attribute only
[ [ 'dir' => 'invalid' ], [ null, null, false, '' ] ],
[ [ 'dir' => 'rtl' ], [ null, null, false, ' class="mw-cite-dir-rtl"' ] ],
[ [ 'follow' => 'f' ], [ null, null, 'f', null ] ],
[ [ 'group' => 'g' ], [ null, 'g', null, null ] ],
[ [ 'invalid' => 'i' ], [ false, false, false, false ] ],
[ [ 'name' => 'n' ], [ 'n', null, null, null ] ],
[ [ 'name' => null ], [ false, false, false, false ] ],
[ [ 'refines' => 'r' ], [ null, null, null, null ] ],
[ [ 'dir' => 'invalid' ], [ null, null, false, '', null ] ],
[ [ 'dir' => 'rtl' ], [ null, null, false, ' class="mw-cite-dir-rtl"', null ] ],
[ [ 'follow' => 'f' ], [ null, null, 'f', null, null ] ],
[ [ 'group' => 'g' ], [ null, 'g', null, null, null ] ],
[ [ 'invalid' => 'i' ], [ false, false, false, false, false ] ],
[ [ 'name' => 'n' ], [ 'n', null, null, null, null ] ],
[ [ 'name' => null ], [ false, false, false, false, false ] ],
[ [ 'refines' => 'r' ], [ null, null, null, null, 'r' ] ],
// Pairs
[ [ 'follow' => 'f', 'name' => 'n' ], [ false, false, false, false ] ],
[ [ 'follow' => null, 'name' => null ], [ false, false, false, false ] ],
[ [ 'follow' => 'f', 'refines' => 'r' ], [ null, null, 'f', null ] ],
[ [ 'group' => 'r', 'name' => 'n' ], [ 'n', 'r', null, null ] ],
[ [ 'follow' => 'f', 'name' => 'n' ], [ false, false, false, false, false ] ],
[ [ 'follow' => null, 'name' => null ], [ false, false, false, false, false ] ],
[ [ 'follow' => 'f', 'refines' => 'r' ], [ null, null, 'f', null, 'r' ] ],
[ [ 'group' => 'g', 'name' => 'n' ], [ 'n', 'g', null, null, null ] ],
// Combinations of 3 or more attributes
[
[ 'group' => 'r', 'name' => 'n', 'refines' => 'f', 'dir' => 'rtl' ],
[ 'n', 'r', null, ' class="mw-cite-dir-rtl"' ]
[ 'group' => 'g', 'name' => 'n', 'refines' => 'r', 'dir' => 'rtl' ],
[ 'n', 'g', null, ' class="mw-cite-dir-rtl"', 'r' ]
],
];
}