Merge "Memory setting for djvutext is now a constant"
[lhc/web/wiklou.git] / includes / Linker.php
index 12edcc8..408538b 100644 (file)
@@ -1376,7 +1376,18 @@ class Linker {
                self::$commentContextTitle = $title;
                self::$commentLocal = $local;
                $html = preg_replace_callback(
-                       '/\[\[:?(.*?)(\|(.*?))*\]\]([^[]*)/',
+                       '/
+                               \[\[
+                               :? # ignore optional leading colon
+                               ([^\]|]+) # 1. link target; page names cannot include ] or |
+                               (?:\|
+                                       # 2. a pipe-separated substring; only the last is captured
+                                       # Stop matching at | and ]] without relying on backtracking.
+                                       ((?:]?[^\]|])*+)
+                               )*
+                               \]\]
+                               ([^[]*) # 3. link trail (the text up until the next link)
+                       /x',
                        array( 'Linker', 'formatLinksInCommentCallback' ),
                        $comment );
                self::$commentContextTitle = null;
@@ -1402,8 +1413,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 +1429,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 = "";