Moving Conrad's recent parser work out to a branch. Reverted r62434, r62416, r62150...
authorTim Starling <tstarling@users.mediawiki.org>
Fri, 19 Feb 2010 05:19:32 +0000 (05:19 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Fri, 19 Feb 2010 05:19:32 +0000 (05:19 +0000)
RELEASE-NOTES
includes/EditPage.php
includes/Linker.php
includes/MagicWord.php
includes/parser/CoreParserFunctions.php
includes/parser/Parser.php
languages/messages/MessagesEn.php
maintenance/parserTests.txt

index 738466e..4dab4c5 100644 (file)
@@ -321,12 +321,6 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
   maintenance/tests/.
 * importImages.php maintenance script can now use the original uploader and 
 comment from another wiki.
   maintenance/tests/.
 * importImages.php maintenance script can now use the original uploader and 
 comment from another wiki.
-* (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
-* (bug 7264)  Magic word to give Page Title as if pipe-trick performed on it
-  {{pipetrick:}}
-* (bug 20339) Allow using the pipe trick in log reasons
 * Support for Turck MMCache was removed
 
 === Bug fixes in 1.16 ===
 * Support for Turck MMCache was removed
 
 === Bug fixes in 1.16 ===
@@ -756,10 +750,6 @@ comment from another wiki.
   as it appears in extensions as was the case before r30117 where it
   was unintentionally sorted along with other fields.
 * (bug 19334) Textarea no longer jumps when editing longer articles in IE8
   as it appears in extensions as was the case before r30117 where it
   was unintentionally sorted along with other fields.
 * (bug 19334) Textarea no longer jumps when editing longer articles in IE8
-* (bug 5210)  preload parser should parse <noinclude> (as well as <includeonly>)
-* (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
 * Truncate summary of page moves in revision comment field to avoid broken
   multibyte characters
 * (bug 22540) ForeignApiRepos no longer try to store thumbnails that don't exist
 * Truncate summary of page moves in revision comment field to avoid broken
   multibyte characters
 * (bug 22540) ForeignApiRepos no longer try to store thumbnails that don't exist
index a6a69a8..2d9c2ff 100644 (file)
@@ -227,13 +227,22 @@ class EditPage {
         * @return string The contents of the page.
         */
        protected function getPreloadedText( $preload ) {
         * @return string The contents of the page.
         */
        protected function getPreloadedText( $preload ) {
-               global $wgParser, $wgUser;
                if ( !empty( $this->mPreloadText ) ) {
                        return $this->mPreloadText;
                if ( !empty( $this->mPreloadText ) ) {
                        return $this->mPreloadText;
+               } elseif ( $preload === '' ) {
+                       return '';
                } else {
                        $preloadTitle = Title::newFromText( $preload );
                        if ( isset( $preloadTitle ) && $preloadTitle->userCanRead() ) {
                } else {
                        $preloadTitle = Title::newFromText( $preload );
                        if ( isset( $preloadTitle ) && $preloadTitle->userCanRead() ) {
-                               return $wgParser->getTransclusionText( $preloadTitle, ParserOptions::newFromUser( $wgUser ) );
+                               $rev = Revision::newFromTitle( $preloadTitle );
+                               if ( is_object( $rev ) ) {
+                                       $text = $rev->getText();
+                                       // TODO FIXME: AAAAAAAAAAA, this shouldn't be implementing
+                                       // its own mini-parser! -ævar
+                                       $text = preg_replace( '~</?includeonly>~', '', $text );
+                                       return $text;
+                               } else
+                                       return '';
                        }
                }
        }
                        }
                }
        }
index fe2ffa5..c049f47 100644 (file)
@@ -1086,11 +1086,6 @@ class Linker {
                # Handle link renaming [[foo|text]] will show link as "text"
                if( $match[3] != "" ) {
                        $text = $match[3];
                # Handle link renaming [[foo|text]] will show link as "text"
                if( $match[3] != "" ) {
                        $text = $match[3];
-                       if( $match[1] === "" && $this->commentContextTitle ) {
-                               $match[1] = Linker::getPipeTrickLink( $text, $this->commentContextTitle );
-                       }
-               } elseif( $match[2] == "|" ) {
-                       $text = Linker::getPipeTrickText( $match[1] );
                } else {
                        $text = $match[1];
                }
                } else {
                        $text = $match[1];
                }
@@ -1210,79 +1205,6 @@ class Linker {
                return $ret;
        }
 
                return $ret;
        }
 
-       /**
-        * Returns valid title characters and namespace characters for pipe trick.
-        *
-        * FIXME: the namespace characters should not be specified like this...
-        */
-       static function getPipeTrickCharacterClasses() {
-               global $wgLegalTitleChars;
-               return  array( "[$wgLegalTitleChars]", '[ _0-9A-Za-z\x80-\xff-]' );
-       }
-
-       /**
-        * 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|]]
-        * [[#title (context)|]] [[../context/title (context), context|]]
-        * all return the |title]] with no context or indicative punctuation.
-        *
-        * @param string $link from [[$link|]]
-        * @return string $text for [[$link|$text]]
-        */
-       static function getPipeTrickText( $link ) {
-               static $rexps = FALSE;
-               if( !$rexps ) {
-                       list( $tc, $nc ) = Linker::getPipeTrickCharacterClasses();
-                       $rexps = array (
-                               # try this first, to turn "[[A, B (C)|]]" into "A, B"
-                               "/^(:?$nc+:|[:#\/]|$tc+[\\/#]|)($tc+?)( \\($tc+\\)| ($tc+))$/", # [[ns:page (context)|]]
-                               "/^(:?$nc+:|[:#\/]|$tc+[\\/#]|)($tc+?)( \\($tc+\\)| ($tc+)|)((?:,|,) $tc+|)$/",  # [[ns:page (context), context|]]
-                       );  
-               }
-               $text = urldecode( $link );
-
-               for( $i = 0; $i < count( $rexps ); $i++) {
-                       if( preg_match( $rexps[$i], $text, $m ) ) 
-                               return $m[2];
-               }
-               return $text;
-       }
-
-       /**
-        * From the [[|link-text]] return the title as though the user typed [[title|link-text]]
-        *
-        * On most pages this will return link-text or "" if the link-text is not a valid title
-        * On pages like [[ns:title (context)]] and [[ns:title, context]] it will act like
-        * [[ns:link-text (context)|link-text]] and [[ns:link-text, context|link-text]]
-        *
-        * @param string $text from [[|$text]]
-        * @param Title $title to resolve the link against
-        * @return string $link for [[$link|$text]]
-        */
-       static function getPipeTrickLink( $text, $title ) {
-               static $rexps = FALSE, $tc;
-               if( !$rexps ) {
-                       list( $tc, $nc ) = Linker::getPipeTrickCharacterClasses();
-                       $rexps = array (
-                               "/^($nc+:|)$tc+?( \\($tc+\\)| ($tc+))$/", # [[ns:page (context)|]]
-                               "/^($nc+:|)$tc+?(?:(?: \\($tc+\\)| ($tc+)|)((?:,|,) $tc+|))$/"  # [[ns:page (context), context|]]
-                       );
-               }
-
-               if( !preg_match( "/^$tc+$/", $text ) )
-                       return '';
-
-               $t = $title->getText();
-
-               for( $i = 0; $i < count( $rexps ); $i++) {
-                       if( preg_match( $rexps[$i], $t, $m ) )
-                               return "$m[1]$text$m[2]";
-               }
-               return $text;
-       }
-
        /**
         * Wrap a comment in standard punctuation and formatting if
         * it's non-empty, otherwise return empty string.
        /**
         * Wrap a comment in standard punctuation and formatting if
         * it's non-empty, otherwise return empty string.
index fe30215..ecbdf81 100644 (file)
@@ -84,8 +84,6 @@ class MagicWord {
                'revisionuser',
                'subpagename',
                'subpagenamee',
                'revisionuser',
                'subpagename',
                'subpagenamee',
-               'pipetrick',
-               'pipetricke',
                'talkspace',
                'talkspacee',
                'subjectspace',
                'talkspace',
                'talkspacee',
                'subjectspace',
index affc3e4..8abcc04 100644 (file)
@@ -67,8 +67,6 @@ class CoreParserFunctions {
                $parser->setFunctionHook( 'talkpagenamee',    array( __CLASS__, 'talkpagenamee'    ), SFH_NO_HASH );
                $parser->setFunctionHook( 'subjectpagename',  array( __CLASS__, 'subjectpagename'  ), SFH_NO_HASH );
                $parser->setFunctionHook( 'subjectpagenamee', array( __CLASS__, 'subjectpagenamee' ), SFH_NO_HASH );
                $parser->setFunctionHook( 'talkpagenamee',    array( __CLASS__, 'talkpagenamee'    ), SFH_NO_HASH );
                $parser->setFunctionHook( 'subjectpagename',  array( __CLASS__, 'subjectpagename'  ), SFH_NO_HASH );
                $parser->setFunctionHook( 'subjectpagenamee', array( __CLASS__, 'subjectpagenamee' ), SFH_NO_HASH );
-               $parser->setFunctionHook( 'pipetrick',        array( __CLASS__, 'pipetrick'        ), SFH_NO_HASH );
-               $parser->setFunctionHook( 'pipetricke',       array( __CLASS__, 'pipetricke'       ), SFH_NO_HASH );
                $parser->setFunctionHook( 'tag',              array( __CLASS__, 'tagObj'           ), SFH_OBJECT_ARGS );
                $parser->setFunctionHook( 'formatdate',       array( __CLASS__, 'formatDate'       ) );
 
                $parser->setFunctionHook( 'tag',              array( __CLASS__, 'tagObj'           ), SFH_OBJECT_ARGS );
                $parser->setFunctionHook( 'formatdate',       array( __CLASS__, 'formatDate'       ) );
 
@@ -441,27 +439,6 @@ class CoreParserFunctions {
                return $t->getSubjectPage()->getPrefixedUrl();
        }
 
                return $t->getSubjectPage()->getPrefixedUrl();
        }
 
-       /**
-        * Performs the pipe trick in the same manner as [[title|]] or [[|title]].
-        * {{#pipetrick:title}} == {{#pipetrick:title|}} -> Parser::getPipeTrickText
-        * {{#pipetrick:|title}} -> Parser::getPipeTrickLink (rarer)
-        * See http://en.wikipedia.org/wiki/Help:Pipe_trick and the Parser documentation
-        * for more information.
-        */
-       static function pipetrick( $parser, $link = '', $text = '' ) {
-               if ( $link )
-                       return $parser->getPipeTrickText( $link );
-               else
-                       return $parser->getPipeTrickLink( $text );
-       }
-
-       /**
-        * Performs the pipetrick and then url encodes the result
-        */
-       static function pipetricke( $parser, $link = '', $text = '' ) {
-               return wfUrlEncode( str_replace( ' ', '_', self::pipetrick( $parser, $link, $text ) ) );
-       }
-
        /**
         * Return the number of pages in the given category, or 0 if it's nonexis-
         * tent.  This is an expensive parser function and can't be called too many
        /**
         * Return the number of pages in the given category, or 0 if it's nonexis-
         * tent.  This is an expensive parser function and can't be called too many
index 298aa3d..f7bb478 100644 (file)
@@ -15,7 +15,7 @@
  * (which in turn the browser understands, and can display).
  *
  * <pre>
  * (which in turn the browser understands, and can display).
  *
  * <pre>
- * There are six main entry points into the Parser class:
+ * There are five main entry points into the Parser class:
  * parse()
  *   produces HTML output
  * preSaveTransform().
  * parse()
  *   produces HTML output
  * preSaveTransform().
@@ -26,8 +26,6 @@
  *   Cleans a signature before saving it to preferences
  * extractSections()
  *   Extracts sections from an article for section editing
  *   Cleans a signature before saving it to preferences
  * extractSections()
  *   Extracts sections from an article for section editing
- * getTransclusionText()
- *   Extracts the text of a template with only <includeonly>, etc., parsed
  *
  * Globals used:
  *    objects:   $wgLang, $wgContLang
  *
  * Globals used:
  *    objects:   $wgLang, $wgContLang
@@ -84,7 +82,6 @@ class Parser
        const OT_WIKI = 2;
        const OT_PREPROCESS = 3;
        const OT_MSG = 3;
        const OT_WIKI = 2;
        const OT_PREPROCESS = 3;
        const OT_MSG = 3;
-       const OT_INCLUDES = 4;
 
        // Marker Suffix needs to be accessible staticly.
        const MARKER_SUFFIX = "-QINU\x7f";
 
        // Marker Suffix needs to be accessible staticly.
        const MARKER_SUFFIX = "-QINU\x7f";
@@ -371,29 +368,24 @@ class Parser
 
                wfRunHooks( 'ParserBeforeTidy', array( &$this, &$text ) );
 
 
                wfRunHooks( 'ParserBeforeTidy', array( &$this, &$text ) );
 
-               if ( $this->mTransparentTagHooks ) {
-                       //!JF Move to its own function
-                       $uniq_prefix = $this->mUniqPrefix;
-                       $matches = array();
-                       $elements = array_keys( $this->mTransparentTagHooks );
-                       $text = self::extractTagsAndParams( $elements, $text, $matches, $uniq_prefix );
-
-                       foreach( $matches as $marker => $data ) {
-                               list( $element, $content, $params, $tag ) = $data;
-                               $tagName = strtolower( $element );
-                               if( isset( $this->mTransparentTagHooks[$tagName] ) ) {
-                                       $output = call_user_func_array( $this->mTransparentTagHooks[$tagName],
-                                               array( $content, $params, $this ) );
-                               } else {
-                                       $output = $tag;
-                               }
-                               $this->mStripState->general->setPair( $marker, $output );
+//!JF Move to its own function
+
+               $uniq_prefix = $this->mUniqPrefix;
+               $matches = array();
+               $elements = array_keys( $this->mTransparentTagHooks );
+               $text = self::extractTagsAndParams( $elements, $text, $matches, $uniq_prefix );
+
+               foreach( $matches as $marker => $data ) {
+                       list( $element, $content, $params, $tag ) = $data;
+                       $tagName = strtolower( $element );
+                       if( isset( $this->mTransparentTagHooks[$tagName] ) ) {
+                               $output = call_user_func_array( $this->mTransparentTagHooks[$tagName],
+                                       array( $content, $params, $this ) );
+                       } else {
+                               $output = $tag;
                        }
                        }
+                       $this->mStripState->general->setPair( $marker, $output );
                }
                }
-
-               # This was originally inserted for transparent tag hooks (now deprecated)
-               # but some extensions (notably <poem>) rely on the extra unstripGeneral()
-               # after unstripNoWiki() so they can modify the contents of <nowiki> tags.
                $text = $this->mStripState->unstripGeneral( $text );
 
                $text = Sanitizer::normalizeCharReferences( $text );
                $text = $this->mStripState->unstripGeneral( $text );
 
                $text = Sanitizer::normalizeCharReferences( $text );
@@ -497,26 +489,6 @@ class Parser
                return $text;
        }
 
                return $text;
        }
 
-       /**
-        * Get the wikitext of a page as though it was transcluded.
-        *
-        * Specifically <includeonly> etc. are parsed, redirects are followed, comments
-        * are removed, but templates arguments and parser functions are untouched.
-        *
-        * This is not called by the parser itself, see braceSubstitution for its transclusion. 
-        */
-       public function getTransclusionText( $title, $options ) {
-               // Must initialize first
-               $this->clearState();
-               $this->setOutputType( self::OT_INCLUDES );
-               $this->mOptions = $options;
-               $this->setTitle( new FakeTitle ); 
-
-               list( $text, $title ) = $this->getTemplateDom( $title );
-               $flags = PPFrame::NO_ARGS | PPFrame::NO_TEMPLATES;
-               return $this->getPreprocessor()->newFrame()->expand( $text, $flags );
-       }
-
        /**
         * Get a random string
         *
        /**
         * Get a random string
         *
@@ -1522,7 +1494,7 @@ class Parser
                if ( !$tc ) {
                        $tc = Title::legalChars() . '#%';
                        # Match a link having the form [[namespace:link|alternate]]trail
                if ( !$tc ) {
                        $tc = Title::legalChars() . '#%';
                        # Match a link having the form [[namespace:link|alternate]]trail
-                       $e1 = "/^([{$tc}]*)(\\|.*?)?]](.*)\$/sD";
+                       $e1 = "/^([{$tc}]+)(?:\\|(.+?))?]](.*)\$/sD";
                        # Match cases where there is no "]]", which might still be images
                        $e1_img = "/^([{$tc}]+)\\|(.*)\$/sD";
                }
                        # Match cases where there is no "]]", which might still be images
                        $e1_img = "/^([{$tc}]+)\\|(.*)\$/sD";
                }
@@ -1602,15 +1574,7 @@ class Parser
 
                        wfProfileIn( __METHOD__."-e1" );
                        if ( preg_match( $e1, $line, $m ) ) { # page with normal text or alt
 
                        wfProfileIn( __METHOD__."-e1" );
                        if ( preg_match( $e1, $line, $m ) ) { # page with normal text or alt
-
-                               if( $m[2] === '' ) {
-                                       $text = '';
-                               } elseif( $m[2] === '|' ) { 
-                                       $text = $this->getPipeTrickText( $m[1] );
-                               } else {
-                                       $text = substr( $m[2], 1 );
-                               }
-
+                               $text = $m[2];
                                # If we get a ] at the beginning of $m[3] that means we have a link that's something like:
                                # [[Image:Foo.jpg|[http://example.com desc]]] <- having three ] in a row fucks up,
                                # the real problem is with the $e1 regex
                                # If we get a ] at the beginning of $m[3] that means we have a link that's something like:
                                # [[Image:Foo.jpg|[http://example.com desc]]] <- having three ] in a row fucks up,
                                # the real problem is with the $e1 regex
@@ -1627,20 +1591,18 @@ class Parser
                                        $text .= ']'; # so that replaceExternalLinks($text) works later
                                        $m[3] = substr( $m[3], 1 );
                                }
                                        $text .= ']'; # so that replaceExternalLinks($text) works later
                                        $m[3] = substr( $m[3], 1 );
                                }
-
-                               # Handle pipe-trick for [[|<blah>]]
-                               $lnk = $m[1] === '' ? $this->getPipeTrickLink( $text ) : $m[1];
                                # fix up urlencoded title texts
                                # fix up urlencoded title texts
-                               if( strpos( $lnk, '%' ) !== false ) {
+                               if( strpos( $m[1], '%' ) !== false ) {
                                        # Should anchors '#' also be rejected?
                                        # Should anchors '#' also be rejected?
-                                       $lnk = str_replace( array('<', '>'), array('&lt;', '&gt;'), urldecode($lnk) );
+                                       $m[1] = str_replace( array('<', '>'), array('&lt;', '&gt;'), urldecode($m[1]) );
                                }
                                }
-
                                $trail = $m[3];
                        } elseif( preg_match($e1_img, $line, $m) ) { # Invalid, but might be an image with a link in its caption
                                $might_be_img = true;
                                $text = $m[2];
                                $trail = $m[3];
                        } elseif( preg_match($e1_img, $line, $m) ) { # Invalid, but might be an image with a link in its caption
                                $might_be_img = true;
                                $text = $m[2];
-                               $lnk = strpos( $m[1], '%' ) === false ? $m[1] : urldecode( $m[1] );
+                               if ( strpos( $m[1], '%' ) !== false ) {
+                                       $m[1] = urldecode($m[1]);
+                               }
                                $trail = "";
                        } else { # Invalid form; output directly
                                $s .= $prefix . '[[' . $line ;
                                $trail = "";
                        } else { # Invalid form; output directly
                                $s .= $prefix . '[[' . $line ;
@@ -1653,7 +1615,7 @@ class Parser
                        # Don't allow internal links to pages containing
                        # PROTO: where PROTO is a valid URL protocol; these
                        # should be external links.
                        # Don't allow internal links to pages containing
                        # PROTO: where PROTO is a valid URL protocol; these
                        # should be external links.
-                       if ( preg_match( '/^\b(?:' . wfUrlProtocols() . ')/', $lnk ) ) {
+                       if ( preg_match( '/^\b(?:' . wfUrlProtocols() . ')/', $m[1] ) ) {
                                $s .= $prefix . '[[' . $line ;
                                wfProfileOut( __METHOD__."-misc" );
                                continue;
                                $s .= $prefix . '[[' . $line ;
                                wfProfileOut( __METHOD__."-misc" );
                                continue;
@@ -1661,12 +1623,12 @@ class Parser
 
                        # Make subpage if necessary
                        if ( $useSubpages ) {
 
                        # Make subpage if necessary
                        if ( $useSubpages ) {
-                               $link = $this->maybeDoSubpageLink( $lnk, $text );
+                               $link = $this->maybeDoSubpageLink( $m[1], $text );
                        } else {
                        } else {
-                               $link = $lnk;
+                               $link = $m[1];
                        }
 
                        }
 
-                       $noforce = (substr( $lnk, 0, 1 ) !== ':');
+                       $noforce = (substr( $m[1], 0, 1 ) !== ':');
                        if (!$noforce) {
                                # Strip off leading ':'
                                $link = substr( $link, 1 );
                        if (!$noforce) {
                                # Strip off leading ':'
                                $link = substr( $link, 1 );
@@ -1914,25 +1876,6 @@ class Parser
                return Linker::normalizeSubpageLink( $this->mTitle, $target, $text );
        }
 
                return Linker::normalizeSubpageLink( $this->mTitle, $target, $text );
        }
 
-       /**
-        * From the [[title|]] return link-text as though the used typed [[title|link-text]]
-        * @param string $link from [[$link|]]
-        * @return string $text for [[$link|$text]]
-        */
-       function getPipeTrickText( $link ) {
-               return Linker::getPipeTrickText( $link );
-       }
-
-       /**
-        * From the [[|link-text]] return the title as though the user typed [[title|link-text]]
-        * @param string $text from [[|$text]]
-        * @param Title $title to resolve the link against
-        * @return string $link for [[$link|$text]]
-        */
-       function getPipeTrickLink( $text ) {
-               return Linker::getPipeTrickLink( $text, $this->mTitle );
-       }
-
        /**#@+
         * Used by doBlockLevels()
         * @private
        /**#@+
         * Used by doBlockLevels()
         * @private
@@ -2495,14 +2438,6 @@ class Parser
                                $subjPage = $this->mTitle->getSubjectPage();
                                $value = $subjPage->getPrefixedUrl();
                                break;
                                $subjPage = $this->mTitle->getSubjectPage();
                                $value = $subjPage->getPrefixedUrl();
                                break;
-                       case 'pipetrick':
-                               $text = $this->mTitle->getText();
-                               $value = $this->getPipeTrickText( $text );
-                               break;
-                       case 'pipetricke':
-                               $text = $this->mTitle->getText();
-                               $value = wfUrlEncode( str_replace( ' ', '_', $this->getPipeTrickText( $text ) ) );
-                               break;
                        case 'revisionid':
                                // Let the edit saving system know we should parse the page
                                // *after* a revision ID has been assigned.
                        case 'revisionid':
                                // Let the edit saving system know we should parse the page
                                // *after* a revision ID has been assigned.
@@ -4045,11 +3980,32 @@ class Parser
                        '~~~' => $sigText
                ) );
 
                        '~~~' => $sigText
                ) );
 
-               # Links of the form [[|<blah>]] or [[<blah>|]] perform pipe tricks
-               # Note this only allows the # in the position it works.
+               # Context links: [[|name]] and [[name (context)|]]
+               #
                global $wgLegalTitleChars;
                global $wgLegalTitleChars;
-               $pipeTrickRe = "/\[\[(?:(\\|)([$wgLegalTitleChars]+)|([#$wgLegalTitleChars]+)\\|)\]\]/";
-               $text = preg_replace_callback( $pipeTrickRe, array( $this, 'pstPipeTrickCallback' ), $text );
+               $tc = "[$wgLegalTitleChars]";
+               $nc = '[ _0-9A-Za-z\x80-\xff-]'; # Namespaces can use non-ascii!
+
+               $p1 = "/\[\[(:?$nc+:|:|)($tc+?)( \\($tc+\\))\\|]]/";            # [[ns:page (context)|]]
+               $p4 = "/\[\[(:?$nc+:|:|)($tc+?)(($tc+))\\|]]/";             # [[ns:page(context)|]]
+               $p3 = "/\[\[(:?$nc+:|:|)($tc+?)( \\($tc+\\)|)(, $tc+|)\\|]]/";  # [[ns:page (context), context|]]
+               $p2 = "/\[\[\\|($tc+)]]/";                                      # [[|page]]
+
+               # try $p1 first, to turn "[[A, B (C)|]]" into "[[A, B (C)|A, B]]"
+               $text = preg_replace( $p1, '[[\\1\\2\\3|\\2]]', $text );
+               $text = preg_replace( $p4, '[[\\1\\2\\3|\\2]]', $text );
+               $text = preg_replace( $p3, '[[\\1\\2\\3\\4|\\2]]', $text );
+
+               $t = $this->mTitle->getText();
+               $m = array();
+               if ( preg_match( "/^($nc+:|)$tc+?( \\($tc+\\))$/", $t, $m ) ) {
+                       $text = preg_replace( $p2, "[[$m[1]\\1$m[2]|\\1]]", $text );
+               } elseif ( preg_match( "/^($nc+:|)$tc+?(, $tc+|)$/", $t, $m ) && "$m[1]$m[2]" != '' ) {
+                       $text = preg_replace( $p2, "[[$m[1]\\1$m[2]|\\1]]", $text );
+               } else {
+                       # if there's no context, don't bother duplicating the title
+                       $text = preg_replace( $p2, '[[\\1]]', $text );
+               }
 
                # Trim trailing whitespace
                $text = rtrim( $text );
 
                # Trim trailing whitespace
                $text = rtrim( $text );
@@ -4057,25 +4013,6 @@ class Parser
                return $text;
        }
 
                return $text;
        }
 
-       /**
-        * Called from pstPass2 to perform the pipe trick on links.
-        * Original was either [[|text]] or [[link|]]
-        *
-        * @param Array ("|" or "", text, link) $m
-        */
-       function pstPipeTrickCallback( $m )
-       {
-               if( $m[1] ) { # [[|<blah>]]
-                       $text = $m[2];
-                       $link = $this->getPipeTrickLink( $text );
-               } else { # [[<blah>|]]
-                       $link = $m[3];
-                       $text = $this->getPipeTrickText( $link );
-               }
-
-               return $link === $text ? "[[$link]]" : "[[$link|$text]]";
-       }
-
        /**
         * Fetch the user's signature text, if any, and normalize to
         * validated, ready-to-insert wikitext.
        /**
         * Fetch the user's signature text, if any, and normalize to
         * validated, ready-to-insert wikitext.
@@ -4256,9 +4193,7 @@ class Parser
                return $oldVal;
        }
 
                return $oldVal;
        }
 
-       /* An old work-around for bug 2257 - deprecated 2010-02-13 */
        function setTransparentTagHook( $tag, $callback ) {
        function setTransparentTagHook( $tag, $callback ) {
-               wfDeprecated( __METHOD__ );
                $tag = strtolower( $tag );
                $oldVal = isset( $this->mTransparentTagHooks[$tag] ) ? $this->mTransparentTagHooks[$tag] : null;
                $this->mTransparentTagHooks[$tag] = $callback;
                $tag = strtolower( $tag );
                $oldVal = isset( $this->mTransparentTagHooks[$tag] ) ? $this->mTransparentTagHooks[$tag] : null;
                $this->mTransparentTagHooks[$tag] = $callback;
index c8f0c00..e3643f2 100644 (file)
@@ -263,8 +263,6 @@ $magicWords = array(
        'talkpagenamee'          => array( 1,    'TALKPAGENAMEE'          ),
        'subjectpagename'        => array( 1,    'SUBJECTPAGENAME', 'ARTICLEPAGENAME' ),
        'subjectpagenamee'       => array( 1,    'SUBJECTPAGENAMEE', 'ARTICLEPAGENAMEE' ),
        'talkpagenamee'          => array( 1,    'TALKPAGENAMEE'          ),
        'subjectpagename'        => array( 1,    'SUBJECTPAGENAME', 'ARTICLEPAGENAME' ),
        'subjectpagenamee'       => array( 1,    'SUBJECTPAGENAMEE', 'ARTICLEPAGENAMEE' ),
-       'pipetrick'              => array( 1,    'PIPETRICK'              ),
-       'pipetricke'             => array( 1,    'PIPETRICKE'             ),
        'msg'                    => array( 0,    'MSG:'                   ),
        'subst'                  => array( 0,    'SUBST:'                 ),
        'safesubst'              => array( 0,    'SAFESUBST:'             ),
        'msg'                    => array( 0,    'MSG:'                   ),
        'subst'                  => array( 0,    'SUBST:'                 ),
        'safesubst'              => array( 0,    'SAFESUBST:'             ),
index 023f955..860b589 100644 (file)
@@ -2021,41 +2021,6 @@ title=[[User:Ævar Arnfjörð Bjarmason]]
 </p>
 !! end
 
 </p>
 !! end
 
-!! test
-Magic Word: {{PIPETRICK}}
-!! options
-title=[[Some (page)]]
-!! input
-{{PIPETRICK}}
-{{PIPETRICK:Hello (one)}}
-{{PIPETRICK:World, hi|}}
-{{PIPETRICK:|Other}}
-!! result
-<p>Some
-Hello
-World
-Other (page)
-</p>
-!! end
-
-!! test
-Magic Word: {{PIPETRICKE}}
-!! options
-title=[[Some other (page)]]
-!! input
-{{PIPETRICKE}}
-{{PIPETRICKE:User:Ævar Arnfjörð Bjarmason}}
-{{PIPETRICKE:#Something to do|}}
-{{PIPETRICKE:|The?last}}
-!! result
-<p>Some_other
-%C3%86var_Arnfj%C3%B6r%C3%B0_Bjarmason
-Something_to_do
-The%3Flast_(page)
-</p>
-!! end
-
-
 !! test
 Magic Word: {{REVISIONID}}
 !! input
 !! test
 Magic Word: {{REVISIONID}}
 !! input
@@ -3033,48 +2998,6 @@ pst
 [[:Bar:X (Y) Z|X (Y) Z]]
 !! end
 
 [[: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") to sections on other pages
-!! options
-pst
-!! input
-[[other#page|]]
-[[Help:Somewhere/completely (wierd)#section (two)|]]
-!! result
-[[other#page|page]]
-[[Help:Somewhere/completely (wierd)#section (two)|section]]
-!! 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
 !! test
 pre-save transform: context links ("pipe trick") with interwiki prefix
 !! options
@@ -3189,65 +3112,6 @@ pst title=[[Ns:Somearticle (IGNORED), Context]]
 [[Ns:Article, Context|Article]]
 !! end
 
 [[Ns:Article, Context|Article]]
 !! end
 
-!! test
-pre-save transform: context links ("pipe trick") with url escaped page names
-!! options
-pst
-!! input
-[[Hello wo%52ld|]]
-[[Hello wo%52ld (again)|]]
-!! result
-[[Hello wo%52ld|Hello woRld]]
-[[Hello wo%52ld (again)|Hello woRld]]
-!! end
-
-!! test
-pre-save transform: context links ("pipe trick") with variables are not pre-empted
-!! options
-pst title=[[Test (page)]]
-!! input
-[[{{{1|}}}|]]
-[[|{{{1|}}}]]
-[[{{subst:PAGENAME}}|]]
-!! result
-[[{{{1|}}}|]]
-[[|{{{1|}}}]]
-[[Test (page)|Test]]
-!! end
-
-!! article
-Template:pipetest
-!! text
-[[{{{1}}}|]]
-!! endarticle
-
-!! article
-Template:testpipe
-!! text
-[[|{{{1}}}]]
-!! endarticle
-
-!! test
-("pipe trick") should work outside PST
-!!options
-title=[[Help:hello (world)]]
-!! input 
-{{pipetest|hi (world)}}
-{{pipetest|hi (world), world}}
-{{pipetest|Help:hi (world), world}}
-{{pipetest|:Help:hi (world), world}}
-{{testpipe|hi}}
-[[{{PAGENAME}}|]]
-!! result
-<p><a href="/index.php?title=Hi_(world)&amp;action=edit&amp;redlink=1" class="new" title="Hi (world) (page does not exist)">hi</a>
-<a href="/index.php?title=Hi_(world),_world&amp;action=edit&amp;redlink=1" class="new" title="Hi (world), world (page does not exist)">hi</a>
-<a href="/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>
-<a href="/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>
-<a href="/index.php?title=Hi_(world)&amp;action=edit&amp;redlink=1" class="new" title="Hi (world) (page does not exist)">hi</a>
-<a href="/index.php?title=Hello_(world)&amp;action=edit&amp;redlink=1" class="new" title="Hello (world) (page does not exist)">Hello</a>
-</p>
-!! end
-
 
 ###
 ### Message transform tests
 
 ###
 ### Message transform tests
@@ -7745,17 +7609,6 @@ title=[[Main Page]]
 <a href="/wiki/Main_Page#section" title="Main Page">#section</a>
 !! end
 
 <a href="/wiki/Main_Page#section" title="Main Page">#section</a>
 !! end
 
-!! test
-Edit comment with pipe trick
-!! options
-comment
-title=[[Article (context)]]
-!! input
-[[Hello (World)|]] [[|Entry]]
-!! result
-<a href="/index.php?title=Hello_(World)&amp;action=edit&amp;redlink=1" class="new" title="Hello (World) (page does not exist)">Hello</a> <a href="/index.php?title=Entry_(context)&amp;action=edit&amp;redlink=1" class="new" title="Entry (context) (page does not exist)">Entry</a>
-!! end
-
 !!article
 MediaWiki:bad image list
 !!text
 !!article
 MediaWiki:bad image list
 !!text