From 76d285dc36b80aec6caea6566b2f9e05cc536ed8 Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Tue, 9 Feb 2010 01:05:49 +0000 Subject: [PATCH] More sensible semantics for pipe trick with section links after r62076 [[hello#world|]] -> [[hello#world|world]] (not [[hello#world]]) --- includes/Linker.php | 4 ++-- includes/parser/Parser.php | 4 ++-- maintenance/parserTests.txt | 12 ++++++++++++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/includes/Linker.php b/includes/Linker.php index 1d9f9fdbfa..fe2ffa5b6b 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -1237,8 +1237,8 @@ class Linker { list( $tc, $nc ) = Linker::getPipeTrickCharacterClasses(); $rexps = array ( # try this first, to turn "[[A, B (C)|]]" into "A, B" - "/^(:?$nc+:|[:#\/]|$tc+\\/|)($tc+?)( \\($tc+\\)| ($tc+))$/", # [[ns:page (context)|]] - "/^(:?$nc+:|[:#\/]|$tc+\\/|)($tc+?)( \\($tc+\\)| ($tc+)|)((?:,|,) $tc+|)$/", # [[ns:page (context), context|]] + "/^(:?$nc+:|[:#\/]|$tc+[\\/#]|)($tc+?)( \\($tc+\\)| ($tc+))$/", # [[ns:page (context)|]] + "/^(:?$nc+:|[:#\/]|$tc+[\\/#]|)($tc+?)( \\($tc+\\)| ($tc+)|)((?:,|,) $tc+|)$/", # [[ns:page (context), context|]] ); } $text = urldecode( $link ); diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index 7a2a36aee7..9f3d89f261 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -4033,9 +4033,9 @@ class Parser ) ); # Links of the form [[|]] or [[|]] perform pipe tricks - # Note this only allows the # in the one position it works. + # Note this only allows the # in the position it works. global $wgLegalTitleChars; - $pipeTrickRe = "/\[\[(?:(\\|)([$wgLegalTitleChars]+)|(#?[$wgLegalTitleChars]+)\\|)\]\]/"; + $pipeTrickRe = "/\[\[(?:(\\|)([$wgLegalTitleChars]+)|([#$wgLegalTitleChars]+)\\|)\]\]/"; $text = preg_replace_callback( $pipeTrickRe, array( $this, 'pstPipeTrickCallback' ), $text ); # Trim trailing whitespace diff --git a/maintenance/parserTests.txt b/maintenance/parserTests.txt index 578d0ff247..5eb095ca3a 100644 --- a/maintenance/parserTests.txt +++ b/maintenance/parserTests.txt @@ -3051,6 +3051,18 @@ pst [[../context/relative (extra)|relative]] !! end +!! test +pre-save transform: context links ("pipe trick") to sections on other pages +!! options +pst +!! input +[[other#page|]] +[[Help:Somewhere/completely (wierd)#section (two)|]] +!! result +[[other#page|page]] +[[Help:Somewhere/completely (wierd)#section (two)|section]] +!! end + !! test pre-save transform: context links ("pipe trick") with full-width characters !! options -- 2.20.1