From: Conrad Irwin Date: Sun, 7 Feb 2010 02:15:26 +0000 (+0000) Subject: Update Pipe Trick semantics per bug 845 and bug 21660 X-Git-Tag: 1.31.0-rc.0~37899 X-Git-Url: http://git.cyclocoop.org/data/Fool?a=commitdiff_plain;h=8e258183ae0af24967e823dcc665ff1359fe44ba;p=lhc%2Fweb%2Fwiklou.git Update Pipe Trick semantics per bug 845 and bug 21660 Allows fullwidth variants of "(", ")", and "," everywhere Adds [[#section|]] -> [[#section|section]] (initial # only) Adds [[/sub/section|]] -> [[/sub/section|section]] --- diff --git a/RELEASE-NOTES b/RELEASE-NOTES index c8021619c1..f0d3a73bec 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -832,6 +832,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * (bug 5210) preload parser should parse (as well as ) * (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 === diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index fa8b8364c2..3f97d78bba 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -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 [[|]] or [[|]] 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] ) { # [[|]] $text = $m[2]; diff --git a/maintenance/parserTests.txt b/maintenance/parserTests.txt index 12615e01eb..9a3d98cefd 100644 --- a/maintenance/parserTests.txt +++ b/maintenance/parserTests.txt @@ -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