r68491 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r68490‎ | r68491 | r68492 >
Date:23:29, 23 June 2010
Author:platonides
Status:ok (Comments)
Tags:
Comment:
Disable pretty italics inside links. Now the italics inside a link alternate text will be handled on its own scope but if they come from the page title, they won't be parsed at all. This is a middle way solution to bug 4598. Now all bug 4598 tests pass.

Pretty italics mean that italics go across links: ''Some [[Link|pretty ''italics'' and stuff]]! -> ''Some [[Link|pretty ''italics'' and stuff]]! -> <i>Some <a>pretty <i>italics</i> and stuff</a>!</i>

This also fixes bug 24093, where interface messages saying '''[[$1]]''' has been deleted/renamed/links here were being bitten by this feature.

The best resolution would be to make pretty italics still work inside alternates, feel free to do so, but doesn't seem worth at this point. The right solution should be to rewrite the quotes handling so it takes its scope into account.
Modified paths:
  • /trunk/phase3/includes/Linker.php (modified) (history)
  • /trunk/phase3/includes/parser/Parser.php (modified) (history)
  • /trunk/phase3/maintenance/parserTests.txt (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/parserTests.txt
@@ -1462,12 +1462,10 @@
14631463
14641464 !! test
14651465 Link containing double-single-quotes '' (bug 4598)
1466 -!! options
1467 -disabled
14681466 !! input
14691467 [[Lista d''e paise d''o munno]]
14701468 !! result
1471 -<p><a href="https://www.mediawiki.org/index.php?title=Lista_d%27%27e_paise_d%27%27o_munno&amp;action=edit" class="new" title="Lista d''e paise d''o munno">Lista d''e paise d''o munno</a>
 1469+<p><a href="https://www.mediawiki.org/index.php?title=Lista_d%27%27e_paise_d%27%27o_munno&amp;action=edit&amp;redlink=1" class="new" title="Lista d''e paise d''o munno (page does not exist)">Lista d''e paise d''o munno</a>
14721470 </p>
14731471 !! end
14741472
@@ -1485,11 +1483,29 @@
14861484 !! input
14871485 ''Some [[Link|pretty ''italics'' and stuff]]!
14881486 !! result
1489 -<p><i>Some </i><a href="https://www.mediawiki.org/index.php?title=Link&amp;action=edit&amp;redlink=1" class="new" title="Link (page does not exist)"><i>pretty </i>italics<i> and stuff</i></a><i>!</i>
 1487+<p><i>Some <a href="https://www.mediawiki.org/index.php?title=Link&amp;action=edit&amp;redlink=1" class="new" title="Link (page does not exist)">pretty <i>italics</i> and stuff</a>!</i>
14901488 </p>
14911489 !! end
14921490
14931491 !! test
 1492+Link with double quotes in title part (literal) and alternate part (interpreted)
 1493+!! input
 1494+[[File:Denys Savchenko ''Pentecoste''.jpg]]
 1495+
 1496+[[''Pentecoste'']]
 1497+
 1498+[[''Pentecoste''|Pentecoste]]
 1499+
 1500+[[''Pentecoste''|''Pentecoste'']]
 1501+!! result
 1502+<p><a href="https://www.mediawiki.org/index.php?title=Special:Upload&amp;wpDestFile=Denys_Savchenko_%27%27Pentecoste%27%27.jpg" class="new" title="File:Denys Savchenko &#39;&#39;Pentecoste&#39;&#39;.jpg">File:Denys Savchenko <i>Pentecoste</i>.jpg</a>
 1503+</p><p><a href="https://www.mediawiki.org/index.php?title=%27%27Pentecoste%27%27&amp;action=edit&amp;redlink=1" class="new" title="''Pentecoste'' (page does not exist)">''Pentecoste''</a>
 1504+</p><p><a href="https://www.mediawiki.org/index.php?title=%27%27Pentecoste%27%27&amp;action=edit&amp;redlink=1" class="new" title="''Pentecoste'' (page does not exist)">Pentecoste</a>
 1505+</p><p><a href="https://www.mediawiki.org/index.php?title=%27%27Pentecoste%27%27&amp;action=edit&amp;redlink=1" class="new" title="''Pentecoste'' (page does not exist)"><i>Pentecoste</i></a>
 1506+</p>
 1507+!! end
 1508+
 1509+!! test
14941510 Plain link to URL
14951511 !! input
14961512 [[http://www.example.com]]
Index: trunk/phase3/includes/parser/Parser.php
@@ -1072,9 +1072,9 @@
10731073 $df = DateFormatter::getInstance();
10741074 $text = $df->reformat( $this->mOptions->getDateFormat(), $text );
10751075 }
1076 - $text = $this->doAllQuotes( $text );
10771076 $text = $this->replaceInternalLinks( $text );
10781077 $text = $this->replaceExternalLinks( $text );
 1078+ $text = $this->doAllQuotes( $text );
10791079
10801080 # replaceInternalLinks may sometimes leave behind
10811081 # absolute URLs, which have to be masked to hide them from replaceExternalLinks
@@ -1841,6 +1841,11 @@
18421842 $wasblank = ( $text == '' );
18431843 if ( $wasblank ) {
18441844 $text = $link;
 1845+ } else {
 1846+ # Bug 4598 madness. Handle the quotes only if they come from the alternate part
 1847+ # [[Lista d''e paise d''o munno]] -> <a href="">Lista d''e paise d''o munno</a>
 1848+ # [[Criticism of Harry Potter|Criticism of ''Harry Potter'']] -> <a href="Criticism of Harry Potter">Criticism of <i>Harry Potter</i></a>
 1849+ $text = $this->doQuotes($text);
18451850 }
18461851
18471852 # Link not escaped by : , create the various objects
Index: trunk/phase3/includes/Linker.php
@@ -693,11 +693,9 @@
694694 list( $inside, $trail ) = self::splitTrail( $trail );
695695
696696 wfProfileOut( __METHOD__ );
697 - return Html::element( 'a', array(
698 - 'href' => $href,
699 - 'class' => 'new',
700 - 'title' => $title->getPrefixedText()
701 - ), $prefix . $text . $inside ) . $trail;
 697+ return '<a href="' . htmlspecialchars( $href ) . '" class="new" title="' .
 698+ htmlspecialchars( $title->getPrefixedText(), ENT_QUOTES ) . '">' .
 699+ htmlspecialchars( $prefix . $text . $inside, ENT_NOQUOTES ) . '</a>' . $trail;
702700 } else {
703701 wfProfileOut( __METHOD__ );
704702 return $this->makeKnownLinkObj( $title, $text, $query, $trail, $prefix );
@@ -751,7 +749,7 @@
752750 $url = $this->getUploadUrl( $title );
753751 $class = 'new';
754752 }
755 - $alt = htmlspecialchars( $title->getText() );
 753+ $alt = htmlspecialchars( $title->getText(), ENT_QUOTES );
756754 if( $text == '' ) {
757755 $text = $alt;
758756 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r68515Follow up r68491....platonides13:44, 24 June 2010
r78360Fixed comments and indenting style from r68491.tstarling09:01, 14 December 2010

Comments

#Comment by Nikerabbit (talk | contribs)   05:54, 24 June 2010

But we still can't remove the ugly wfEscapeWikiText hack for params passed to messages?

+# Lista d''e paise d''o munno -> <a href="">Lista de paise do munno</a>

Surely there should be a target also?

#Comment by Hashar (talk | contribs)   22:52, 6 November 2010

You are my hero!

#Comment by Tim Starling (talk | contribs)   08:57, 14 December 2010

What is with the ENT_NOQUOTES/ENT_QUOTES stuff? Is it just to make the parser tests work?

#Comment by Platonides (talk | contribs)   16:57, 14 December 2010

That Linker.php code is inside of makeMediaLinkObj/makeBrokenImageLinkObj. Converting ' into &#39; with ENT_QUOTES avoids doAllQuotes() to change literal ' inside of alt/title text into <i> </i> (having htmlesque titles is legal, but not what we expect. We want to show the quotes in the title).

Status & tagging log