From 75cd6a90693ecac9e7d28a8fb43d9e408ab5b3a2 Mon Sep 17 00:00:00 2001 From: Chad Horohoe Date: Thu, 27 Aug 2009 22:27:42 +0000 Subject: [PATCH] Revert r53534 (bug 15745, Make the edit summary link parser detect links more like the real parser). Causes preg_replace_callback bug in 5.2.8 and below, crashes lots of things. See bug 19845 and http://bugs.php.net/bug.php?id=48501 --- RELEASE-NOTES | 2 -- includes/Linker.php | 24 ++++++------------------ maintenance/parserTests.txt | 11 ----------- 3 files changed, 6 insertions(+), 31 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index e8caad0627..dd456bfa94 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -348,8 +348,6 @@ this. Was used when mwEmbed was going to be an extension. * (bug 17374) Special:Export no longer exports multiple copies of pages * (bug 19818) Edits to user CSS/JS subpages can now be marked as patrolled by users who can't edit them -* (bug 15745) The edit summary link parser now handles mismatched brackets - better * (bug 19839) Comments in log items are no more double escaped * (bug 18161) Fix inconsistent separators in watchlist link toolbars with "enhanced recent changes" diff --git a/includes/Linker.php b/includes/Linker.php index 7a86100ce0..fbc4a8309d 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -1012,22 +1012,10 @@ class Linker { public function formatLinksInComment( $comment, $title = null, $local = false ) { $this->commentContextTitle = $title; $this->commentLocal = $local; - # Borrowed from Parser::replaceInternalLinks2 - $parts = StringUtils::explode( '[[', ' ' . $comment ); - $start = $parts->current(); - $parts->next(); - $line = $parts->current(); - $html = substr( $start, 1 ); - for ( ; $line !== false && $line !== null ; $parts->next(), $line = $parts->current() ) { - $linked = preg_replace_callback( - '/^:?(.*?)(\|(.*?))*\]\]([^[]*)/', - array( $this, 'formatLinksInCommentCallback' ), - $line, -1, $count ); - if( !$count ) { // No valid link found, put the brackets back - $linked = '[[' . $linked; - } - $html .= $linked; - } + $html = preg_replace_callback( + '/\[\[:?(.*?)(\|(.*?))*\]\]([^[]*)/', + array( $this, 'formatLinksInCommentCallback' ), + $comment ); unset( $this->commentContextTitle ); unset( $this->commentLocal ); return $html; @@ -1056,7 +1044,7 @@ class Linker { $thelink = null; if( preg_match( '/^' . $medians . '(.*)$/i', $match[1], $submatch ) ) { # Media link; trail not supported. - $linkRegexp = '/^(.*?)\]\]/'; + $linkRegexp = '/\[\[(.*?)\]\]/'; $title = Title::makeTitleSafe( NS_FILE, $submatch[1] ); $thelink = $this->makeMediaLinkObj( $title, $text ); } else { @@ -1066,7 +1054,7 @@ class Linker { } else { $trail = ""; } - $linkRegexp = '/^(.*?)\]\]' . preg_quote( $trail, '/' ) . '/'; + $linkRegexp = '/\[\[(.*?)\]\]' . preg_quote( $trail, '/' ) . '/'; if (isset($match[1][0]) && $match[1][0] == ':') $match[1] = substr($match[1], 1); list( $inside, $trail ) = Linker::splitTrail( $trail ); diff --git a/maintenance/parserTests.txt b/maintenance/parserTests.txt index f020094141..8359126272 100644 --- a/maintenance/parserTests.txt +++ b/maintenance/parserTests.txt @@ -7515,17 +7515,6 @@ title=[[Main Page]] #section !! end -!! test -Edit comment with mismatched brackets (bug 15745) -!! options -comment -title=[[Main Page]] -!!input -Some text, a [[broken link|bad and a [[good link|good]] -!! result -Some text, a [[broken link|bad and a good -!! end - TODO: more images more tables -- 2.20.1