Index: trunk/phase3/maintenance/parserTests.txt |
— | — | @@ -7713,6 +7713,17 @@ |
7714 | 7714 | <a href="https://www.mediawiki.org/wiki/Main_Page#section" title="Main Page">#section</a> |
7715 | 7715 | !! end |
7716 | 7716 | |
| 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)&action=edit&redlink=1" class="new" title="Hello (World) (page does not exist)">Hello</a> <a href="https://www.mediawiki.org/index.php?title=Entry_(context)&action=edit&redlink=1" class="new" title="Entry (context) (page does not exist)">Entry</a> |
| 7726 | +!! end |
| 7727 | + |
7717 | 7728 | !!article |
7718 | 7729 | MediaWiki:bad image list |
7719 | 7730 | !!text |
— | — | @@ -7739,6 +7750,7 @@ |
7740 | 7751 | !! end |
7741 | 7752 | |
7742 | 7753 | |
| 7754 | + |
7743 | 7755 | TODO: |
7744 | 7756 | more images |
7745 | 7757 | more tables |
Index: trunk/phase3/includes/parser/Parser.php |
— | — | @@ -1913,69 +1913,22 @@ |
1914 | 1914 | } |
1915 | 1915 | |
1916 | 1916 | /** |
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 | | - /** |
1927 | 1917 | * 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]] |
1933 | 1920 | */ |
1934 | 1921 | 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 ); |
1951 | 1923 | } |
1952 | 1924 | |
1953 | 1925 | /** |
1954 | 1926 | * 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]] |
1959 | 1930 | */ |
1960 | 1931 | 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 ); |
1980 | 1933 | } |
1981 | 1934 | |
1982 | 1935 | /**#@+ |
— | — | @@ -4073,8 +4026,8 @@ |
4074 | 4027 | |
4075 | 4028 | # Links of the form [[|<blah>]] or [[<blah>|]] perform pipe tricks |
4076 | 4029 | # 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]+)\\|)\]\]/"; |
4079 | 4032 | $text = preg_replace_callback( $pipeTrickRe, array( $this, 'pstPipeTrickCallback' ), $text ); |
4080 | 4033 | |
4081 | 4034 | # Trim trailing whitespace |
Index: trunk/phase3/includes/Linker.php |
— | — | @@ -1086,6 +1086,11 @@ |
1087 | 1087 | # Handle link renaming [[foo|text]] will show link as "text" |
1088 | 1088 | if( $match[3] != "" ) { |
1089 | 1089 | $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] ); |
1090 | 1095 | } else { |
1091 | 1096 | $text = $match[1]; |
1092 | 1097 | } |
— | — | @@ -1206,6 +1211,79 @@ |
1207 | 1212 | } |
1208 | 1213 | |
1209 | 1214 | /** |
| 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 | + /** |
1210 | 1288 | * Wrap a comment in standard punctuation and formatting if |
1211 | 1289 | * it's non-empty, otherwise return empty string. |
1212 | 1290 | * |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -835,6 +835,7 @@ |
836 | 836 | * (bug 845) [[#foo|]], [[/bar|]] should be equivalent to [[#foo|foo]], [[/bar|bar]] (new use of "pipe trick") |
837 | 837 | * (bug 21660) Support full-width commas for pipe trick |
838 | 838 | * (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 |
839 | 840 | |
840 | 841 | === Languages updated in 1.16 === |
841 | 842 | |