r62076 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r62075‎ | r62076 | r62077 >
Date:02:15, 7 February 2010
Author:conrad
Status:reverted
Tags:
Comment:
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]]
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/parser/Parser.php (modified) (history)
  • /trunk/phase3/maintenance/parserTests.txt (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/parserTests.txt
@@ -2999,6 +2999,36 @@
30003000 !! end
30013001
30023002 !! test
 3003+pre-save transform: context links ("pipe trick") based on current page
 3004+!! options
 3005+pst
 3006+!! input
 3007+[[#section|]]
 3008+[[#section (context)|]]
 3009+[[/relative|]]
 3010+[[../context/relative|]]
 3011+[[../context/relative (extra)|]]
 3012+!! result
 3013+[[#section|section]]
 3014+[[#section (context)|section]]
 3015+[[/relative|relative]]
 3016+[[../context/relative|relative]]
 3017+[[../context/relative (extra)|relative]]
 3018+!! end
 3019+
 3020+!! test
 3021+pre-save transform: context links ("pipe trick") with full-width characters
 3022+!! options
 3023+pst
 3024+!! input
 3025+[[title, context|]]
 3026+[[title (context)|]]
 3027+!! result
 3028+[[title, context|title]]
 3029+[[title (context)|title]]
 3030+!! end
 3031+
 3032+!! test
30033033 pre-save transform: context links ("pipe trick") with interwiki prefix
30043034 !! options
30053035 pst
Index: trunk/phase3/includes/parser/Parser.php
@@ -1917,7 +1917,8 @@
19181918 * From the [[title|]] return link-text as though the used typed [[title|link-text]]
19191919 *
19201920 * For most links this be as though the user typed [[ns:title|title]]
1921 - * However [[ns:title (context)]], [[ns:title, context]] and [[ns:title (context), context]]
 1921+ * However [[ns:title (context)|]], [[ns:title, context|]] and [[ns:title (context), context|]]
 1922+ * [[#title (context)|]] [[../context/title (context), context|]]
19221923 * all return the |title]] with no context or indicative punctuation.
19231924 */
19241925 function getPipeTrickText( $link ) {
@@ -1926,8 +1927,8 @@
19271928 list( $tc, $nc ) = Parser::getPipeTrickCharacterClasses();
19281929 $rexps = array (
19291930 # try this first, to turn "[[A, B (C)|]]" into "A, B"
1930 - "/^(:?$nc+:|:|)($tc+?)( \\($tc+\\)| ($tc+))$/", # [[ns:page (context)|]]
1931 - "/^(:?$nc+:|:|)($tc+?)( \\($tc+\\)|)(, $tc+|)$/" # [[ns:page (context), context|]]
 1931+ "/^(:?$nc+:|[:#\/]|$tc+\\/|)($tc+?)( \\($tc+\\)| ($tc+))$/", # [[ns:page (context)|]]
 1932+ "/^(:?$nc+:|[:#\/]|$tc+\\/|)($tc+?)( \\($tc+\\)| ($tc+)|)((?:,|,) $tc+|)$/", # [[ns:page (context), context|]]
19321933 );
19331934 }
19341935 $text = urldecode( $link );
@@ -1951,8 +1952,8 @@
19521953 if( !$rexps ) {
19531954 list( $tc, $nc ) = Parser::getPipeTrickCharacterClasses();
19541955 $rexps = array (
1955 - "/^($nc+:|)$tc+?( \\($tc+\\))$/", # [[ns:page (context)]]
1956 - "/^($nc+:|)$tc+?(, $tc+|)$/" # [[ns:page, context]]
 1956+ "/^($nc+:|)$tc+?( \\($tc+\\)| ($tc+))$/", # [[ns:page (context)|]]
 1957+ "/^($nc+:|)$tc+?(?:(?: \\($tc+\\)| ($tc+)|)((?:,|,) $tc+|))$/" # [[ns:page (context), context|]]
19571958 );
19581959 }
19591960
@@ -4062,9 +4063,10 @@
40634064 ) );
40644065
40654066 # Links of the form [[|<blah>]] or [[<blah>|]] perform pipe tricks
 4067+ # Note this only allows the # in the one position it works.
40664068 list( $tc, $nc ) = Parser::getPipeTrickCharacterClasses();
4067 - $pipeTrickRe = "/\[\[(?:(\\|)($tc+)|($tc+)\\|)\]\]/";
4068 - $text = preg_replace_callback( $pipeTrickRe, array( $this, 'pstPipeTrickCallback' ), $text);
 4069+ $pipeTrickRe = "/\[\[(?:(\\|)($tc+)|(#?$tc+)\\|)\]\]/";
 4070+ $text = preg_replace_callback( $pipeTrickRe, array( $this, 'pstPipeTrickCallback' ), $text );
40694071
40704072 # Trim trailing whitespace
40714073 $text = rtrim( $text );
@@ -4078,7 +4080,7 @@
40794081 *
40804082 * @param Array ("|" or "", text, link) $m
40814083 */
4082 - function pstPipeTrickCallback($m)
 4084+ function pstPipeTrickCallback( $m )
40834085 {
40844086 if( $m[1] ) { # [[|<blah>]]
40854087 $text = $m[2];
Index: trunk/phase3/RELEASE-NOTES
@@ -832,6 +832,8 @@
833833 * (bug 5210) preload parser should parse <noinclude> (as well as <includeonly>)
834834 * (bug 8785) Pipe trick should work with colon functions
835835 * (bug 4099) Pipe trick doesn't work when emptiness is only provided by empty template parameter
 836+* (bug 845) [[#foo|]], [[/bar|]] should be equivalent to [[#foo|foo]], [[/bar|bar]] (new use of "pipe trick")
 837+* (bug 21660) Support full-width commas for pipe trick
836838
837839 === Languages updated in 1.16 ===
838840

Follow-up revisions

RevisionCommit summaryAuthorDate
r62150More sensible semantics for pipe trick with section links after r62076...conrad01:05, 9 February 2010
r62194Pretty sure that...reedy20:46, 9 February 2010
r62689Moving Conrad's recent parser work out to a branch. Reverted r62434, r62416, ...tstarling05:19, 19 February 2010

Status & tagging log