Merge "Further tweaks to pipe trick documentation (follow-up Iaf365e31)"
[lhc/web/wiklou.git] / includes / parser / Parser.php
index 2c8b6e5..36f6273 100644 (file)
@@ -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
         */
@@ -405,9 +412,7 @@ class 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.
@@ -542,7 +547,7 @@ class Parser {
         * 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 ) {
@@ -774,12 +779,7 @@ class Parser {
         * Get the language object for language conversion
         */
        function getConverterLanguage() {
-               global $wgBug34832TransitionalRollback, $wgContLang;
-               if ( $wgBug34832TransitionalRollback ) {
-                       return $wgContLang;
-               } else {
-                       return $this->getTargetLanguage();
-               }
+               return $this->getTargetLanguage();
        }
 
        /**
@@ -1307,7 +1307,8 @@ class Parser {
                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
@@ -1606,7 +1607,25 @@ class Parser {
                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
@@ -1619,13 +1638,8 @@ class Parser {
         */
        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();
                }
@@ -3617,7 +3631,7 @@ class Parser {
 
                        if ( $rev ) {
                                $content = $rev->getContent();
-                               $text = $content->getWikitextForTransclusion();
+                               $text = $content ? $content->getWikitextForTransclusion() : null;
 
                                if ( $text === false || $text === null ) {
                                        $text = false;
@@ -4675,11 +4689,7 @@ class Parser {
                        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;