From 3a751a39b17f8f2ccc1c4ae2ed8353ef5f77e5ea Mon Sep 17 00:00:00 2001 From: Kevin Israel Date: Thu, 25 Oct 2012 09:54:52 -0400 Subject: [PATCH] Optimized regex in Linker.php Optimized the regex in Linker::formatLinksInComment(). Change-Id: Idea5554bcb8d7e78ddf972ce4c9827fa738ff837 --- includes/Linker.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/includes/Linker.php b/includes/Linker.php index 12edcc85c2..9b4901573f 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -1376,7 +1376,7 @@ class Linker { self::$commentContextTitle = $title; self::$commentLocal = $local; $html = preg_replace_callback( - '/\[\[:?(.*?)(\|(.*?))*\]\]([^[]*)/', + '/\[\[:?([^\]|]+)(?:\|((?:]?[^\]|])*+))*\]\]([^[]*)/', array( 'Linker', 'formatLinksInCommentCallback' ), $comment ); self::$commentContextTitle = null; @@ -1402,8 +1402,8 @@ class Linker { } # Handle link renaming [[foo|text]] will show link as "text" - if ( $match[3] != "" ) { - $text = $match[3]; + if ( $match[2] != "" ) { + $text = $match[2]; } else { $text = $match[1]; } @@ -1418,7 +1418,7 @@ class Linker { } } else { # Other kind of link - if ( preg_match( $wgContLang->linkTrail(), $match[4], $submatch ) ) { + if ( preg_match( $wgContLang->linkTrail(), $match[3], $submatch ) ) { $trail = $submatch[1]; } else { $trail = ""; -- 2.20.1