From 6b9014bda5deab91492e87f82b70658ddfa5b476 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 e5db232..66cb7e7 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -1373,7 +1373,7 @@ class Linker { self::$commentContextTitle = $title; self::$commentLocal = $local; $html = preg_replace_callback( - '/\[\[:?(.*?)(\|(.*?))*\]\]([^[]*)/', + '/\[\[:?([^\]|]+)(?:\|((?:]?[^\]|])*+))*\]\]([^[]*)/', array( 'Linker', 'formatLinksInCommentCallback' ), $comment ); self::$commentContextTitle = null; @@ -1399,8 +1399,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]; } @@ -1415,7 +1415,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 = ""; -- 1.8.0