parser: document what 0/null rev IDs do when given to Parser::parse
authorAaron Schulz <aschulz@wikimedia.org>
Thu, 27 Jun 2019 07:17:06 +0000 (00:17 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Wed, 21 Aug 2019 18:13:49 +0000 (11:13 -0700)
This was extremely obscure and tricky to figure out before

Change-Id: Ibdbb669431819eecd34de508735864e977d51021

includes/content/AbstractContent.php
includes/content/Content.php
includes/content/WikitextContent.php
includes/parser/Parser.php
tests/phpunit/includes/parser/ParserMethodsTest.php

index c82b473..eb9ef85 100644 (file)
@@ -529,7 +529,7 @@ abstract class AbstractContent implements Content {
         * @since 1.24
         *
         * @param Title $title Context title for parsing
-        * @param int|null $revId Revision ID (for {{REVISIONID}})
+        * @param int|null $revId Revision ID being rendered
         * @param ParserOptions|null $options
         * @param bool $generateHtml Whether or not to generate HTML
         *
@@ -575,7 +575,8 @@ abstract class AbstractContent implements Content {
         * @since 1.24
         *
         * @param Title $title Context title for parsing
-        * @param int|null $revId Revision ID (for {{REVISIONID}})
+        * @param int|null $revId ID of the revision being rendered.
+        *  See Parser::parse() for the ramifications.
         * @param ParserOptions $options
         * @param bool $generateHtml Whether or not to generate HTML
         * @param ParserOutput &$output The output object to fill (reference).
index 2637aa6..8596619 100644 (file)
@@ -269,7 +269,8 @@ interface Content {
         *       may call ParserOutput::recordOption() on the output object.
         *
         * @param Title $title The page title to use as a context for rendering.
-        * @param int|null $revId Optional revision ID being rendered.
+        * @param int|null $revId ID of the revision being rendered.
+        *  See Parser::parse() for the ramifications. (default: null)
         * @param ParserOptions|null $options Any parser options.
         * @param bool $generateHtml Whether to generate HTML (default: true). If false,
         *        the result of calling getText() on the ParserOutput object returned by
index 8e5e0a8..70b638b 100644 (file)
@@ -329,7 +329,8 @@ class WikitextContent extends TextContent {
         * using the global Parser service.
         *
         * @param Title $title
-        * @param int|null $revId Revision to pass to the parser (default: null)
+        * @param int|null $revId ID of the revision being rendered.
+        *  See Parser::parse() for the ramifications. (default: null)
         * @param ParserOptions $options (default: null)
         * @param bool $generateHtml (default: true)
         * @param ParserOutput &$output ParserOutput representing the HTML form of the text,
index b643c3f..f982de4 100644 (file)
@@ -530,7 +530,10 @@ class Parser {
         * @param ParserOptions $options
         * @param bool $linestart
         * @param bool $clearState
-        * @param int|null $revid Number to pass in {{REVISIONID}}
+        * @param int|null $revid ID of the revision being rendered. This is used to render
+        *  REVISION* magic words. 0 means that any current revision will be used. Null means
+        *  that {{REVISIONID}}/{{REVISIONUSER}} will be empty and {{REVISIONTIMESTAMP}} will
+        *  use the current timestamp.
         * @return ParserOutput A ParserOutput
         * @return-taint escaped
         */
index 651c871..4175ead 100644 (file)
@@ -234,6 +234,7 @@ class ParserMethodsTest extends MediaWikiLangTestCase {
                $po = new ParserOptions( $frank );
 
                yield 'current' => [ $text, $po, 0, 'user:CurrentAuthor;id:200;time:20160606000000;' ];
+               yield 'current' => [ $text, $po, null, 'user:;id:;time:' ];
                yield 'current with ID' => [ $text, $po, 200, 'user:CurrentAuthor;id:200;time:20160606000000;' ];
 
                $text = '* user:{{REVISIONUSER}};id:{{REVISIONID}};time:{{REVISIONTIMESTAMP}};';