r109682 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r109681‎ | r109682 | r109683 >
Date:16:27, 21 January 2012
Author:platonides
Status:ok
Tags:
Comment:
Bug 33845: Headings become cursive in TOC when they contain an image
Fixes the problems with r102179 and r102179, as there are
valid tags which begin the same, which meant they were not removed from
the TOC (the second regex, intended to remove tag parameters, then converted
<img or <blockquote> into <i> / <b>).
The same problem existed in the original regex, but as there are no valid
tags which begin with sup or sub, it never happened).

Added comment explaining the tocline regex, and added a bunch of parser tests.
Modified paths:
  • /trunk/phase3/includes/parser/Parser.php (modified) (history)
  • /trunk/phase3/tests/parser/parserTests.txt (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/parser/parserTests.txt
@@ -8976,6 +8976,99 @@
89778977
89788978 !! end
89798979
 8980+!! test
 8981+Bug 33845: Headings become cursive in TOC when they contain an image
 8982+!! options
 8983+title=[[Main Page]]
 8984+!! input
 8985+__TOC__
 8986+== Image [[Image:foobar.jpg]] ==
 8987+!! result
 8988+<table id="toc" class="toc"><tr><td><div id="toctitle"><h2>Contents</h2></div>
 8989+<ul>
 8990+<li class="toclevel-1 tocsection-1"><a href="#Image"><span class="tocnumber">1</span> <span class="toctext">Image</span></a></li>
 8991+</ul>
 8992+</td></tr></table>
 8993+<h2><span class="editsection">[<a href="https://www.mediawiki.org/index.php?title=Main_Page&amp;action=edit&amp;section=1" title="Edit section: Image">edit</a>]</span> <span class="mw-headline" id="Image"> Image <a href="https://www.mediawiki.org/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></h2>
 8994+
 8995+!! end
 8996+
 8997+!! test
 8998+Bug 33845 (2): Headings become bold in TOC when they contain a blockquote
 8999+!! options
 9000+title=[[Main Page]]
 9001+!! input
 9002+__TOC__
 9003+== <blockquote>Quote</blockquote> ==
 9004+!! result
 9005+<table id="toc" class="toc"><tr><td><div id="toctitle"><h2>Contents</h2></div>
 9006+<ul>
 9007+<li class="toclevel-1 tocsection-1"><a href="#Quote"><span class="tocnumber">1</span> <span class="toctext">Quote</span></a></li>
 9008+</ul>
 9009+</td></tr></table>
 9010+<h2><span class="editsection">[<a href="https://www.mediawiki.org/index.php?title=Main_Page&amp;action=edit&amp;section=1" title="Edit section: Quote">edit</a>]</span> <span class="mw-headline" id="Quote"> <blockquote>Quote</blockquote> </span></h2>
 9011+
 9012+!! end
 9013+
 9014+!! test
 9015+Unclosed tags in TOC
 9016+!! options
 9017+title=[[Main Page]]
 9018+!! input
 9019+__TOC__
 9020+== Proof: 2 < 3 ==
 9021+<small>Hanc marginis exiguitas non caperet.</small>
 9022+QED
 9023+!! result
 9024+<table id="toc" class="toc"><tr><td><div id="toctitle"><h2>Contents</h2></div>
 9025+<ul>
 9026+<li class="toclevel-1 tocsection-1"><a href="#Proof:_2_.3C_3"><span class="tocnumber">1</span> <span class="toctext">Proof: 2 &lt; 3</span></a></li>
 9027+</ul>
 9028+</td></tr></table>
 9029+<h2><span class="editsection">[<a href="https://www.mediawiki.org/index.php?title=Main_Page&amp;action=edit&amp;section=1" title="Edit section: Proof: 2 &lt; 3">edit</a>]</span> <span class="mw-headline" id="Proof:_2_.3C_3"> Proof: 2 &lt; 3 </span></h2>
 9030+<p><small>Hanc marginis exiguitas non caperet.</small>
 9031+QED
 9032+</p>
 9033+!! end
 9034+
 9035+!! test
 9036+Multiple tags in TOC
 9037+!! input
 9038+__TOC__
 9039+== <i>Foo</i> <b>Bar</b> ==
 9040+
 9041+== <i>Foo</i> <blockquote>Bar</blockquote> ==
 9042+!! result
 9043+<table id="toc" class="toc"><tr><td><div id="toctitle"><h2>Contents</h2></div>
 9044+<ul>
 9045+<li class="toclevel-1 tocsection-1"><a href="#Foo_Bar"><span class="tocnumber">1</span> <span class="toctext"><i>Foo</i> <b>Bar</b></span></a></li>
 9046+<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>
 9047+</ul>
 9048+</td></tr></table>
 9049+<h2><span class="editsection">[<a href="https://www.mediawiki.org/index.php?title=Parser_test&amp;action=edit&amp;section=1" title="Edit section: Foo Bar">edit</a>]</span> <span class="mw-headline" id="Foo_Bar"> <i>Foo</i> <b>Bar</b> </span></h2>
 9050+<h2><span class="editsection">[<a href="https://www.mediawiki.org/index.php?title=Parser_test&amp;action=edit&amp;section=2" title="Edit section: Foo Bar">edit</a>]</span> <span class="mw-headline" id="Foo_Bar_2"> <i>Foo</i> <blockquote>Bar</blockquote> </span></h2>
 9051+
 9052+!! end
 9053+
 9054+!! test
 9055+Tags with parameters in TOC
 9056+!! input
 9057+__TOC__
 9058+== <sup class="in-h2">Hello</sup> ==
 9059+
 9060+== <sup class="a > b">Evilbye</sup> ==
 9061+!! result
 9062+<table id="toc" class="toc"><tr><td><div id="toctitle"><h2>Contents</h2></div>
 9063+<ul>
 9064+<li class="toclevel-1 tocsection-1"><a href="#Hello"><span class="tocnumber">1</span> <span class="toctext"><sup>Hello</sup></span></a></li>
 9065+<li class="toclevel-1 tocsection-2"><a href="#b.22.3EEvilbye"><span class="tocnumber">2</span> <span class="toctext"><sup> b"&gt;Evilbye</sup></span></a></li>
 9066+</ul>
 9067+</td></tr></table>
 9068+<h2><span class="editsection">[<a href="https://www.mediawiki.org/index.php?title=Parser_test&amp;action=edit&amp;section=1" title="Edit section: Hello">edit</a>]</span> <span class="mw-headline" id="Hello"> <sup class="in-h2">Hello</sup> </span></h2>
 9069+<h2><span class="editsection">[<a href="https://www.mediawiki.org/index.php?title=Parser_test&amp;action=edit&amp;section=2" title="Edit section: b&quot;>Evilbye">edit</a>]</span> <span class="mw-headline" id="b.22.3EEvilbye"> <sup> b"&gt;Evilbye</sup> </span></h2>
 9070+
 9071+!! end
 9072+
89809073 !! article
89819074 MediaWiki:Bug32057
89829075 !! text
Index: trunk/phase3/includes/parser/Parser.php
@@ -4048,9 +4048,11 @@
40494049 # link text with suffix
40504050 $safeHeadline = $this->replaceLinkHoldersText( $safeHeadline );
40514051
4052 - # Strip out HTML (other than plain <sup> and <sub>: bug 8393, or <i>: bug 26375)
 4052+ # Strip out HTML (first regex removes any tag not allowed)
 4053+ # Allowed tags are <sup> and <sub> (bug 8393), <i> (bug 26375) and <b> (r105284)
 4054+ # We strip any parameter from accepted tags (second regex)
40534055 $tocline = preg_replace(
4054 - array( '#<(?!/?(sup|sub|i|b)).*?'.'>#', '#<(/?(sup|sub|i|b)).*?'.'>#' ),
 4056+ array( '#<(?!/?(sup|sub|i|b)(?: [^>]*)?>).*?'.'>#', '#<(/?(sup|sub|i|b))(?: .*?)?'.'>#' ),
40554057 array( '', '<$1>' ),
40564058 $safeHeadline
40574059 );

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r102179Bug 26375 - Italics should be passed to TOC...platonides15:07, 6 November 2011

Status & tagging log