From 9d706047f381ffdfedcddde39baf46e4648b6489 Mon Sep 17 00:00:00 2001 From: Adam Wight Date: Tue, 12 Nov 2019 11:03:44 +0100 Subject: [PATCH] Rename refines -> extends Bug: T171581 Change-Id: I42b2d8859f2958357024cbba089715c10712f370 --- includes/Cite.php | 21 ++++---- tests/parser/bookReferencing.txt | 84 ++++++++++++++++---------------- tests/phpunit/CiteTest.php | 10 ++-- 3 files changed, 57 insertions(+), 58 deletions(-) diff --git a/includes/Cite.php b/includes/Cite.php index d96a7d0cd..1b4e74d69 100644 --- a/includes/Cite.php +++ b/includes/Cite.php @@ -52,9 +52,8 @@ class Cite { /** * Wikitext attribute name for Book Referencing. - * TODO: Still under discussion. */ - public const REFINES_ATTRIBUTE = 'refines'; + public const BOOK_REF_ATTRIBUTE = 'extends'; /** * Page property key for the Book Referencing `extends` attribute. @@ -237,7 +236,7 @@ class Cite { Parser $parser ) { # The key here is the "name" attribute. - list( $key, $group, $follow, $dir, $refines ) = $this->refArg( $argv ); + list( $key, $group, $follow, $dir, $extends ) = $this->refArg( $argv ); // empty string indicate invalid dir if ( $dir === '' && $text !== '' ) { $text .= $this->plainError( 'cite_error_ref_invalid_dir', $argv['dir'] ); @@ -249,7 +248,7 @@ class Cite { // Tag every page where Book Referencing has been used. This code and the properties // will be removed once the feature is stable. See T237531. - if ( $refines ) { + if ( $extends ) { $parser->getOutput()->setProperty( self::BOOK_REF_PROPERTY, true ); } @@ -393,7 +392,7 @@ class Cite { * "group" : Group to which it belongs. Needs to be passed to too. * "follow" : If the current reference is the continuation of another, key of that reference. * "dir" : set direction of text (ltr/rtl) - * "refines": Points to a named reference which serves as the context for this reference. + * "extends": Points to a named reference which serves as the context for this reference. * * @param string[] $argv The argument vector * @return (string|false|null)[] An array with exactly four elements, where each is a string on @@ -407,7 +406,7 @@ class Cite { $key = null; $follow = null; $dir = null; - $refines = null; + $extends = null; if ( isset( $argv['dir'] ) ) { // compare the dir attribute value against an explicit whitelist. @@ -426,7 +425,7 @@ class Cite { } if ( isset( $argv['follow'] ) && - ( isset( $argv['name'] ) || isset( $argv[self::REFINES_ATTRIBUTE] ) ) + ( isset( $argv['name'] ) || isset( $argv[self::BOOK_REF_ATTRIBUTE] ) ) ) { return [ false, false, false, false, false ]; } @@ -446,9 +445,9 @@ class Cite { $group = $argv['group']; unset( $argv['group'] ); } - if ( $wgCiteBookReferencing && isset( $argv[self::REFINES_ATTRIBUTE] ) ) { - $refines = trim( $argv[self::REFINES_ATTRIBUTE] ); - unset( $argv[self::REFINES_ATTRIBUTE] ); + if ( $wgCiteBookReferencing && isset( $argv[self::BOOK_REF_ATTRIBUTE] ) ) { + $extends = trim( $argv[self::BOOK_REF_ATTRIBUTE] ); + unset( $argv[self::BOOK_REF_ATTRIBUTE] ); } if ( $argv !== [] ) { @@ -456,7 +455,7 @@ class Cite { return [ false, false, false, false, false ]; } - return [ $key, $group, $follow, $dir, $refines ]; + return [ $key, $group, $follow, $dir, $extends ]; } /** diff --git a/tests/parser/bookReferencing.txt b/tests/parser/bookReferencing.txt index 5ff85c711..793a9d850 100644 --- a/tests/parser/bookReferencing.txt +++ b/tests/parser/bookReferencing.txt @@ -1,10 +1,10 @@ !! test -Refines attribute rejected by default +Book Referencing attribute rejected by default !! config wgCiteBookReferencing=false !! wikitext [foo] -[bar] +[bar] !! html/php

[1] Cite error: Invalid <ref> tag; @@ -18,12 +18,12 @@ invalid names, e.g. too many

    [foo] -[bar] +[bar] !! html/php

    [1]

    @@ -38,13 +38,13 @@ wgCiteBookReferencing=true # TODO: # * Subnumbering and indent. !! test -T236256 - Refining the same base multiple times is fine +T236256 - Extending the same base multiple times is fine !! config wgCiteBookReferencing=true !! wikitext book -page 2 -page 3 +page 2 +page 3 !! html/php

    [1] @@ -64,13 +64,13 @@ wgCiteBookReferencing=true # TODO: # * Subnumbering and indent. !! test -T236256 - Naming refinements is fine +T236256 - Naming book references is fine !! config wgCiteBookReferencing=true !! wikitext book -page 2 -page 3 +page 2 +page 3 @@ -94,11 +94,11 @@ wgCiteBookReferencing=true # TODO: # * Should render an error. !! test -T236256 - Refining a reference that doesn't exist #1 +T236256 - Extending a reference that doesn't exist #1 !! config wgCiteBookReferencing=true !! wikitext -page 1 +page 1 !! html/php [1]

    1. page 1 @@ -109,12 +109,12 @@ wgCiteBookReferencing=true # TODO: # * Should render an error at the second reference. !! test -T236256 - Refining a reference that doesn't exist #2 +T236256 - Extending a reference that doesn't exist #2 !! config wgCiteBookReferencing=true !! wikitext book -page 1 +page 1 !! html/php

      [1]

      @@ -133,7 +133,7 @@ wgCiteBookReferencing=true !! wikitext book magazine -page 1 +page 1 !! html/php

      [1] [1] @@ -147,13 +147,13 @@ wgCiteBookReferencing=true !! end !! test -T236256 - Can't reuse a name for two refinements +T236256 - Can't reuse a name for two book references !! config wgCiteBookReferencing=true !! wikitext book -page 2 -page 3 +page 2 +page 3 !! html/php

      [1] @@ -171,13 +171,13 @@ wgCiteBookReferencing=true # TODO: # * Should render an error on ref-3. !! test -T236256 - Cant refine a refined ref (no nesting). +T236256 - Cant extend a book reference (no nesting). !! config wgCiteBookReferencing=true !! wikitext book -page 2 -section 3 +page 2 +section 3 !! html/php

      [1] @@ -200,7 +200,7 @@ T236256 - Named reference without text wgCiteBookReferencing=true !! wikitext -page 1 +page 1 !! html/php

      [1]

      @@ -213,12 +213,12 @@ no text was provided for refs named a
    2. !! end !! test -T236256 - No text for a refinement +T236256 - No text for a book reference !! config wgCiteBookReferencing=true !! wikitext book - + !! html/php

      [1]

      @@ -229,12 +229,12 @@ wgCiteBookReferencing=true !! end !! test -T236256 - Empty text for a refinement +T236256 - Empty text for a book reference !! config wgCiteBookReferencing=true !! wikitext book - + !! html/php

      [1] Cite error: Invalid <ref> tag; @@ -246,12 +246,12 @@ refs with no name must have content

        book - + !! html/php

        [1]

        @@ -271,7 +271,7 @@ T236256 - Everything in the same group wgCiteBookReferencing=true !! wikitext book -page +page !! html/php @@ -290,12 +290,12 @@ wgCiteBookReferencing=true # TODO: # * Should render an error at the second reference. !! test -T236256 - Base and refinement in different groups +T236256 - Base and book reference in different groups !! config wgCiteBookReferencing=true !! wikitext book -page +page !! html/php @@ -315,12 +315,12 @@ wgCiteBookReferencing=true # TODO: # * Should render an error at the second reference. !! test -T236256 - Refinement in the unnamed default group +T236256 - Extending in the unnamed default group !! config wgCiteBookReferencing=true !! wikitext book -page +page !! html/php

        [g1 1] @@ -343,7 +343,7 @@ T236256 - Base in the unnamed default group wgCiteBookReferencing=true !! wikitext book -page +page !! html/php

        [1] @@ -361,13 +361,13 @@ wgCiteBookReferencing=true # TODO: # * Subnumbering and indent. !! test -T236256 - Refining a multi-part ref should be fine +T236256 - Extending a multi-part ref should be fine !! config wgCiteBookReferencing=true !! wikitext part 1 part 2 -ok +ok !! html/php

        [1] @@ -384,12 +384,12 @@ wgCiteBookReferencing=true # TODO: # * Should render an error at the third reference. !! test -T236256 - Dont allow splitting a refinement for now +T236256 - Dont allow splitting a book reference for now !! config wgCiteBookReferencing=true !! wikitext book -page 2 +page 2 and page 3 the same time? !! html/php @@ -407,12 +407,12 @@ wgCiteBookReferencing=true # TODO: # * Should render an error at the second reference. !! test -T236256 - Cant be a follow up and a refinement the same time +T236256 - Cant be a follow up and a book reference the same time !! config wgCiteBookReferencing=true !! wikitext book 1 -huh? +huh? !! html/php

        [1] @@ -428,13 +428,13 @@ invalid names, e.g. too many # TODO: # * Should render an error at the third reference. !! test -T236256 - Can't be a follow up and a refinement the same time, even when referencing 2 different bases +T236256 - Can't be a follow up and a book reference the same time, even when referencing 2 different bases !! config wgCiteBookReferencing=true !! wikitext book 1 book 2 -huh? +huh? !! html/php

        [1] diff --git a/tests/phpunit/CiteTest.php b/tests/phpunit/CiteTest.php index 4cac5a361..aa85c1db3 100644 --- a/tests/phpunit/CiteTest.php +++ b/tests/phpunit/CiteTest.php @@ -38,18 +38,18 @@ class CiteTest extends MediaWikiTestCase { [ [ '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' ] ], + [ [ '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', 'refines' => 'r' ], [ false, false, false, false, false ] ], + [ [ 'follow' => 'f', 'extends' => 'e' ], [ false, false, false, false, false ] ], [ [ 'group' => 'g', 'name' => 'n' ], [ 'n', 'g', null, null, null ] ], // Combinations of 3 or more attributes [ - [ 'group' => 'g', 'name' => 'n', 'refines' => 'r', 'dir' => 'rtl' ], - [ 'n', 'g', null, ' class="mw-cite-dir-rtl"', 'r' ] + [ 'group' => 'g', 'name' => 'n', 'extends' => 'e', 'dir' => 'rtl' ], + [ 'n', 'g', null, ' class="mw-cite-dir-rtl"', 'e' ] ], ]; } @@ -95,7 +95,7 @@ class CiteTest extends MediaWikiTestCase { $cite = new Cite(); $cite->ref( 'contentA', [ 'name' => 'a' ], $mockParser, $mockPPframe ); - $cite->ref( 'contentB', [ Cite::REFINES_ATTRIBUTE => 'a' ], $mockParser, $mockPPframe ); + $cite->ref( 'contentB', [ Cite::BOOK_REF_ATTRIBUTE => 'a' ], $mockParser, $mockPPframe ); } }