Update Pipe Trick semantics per bug 845 and bug 21660
authorConrad Irwin <conrad@users.mediawiki.org>
Sun, 7 Feb 2010 02:15:26 +0000 (02:15 +0000)
committerConrad Irwin <conrad@users.mediawiki.org>
Sun, 7 Feb 2010 02:15:26 +0000 (02:15 +0000)
Allows fullwidth variants of "(", ")", and "," everywhere
Adds [[#section|]] -> [[#section|section]] (initial # only)
Adds [[/sub/section|]] -> [[/sub/section|section]]

RELEASE-NOTES
includes/parser/Parser.php
maintenance/parserTests.txt

index c802161..f0d3a73 100644 (file)
@@ -832,6 +832,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 * (bug 5210)  preload parser should parse <noinclude> (as well as <includeonly>)
 * (bug 8785)  Pipe trick should work with colon functions 
 * (bug 4099)  Pipe trick doesn't work when emptiness is only provided by empty template parameter 
+* (bug 845)   [[#foo|]], [[/bar|]] should be equivalent to [[#foo|foo]], [[/bar|bar]] (new use of "pipe trick")
+* (bug 21660) Support full-width commas for pipe trick
 
 === Languages updated in 1.16 ===
 
index fa8b836..3f97d78 100644 (file)
@@ -1917,7 +1917,8 @@ class Parser
         * From the [[title|]] return link-text as though the used typed [[title|link-text]]
         *
         * For most links this be as though the user typed [[ns:title|title]]
-        * However [[ns:title (context)]], [[ns:title, context]] and [[ns:title (context), context]]
+        * However [[ns:title (context)|]], [[ns:title, context|]] and [[ns:title (context), context|]]
+        * [[#title (context)|]] [[../context/title (context), context|]]
         * all return the |title]] with no context or indicative punctuation.
         */
        function getPipeTrickText( $link ) {
@@ -1926,8 +1927,8 @@ class Parser
                        list( $tc, $nc ) = Parser::getPipeTrickCharacterClasses();
                        $rexps = array (
                                # try this first, to turn "[[A, B (C)|]]" into "A, B"
-                               "/^(:?$nc+:|:|)($tc+?)( \\($tc+\\)| ($tc+))$/", # [[ns:page (context)|]]
-                               "/^(:?$nc+:|:|)($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 );
@@ -1951,8 +1952,8 @@ class Parser
                if( !$rexps ) {
                        list( $tc, $nc ) = Parser::getPipeTrickCharacterClasses();
                        $rexps = array (
-                               "/^($nc+:|)$tc+?( \\($tc+\\))$/", # [[ns:page (context)]]
-                               "/^($nc+:|)$tc+?(, $tc+|)$/"      # [[ns:page, context]]
+                               "/^($nc+:|)$tc+?( \\($tc+\\)| ($tc+))$/", # [[ns:page (context)|]]
+                               "/^($nc+:|)$tc+?(?:(?: \\($tc+\\)| ($tc+)|)((?:,|,) $tc+|))$/"  # [[ns:page (context), context|]]
                        );
                }
 
@@ -4062,9 +4063,10 @@ class Parser
                ) );
 
                # Links of the form [[|<blah>]] or [[<blah>|]] perform pipe tricks
+               # Note this only allows the # in the one position it works.
                list( $tc, $nc ) = Parser::getPipeTrickCharacterClasses();
-               $pipeTrickRe = "/\[\[(?:(\\|)($tc+)|($tc+)\\|)\]\]/";
-               $text = preg_replace_callback( $pipeTrickRe, array( $this, 'pstPipeTrickCallback' ), $text);
+               $pipeTrickRe = "/\[\[(?:(\\|)($tc+)|(#?$tc+)\\|)\]\]/";
+               $text = preg_replace_callback( $pipeTrickRe, array( $this, 'pstPipeTrickCallback' ), $text );
 
                # Trim trailing whitespace
                $text = rtrim( $text );
@@ -4078,7 +4080,7 @@ class Parser
         *
         * @param Array ("|" or "", text, link) $m
         */
-       function pstPipeTrickCallback($m)
+       function pstPipeTrickCallback( $m )
        {
                if( $m[1] ) { # [[|<blah>]]
                        $text = $m[2];
index 12615e0..9a3d98c 100644 (file)
@@ -2998,6 +2998,36 @@ pst
 [[:Bar:X (Y) Z|X (Y) Z]]
 !! end
 
+!! test
+pre-save transform: context links ("pipe trick") based on current page
+!! options
+pst
+!! input
+[[#section|]]
+[[#section (context)|]]
+[[/relative|]]
+[[../context/relative|]]
+[[../context/relative (extra)|]]
+!! result
+[[#section|section]]
+[[#section (context)|section]]
+[[/relative|relative]]
+[[../context/relative|relative]]
+[[../context/relative (extra)|relative]]
+!! end
+
+!! test
+pre-save transform: context links ("pipe trick") with full-width characters
+!! options
+pst
+!! input
+[[title, context|]]
+[[title (context)|]]
+!! result
+[[title, context|title]]
+[[title (context)|title]]
+!! end
+
 !! test
 pre-save transform: context links ("pipe trick") with interwiki prefix
 !! options