Merge "Further tweaks to pipe trick documentation (follow-up Iaf365e31)"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 24 Jan 2013 15:48:24 +0000 (15:48 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 24 Jan 2013 15:48:24 +0000 (15:48 +0000)
1  2 
includes/parser/Parser.php

@@@ -246,13 -246,6 +246,13 @@@ class Parser 
                }
        }
  
 +      /**
 +       * Allow extensions to clean up when the parser is cloned
 +       */
 +      function __clone() {
 +              wfRunHooks( 'ParserCloned', array( $this ) );
 +      }
 +
        /**
         * Do various kinds of initialisation on the first call of the parser
         */
                if ( !( $options->getDisableContentConversion()
                                || isset( $this->mDoubleUnderscores['nocontentconvert'] ) ) )
                {
 -                      # Run convert unconditionally in 1.18-compatible mode
 -                      global $wgBug34832TransitionalRollback;
 -                      if ( $wgBug34832TransitionalRollback || !$this->mOptions->getInterfaceMessage() ) {
 +                      if ( !$this->mOptions->getInterfaceMessage() ) {
                                # The position of the convert() call should not be changed. it
                                # assumes that the links are all replaced and the only thing left
                                # is the <nowiki> mark.
         * Also removes comments.
         * @return mixed|string
         */
 -      function preprocess( $text, Title $title, ParserOptions $options, $revid = null ) {
 +      function preprocess( $text, Title $title = null, ParserOptions $options, $revid = null ) {
                wfProfileIn( __METHOD__ );
                $this->startParse( $title, $options, self::OT_PREPROCESS, true );
                if ( $revid !== null ) {
         * Get the language object for language conversion
         */
        function getConverterLanguage() {
 -              global $wgBug34832TransitionalRollback, $wgContLang;
 -              if ( $wgBug34832TransitionalRollback ) {
 -                      return $wgContLang;
 -              } else {
 -                      return $this->getTargetLanguage();
 -              }
 +              return $this->getTargetLanguage();
        }
  
        /**
                if ( $text === false ) {
                        # Not an image, make a link
                        $text = Linker::makeExternalLink( $url,
 -                              $this->getConverterLanguage()->markNoConversion($url), true, 'free',
 +                              $this->getConverterLanguage()->markNoConversion( $url, true ),
 +                              true, 'free',
                                $this->getExternalLinkAttribs( $url ) );
                        # Register it in the output object...
                        # Replace unnecessary URL escape codes with their equivalent characters
                wfProfileOut( __METHOD__ );
                return $s;
        }
 -
 +      /**
 +       * Get the rel attribute for a particular external link.
 +       *
 +       * @since 1.21
 +       * @param $url String|bool optional URL, to extract the domain from for rel =>
 +       *   nofollow if appropriate
 +       * @param $title Title optional Title, for wgNoFollowNsExceptions lookups
 +       * @return string|null rel attribute for $url
 +       */
 +      public static function getExternalLinkRel( $url = false, $title = null ) {
 +              global $wgNoFollowLinks, $wgNoFollowNsExceptions, $wgNoFollowDomainExceptions;
 +              $ns = $title ? $title->getNamespace() : false;
 +              if ( $wgNoFollowLinks && !in_array( $ns, $wgNoFollowNsExceptions ) &&
 +                              !wfMatchesDomainList( $url, $wgNoFollowDomainExceptions ) )
 +              {
 +                      return 'nofollow';
 +              }
 +              return null;
 +      }
        /**
         * Get an associative array of additional HTML attributes appropriate for a
         * particular external link.  This currently may include rel => nofollow
         */
        function getExternalLinkAttribs( $url = false ) {
                $attribs = array();
 -              global $wgNoFollowLinks, $wgNoFollowNsExceptions, $wgNoFollowDomainExceptions;
 -              $ns = $this->mTitle->getNamespace();
 -              if ( $wgNoFollowLinks && !in_array( $ns, $wgNoFollowNsExceptions ) &&
 -                              !wfMatchesDomainList( $url, $wgNoFollowDomainExceptions ) )
 -              {
 -                      $attribs['rel'] = 'nofollow';
 -              }
 +              $attribs['rel'] = self::getExternalLinkRel( $url, $this->mTitle );
 +
                if ( $this->mOptions->getExternalLinkTarget() ) {
                        $attribs['target'] = $this->mOptions->getExternalLinkTarget();
                }
  
                        if ( $rev ) {
                                $content = $rev->getContent();
 -                              $text = $content->getWikitextForTransclusion();
 +                              $text = $content ? $content->getWikitextForTransclusion() : null;
  
                                if ( $text === false || $text === null ) {
                                        $text = false;
                        '~~~' => $sigText
                ) );
  
-               # Context links ("pipe trick"): [[|name]] and [[name (context)|]]
+               # Context links ("pipe tricks"): [[|name]] and [[name (context)|]]
                $tc = '[' . Title::legalChars() . ']';
                $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)|]] (double-width brackets, added in r40257)
-               $p3 = "/\[\[(:?$nc+:|:|)($tc+?)( ?\\($tc+\\)|)((?:, |,)$tc+|)\\|]]/"; # [[ns:page (context), context|]]
-               $p2 = "/\[\[\\|($tc+)]]/";                                             # [[|page]]
+               $p1 = "/\[\[(:?$nc+:|:|)($tc+?)( ?\\($tc+\\))\\|]]/";                   # [[ns:page (context)|]]
+               $p4 = "/\[\[(:?$nc+:|:|)($tc+?)( ?($tc+))\\|]]/";                           # [[ns:page(context)|]] (double-width brackets, added in r40257)
+               $p3 = "/\[\[(:?$nc+:|:|)($tc+?)( ?\\($tc+\\)|)((?:, |,)$tc+|)\\|]]/";         # [[ns:page (context), context|]] (using either single or double-width comma)
+               $p2 = "/\[\[\\|($tc+)]]/";                                              # [[|page]] (reverse pipe trick: add context from page title)
  
                # try $p1 first, to turn "[[A, B (C)|]]" into "[[A, B (C)|A, B]]"
                $text = preg_replace( $p1, '[[\\1\\2\\3|\\2]]', $text );
                        global $wgTitle;
                        $title = $wgTitle;
                }
 -              if ( !$title ) {
 -                      # It's not uncommon having a null $wgTitle in scripts. See r80898
 -                      # Create a ghost title in such case
 -                      $title = Title::newFromText( 'Dwimmerlaik' );
 -              }
 +
                $text = $this->preprocess( $text, $title, $options );
  
                $executing = false;