mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite
synced 2024-11-24 06:54:00 +00:00
Show error when extending a subreference
Change-Id: Iaa47e302e5e49dfc190fde37567a3e7a2e743d67
This commit is contained in:
parent
484373c21e
commit
81261493c2
|
@ -98,6 +98,14 @@ class FootnoteBodyFormatter {
|
||||||
$parserInput .= $this->closeIndention( $indented );
|
$parserInput .= $this->closeIndention( $indented );
|
||||||
$indented = false;
|
$indented = false;
|
||||||
}
|
}
|
||||||
|
// Make sure the parent is not a subreference.
|
||||||
|
// FIXME: Move to a validation function.
|
||||||
|
if ( isset( $value['extends'] ) &&
|
||||||
|
isset( $groupRefs[$value['extends']]['extends'] )
|
||||||
|
) {
|
||||||
|
$value['text'] = ( $value['text'] ?? '' ) .
|
||||||
|
$this->errorReporter->plain( 'cite_error_ref_too_many_keys' );
|
||||||
|
}
|
||||||
$parserInput .= $this->referencesFormatEntry( $key, $value, $isSectionPreview ) . "\n";
|
$parserInput .= $this->referencesFormatEntry( $key, $value, $isSectionPreview ) . "\n";
|
||||||
}
|
}
|
||||||
$parserInput .= $this->closeIndention( $indented );
|
$parserInput .= $this->closeIndention( $indented );
|
||||||
|
@ -144,9 +152,6 @@ class FootnoteBodyFormatter {
|
||||||
$error = '';
|
$error = '';
|
||||||
$extraAttributes = '';
|
$extraAttributes = '';
|
||||||
|
|
||||||
// TODO: Show an error if isset( $val['__placeholder__'] ), this is caused by extends
|
|
||||||
// with a missing parent.
|
|
||||||
|
|
||||||
if ( isset( $val['dir'] ) ) {
|
if ( isset( $val['dir'] ) ) {
|
||||||
$dir = strtolower( $val['dir'] );
|
$dir = strtolower( $val['dir'] );
|
||||||
if ( in_array( $dir, [ 'ltr', 'rtl' ] ) ) {
|
if ( in_array( $dir, [ 'ltr', 'rtl' ] ) ) {
|
||||||
|
|
|
@ -164,8 +164,6 @@ wgCiteBookReferencing=true
|
||||||
</ol></div>
|
</ol></div>
|
||||||
!! end
|
!! end
|
||||||
|
|
||||||
# TODO:
|
|
||||||
# * Should render an error on ref-3.
|
|
||||||
!! test
|
!! test
|
||||||
T236256 - Can't extend a book reference (no nesting).
|
T236256 - Can't extend a book reference (no nesting).
|
||||||
!! config
|
!! config
|
||||||
|
@ -184,7 +182,8 @@ wgCiteBookReferencing=true
|
||||||
<li id="cite_note-a-1"><span class="mw-cite-backlink"><a href="#cite_ref-a_1-0">↑</a></span> <span class="reference-text">book</span>
|
<li id="cite_note-a-1"><span class="mw-cite-backlink"><a href="#cite_ref-a_1-0">↑</a></span> <span class="reference-text">book</span>
|
||||||
<ol class="mw-extended-references"><li id="cite_note-b-2"><span class="mw-cite-backlink"><a href="#cite_ref-b_2-0">↑</a></span> <span class="reference-text">page 2</span>
|
<ol class="mw-extended-references"><li id="cite_note-b-2"><span class="mw-cite-backlink"><a href="#cite_ref-b_2-0">↑</a></span> <span class="reference-text">page 2</span>
|
||||||
</li>
|
</li>
|
||||||
<li id="cite_note-3"><span class="mw-cite-backlink"><a href="#cite_ref-3">↑</a></span> <span class="reference-text">section 3</span>
|
<li id="cite_note-3"><span class="mw-cite-backlink"><a href="#cite_ref-3">↑</a></span> <span class="reference-text">section 3<span class="error mw-ext-cite-error" lang="en" dir="ltr">Cite error: Invalid <code><ref></code> tag;
|
||||||
|
invalid names, e.g. too many</span></span>
|
||||||
</li>
|
</li>
|
||||||
</ol></li>
|
</ol></li>
|
||||||
</ol></div>
|
</ol></div>
|
||||||
|
|
|
@ -27,6 +27,13 @@ class FootnoteBodyFormatterTest extends MediaWikiUnitTestCase {
|
||||||
$mockParser = $this->createMock( Parser::class );
|
$mockParser = $this->createMock( Parser::class );
|
||||||
$mockParser->method( 'recursiveTagParse' )->willReturnArgument( 0 );
|
$mockParser->method( 'recursiveTagParse' )->willReturnArgument( 0 );
|
||||||
/** @var Parser $mockParser */
|
/** @var Parser $mockParser */
|
||||||
|
$mockErrorReporter = $this->createMock( CiteErrorReporter::class );
|
||||||
|
$mockErrorReporter->method( 'plain' )->willReturnCallback(
|
||||||
|
function ( ...$args ) {
|
||||||
|
return json_encode( $args );
|
||||||
|
}
|
||||||
|
);
|
||||||
|
/** @var CiteErrorReporter $mockErrorReporter */
|
||||||
$mockMessageLocalizer = $this->createMock( ReferenceMessageLocalizer::class );
|
$mockMessageLocalizer = $this->createMock( ReferenceMessageLocalizer::class );
|
||||||
$mockMessageLocalizer->method( 'msg' )->willReturnCallback(
|
$mockMessageLocalizer->method( 'msg' )->willReturnCallback(
|
||||||
function ( ...$args ) {
|
function ( ...$args ) {
|
||||||
|
@ -41,7 +48,7 @@ class FootnoteBodyFormatterTest extends MediaWikiUnitTestCase {
|
||||||
/** @var FootnoteBodyFormatter $formatter */
|
/** @var FootnoteBodyFormatter $formatter */
|
||||||
$formatter = TestingAccessWrapper::newFromObject( new FootnoteBodyFormatter(
|
$formatter = TestingAccessWrapper::newFromObject( new FootnoteBodyFormatter(
|
||||||
$mockParser,
|
$mockParser,
|
||||||
$this->createMock( CiteErrorReporter::class ),
|
$mockErrorReporter,
|
||||||
$this->createMock( CiteKeyFormatter::class ),
|
$this->createMock( CiteKeyFormatter::class ),
|
||||||
$mockMessageLocalizer ) );
|
$mockMessageLocalizer ) );
|
||||||
|
|
||||||
|
@ -94,6 +101,37 @@ class FootnoteBodyFormatterTest extends MediaWikiUnitTestCase {
|
||||||
"\n|)</li>\n" .
|
"\n|)</li>\n" .
|
||||||
'</ol></div>'
|
'</ol></div>'
|
||||||
],
|
],
|
||||||
|
'Subref of subref' => [
|
||||||
|
[
|
||||||
|
0 => [
|
||||||
|
'extends' => 'a',
|
||||||
|
'extendsIndex' => 1,
|
||||||
|
'key' => 1,
|
||||||
|
'number' => 1,
|
||||||
|
'text' => 't1',
|
||||||
|
],
|
||||||
|
'a' => [
|
||||||
|
'extends' => 'b',
|
||||||
|
'extendsIndex' => 1,
|
||||||
|
'key' => 2,
|
||||||
|
'number' => 1,
|
||||||
|
'text' => 't2',
|
||||||
|
],
|
||||||
|
'b' => [
|
||||||
|
'key' => 3,
|
||||||
|
'number' => 1,
|
||||||
|
'text' => 't3',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'<div class="mw-references-wrap"><ol class="references">' . "\n" .
|
||||||
|
'<li>(cite_references_link_many|||<span class="reference-text">t3</span>' . "\n" .
|
||||||
|
'|)<ol class="mw-extended-references"><li>(cite_references_link_many|||' .
|
||||||
|
'<span class="reference-text">t1["cite_error_ref_too_many_keys"]</span>' .
|
||||||
|
"\n|)</li>\n" .
|
||||||
|
'<li>(cite_references_link_many|||<span class="reference-text">t2</span>' .
|
||||||
|
"\n|)</li>\n</ol></li>\n" .
|
||||||
|
'</ol></div>'
|
||||||
|
],
|
||||||
'Use columns' => [
|
'Use columns' => [
|
||||||
[
|
[
|
||||||
0 => [ 'key' => 1, 'text' => 't' ],
|
0 => [ 'key' => 1, 'text' => 't' ],
|
||||||
|
|
Loading…
Reference in a new issue