aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorC. Scott Ananian <cscott@cscott.net>2022-07-27 18:07:09 -0400
committerC. Scott Ananian <cscott@cscott.net>2022-07-27 18:45:59 -0400
commit6d5c62f5cfe8755ca3182ead231773fe460c81f4 (patch)
treeecc5e1530d740e2989c78a843229c2ac865e9d33
parent8f39383e66a82427f3e59ae0e51e451ce854780d (diff)
downloadmediawikicore-6d5c62f5cfe8755ca3182ead231773fe460c81f4.tar.gz
mediawikicore-6d5c62f5cfe8755ca3182ead231773fe460c81f4.zip
ParserOutputFlags: change HIDE_TOC to SHOW_TOC
When I implemented the ParserOutput merge logic in OutputPage (I0909ac85c6c785d9089b077a16923c61d6a09996) I realized that consistent "combine with OR" merge logic for the TOC flag is obtained only if we invert the flag; that is, the existing code showed a TOC *if any ParserOutput contained a shown TOC* otherwise the TOC was hidden. I'd originally implemented this in I35e199cca40c0e4359ac493e5806dcf4ae49321c with the opposite sense in order to avoid having to wait for ParserCache contents to expire: since the default on most pages was to have the TOC shown anyway, if "out of date" parser cache entries were missing a HIDE_TOC flag, it wouldn't be a big deal, whereas if a SHOW_TOC flag were required then upon deploy all cached pages would lose their TOC rendering. BUT a better solution is just to let a "parser cache expiration time" elapse between the time we start generating this flag and the time we start using it. The existing patch to export this (I6cf76c870124c162dc1bcbc2f7e9ca0c5fdcd10e) uses ParserOutput::getTOCHTML() anyway, so we can just wait to switch this over to use the SHOW_TOC flag (I10c3d06fb162103c06395bf9d1d27ac3c199d7b6) until the parser cache has expired. Anyway, this is a bit of a hassle to switch now, but I think having consistent merge semantics for ParserOutput flags is worth the short-term pain. Bug: T310083 Change-Id: I3b76010f1e2283add629b84bf3824f215f932903
-rw-r--r--includes/parser/Parser.php9
-rw-r--r--includes/parser/ParserOutputFlags.php6
-rw-r--r--tests/parser/parserTests.txt72
3 files changed, 45 insertions, 42 deletions
diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php
index 02bde1514840..c2e0fe7e5d1a 100644
--- a/includes/parser/Parser.php
+++ b/includes/parser/Parser.php
@@ -4511,9 +4511,12 @@ class Parser {
}
$toc = Linker::tocList( $toc, $this->mOptions->getUserLangObj() );
$this->mOutput->setTOCHTML( $toc );
- } else {
- // Record the fact that the TOC should not be shown. T294950
- $this->mOutput->setOutputFlag( ParserOutputFlags::HIDE_TOC );
+ // Record the fact that the TOC should be shown. T294950
+ // (We shouldn't be looking at ::getTOCHTML() for this because
+ // eventually that will be replaced (T293513) and
+ // ::getSections() will contain sections even if there aren't
+ // $enoughToc to show.)
+ $this->mOutput->setOutputFlag( ParserOutputFlags::SHOW_TOC );
}
if ( $isMain && !$suppressToc ) {
diff --git a/includes/parser/ParserOutputFlags.php b/includes/parser/ParserOutputFlags.php
index 007083d589fb..efda54ccca66 100644
--- a/includes/parser/ParserOutputFlags.php
+++ b/includes/parser/ParserOutputFlags.php
@@ -94,9 +94,9 @@ class ParserOutputFlags {
// These flags are stored in the ParserOutput::$mFlags array
/**
- * @var string Hide the table of contents in the skin?
+ * @var string Show the table of contents in the skin?
*/
- public const HIDE_TOC = 'hide-toc';
+ public const SHOW_TOC = 'show-toc';
/**
* @var string Used to suppress language conversion in ToC contents.
@@ -166,7 +166,7 @@ class ParserOutputFlags {
self::NO_INDEX_POLICY,
self::NEW_SECTION,
self::HIDE_NEW_SECTION,
- self::HIDE_TOC,
+ self::SHOW_TOC,
self::PREVENT_CLICKJACKING,
self::VARY_REVISION,
self::VARY_REVISION_ID,
diff --git a/tests/parser/parserTests.txt b/tests/parser/parserTests.txt
index e40401c98b18..81d0643c4e86 100644
--- a/tests/parser/parserTests.txt
+++ b/tests/parser/parserTests.txt
@@ -11483,7 +11483,7 @@ showflags
!! html/*
<p>1337
</p>
-flags=hide-toc, vary-revision-id
+flags=vary-revision-id
!! end
!! test
@@ -11496,7 +11496,7 @@ showflags
!! html/*
<p>1337
</p>
-flags=hide-toc, vary-revision-id
+flags=vary-revision-id
!! end
!! test
@@ -11510,7 +11510,7 @@ showflags
!! html/*
<p>19700101000203
</p>
-flags=hide-toc
+flags=
!! end
!! test
@@ -11523,7 +11523,7 @@ showflags
!! html/*
<p>123
</p>
-flags=hide-toc, vary-revision-timestamp
+flags=vary-revision-timestamp
!! end
!! test
@@ -11537,7 +11537,7 @@ showflags
!! html/*
<p>127.0.0.1
</p>
-flags=hide-toc, vary-user
+flags=vary-user
!! end
!! test
@@ -11551,7 +11551,7 @@ showflags
!! html/*
<p>1337
</p>
-flags=hide-toc, vary-revision-id
+flags=vary-revision-id
!! end
!! test
@@ -11563,7 +11563,7 @@ showflags
{{REVISIONID:{{PAGENAME}}}}
!! html/*
-flags=hide-toc, vary-revision-id
+flags=vary-revision-id
!! end
!! test
@@ -11577,7 +11577,7 @@ showflags
!! html/*
<p>19700101000203
</p>
-flags=hide-toc, vary-revision-timestamp
+flags=vary-revision-timestamp
!! end
!! test
@@ -11591,7 +11591,7 @@ showflags
!! html/*
<p>1
</p>
-flags=hide-toc, vary-revision-timestamp
+flags=vary-revision-timestamp
!! end
!! test
@@ -11605,7 +11605,7 @@ showflags
!! html/*
<p>01
</p>
-flags=hide-toc, vary-revision-timestamp
+flags=vary-revision-timestamp
!! end
!! test
@@ -11619,7 +11619,7 @@ showflags
!! html/*
<p>1970
</p>
-flags=hide-toc, vary-revision-timestamp
+flags=vary-revision-timestamp
!! end
!! test
@@ -11633,7 +11633,7 @@ showflags
!! html/*
<p>25
</p>
-flags=hide-toc, vary-revision-sha1
+flags=vary-revision-sha1
!! end
!! test
@@ -16795,67 +16795,67 @@ __NOTOC__
<h3><span class="mw-headline" id="Section_1">Section 1</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Template:Sections&amp;action=edit&amp;section=T-1" title="Edit section: Section 1">edit</a><span class="mw-editsection-bracket">]</span></span></h3>
<h2><span class="mw-headline" id="Section_2">Section 2</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Template:Sections&amp;action=edit&amp;section=T-2" title="Edit section: Section 2">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<h2><span class="mw-headline" id="Section_4">Section 4</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=2" title="Edit section: Section 4">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
-flags=hide-toc
+flags=
!! end
!! test
-T307691: hide-toc flag: no sections
+T307691: show-toc flag: no sections
!! options
showflags
!! wikitext
!! html/php
-flags=hide-toc
+flags=
!! end
# You can't force a TOC if there aren't any sections
!! test
-T307691: hide-toc flag: no sections, but __FORCETOC__
+T307691: show-toc flag: no sections, but __FORCETOC__
!! options
showflags
!! wikitext
__FORCETOC__
!! html/php
-flags=hide-toc
+flags=
!! end
# Placing a manual __TOC__ doesn't do anything if there aren't any sections
!! test
-T307691: hide-toc flag: no sections, but __TOC__
+T307691: show-toc flag: no sections, but __TOC__
!! options
showflags
!! wikitext
__TOC__
!! html/php
-flags=hide-toc
+flags=
!! end
!! test
-T307691: hide-toc flag: no sections, and __NOTOC__
+T307691: show-toc flag: no sections, and __NOTOC__
!! options
showflags
!! wikitext
__NOTOC__
!! html/php
-flags=hide-toc
+flags=
!! end
!! test
-T307691: hide-toc flag: not "enough" sections
+T307691: show-toc flag: not "enough" sections
!! options
showflags
!! wikitext
== One ==
!! html/php
<h2><span class="mw-headline" id="One">One</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=1" title="Edit section: One">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
-flags=hide-toc
+flags=
!! end
!! test
-T307691: hide-toc flag: not "enough" sections, but __FORCETOC__
+T307691: show-toc flag: not "enough" sections, but __FORCETOC__
!! options
showflags
!! wikitext
@@ -16869,11 +16869,11 @@ __FORCETOC__
</div>
<h2><span class="mw-headline" id="One">One</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=1" title="Edit section: One">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
-flags=
+flags=show-toc
!! end
!! test
-T307691: hide-toc flag: not "enough" sections, but __TOC__
+T307691: show-toc flag: not "enough" sections, but __TOC__
!! options
showflags
!! wikitext
@@ -16886,11 +16886,11 @@ __TOC__
<li class="toclevel-1 tocsection-1"><a href="#One"><span class="tocnumber">1</span> <span class="toctext">One</span></a></li>
</ul>
</div>
-flags=
+flags=show-toc
!! end
!! test
-T307691: hide-toc flag: not "enough" sections, and __NOTOC__
+T307691: show-toc flag: not "enough" sections, and __NOTOC__
!! options
showflags
!! wikitext
@@ -16898,11 +16898,11 @@ __NOTOC__
== One ==
!! html/php
<h2><span class="mw-headline" id="One">One</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=1" title="Edit section: One">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
-flags=hide-toc
+flags=
!! end
!! test
-T307691: hide-toc flag: "enough" sections
+T307691: show-toc flag: "enough" sections
!! options
showflags
!! wikitext
@@ -16930,11 +16930,11 @@ showflags
<h3><span class="mw-headline" id="Two">Two</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=2" title="Edit section: Two">edit</a><span class="mw-editsection-bracket">]</span></span></h3>
<h2><span class="mw-headline" id="Three">Three</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=3" title="Edit section: Three">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<h3><span class="mw-headline" id="Four">Four</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=4" title="Edit section: Four">edit</a><span class="mw-editsection-bracket">]</span></span></h3>
-flags=
+flags=show-toc
!! end
!! test
-T307691: hide-toc flag: "enough" sections and __FORCETOC__
+T307691: show-toc flag: "enough" sections and __FORCETOC__
!! options
showflags
!! wikitext
@@ -16963,11 +16963,11 @@ __FORCETOC__
<h3><span class="mw-headline" id="Two">Two</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=2" title="Edit section: Two">edit</a><span class="mw-editsection-bracket">]</span></span></h3>
<h2><span class="mw-headline" id="Three">Three</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=3" title="Edit section: Three">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<h3><span class="mw-headline" id="Four">Four</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=4" title="Edit section: Four">edit</a><span class="mw-editsection-bracket">]</span></span></h3>
-flags=
+flags=show-toc
!! end
!! test
-T307691: hide-toc flag: "enough" sections and __NOTOC__
+T307691: show-toc flag: "enough" sections and __NOTOC__
!! options
showflags
!! wikitext
@@ -16981,7 +16981,7 @@ __NOTOC__
<h3><span class="mw-headline" id="Two">Two</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=2" title="Edit section: Two">edit</a><span class="mw-editsection-bracket">]</span></span></h3>
<h2><span class="mw-headline" id="Three">Three</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=3" title="Edit section: Three">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<h3><span class="mw-headline" id="Four">Four</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=4" title="Edit section: Four">edit</a><span class="mw-editsection-bracket">]</span></span></h3>
-flags=hide-toc
+flags=
!! end
!! test
@@ -20669,7 +20669,7 @@ __FORCETOC__
!! html/php
<p><br />
</p>
-flags=hide-toc
+flags=
!! end
!! test