From 3de7d6f25c53db94381dd0438524138f164bca1f Mon Sep 17 00:00:00 2001 From: Alex Z Date: Mon, 20 Jul 2009 06:29:46 +0000 Subject: [PATCH] (bug 15745) Make the edit summary link parser detect links more like the real parser, added a parser test for it --- RELEASE-NOTES | 2 ++ includes/Linker.php | 24 ++++++++++++++++++------ maintenance/parserTests.txt | 11 +++++++++++ 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index bd7f1b27d7..d7db796424 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -304,6 +304,8 @@ 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 == API changes in 1.16 == diff --git a/includes/Linker.php b/includes/Linker.php index d059d76c45..3cdb545aa3 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -1012,10 +1012,22 @@ class Linker { public function formatLinksInComment( $comment, $title = null, $local = false ) { $this->commentContextTitle = $title; $this->commentLocal = $local; - $html = preg_replace_callback( - '/\[\[:?(.*?)(\|(.*?))*\]\]([^[]*)/', - array( $this, 'formatLinksInCommentCallback' ), - $comment ); + # 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; + } unset( $this->commentContextTitle ); unset( $this->commentLocal ); return $html; @@ -1043,7 +1055,7 @@ class Linker { $submatch = array(); 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 { @@ -1053,7 +1065,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 2b2d2a21bf..099ee3d766 100644 --- a/maintenance/parserTests.txt +++ b/maintenance/parserTests.txt @@ -7456,6 +7456,17 @@ 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