r62689 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r62688‎ | r62689 | r62690 >
Date:05:19, 19 February 2010
Author:tstarling
Status:ok
Tags:
Comment:
Moving Conrad's recent parser work out to a branch. Reverted r62434, r62416, r62150, r62111, r62085, r62081, r62080, r62077, r62076, r62069, r62049, r62035.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/EditPage.php (modified) (history)
  • /trunk/phase3/includes/Linker.php (modified) (history)
  • /trunk/phase3/includes/MagicWord.php (modified) (history)
  • /trunk/phase3/includes/parser/CoreParserFunctions.php (modified) (history)
  • /trunk/phase3/includes/parser/Parser.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesEn.php (modified) (history)
  • /trunk/phase3/maintenance/parserTests.txt (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/parserTests.txt
@@ -2022,41 +2022,6 @@
20232023 !! end
20242024
20252025 !! test
2026 -Magic Word: {{PIPETRICK}}
2027 -!! options
2028 -title=[[Some (page)]]
2029 -!! input
2030 -{{PIPETRICK}}
2031 -{{PIPETRICK:Hello (one)}}
2032 -{{PIPETRICK:World, hi|}}
2033 -{{PIPETRICK:|Other}}
2034 -!! result
2035 -<p>Some
2036 -Hello
2037 -World
2038 -Other (page)
2039 -</p>
2040 -!! end
2041 -
2042 -!! test
2043 -Magic Word: {{PIPETRICKE}}
2044 -!! options
2045 -title=[[Some other (page)]]
2046 -!! input
2047 -{{PIPETRICKE}}
2048 -{{PIPETRICKE:User:Ævar Arnfjörð Bjarmason}}
2049 -{{PIPETRICKE:#Something to do|}}
2050 -{{PIPETRICKE:|The?last}}
2051 -!! result
2052 -<p>Some_other
2053 -%C3%86var_Arnfj%C3%B6r%C3%B0_Bjarmason
2054 -Something_to_do
2055 -The%3Flast_(page)
2056 -</p>
2057 -!! end
2058 -
2059 -
2060 -!! test
20612026 Magic Word: {{REVISIONID}}
20622027 !! input
20632028 {{REVISIONID}}
@@ -3034,48 +2999,6 @@
30353000 !! end
30363001
30373002 !! test
3038 -pre-save transform: context links ("pipe trick") based on current page
3039 -!! options
3040 -pst
3041 -!! input
3042 -[[#section|]]
3043 -[[#section (context)|]]
3044 -[[/relative|]]
3045 -[[../context/relative|]]
3046 -[[../context/relative (extra)|]]
3047 -!! result
3048 -[[#section|section]]
3049 -[[#section (context)|section]]
3050 -[[/relative|relative]]
3051 -[[../context/relative|relative]]
3052 -[[../context/relative (extra)|relative]]
3053 -!! end
3054 -
3055 -!! test
3056 -pre-save transform: context links ("pipe trick") to sections on other pages
3057 -!! options
3058 -pst
3059 -!! input
3060 -[[other#page|]]
3061 -[[Help:Somewhere/completely (wierd)#section (two)|]]
3062 -!! result
3063 -[[other#page|page]]
3064 -[[Help:Somewhere/completely (wierd)#section (two)|section]]
3065 -!! end
3066 -
3067 -!! test
3068 -pre-save transform: context links ("pipe trick") with full-width characters
3069 -!! options
3070 -pst
3071 -!! input
3072 -[[title, context|]]
3073 -[[title (context)|]]
3074 -!! result
3075 -[[title, context|title]]
3076 -[[title (context)|title]]
3077 -!! end
3078 -
3079 -!! test
30803003 pre-save transform: context links ("pipe trick") with interwiki prefix
30813004 !! options
30823005 pst
@@ -3189,66 +3112,7 @@
31903113 [[Ns:Article, Context|Article]]
31913114 !! end
31923115
3193 -!! test
3194 -pre-save transform: context links ("pipe trick") with url escaped page names
3195 -!! options
3196 -pst
3197 -!! input
3198 -[[Hello wo%52ld|]]
3199 -[[Hello wo%52ld (again)|]]
3200 -!! result
3201 -[[Hello wo%52ld|Hello woRld]]
3202 -[[Hello wo%52ld (again)|Hello woRld]]
3203 -!! end
32043116
3205 -!! test
3206 -pre-save transform: context links ("pipe trick") with variables are not pre-empted
3207 -!! options
3208 -pst title=[[Test (page)]]
3209 -!! input
3210 -[[{{{1|}}}|]]
3211 -[[|{{{1|}}}]]
3212 -[[{{subst:PAGENAME}}|]]
3213 -!! result
3214 -[[{{{1|}}}|]]
3215 -[[|{{{1|}}}]]
3216 -[[Test (page)|Test]]
3217 -!! end
3218 -
3219 -!! article
3220 -Template:pipetest
3221 -!! text
3222 -[[{{{1}}}|]]
3223 -!! endarticle
3224 -
3225 -!! article
3226 -Template:testpipe
3227 -!! text
3228 -[[|{{{1}}}]]
3229 -!! endarticle
3230 -
3231 -!! test
3232 -("pipe trick") should work outside PST
3233 -!!options
3234 -title=[[Help:hello (world)]]
3235 -!! input
3236 -{{pipetest|hi (world)}}
3237 -{{pipetest|hi (world), world}}
3238 -{{pipetest|Help:hi (world), world}}
3239 -{{pipetest|:Help:hi (world), world}}
3240 -{{testpipe|hi}}
3241 -[[{{PAGENAME}}|]]
3242 -!! result
3243 -<p><a href="https://www.mediawiki.org/index.php?title=Hi_(world)&amp;action=edit&amp;redlink=1" class="new" title="Hi (world) (page does not exist)">hi</a>
3244 -<a href="https://www.mediawiki.org/index.php?title=Hi_(world),_world&amp;action=edit&amp;redlink=1" class="new" title="Hi (world), world (page does not exist)">hi</a>
3245 -<a href="https://www.mediawiki.org/index.php?title=Help:Hi_(world),_world&amp;action=edit&amp;redlink=1" class="new" title="Help:Hi (world), world (page does not exist)">hi</a>
3246 -<a href="https://www.mediawiki.org/index.php?title=Help:Hi_(world),_world&amp;action=edit&amp;redlink=1" class="new" title="Help:Hi (world), world (page does not exist)">hi</a>
3247 -<a href="https://www.mediawiki.org/index.php?title=Hi_(world)&amp;action=edit&amp;redlink=1" class="new" title="Hi (world) (page does not exist)">hi</a>
3248 -<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>
3249 -</p>
3250 -!! end
3251 -
3252 -
32533117 ###
32543118 ### Message transform tests
32553119 ###
@@ -7745,17 +7609,6 @@
77467610 <a href="https://www.mediawiki.org/wiki/Main_Page#section" title="Main Page">#section</a>
77477611 !! end
77487612
7749 -!! test
7750 -Edit comment with pipe trick
7751 -!! options
7752 -comment
7753 -title=[[Article (context)]]
7754 -!! input
7755 -[[Hello (World)|]] [[|Entry]]
7756 -!! result
7757 -<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>
7758 -!! end
7759 -
77607613 !!article
77617614 MediaWiki:bad image list
77627615 !!text
Index: trunk/phase3/includes/parser/Parser.php
@@ -15,7 +15,7 @@
1616 * (which in turn the browser understands, and can display).
1717 *
1818 * <pre>
19 - * There are six main entry points into the Parser class:
 19+ * There are five main entry points into the Parser class:
2020 * parse()
2121 * produces HTML output
2222 * preSaveTransform().
@@ -26,8 +26,6 @@
2727 * Cleans a signature before saving it to preferences
2828 * extractSections()
2929 * Extracts sections from an article for section editing
30 - * getTransclusionText()
31 - * Extracts the text of a template with only <includeonly>, etc., parsed
3230 *
3331 * Globals used:
3432 * objects: $wgLang, $wgContLang
@@ -84,7 +82,6 @@
8583 const OT_WIKI = 2;
8684 const OT_PREPROCESS = 3;
8785 const OT_MSG = 3;
88 - const OT_INCLUDES = 4;
8986
9087 // Marker Suffix needs to be accessible staticly.
9188 const MARKER_SUFFIX = "-QINU\x7f";
@@ -371,29 +368,24 @@
372369
373370 wfRunHooks( 'ParserBeforeTidy', array( &$this, &$text ) );
374371
375 - if ( $this->mTransparentTagHooks ) {
376 - //!JF Move to its own function
377 - $uniq_prefix = $this->mUniqPrefix;
378 - $matches = array();
379 - $elements = array_keys( $this->mTransparentTagHooks );
380 - $text = self::extractTagsAndParams( $elements, $text, $matches, $uniq_prefix );
 372+//!JF Move to its own function
381373
382 - foreach( $matches as $marker => $data ) {
383 - list( $element, $content, $params, $tag ) = $data;
384 - $tagName = strtolower( $element );
385 - if( isset( $this->mTransparentTagHooks[$tagName] ) ) {
386 - $output = call_user_func_array( $this->mTransparentTagHooks[$tagName],
387 - array( $content, $params, $this ) );
388 - } else {
389 - $output = $tag;
390 - }
391 - $this->mStripState->general->setPair( $marker, $output );
 374+ $uniq_prefix = $this->mUniqPrefix;
 375+ $matches = array();
 376+ $elements = array_keys( $this->mTransparentTagHooks );
 377+ $text = self::extractTagsAndParams( $elements, $text, $matches, $uniq_prefix );
 378+
 379+ foreach( $matches as $marker => $data ) {
 380+ list( $element, $content, $params, $tag ) = $data;
 381+ $tagName = strtolower( $element );
 382+ if( isset( $this->mTransparentTagHooks[$tagName] ) ) {
 383+ $output = call_user_func_array( $this->mTransparentTagHooks[$tagName],
 384+ array( $content, $params, $this ) );
 385+ } else {
 386+ $output = $tag;
392387 }
 388+ $this->mStripState->general->setPair( $marker, $output );
393389 }
394 -
395 - # This was originally inserted for transparent tag hooks (now deprecated)
396 - # but some extensions (notably <poem>) rely on the extra unstripGeneral()
397 - # after unstripNoWiki() so they can modify the contents of <nowiki> tags.
398390 $text = $this->mStripState->unstripGeneral( $text );
399391
400392 $text = Sanitizer::normalizeCharReferences( $text );
@@ -498,26 +490,6 @@
499491 }
500492
501493 /**
502 - * Get the wikitext of a page as though it was transcluded.
503 - *
504 - * Specifically <includeonly> etc. are parsed, redirects are followed, comments
505 - * are removed, but templates arguments and parser functions are untouched.
506 - *
507 - * This is not called by the parser itself, see braceSubstitution for its transclusion.
508 - */
509 - public function getTransclusionText( $title, $options ) {
510 - // Must initialize first
511 - $this->clearState();
512 - $this->setOutputType( self::OT_INCLUDES );
513 - $this->mOptions = $options;
514 - $this->setTitle( new FakeTitle );
515 -
516 - list( $text, $title ) = $this->getTemplateDom( $title );
517 - $flags = PPFrame::NO_ARGS | PPFrame::NO_TEMPLATES;
518 - return $this->getPreprocessor()->newFrame()->expand( $text, $flags );
519 - }
520 -
521 - /**
522494 * Get a random string
523495 *
524496 * @private
@@ -1522,7 +1494,7 @@
15231495 if ( !$tc ) {
15241496 $tc = Title::legalChars() . '#%';
15251497 # Match a link having the form [[namespace:link|alternate]]trail
1526 - $e1 = "/^([{$tc}]*)(\\|.*?)?]](.*)\$/sD";
 1498+ $e1 = "/^([{$tc}]+)(?:\\|(.+?))?]](.*)\$/sD";
15271499 # Match cases where there is no "]]", which might still be images
15281500 $e1_img = "/^([{$tc}]+)\\|(.*)\$/sD";
15291501 }
@@ -1602,15 +1574,7 @@
16031575
16041576 wfProfileIn( __METHOD__."-e1" );
16051577 if ( preg_match( $e1, $line, $m ) ) { # page with normal text or alt
1606 -
1607 - if( $m[2] === '' ) {
1608 - $text = '';
1609 - } elseif( $m[2] === '|' ) {
1610 - $text = $this->getPipeTrickText( $m[1] );
1611 - } else {
1612 - $text = substr( $m[2], 1 );
1613 - }
1614 -
 1578+ $text = $m[2];
16151579 # If we get a ] at the beginning of $m[3] that means we have a link that's something like:
16161580 # [[Image:Foo.jpg|[http://example.com desc]]] <- having three ] in a row fucks up,
16171581 # the real problem is with the $e1 regex
@@ -1627,20 +1591,18 @@
16281592 $text .= ']'; # so that replaceExternalLinks($text) works later
16291593 $m[3] = substr( $m[3], 1 );
16301594 }
1631 -
1632 - # Handle pipe-trick for [[|<blah>]]
1633 - $lnk = $m[1] === '' ? $this->getPipeTrickLink( $text ) : $m[1];
16341595 # fix up urlencoded title texts
1635 - if( strpos( $lnk, '%' ) !== false ) {
 1596+ if( strpos( $m[1], '%' ) !== false ) {
16361597 # Should anchors '#' also be rejected?
1637 - $lnk = str_replace( array('<', '>'), array('&lt;', '&gt;'), urldecode($lnk) );
 1598+ $m[1] = str_replace( array('<', '>'), array('&lt;', '&gt;'), urldecode($m[1]) );
16381599 }
1639 -
16401600 $trail = $m[3];
16411601 } elseif( preg_match($e1_img, $line, $m) ) { # Invalid, but might be an image with a link in its caption
16421602 $might_be_img = true;
16431603 $text = $m[2];
1644 - $lnk = strpos( $m[1], '%' ) === false ? $m[1] : urldecode( $m[1] );
 1604+ if ( strpos( $m[1], '%' ) !== false ) {
 1605+ $m[1] = urldecode($m[1]);
 1606+ }
16451607 $trail = "";
16461608 } else { # Invalid form; output directly
16471609 $s .= $prefix . '[[' . $line ;
@@ -1653,7 +1615,7 @@
16541616 # Don't allow internal links to pages containing
16551617 # PROTO: where PROTO is a valid URL protocol; these
16561618 # should be external links.
1657 - if ( preg_match( '/^\b(?:' . wfUrlProtocols() . ')/', $lnk ) ) {
 1619+ if ( preg_match( '/^\b(?:' . wfUrlProtocols() . ')/', $m[1] ) ) {
16581620 $s .= $prefix . '[[' . $line ;
16591621 wfProfileOut( __METHOD__."-misc" );
16601622 continue;
@@ -1661,12 +1623,12 @@
16621624
16631625 # Make subpage if necessary
16641626 if ( $useSubpages ) {
1665 - $link = $this->maybeDoSubpageLink( $lnk, $text );
 1627+ $link = $this->maybeDoSubpageLink( $m[1], $text );
16661628 } else {
1667 - $link = $lnk;
 1629+ $link = $m[1];
16681630 }
16691631
1670 - $noforce = (substr( $lnk, 0, 1 ) !== ':');
 1632+ $noforce = (substr( $m[1], 0, 1 ) !== ':');
16711633 if (!$noforce) {
16721634 # Strip off leading ':'
16731635 $link = substr( $link, 1 );
@@ -1914,25 +1876,6 @@
19151877 return Linker::normalizeSubpageLink( $this->mTitle, $target, $text );
19161878 }
19171879
1918 - /**
1919 - * From the [[title|]] return link-text as though the used typed [[title|link-text]]
1920 - * @param string $link from [[$link|]]
1921 - * @return string $text for [[$link|$text]]
1922 - */
1923 - function getPipeTrickText( $link ) {
1924 - return Linker::getPipeTrickText( $link );
1925 - }
1926 -
1927 - /**
1928 - * From the [[|link-text]] return the title as though the user typed [[title|link-text]]
1929 - * @param string $text from [[|$text]]
1930 - * @param Title $title to resolve the link against
1931 - * @return string $link for [[$link|$text]]
1932 - */
1933 - function getPipeTrickLink( $text ) {
1934 - return Linker::getPipeTrickLink( $text, $this->mTitle );
1935 - }
1936 -
19371880 /**#@+
19381881 * Used by doBlockLevels()
19391882 * @private
@@ -2495,14 +2438,6 @@
24962439 $subjPage = $this->mTitle->getSubjectPage();
24972440 $value = $subjPage->getPrefixedUrl();
24982441 break;
2499 - case 'pipetrick':
2500 - $text = $this->mTitle->getText();
2501 - $value = $this->getPipeTrickText( $text );
2502 - break;
2503 - case 'pipetricke':
2504 - $text = $this->mTitle->getText();
2505 - $value = wfUrlEncode( str_replace( ' ', '_', $this->getPipeTrickText( $text ) ) );
2506 - break;
25072442 case 'revisionid':
25082443 // Let the edit saving system know we should parse the page
25092444 // *after* a revision ID has been assigned.
@@ -4045,12 +3980,33 @@
40463981 '~~~' => $sigText
40473982 ) );
40483983
4049 - # Links of the form [[|<blah>]] or [[<blah>|]] perform pipe tricks
4050 - # Note this only allows the # in the position it works.
 3984+ # Context links: [[|name]] and [[name (context)|]]
 3985+ #
40513986 global $wgLegalTitleChars;
4052 - $pipeTrickRe = "/\[\[(?:(\\|)([$wgLegalTitleChars]+)|([#$wgLegalTitleChars]+)\\|)\]\]/";
4053 - $text = preg_replace_callback( $pipeTrickRe, array( $this, 'pstPipeTrickCallback' ), $text );
 3987+ $tc = "[$wgLegalTitleChars]";
 3988+ $nc = '[ _0-9A-Za-z\x80-\xff-]'; # Namespaces can use non-ascii!
40543989
 3990+ $p1 = "/\[\[(:?$nc+:|:|)($tc+?)( \\($tc+\\))\\|]]/"; # [[ns:page (context)|]]
 3991+ $p4 = "/\[\[(:?$nc+:|:|)($tc+?)(($tc+))\\|]]/"; # [[ns:page(context)|]]
 3992+ $p3 = "/\[\[(:?$nc+:|:|)($tc+?)( \\($tc+\\)|)(, $tc+|)\\|]]/"; # [[ns:page (context), context|]]
 3993+ $p2 = "/\[\[\\|($tc+)]]/"; # [[|page]]
 3994+
 3995+ # try $p1 first, to turn "[[A, B (C)|]]" into "[[A, B (C)|A, B]]"
 3996+ $text = preg_replace( $p1, '[[\\1\\2\\3|\\2]]', $text );
 3997+ $text = preg_replace( $p4, '[[\\1\\2\\3|\\2]]', $text );
 3998+ $text = preg_replace( $p3, '[[\\1\\2\\3\\4|\\2]]', $text );
 3999+
 4000+ $t = $this->mTitle->getText();
 4001+ $m = array();
 4002+ if ( preg_match( "/^($nc+:|)$tc+?( \\($tc+\\))$/", $t, $m ) ) {
 4003+ $text = preg_replace( $p2, "[[$m[1]\\1$m[2]|\\1]]", $text );
 4004+ } elseif ( preg_match( "/^($nc+:|)$tc+?(, $tc+|)$/", $t, $m ) && "$m[1]$m[2]" != '' ) {
 4005+ $text = preg_replace( $p2, "[[$m[1]\\1$m[2]|\\1]]", $text );
 4006+ } else {
 4007+ # if there's no context, don't bother duplicating the title
 4008+ $text = preg_replace( $p2, '[[\\1]]', $text );
 4009+ }
 4010+
40554011 # Trim trailing whitespace
40564012 $text = rtrim( $text );
40574013
@@ -4058,25 +4014,6 @@
40594015 }
40604016
40614017 /**
4062 - * Called from pstPass2 to perform the pipe trick on links.
4063 - * Original was either [[|text]] or [[link|]]
4064 - *
4065 - * @param Array ("|" or "", text, link) $m
4066 - */
4067 - function pstPipeTrickCallback( $m )
4068 - {
4069 - if( $m[1] ) { # [[|<blah>]]
4070 - $text = $m[2];
4071 - $link = $this->getPipeTrickLink( $text );
4072 - } else { # [[<blah>|]]
4073 - $link = $m[3];
4074 - $text = $this->getPipeTrickText( $link );
4075 - }
4076 -
4077 - return $link === $text ? "[[$link]]" : "[[$link|$text]]";
4078 - }
4079 -
4080 - /**
40814018 * Fetch the user's signature text, if any, and normalize to
40824019 * validated, ready-to-insert wikitext.
40834020 * If you have pre-fetched the nickname or the fancySig option, you can
@@ -4256,9 +4193,7 @@
42574194 return $oldVal;
42584195 }
42594196
4260 - /* An old work-around for bug 2257 - deprecated 2010-02-13 */
42614197 function setTransparentTagHook( $tag, $callback ) {
4262 - wfDeprecated( __METHOD__ );
42634198 $tag = strtolower( $tag );
42644199 $oldVal = isset( $this->mTransparentTagHooks[$tag] ) ? $this->mTransparentTagHooks[$tag] : null;
42654200 $this->mTransparentTagHooks[$tag] = $callback;
Index: trunk/phase3/includes/parser/CoreParserFunctions.php
@@ -67,8 +67,6 @@
6868 $parser->setFunctionHook( 'talkpagenamee', array( __CLASS__, 'talkpagenamee' ), SFH_NO_HASH );
6969 $parser->setFunctionHook( 'subjectpagename', array( __CLASS__, 'subjectpagename' ), SFH_NO_HASH );
7070 $parser->setFunctionHook( 'subjectpagenamee', array( __CLASS__, 'subjectpagenamee' ), SFH_NO_HASH );
71 - $parser->setFunctionHook( 'pipetrick', array( __CLASS__, 'pipetrick' ), SFH_NO_HASH );
72 - $parser->setFunctionHook( 'pipetricke', array( __CLASS__, 'pipetricke' ), SFH_NO_HASH );
7371 $parser->setFunctionHook( 'tag', array( __CLASS__, 'tagObj' ), SFH_OBJECT_ARGS );
7472 $parser->setFunctionHook( 'formatdate', array( __CLASS__, 'formatDate' ) );
7573
@@ -442,27 +440,6 @@
443441 }
444442
445443 /**
446 - * Performs the pipe trick in the same manner as [[title|]] or [[|title]].
447 - * {{#pipetrick:title}} == {{#pipetrick:title|}} -> Parser::getPipeTrickText
448 - * {{#pipetrick:|title}} -> Parser::getPipeTrickLink (rarer)
449 - * See http://en.wikipedia.org/wiki/Help:Pipe_trick and the Parser documentation
450 - * for more information.
451 - */
452 - static function pipetrick( $parser, $link = '', $text = '' ) {
453 - if ( $link )
454 - return $parser->getPipeTrickText( $link );
455 - else
456 - return $parser->getPipeTrickLink( $text );
457 - }
458 -
459 - /**
460 - * Performs the pipetrick and then url encodes the result
461 - */
462 - static function pipetricke( $parser, $link = '', $text = '' ) {
463 - return wfUrlEncode( str_replace( ' ', '_', self::pipetrick( $parser, $link, $text ) ) );
464 - }
465 -
466 - /**
467444 * Return the number of pages in the given category, or 0 if it's nonexis-
468445 * tent. This is an expensive parser function and can't be called too many
469446 * times per page.
Index: trunk/phase3/includes/Linker.php
@@ -1086,11 +1086,6 @@
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] );
10951090 } else {
10961091 $text = $match[1];
10971092 }
@@ -1211,79 +1206,6 @@
12121207 }
12131208
12141209 /**
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 - /**
12881210 * Wrap a comment in standard punctuation and formatting if
12891211 * it's non-empty, otherwise return empty string.
12901212 *
Index: trunk/phase3/includes/EditPage.php
@@ -227,13 +227,22 @@
228228 * @return string The contents of the page.
229229 */
230230 protected function getPreloadedText( $preload ) {
231 - global $wgParser, $wgUser;
232231 if ( !empty( $this->mPreloadText ) ) {
233232 return $this->mPreloadText;
 233+ } elseif ( $preload === '' ) {
 234+ return '';
234235 } else {
235236 $preloadTitle = Title::newFromText( $preload );
236237 if ( isset( $preloadTitle ) && $preloadTitle->userCanRead() ) {
237 - return $wgParser->getTransclusionText( $preloadTitle, ParserOptions::newFromUser( $wgUser ) );
 238+ $rev = Revision::newFromTitle( $preloadTitle );
 239+ if ( is_object( $rev ) ) {
 240+ $text = $rev->getText();
 241+ // TODO FIXME: AAAAAAAAAAA, this shouldn't be implementing
 242+ // its own mini-parser! -ævar
 243+ $text = preg_replace( '~</?includeonly>~', '', $text );
 244+ return $text;
 245+ } else
 246+ return '';
238247 }
239248 }
240249 }
Index: trunk/phase3/includes/MagicWord.php
@@ -84,8 +84,6 @@
8585 'revisionuser',
8686 'subpagename',
8787 'subpagenamee',
88 - 'pipetrick',
89 - 'pipetricke',
9088 'talkspace',
9189 'talkspacee',
9290 'subjectspace',
Index: trunk/phase3/languages/messages/MessagesEn.php
@@ -263,8 +263,6 @@
264264 'talkpagenamee' => array( 1, 'TALKPAGENAMEE' ),
265265 'subjectpagename' => array( 1, 'SUBJECTPAGENAME', 'ARTICLEPAGENAME' ),
266266 'subjectpagenamee' => array( 1, 'SUBJECTPAGENAMEE', 'ARTICLEPAGENAMEE' ),
267 - 'pipetrick' => array( 1, 'PIPETRICK' ),
268 - 'pipetricke' => array( 1, 'PIPETRICKE' ),
269267 'msg' => array( 0, 'MSG:' ),
270268 'subst' => array( 0, 'SUBST:' ),
271269 'safesubst' => array( 0, 'SAFESUBST:' ),
Index: trunk/phase3/RELEASE-NOTES
@@ -321,12 +321,6 @@
322322 maintenance/tests/.
323323 * importImages.php maintenance script can now use the original uploader and
324324 comment from another wiki.
325 -* (bug 845) [[#foo|]], [[/bar|]] should be equivalent to [[#foo|foo]],
326 - [[/bar|bar]] (new use of "pipe trick")
327 -* (bug 21660) Support full-width commas for pipe trick
328 -* (bug 7264) Magic word to give Page Title as if pipe-trick performed on it
329 - {{pipetrick:}}
330 -* (bug 20339) Allow using the pipe trick in log reasons
331325 * Support for Turck MMCache was removed
332326
333327 === Bug fixes in 1.16 ===
@@ -756,10 +750,6 @@
757751 as it appears in extensions as was the case before r30117 where it
758752 was unintentionally sorted along with other fields.
759753 * (bug 19334) Textarea no longer jumps when editing longer articles in IE8
760 -* (bug 5210) preload parser should parse <noinclude> (as well as <includeonly>)
761 -* (bug 8785) Pipe trick should work with colon functions
762 -* (bug 4099) Pipe trick doesn't work when emptiness is only provided by empty
763 - template parameter
764754 * Truncate summary of page moves in revision comment field to avoid broken
765755 multibyte characters
766756 * (bug 22540) ForeignApiRepos no longer try to store thumbnails that don't exist

Follow-up revisions

RevisionCommit summaryAuthorDate
r62690Reverted the extension part of r62416, core part was reverted in r62689.tstarling05:21, 19 February 2010
r62693Local changes, by reverse-merging r62689.tstarling05:29, 19 February 2010

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r62035bug 5210 - add getTransclusionText() to the Parser to remove the horrible (and...conrad16:49, 5 February 2010
r62049style fixes for r62035conrad21:52, 5 February 2010
r62069Allow pipe trick to work after PST....conrad15:00, 6 February 2010
r62076Update Pipe Trick semantics per bug 845 and bug 21660...conrad02:15, 7 February 2010
r62077Bug 7264 - Magic word to give Page Title as if pipe-trick performed on it {{...conrad02:36, 7 February 2010
r62080Initialize parser properly in getTransclusionText()conrad11:59, 7 February 2010
r62081Fixes for r62077...conrad13:17, 7 February 2010
r62085Fix bug 20339 allow pipe-trick in log reasons...conrad14:50, 7 February 2010
r62111partial revert for r62081. Make {{PIPETRICK}} like {{PAGENAME}}, add {{PIPETR...conrad02:07, 8 February 2010
r62150More sensible semantics for pipe trick with section links after r62076...conrad01:05, 9 February 2010
r62416Deprecate old undocumented workaround to bug 2257 (setTransparentTagHook)conrad02:22, 13 February 2010
r62434Fix for <poem> after r62416conrad14:41, 13 February 2010

Status & tagging log