r26409 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r26408‎ | r26409 | r26410 >
Date:18:59, 4 October 2007
Author:brion
Status:old
Tags:
Comment:
* (bug 11560) Fix broken HTML output from weird link nesting in edit comments.
Nested links (as in image caption text) still don't work _right_ but they're
less wrong.

Linker::formatComment() used a multi-pass run without proper protections,
making it possible for a later 'link' to erase a previous pass's start
or end tag. Switched to a single-pass run with preg_replace_callback which
avoids this.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/Linker.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Linker.php
@@ -988,42 +988,49 @@
989989 * Formats wiki links and media links in text; all other wiki formatting
990990 * is ignored
991991 *
 992+ * @fixme doesn't handle sub-links as in image thumb texts like the main parser
992993 * @param string $comment Text to format links in
993994 * @return string
994995 */
995996 public function formatLinksInComment( $comment ) {
 997+ return preg_replace_callback(
 998+ '/\[\[:?(.*?)(\|(.*?))*\]\]([^[]*)/',
 999+ array( $this, 'formatLinksInCommentCallback' ),
 1000+ $comment );
 1001+ }
 1002+
 1003+ protected function formatLinksInCommentCallback( $match ) {
9961004 global $wgContLang;
9971005
9981006 $medians = '(?:' . preg_quote( Namespace::getCanonicalName( NS_MEDIA ), '/' ) . '|';
9991007 $medians .= preg_quote( $wgContLang->getNsText( NS_MEDIA ), '/' ) . '):';
 1008+
 1009+ $comment = $match[0];
10001010
1001 - $match = array();
1002 - while(preg_match('/\[\[:?(.*?)(\|(.*?))*\]\](.*)$/',$comment,$match)) {
1003 - # Handle link renaming [[foo|text]] will show link as "text"
1004 - if( "" != $match[3] ) {
1005 - $text = $match[3];
 1011+ # Handle link renaming [[foo|text]] will show link as "text"
 1012+ if( "" != $match[3] ) {
 1013+ $text = $match[3];
 1014+ } else {
 1015+ $text = $match[1];
 1016+ }
 1017+ $submatch = array();
 1018+ if( preg_match( '/^' . $medians . '(.*)$/i', $match[1], $submatch ) ) {
 1019+ # Media link; trail not supported.
 1020+ $linkRegexp = '/\[\[(.*?)\]\]/';
 1021+ $thelink = $this->makeMediaLink( $submatch[1], "", $text );
 1022+ } else {
 1023+ # Other kind of link
 1024+ if( preg_match( $wgContLang->linkTrail(), $match[4], $submatch ) ) {
 1025+ $trail = $submatch[1];
10061026 } else {
1007 - $text = $match[1];
 1027+ $trail = "";
10081028 }
1009 - $submatch = array();
1010 - if( preg_match( '/^' . $medians . '(.*)$/i', $match[1], $submatch ) ) {
1011 - # Media link; trail not supported.
1012 - $linkRegexp = '/\[\[(.*?)\]\]/';
1013 - $thelink = $this->makeMediaLink( $submatch[1], "", $text );
1014 - } else {
1015 - # Other kind of link
1016 - if( preg_match( $wgContLang->linkTrail(), $match[4], $submatch ) ) {
1017 - $trail = $submatch[1];
1018 - } else {
1019 - $trail = "";
1020 - }
1021 - $linkRegexp = '/\[\[(.*?)\]\]' . preg_quote( $trail, '/' ) . '/';
1022 - if (isset($match[1][0]) && $match[1][0] == ':')
1023 - $match[1] = substr($match[1], 1);
1024 - $thelink = $this->makeLink( $match[1], $text, "", $trail );
1025 - }
1026 - $comment = preg_replace( $linkRegexp, StringUtils::escapeRegexReplacement( $thelink ), $comment, 1 );
 1029+ $linkRegexp = '/\[\[(.*?)\]\]' . preg_quote( $trail, '/' ) . '/';
 1030+ if (isset($match[1][0]) && $match[1][0] == ':')
 1031+ $match[1] = substr($match[1], 1);
 1032+ $thelink = $this->makeLink( $match[1], $text, "", $trail );
10271033 }
 1034+ $comment = preg_replace( $linkRegexp, StringUtils::escapeRegexReplacement( $thelink ), $comment, 1 );
10281035
10291036 return $comment;
10301037 }
Index: trunk/phase3/RELEASE-NOTES
@@ -84,6 +84,9 @@
8585 * (bug 11478) Fix undefined method call in file deletion interface
8686 * (bug 278) Search results no longer highlight incorrect partial word matches
8787 * Compatibility with incorrectly detected old-style DJVU mime types
 88+* (bug 11560) Fix broken HTML output from weird link nesting in edit comments.
 89+ Nested links (as in image caption text) still don't work _right_ but they're
 90+ less wrong.
8891
8992
9093 === API changes in 1.12 ===

Follow-up revisions

RevisionCommit summaryAuthorDate
r26431Merged revisions 26331-26430 via svnmerge from...david06:44, 5 October 2007

Status & tagging log