jenkins-bot has submitted this change and it was merged.
Change subject: Make TOC hideable
......................................................................
Make TOC hideable
Currently, if an extension doesn't want a TOC, it has to remove it manually.
This change wraps the TOC in markers that make it easy to remove it in
ParserOutput
on demand without fragmenting the parser cache with stuff like "use/not use
TOC".
Change-Id: I2889bcb9eb999c9049601e92440132118e1a8a41
---
M includes/OutputPage.php
M includes/parser/Parser.php
M includes/parser/ParserOutput.php
M tests/parser/parserTest.inc
M tests/parser/parserTests.txt
M tests/phpunit/includes/parser/NewParserTest.php
6 files changed, 100 insertions(+), 6 deletions(-)
Approvals:
Subramanya Sastry: Looks good to me, but someone else must approve
Bartosz Dziewoński: Looks good to me, approved
jenkins-bot: Verified
diff --git a/includes/OutputPage.php b/includes/OutputPage.php
index cc3f9b3..ffaf77d 100644
--- a/includes/OutputPage.php
+++ b/includes/OutputPage.php
@@ -256,6 +256,11 @@
private $mTarget = null;
/**
+ * @var bool: Whether output should contain table of contents
+ */
+ private $mEnableTOC = true;
+
+ /**
* Constructor for OutputPage. This should not be called directly.
* Instead a new RequestContext should be created and it will
implicitly create
* a OutputPage tied to that context.
@@ -1606,6 +1611,7 @@
*/
function addParserOutput( &$parserOutput ) {
$this->addParserOutputNoText( $parserOutput );
+ $parserOutput->setTOCEnabled( $this->mEnableTOC );
$text = $parserOutput->getText();
wfRunHooks( 'OutputPageBeforeHTML', array( &$this, &$text ) );
$this->addHTML( $text );
@@ -3648,4 +3654,20 @@
return array();
}
+ /**
+ * Enables/disables TOC, doesn't override __NOTOC__
+ * @param bool $flag
+ * @since 1.22
+ */
+ public function enableTOC( $flag = true ) {
+ $this->mEnableTOC = $flag;
+ }
+
+ /**
+ * @return bool
+ * @since 1.22
+ */
+ public function isTOCEnabled() {
+ return $this->mEnableTOC;
+ }
}
diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php
index 221a630..7dbb202 100644
--- a/includes/parser/Parser.php
+++ b/includes/parser/Parser.php
@@ -115,6 +115,10 @@
# Marker Suffix needs to be accessible staticly.
const MARKER_SUFFIX = "-QINU\x7f";
+ # Markers used for wrapping the table of contents
+ const TOC_START = '<mw:toc>';
+ const TOC_END = '</mw:toc>';
+
# Persistent:
var $mTagHooks = array();
var $mTransparentTagHooks = array();
@@ -2466,7 +2470,7 @@
$openmatch = preg_match(
'/(?:<table|<h1|<h2|<h3|<h4|<h5|<h6|<pre|<tr|<p|<ul|<ol|<dl|<li|<\\/tr|<\\/td|<\\/th)/iS',
$t );
$closematch = preg_match(
'/(?:<\\/table|<\\/h1|<\\/h2|<\\/h3|<\\/h4|<\\/h5|<\\/h6|' .
-
'<td|<th|<\\/?blockquote|<\\/?div|<hr|<\\/pre|<\\/p|' . $this->mUniqPrefix .
'-pre|<\\/li|<\\/ul|<\\/ol|<\\/dl|<\\/?center)/iS', $t );
+
'<td|<th|<\\/?blockquote|<\\/?div|<hr|<\\/pre|<\\/p|<\\/mw:|' .
$this->mUniqPrefix . '-pre|<\\/li|<\\/ul|<\\/ol|<\\/dl|<\\/?center)/iS', $t );
if ( $openmatch or $closematch ) {
$paragraphStack = false;
# TODO bug 5718: paragraph closed
@@ -4520,6 +4524,7 @@
}
$toc = Linker::tocList( $toc,
$this->mOptions->getUserLangObj() );
$this->mOutput->setTOCHTML( $toc );
+ $toc = self::TOC_START . $toc . self::TOC_END;
}
if ( $isMain ) {
diff --git a/includes/parser/ParserOutput.php b/includes/parser/ParserOutput.php
index 9519de9..502f0fd 100644
--- a/includes/parser/ParserOutput.php
+++ b/includes/parser/ParserOutput.php
@@ -47,7 +47,8 @@
$mEditSectionTokens = false, # prefix/suffix markers if edit
sections were output as tokens
$mProperties = array(), # Name/value pairs to be cached
in the DB
$mTOCHTML = '', # HTML of the TOC
- $mTimestamp; # Timestamp of the revision
+ $mTimestamp, # Timestamp of the revision
+ $mTOCEnabled = true; # Whether TOC should be shown,
can't override __NOTOC__
private $mIndexPolicy = ''; # 'index' or 'noindex'? Any
other value will result in no change.
private $mAccessedOptions = array(); # List of ParserOptions
(stored in the keys)
private $mSecondaryDataUpdates = array(); # List of DataUpdate,
used to save info from the page somewhere else.
@@ -68,11 +69,27 @@
}
function getText() {
+ wfProfileIn( __METHOD__ );
+ $text = $this->mText;
if ( $this->mEditSectionTokens ) {
- return preg_replace_callback(
ParserOutput::EDITSECTION_REGEX,
- array( &$this,
'replaceEditSectionLinksCallback' ), $this->mText );
+ $text = preg_replace_callback(
ParserOutput::EDITSECTION_REGEX,
+ array( &$this,
'replaceEditSectionLinksCallback' ), $text );
+ } else {
+ $text = preg_replace( ParserOutput::EDITSECTION_REGEX,
'', $text );
}
- return preg_replace( ParserOutput::EDITSECTION_REGEX, '',
$this->mText );
+
+ // If you have an old cached version of this class - sorry, you
can't disable the TOC
+ if ( isset( $this->mTOCEnabled ) && $this->mTOCEnabled ) {
+ $text = str_replace( array( Parser::TOC_START,
Parser::TOC_END ), '', $text );
+ } else {
+ $text = preg_replace(
+ '#'. preg_quote( Parser::TOC_START ) . '.*?' .
preg_quote( Parser::TOC_END ) . '#s',
+ '',
+ $text
+ );
+ }
+ wfProfileOut( __METHOD__ );
+ return $text;
}
/**
@@ -123,6 +140,7 @@
function getTOCHTML() { return $this->mTOCHTML; }
function getTimestamp() { return $this->mTimestamp; }
function getLimitReportData() { return $this->mLimitReportData; }
+ function getTOCEnabled() { return $this->mTOCEnabled; }
function setText( $text ) { return wfSetVar( $this->mText,
$text ); }
function setLanguageLinks( $ll ) { return wfSetVar(
$this->mLanguageLinks, $ll ); }
@@ -134,6 +152,7 @@
function setIndexPolicy( $policy ) { return wfSetVar(
$this->mIndexPolicy, $policy ); }
function setTOCHTML( $tochtml ) { return wfSetVar(
$this->mTOCHTML, $tochtml ); }
function setTimestamp( $timestamp ) { return wfSetVar(
$this->mTimestamp, $timestamp ); }
+ function setTOCEnabled( $flag ) { return wfSetVar(
$this->mTOCEnabled, $flag ); }
function addCategory( $c, $sort ) { $this->mCategories[$c] = $sort; }
function addLanguageLink( $t ) { $this->mLanguageLinks[] = $t; }
diff --git a/tests/parser/parserTest.inc b/tests/parser/parserTest.inc
index 3f8d7f9..1fac2f5 100644
--- a/tests/parser/parserTest.inc
+++ b/tests/parser/parserTest.inc
@@ -494,6 +494,9 @@
/**
* Get a Parser object
+ *
+ * @param string $preprocessor
+ * @return Parser
*/
function getParser( $preprocessor = null ) {
global $wgParserConf;
@@ -566,6 +569,7 @@
$out = $parser->getPreloadText( $input, $title,
$options );
} else {
$output = $parser->parse( $input, $title, $options,
true, true, 1337 );
+ $output->setTOCEnabled( !isset( $opts['notoc'] ) );
$out = $output->getText();
if ( isset( $opts['showtitle'] ) ) {
@@ -618,7 +622,7 @@
/**
* Use a regex to find out the value of an option
* @param $key String: name of option val to retrieve
- * @param $opts Options array to look in
+ * @param $opts array: Options array to look in
* @param $default Mixed: default value returned if not found
*/
private static function getOptionValue( $key, $opts, $default ) {
diff --git a/tests/parser/parserTests.txt b/tests/parser/parserTests.txt
index 3266b16..8c1ad6c 100644
--- a/tests/parser/parserTests.txt
+++ b/tests/parser/parserTests.txt
@@ -26,6 +26,7 @@
# showtitle make the first line the title
# comment run through Linker::formatComment() instead of main parser
# local format section links in edit comment text as local links
+# notoc disable table of contents
#
# You can also set the following parser properties via test options:
# wgEnableUploads, wgAllowExternalImages, wgMaxTocLevel,
@@ -10103,6 +10104,7 @@
</li>
</ul>
</div>
+
<h2><span class="mw-headline" id="Headline_1">Headline 1</span><span
class="mw-editsection"><span class="mw-editsection-bracket">[</span><a
href="/index.php?title=Parser_test&action=edit&section=1" title="Edit
section: Headline 1">edit</a><span
class="mw-editsection-bracket">]</span></span></h2>
<h3><span class="mw-headline" id="Subheadline_1">Subheadline 1</span><span
class="mw-editsection"><span class="mw-editsection-bracket">[</span><a
href="/index.php?title=Parser_test&action=edit&section=2" title="Edit
section: Subheadline 1">edit</a><span
class="mw-editsection-bracket">]</span></span></h3>
<h5><span class="mw-headline" id="Skipping_a_level">Skipping a
level</span><span class="mw-editsection"><span
class="mw-editsection-bracket">[</span><a
href="/index.php?title=Parser_test&action=edit&section=3" title="Edit
section: Skipping a level">edit</a><span
class="mw-editsection-bracket">]</span></span></h5>
@@ -10158,6 +10160,7 @@
</li>
</ul>
</div>
+
<h1><span class="mw-headline" id="Level_1_Heading">Level 1 Heading</span><span
class="mw-editsection"><span class="mw-editsection-bracket">[</span><a
href="/index.php?title=Parser_test&action=edit&section=1" title="Edit
section: Level 1 Heading">edit</a><span
class="mw-editsection-bracket">]</span></span></h1>
<h2><span class="mw-headline" id="Level_2_Heading">Level 2 Heading</span><span
class="mw-editsection"><span class="mw-editsection-bracket">[</span><a
href="/index.php?title=Parser_test&action=edit&section=2" title="Edit
section: Level 2 Heading">edit</a><span
class="mw-editsection-bracket">]</span></span></h2>
<h3><span class="mw-headline" id="Level_3_Heading">Level 3 Heading</span><span
class="mw-editsection"><span class="mw-editsection-bracket">[</span><a
href="/index.php?title=Parser_test&action=edit&section=3" title="Edit
section: Level 3 Heading">edit</a><span
class="mw-editsection-bracket">]</span></span></h3>
@@ -10200,6 +10203,7 @@
</li>
</ul>
</div>
+
<h2><span class="mw-headline" id="title_1">title 1</span><span
class="mw-editsection"><span class="mw-editsection-bracket">[</span><a
href="/index.php?title=Parser_test&action=edit&section=1" title="Edit
section: title 1">edit</a><span
class="mw-editsection-bracket">]</span></span></h2>
<h3><span class="mw-headline" id="title_1.1">title 1.1</span><span
class="mw-editsection"><span class="mw-editsection-bracket">[</span><a
href="/index.php?title=Parser_test&action=edit&section=2" title="Edit
section: title 1.1">edit</a><span
class="mw-editsection-bracket">]</span></span></h3>
<h4><span class="mw-headline" id="title_1.1.1">title 1.1.1</span><span
class="mw-editsection"><span class="mw-editsection-bracket">[</span><a
href="/index.php?title=Parser_test&action=edit&section=3" title="Edit
section: title 1.1.1">edit</a><span
class="mw-editsection-bracket">]</span></span></h4>
@@ -10236,6 +10240,7 @@
</li>
</ul>
</div>
+
<h2><span class="mw-headline" id="title_1">title 1</span><span
class="mw-editsection"><span class="mw-editsection-bracket">[</span><a
href="/index.php?title=Parser_test&action=edit&section=1" title="Edit
section: title 1">edit</a><span
class="mw-editsection-bracket">]</span></span></h2>
<h3><span class="mw-headline" id="title_1.1">title 1.1</span><span
class="mw-editsection"><span class="mw-editsection-bracket">[</span><a
href="/index.php?title=Parser_test&action=edit&section=2" title="Edit
section: title 1.1">edit</a><span
class="mw-editsection-bracket">]</span></span></h3>
<h4><span class="mw-headline" id="title_1.1.1">title 1.1.1</span><span
class="mw-editsection"><span class="mw-editsection-bracket">[</span><a
href="/index.php?title=Parser_test&action=edit&section=3" title="Edit
section: title 1.1.1">edit</a><span
class="mw-editsection-bracket">]</span></span></h4>
@@ -10266,6 +10271,7 @@
<li class="toclevel-1 tocsection-5"><a href="#Section_2"><span
class="tocnumber">2</span> <span class="toctext">Section 2</span></a></li>
</ul>
</div>
+
<h2><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=Parser_test&action=edit&section=1" title="Edit
section: Section 1">edit</a><span
class="mw-editsection-bracket">]</span></span></h2>
<h3><span class="mw-headline" id="Section_1.1">Section 1.1</span><span
class="mw-editsection"><span class="mw-editsection-bracket">[</span><a
href="/index.php?title=Parser_test&action=edit&section=2" title="Edit
section: Section 1.1">edit</a><span
class="mw-editsection-bracket">]</span></span></h3>
<h4><span class="mw-headline" id="Section_1.1.1">Section 1.1.1</span><span
class="mw-editsection"><span class="mw-editsection-bracket">[</span><a
href="/index.php?title=Parser_test&action=edit&section=3" title="Edit
section: Section 1.1.1">edit</a><span
class="mw-editsection-bracket">]</span></span></h4>
@@ -10358,6 +10364,7 @@
<li class="toclevel-1 tocsection-3"><a href="#title_2"><span
class="tocnumber">2</span> <span class="toctext">title 2</span></a></li>
</ul>
</div>
+
<h2><span class="mw-headline" id="title_1">title 1</span><span
class="mw-editsection"><span class="mw-editsection-bracket">[</span><a
href="/index.php?title=Parser_test&action=edit&section=1" title="Edit
section: title 1">edit</a><span
class="mw-editsection-bracket">]</span></span></h2>
<h3><span class="mw-headline" id="title_1.1">title 1.1</span><span
class="mw-editsection"><span class="mw-editsection-bracket">[</span><a
href="/index.php?title=Parser_test&action=edit&section=2" title="Edit
section: title 1.1">edit</a><span
class="mw-editsection-bracket">]</span></span></h3>
<h2><span class="mw-headline" id="title_2">title 2</span><span
class="mw-editsection"><span class="mw-editsection-bracket">[</span><a
href="/index.php?title=Parser_test&action=edit&section=3" title="Edit
section: title 2">edit</a><span
class="mw-editsection-bracket">]</span></span></h2>
@@ -10421,6 +10428,7 @@
<li class="toclevel-1 tocsection-5"><a href="#text_.22_text"><span
class="tocnumber">5</span> <span class="toctext">text " text</span></a></li>
</ul>
</div>
+
<h2><span class="mw-headline" id="text_.3E_text">text > text</span><span
class="mw-editsection"><span class="mw-editsection-bracket">[</span><a
href="/index.php?title=Parser_test&action=edit&section=1" title="Edit
section: text > text">edit</a><span
class="mw-editsection-bracket">]</span></span></h2>
<p>section 1
</p>
@@ -10455,6 +10463,7 @@
<li class="toclevel-1 tocsection-4"><a href="#.3Ditalic_heading"><span
class="tocnumber">4</span> <span class="toctext">=<i>italic</i>
heading</span></a></li>
</ul>
</div>
+
<h1><span class="mw-headline" id="foo.3D">foo=</span><span
class="mw-editsection"><span class="mw-editsection-bracket">[</span><a
href="/index.php?title=Parser_test&action=edit&section=1" title="Edit
section: foo=">edit</a><span class="mw-editsection-bracket">]</span></span></h1>
<h1><span class="mw-headline" id=".3Dfoo">=foo</span><span
class="mw-editsection"><span class="mw-editsection-bracket">[</span><a
href="/index.php?title=Parser_test&action=edit&section=2" title="Edit
section: =foo">edit</a><span class="mw-editsection-bracket">]</span></span></h1>
<h1><span class="mw-headline" id="italic_heading.3D"><i>italic</i>
heading=</span><span class="mw-editsection"><span
class="mw-editsection-bracket">[</span><a
href="/index.php?title=Parser_test&action=edit&section=3" title="Edit
section: italic heading=">edit</a><span
class="mw-editsection-bracket">]</span></span></h1>
@@ -10492,6 +10501,7 @@
</li>
</ul>
</div>
+
<h1><span class="mw-headline" id="Header_1">Header 1</span></h1>
<h2><span class="mw-headline" id="Header_1.1">Header 1.1</span></h2>
<h2><span class="mw-headline" id="Header_1.2">Header 1.2</span></h2>
@@ -11865,6 +11875,7 @@
<li class="toclevel-1 tocsection-1"><a href="#onmouseover.3D"><span
class="tocnumber">1</span> <span class="toctext">onmouseover=</span></a></li>
</ul>
</div>
+
!! end
@@ -13749,6 +13760,7 @@
</li>
</ul>
</div>
+
<h2><span class="mw-headline" id="2">2</span><span
class="mw-editsection"><span class="mw-editsection-bracket">[</span><a
href="/index.php?title=Parser_test&action=edit&section=1" title="Edit
section: 2">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<h6><span class="mw-headline" id="6">6</span><span
class="mw-editsection"><span class="mw-editsection-bracket">[</span><a
href="/index.php?title=Parser_test&action=edit&section=2" title="Edit
section: 6">edit</a><span class="mw-editsection-bracket">]</span></span></h6>
<h3><span class="mw-headline" id="3">3</span><span
class="mw-editsection"><span class="mw-editsection-bracket">[</span><a
href="/index.php?title=Parser_test&action=edit&section=3" title="Edit
section: 3">edit</a><span class="mw-editsection-bracket">]</span></span></h3>
@@ -15315,6 +15327,7 @@
<li class="toclevel-1 tocsection-1"><a href="#Lost_episodes"><span
class="tocnumber">1</span> <span class="toctext"><i>Lost</i>
episodes</span></a></li>
</ul>
</div>
+
<h2><span class="mw-headline" id="Lost_episodes"><i>Lost</i>
episodes</span><span class="mw-editsection"><span
class="mw-editsection-bracket">[</span><a
href="/index.php?title=Main_Page&action=edit&section=1" title="Edit
section: Lost episodes">edit</a><span
class="mw-editsection-bracket">]</span></span></h2>
!! end
@@ -15332,6 +15345,7 @@
<li class="toclevel-1 tocsection-1"><a
href="#should_be_bold_then_normal_text"><span class="tocnumber">1</span> <span
class="toctext"><b>should be bold</b> then normal text</span></a></li>
</ul>
</div>
+
<h2><span class="mw-headline" id="should_be_bold_then_normal_text"><b>should
be bold</b> then normal text</span><span class="mw-editsection"><span
class="mw-editsection-bracket">[</span><a
href="/index.php?title=Main_Page&action=edit&section=1" title="Edit
section: should be bold then normal text">edit</a><span
class="mw-editsection-bracket">]</span></span></h2>
!! end
@@ -15349,6 +15363,7 @@
<li class="toclevel-1 tocsection-1"><a href="#Image"><span
class="tocnumber">1</span> <span class="toctext">Image</span></a></li>
</ul>
</div>
+
<h2><span class="mw-headline" id="Image">Image <a href="/wiki/File:Foobar.jpg"
class="image"><img alt="Foobar.jpg"
src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220"
/></a></span><span class="mw-editsection"><span
class="mw-editsection-bracket">[</span><a
href="/index.php?title=Main_Page&action=edit&section=1" title="Edit
section: Image">edit</a><span
class="mw-editsection-bracket">]</span></span></h2>
!! end
@@ -15366,6 +15381,7 @@
<li class="toclevel-1 tocsection-1"><a href="#Quote"><span
class="tocnumber">1</span> <span class="toctext">Quote</span></a></li>
</ul>
</div>
+
<h2><span class="mw-headline"
id="Quote"><blockquote>Quote</blockquote></span><span
class="mw-editsection"><span class="mw-editsection-bracket">[</span><a
href="/index.php?title=Main_Page&action=edit&section=1" title="Edit
section: Quote">edit</a><span
class="mw-editsection-bracket">]</span></span></h2>
!! end
@@ -15385,6 +15401,7 @@
<li class="toclevel-1 tocsection-1"><a href="#Proof:_2_.3C_3"><span
class="tocnumber">1</span> <span class="toctext">Proof: 2 < 3</span></a></li>
</ul>
</div>
+
<h2><span class="mw-headline" id="Proof:_2_.3C_3">Proof: 2 < 3</span><span
class="mw-editsection"><span class="mw-editsection-bracket">[</span><a
href="/index.php?title=Main_Page&action=edit&section=1" title="Edit
section: Proof: 2 < 3">edit</a><span
class="mw-editsection-bracket">]</span></span></h2>
<p><small>Hanc marginis exiguitas non caperet.</small>
QED
@@ -15405,6 +15422,7 @@
<li class="toclevel-1 tocsection-2"><a href="#Foo_Bar_2"><span
class="tocnumber">2</span> <span class="toctext"><i>Foo</i> Bar</span></a></li>
</ul>
</div>
+
<h2><span class="mw-headline" id="Foo_Bar"><i>Foo</i> <b>Bar</b></span><span
class="mw-editsection"><span class="mw-editsection-bracket">[</span><a
href="/index.php?title=Parser_test&action=edit&section=1" title="Edit
section: Foo Bar">edit</a><span
class="mw-editsection-bracket">]</span></span></h2>
<h2><span class="mw-headline" id="Foo_Bar_2"><i>Foo</i>
<blockquote>Bar</blockquote></span><span class="mw-editsection"><span
class="mw-editsection-bracket">[</span><a
href="/index.php?title=Parser_test&action=edit&section=2" title="Edit
section: Foo Bar">edit</a><span
class="mw-editsection-bracket">]</span></span></h2>
@@ -15424,6 +15442,7 @@
<li class="toclevel-1 tocsection-2"><a href="#b.22.3EEvilbye"><span
class="tocnumber">2</span> <span class="toctext"><sup>
b">Evilbye</sup></span></a></li>
</ul>
</div>
+
<h2><span class="mw-headline" id="Hello"><sup
class="in-h2">Hello</sup></span><span class="mw-editsection"><span
class="mw-editsection-bracket">[</span><a
href="/index.php?title=Parser_test&action=edit&section=1" title="Edit
section: Hello">edit</a><span
class="mw-editsection-bracket">]</span></span></h2>
<h2><span class="mw-headline" id="b.22.3EEvilbye"><sup>
b">Evilbye</sup></span><span class="mw-editsection"><span
class="mw-editsection-bracket">[</span><a
href="/index.php?title=Parser_test&action=edit&section=2" title="Edit
section: b">Evilbye">edit</a><span
class="mw-editsection-bracket">]</span></span></h2>
@@ -15452,6 +15471,7 @@
<li class="toclevel-1 tocsection-5"><a
href="#Attributes_after_dir_on_these_span_tags_must_be_deleted_from_the_TOC"><span
class="tocnumber">5</span> <span class="toctext"><span dir="ltr">Attributes
after dir on these span tags must be deleted from the TOC</span></span></a></li>
</ul>
</div>
+
<h2><span class="mw-headline" id="C.2B.2B"><span
dir="ltr">C++</span></span><span class="mw-editsection"><span
class="mw-editsection-bracket">[</span><a
href="/index.php?title=Parser_test&action=edit&section=1" title="Edit
section: C++">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<h2><span class="mw-headline" id=".D7.96.D7.91.D7.A0.D7.92.21"><span
dir="rtl">זבנג!</span></span><span class="mw-editsection"><span
class="mw-editsection-bracket">[</span><a
href="/index.php?title=Parser_test&action=edit&section=2" title="Edit
section: זבנג!">edit</a><span
class="mw-editsection-bracket">]</span></span></h2>
<h2><span class="mw-headline"
id="The_attributes_on_these_span_tags_must_be_deleted_from_the_TOC"><span
style="font-style: italic">The attributes on these span tags must be deleted
from the TOC</span></span><span class="mw-editsection"><span
class="mw-editsection-bracket">[</span><a
href="/index.php?title=Parser_test&action=edit&section=3" title="Edit
section: The attributes on these span tags must be deleted from the
TOC">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
@@ -15741,6 +15761,29 @@
</p>
!! end
+!!test
+Disable TOC
+!! options
+notoc
+!! input
+Lead
+== Section 1 ==
+== Section 2 ==
+== Section 3 ==
+== Section 4 ==
+== Section 5 ==
+!! result
+<p>Lead
+</p>
+
+<h2><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=Parser_test&action=edit&section=1" title="Edit
section: Section 1">edit</a><span
class="mw-editsection-bracket">]</span></span></h2>
+<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=Parser_test&action=edit&section=2" title="Edit
section: Section 2">edit</a><span
class="mw-editsection-bracket">]</span></span></h2>
+<h2><span class="mw-headline" id="Section_3">Section 3</span><span
class="mw-editsection"><span class="mw-editsection-bracket">[</span><a
href="/index.php?title=Parser_test&action=edit&section=3" title="Edit
section: Section 3">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&action=edit&section=4" title="Edit
section: Section 4">edit</a><span
class="mw-editsection-bracket">]</span></span></h2>
+<h2><span class="mw-headline" id="Section_5">Section 5</span><span
class="mw-editsection"><span class="mw-editsection-bracket">[</span><a
href="/index.php?title=Parser_test&action=edit&section=5" title="Edit
section: Section 5">edit</a><span
class="mw-editsection-bracket">]</span></span></h2>
+
+!! end
+
###
### Parsoids-specific tests
diff --git a/tests/phpunit/includes/parser/NewParserTest.php
b/tests/phpunit/includes/parser/NewParserTest.php
index ab8e77b..dc1cb0d 100644
--- a/tests/phpunit/includes/parser/NewParserTest.php
+++ b/tests/phpunit/includes/parser/NewParserTest.php
@@ -629,6 +629,7 @@
$out = $parser->getPreloadText( $input, $title,
$options );
} else {
$output = $parser->parse( $input, $title, $options,
true, true, 1337 );
+ $output->setTOCEnabled( !isset( $opts['notoc'] ) );
$out = $output->getText();
if ( isset( $opts['showtitle'] ) ) {
--
To view, visit https://gerrit.wikimedia.org/r/80578
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I2889bcb9eb999c9049601e92440132118e1a8a41
Gerrit-PatchSet: 9
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: MaxSem <[email protected]>
Gerrit-Reviewer: Bartosz Dziewoński <[email protected]>
Gerrit-Reviewer: Chad <[email protected]>
Gerrit-Reviewer: Daniel Friesen <[email protected]>
Gerrit-Reviewer: GWicke <[email protected]>
Gerrit-Reviewer: Kaldari <[email protected]>
Gerrit-Reviewer: Manybubbles <[email protected]>
Gerrit-Reviewer: MaxSem <[email protected]>
Gerrit-Reviewer: Subramanya Sastry <[email protected]>
Gerrit-Reviewer: Tim Starling <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits