From bbc5776faae50739daf49d9e3faf9651b4fcdb8d Mon Sep 17 00:00:00 2001 From: Ilmari Karonen Date: Wed, 26 Jul 2006 18:20:12 +0000 Subject: [PATCH] further simplify context link code; use non-greedy matching instead of modifying the character class --- includes/Parser.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/includes/Parser.php b/includes/Parser.php index 2a2e3fb769..ccb72b34d2 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -3579,19 +3579,18 @@ class Parser # global $wgLegalTitleChars; $tc = "[$wgLegalTitleChars]"; - $np = str_replace( array( '(', ')' ), array( '', '' ), $tc ); # No parens $namespacechar = '[ _0-9A-Za-z\x80-\xff]'; # Namespaces can use non-ascii! - $conpat = "/^({$np}+) \\(({$tc}+)\\)$/"; + $conpat = "/^{$tc}+? \\(({$tc}+)\\)$/"; - $p1 = "/\[\[(:?$namespacechar+:|:|)({$np}+)( \\({$np}+\\)|)\\|]]/"; # [[ns:page (context)|]] + $p1 = "/\[\[(:?$namespacechar+:|:|)({$tc}+?)( \\({$tc}+\\)|)\\|]]/"; # [[ns:page (context)|]] $p2 = "/\[\[\\|({$tc}+)]]/"; # [[|page]] $text = preg_replace( $p1, '[[\\1\\2\\3|\\2]]', $text ); $t = $this->mTitle->getText(); - if ( preg_match( $conpat, $t, $m ) && '' != $m[2] ) { - $text = preg_replace( $p2, "[[\\1 ({$m[2]})|\\1]]", $text ); + if ( preg_match( $conpat, $t, $m ) && '' != $m[1] ) { + $text = preg_replace( $p2, "[[\\1 ({$m[1]})|\\1]]", $text ); } else { $text = preg_replace( $p2, '[[\\1]]', $text ); } -- 2.20.1