r62085 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r62084‎ | r62085 | r62086 >
Date:14:50, 7 February 2010
Author:conrad
Status:reverted
Tags:
Comment:
Fix bug 20339 allow pipe-trick in log reasons

follows on from r62069 moving logic from Parser into Linker
(copying brion's technique for dealing with subpages)
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/Linker.php (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
@@ -7713,6 +7713,17 @@
77147714 <a href="https://www.mediawiki.org/wiki/Main_Page#section" title="Main Page">#section</a>
77157715 !! end
77167716
 7717+!! test
 7718+Edit comment with pipe trick
 7719+!! options
 7720+comment
 7721+title=[[Article (context)]]
 7722+!! input
 7723+[[Hello (World)|]] [[|Entry]]
 7724+!! result
 7725+<a href="https://www.mediawiki.org/index.php?title=Hello_(World)&amp;action=edit&amp;redlink=1" class="new" title="Hello (World) (page does not exist)">Hello</a> <a href="https://www.mediawiki.org/index.php?title=Entry_(context)&amp;action=edit&amp;redlink=1" class="new" title="Entry (context) (page does not exist)">Entry</a>
 7726+!! end
 7727+
77177728 !!article
77187729 MediaWiki:bad image list
77197730 !!text
@@ -7739,6 +7750,7 @@
77407751 !! end
77417752
77427753
 7754+
77437755 TODO:
77447756 more images
77457757 more tables
Index: trunk/phase3/includes/parser/Parser.php
@@ -1913,69 +1913,22 @@
19141914 }
19151915
19161916 /**
1917 - * Returns valid title characters and namespace characters for pipe trick.
1918 - *
1919 - * FIXME: the namespace characters should not be specified like this...
1920 - */
1921 - static function getPipeTrickCharacterClasses() {
1922 - global $wgLegalTitleChars;
1923 - return array( "[$wgLegalTitleChars]", '[ _0-9A-Za-z\x80-\xff-]' );
1924 - }
1925 -
1926 - /**
19271917 * From the [[title|]] return link-text as though the used typed [[title|link-text]]
1928 - *
1929 - * For most links this be as though the user typed [[ns:title|title]]
1930 - * However [[ns:title (context)|]], [[ns:title, context|]] and [[ns:title (context), context|]]
1931 - * [[#title (context)|]] [[../context/title (context), context|]]
1932 - * all return the |title]] with no context or indicative punctuation.
 1918+ * @param string $link from [[$link|]]
 1919+ * @return string $text for [[$link|$text]]
19331920 */
19341921 function getPipeTrickText( $link ) {
1935 - static $rexps = FALSE;
1936 - if( !$rexps ) {
1937 - list( $tc, $nc ) = Parser::getPipeTrickCharacterClasses();
1938 - $rexps = array (
1939 - # try this first, to turn "[[A, B (C)|]]" into "A, B"
1940 - "/^(:?$nc+:|[:#\/]|$tc+\\/|)($tc+?)( \\($tc+\\)| ($tc+))$/", # [[ns:page (context)|]]
1941 - "/^(:?$nc+:|[:#\/]|$tc+\\/|)($tc+?)( \\($tc+\\)| ($tc+)|)((?:,|,) $tc+|)$/", # [[ns:page (context), context|]]
1942 - );
1943 - }
1944 - $text = urldecode( $link );
1945 -
1946 - for( $i = 0; $i < count( $rexps ); $i++) {
1947 - if( preg_match( $rexps[$i], $text, $m ) )
1948 - return $m[2];
1949 - }
1950 - return $text;
 1922+ return Linker::getPipeTrickText( $link );
19511923 }
19521924
19531925 /**
19541926 * From the [[|link-text]] return the title as though the user typed [[title|link-text]]
1955 - *
1956 - * On most pages this will return link-text or "" if the link-text is not a valid title
1957 - * On pages like [[ns:title (context)]] and [[ns:title, context]] it will act like
1958 - * [[ns:link-text (context)|link-text]] and [[ns:link-text, context|link-text]]
 1927+ * @param string $text from [[|$text]]
 1928+ * @param Title $title to resolve the link against
 1929+ * @return string $link for [[$link|$text]]
19591930 */
19601931 function getPipeTrickLink( $text ) {
1961 - static $rexps = FALSE, $tc;
1962 - if( !$rexps ) {
1963 - list( $tc, $nc ) = Parser::getPipeTrickCharacterClasses();
1964 - $rexps = array (
1965 - "/^($nc+:|)$tc+?( \\($tc+\\)| ($tc+))$/", # [[ns:page (context)|]]
1966 - "/^($nc+:|)$tc+?(?:(?: \\($tc+\\)| ($tc+)|)((?:,|,) $tc+|))$/" # [[ns:page (context), context|]]
1967 - );
1968 - }
1969 -
1970 - if( !preg_match( "/^$tc+$/", $text ) )
1971 - return '';
1972 -
1973 - $t = $this->mTitle->getText();
1974 -
1975 - for( $i = 0; $i < count( $rexps ); $i++) {
1976 - if( preg_match( $rexps[$i], $t, $m ) )
1977 - return "$m[1]$text$m[2]";
1978 - }
1979 - return $text;
 1932+ return Linker::getPipeTrickLink( $text, $this->mTitle );
19801933 }
19811934
19821935 /**#@+
@@ -4073,8 +4026,8 @@
40744027
40754028 # Links of the form [[|<blah>]] or [[<blah>|]] perform pipe tricks
40764029 # Note this only allows the # in the one position it works.
4077 - list( $tc, $nc ) = Parser::getPipeTrickCharacterClasses();
4078 - $pipeTrickRe = "/\[\[(?:(\\|)($tc+)|(#?$tc+)\\|)\]\]/";
 4030+ global $wgLegalTitleChars;
 4031+ $pipeTrickRe = "/\[\[(?:(\\|)([$wgLegalTitleChars]+)|(#?[$wgLegalTitleChars]+)\\|)\]\]/";
40794032 $text = preg_replace_callback( $pipeTrickRe, array( $this, 'pstPipeTrickCallback' ), $text );
40804033
40814034 # Trim trailing whitespace
Index: trunk/phase3/includes/Linker.php
@@ -1086,6 +1086,11 @@
10871087 # Handle link renaming [[foo|text]] will show link as "text"
10881088 if( $match[3] != "" ) {
10891089 $text = $match[3];
 1090+ if( $match[1] === "" && $this->commentContextTitle ) {
 1091+ $match[1] = Linker::getPipeTrickLink( $text, $this->commentContextTitle );
 1092+ }
 1093+ } elseif( $match[2] == "|" ) {
 1094+ $text = Linker::getPipeTrickText( $match[1] );
10901095 } else {
10911096 $text = $match[1];
10921097 }
@@ -1206,6 +1211,79 @@
12071212 }
12081213
12091214 /**
 1215+ * Returns valid title characters and namespace characters for pipe trick.
 1216+ *
 1217+ * FIXME: the namespace characters should not be specified like this...
 1218+ */
 1219+ static function getPipeTrickCharacterClasses() {
 1220+ global $wgLegalTitleChars;
 1221+ return array( "[$wgLegalTitleChars]", '[ _0-9A-Za-z\x80-\xff-]' );
 1222+ }
 1223+
 1224+ /**
 1225+ * From the [[title|]] return link-text as though the used typed [[title|link-text]]
 1226+ *
 1227+ * For most links this be as though the user typed [[ns:title|title]]
 1228+ * However [[ns:title (context)|]], [[ns:title, context|]] and [[ns:title (context), context|]]
 1229+ * [[#title (context)|]] [[../context/title (context), context|]]
 1230+ * all return the |title]] with no context or indicative punctuation.
 1231+ *
 1232+ * @param string $link from [[$link|]]
 1233+ * @return string $text for [[$link|$text]]
 1234+ */
 1235+ static function getPipeTrickText( $link ) {
 1236+ static $rexps = FALSE;
 1237+ if( !$rexps ) {
 1238+ list( $tc, $nc ) = Linker::getPipeTrickCharacterClasses();
 1239+ $rexps = array (
 1240+ # try this first, to turn "[[A, B (C)|]]" into "A, B"
 1241+ "/^(:?$nc+:|[:#\/]|$tc+\\/|)($tc+?)( \\($tc+\\)| ($tc+))$/", # [[ns:page (context)|]]
 1242+ "/^(:?$nc+:|[:#\/]|$tc+\\/|)($tc+?)( \\($tc+\\)| ($tc+)|)((?:,|,) $tc+|)$/", # [[ns:page (context), context|]]
 1243+ );
 1244+ }
 1245+ $text = urldecode( $link );
 1246+
 1247+ for( $i = 0; $i < count( $rexps ); $i++) {
 1248+ if( preg_match( $rexps[$i], $text, $m ) )
 1249+ return $m[2];
 1250+ }
 1251+ return $text;
 1252+ }
 1253+
 1254+ /**
 1255+ * From the [[|link-text]] return the title as though the user typed [[title|link-text]]
 1256+ *
 1257+ * On most pages this will return link-text or "" if the link-text is not a valid title
 1258+ * On pages like [[ns:title (context)]] and [[ns:title, context]] it will act like
 1259+ * [[ns:link-text (context)|link-text]] and [[ns:link-text, context|link-text]]
 1260+ *
 1261+ * @param string $text from [[|$text]]
 1262+ * @param Title $title to resolve the link against
 1263+ * @return string $link for [[$link|$text]]
 1264+ */
 1265+ static function getPipeTrickLink( $text, $title ) {
 1266+ static $rexps = FALSE, $tc;
 1267+ if( !$rexps ) {
 1268+ list( $tc, $nc ) = Linker::getPipeTrickCharacterClasses();
 1269+ $rexps = array (
 1270+ "/^($nc+:|)$tc+?( \\($tc+\\)| ($tc+))$/", # [[ns:page (context)|]]
 1271+ "/^($nc+:|)$tc+?(?:(?: \\($tc+\\)| ($tc+)|)((?:,|,) $tc+|))$/" # [[ns:page (context), context|]]
 1272+ );
 1273+ }
 1274+
 1275+ if( !preg_match( "/^$tc+$/", $text ) )
 1276+ return '';
 1277+
 1278+ $t = $title->getText();
 1279+
 1280+ for( $i = 0; $i < count( $rexps ); $i++) {
 1281+ if( preg_match( $rexps[$i], $t, $m ) )
 1282+ return "$m[1]$text$m[2]";
 1283+ }
 1284+ return $text;
 1285+ }
 1286+
 1287+ /**
12101288 * Wrap a comment in standard punctuation and formatting if
12111289 * it's non-empty, otherwise return empty string.
12121290 *
Index: trunk/phase3/RELEASE-NOTES
@@ -835,6 +835,7 @@
836836 * (bug 845) [[#foo|]], [[/bar|]] should be equivalent to [[#foo|foo]], [[/bar|bar]] (new use of "pipe trick")
837837 * (bug 21660) Support full-width commas for pipe trick
838838 * (bug 7264) Magic word to give Page Title as if pipe-trick performed on it {{pipetrick:}}
 839+* (bug 20339) Allow using the pipe trick in log reasons
839840
840841 === Languages updated in 1.16 ===
841842

Follow-up revisions

RevisionCommit summaryAuthorDate
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

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r62069Allow pipe trick to work after PST....conrad15:00, 6 February 2010

Status & tagging log