From 5e8d48b3314c417cd5244e9698dfeabfc12521bf Mon Sep 17 00:00:00 2001 From: Adam Wight Date: Thu, 24 Oct 2019 11:23:44 +0200 Subject: [PATCH] Minimal support for bookreferencing tag Allows the "refines" attribute when the feature flag is set, but doesn't render. This is part of our rollback strategy, so that we aren't left with invalid wikitext in case of undeployment. Bug: T236257 Change-Id: I936be0e62dccb46caeb84162d2c5166956fd9916 --- includes/Cite.php | 14 +++++++++++++ tests/parser/citeParserTests.txt | 35 ++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/includes/Cite.php b/includes/Cite.php index d8af7d34d..b12545203 100644 --- a/includes/Cite.php +++ b/includes/Cite.php @@ -61,6 +61,12 @@ class Cite { */ private const CACHE_DURATION_ONFETCH = 18000; + /** + * Wikitext attribute name for Book Referencing. + * TODO: Still under discussion. + */ + public const REFINES_ATTRIBUTE = 'refines'; + /** * Datastructure representing input, in the format of: * @@ -391,6 +397,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. * * @param string[] $argv The argument vector * @return (string|false|null)[] An array with exactly four elements, where each is a string on @@ -398,6 +405,8 @@ class Cite { * @return-taint tainted */ private function refArg( array $argv ) { + global $wgCiteBookReferencing; + $group = null; $key = null; $follow = null; @@ -438,6 +447,11 @@ class Cite { $group = $argv['group']; unset( $argv['group'] ); } + if ( $wgCiteBookReferencing && isset( $argv[self::REFINES_ATTRIBUTE] ) ) { + // TODO: Extract the name and return it. + // $refines = trim( $argv[self::REFINES_ATTRIBUTE] ); + unset( $argv[self::REFINES_ATTRIBUTE] ); + } if ( $argv !== [] ) { // Invalid key diff --git a/tests/parser/citeParserTests.txt b/tests/parser/citeParserTests.txt index db689c4fb..d5dd509f9 100644 --- a/tests/parser/citeParserTests.txt +++ b/tests/parser/citeParserTests.txt @@ -1709,3 +1709,38 @@ wgFragmentMode=['legacy']

[1]

  1. [bar]
!! end + +!! test +Refines tag rejected by default +!! config +wgCiteBookReferencing=false +!! wikitext +[foo] +[bar] +!! html/php +

[1] +Cite error: Invalid <ref> tag; +

+invalid names, e.g. too many
    +
  1. [foo] +
  2. +
+!! end + +!! test +Refines tag allowed with feature flag set +!! config +wgCiteBookReferencing=true +!! wikitext +[foo] +[bar] +!! html/php +

[1] +

+[2]
    +
  1. [foo] +
  2. +
  3. [bar] +
  4. +
+!! end