If a template is a redirect, register both titles in the templatelinks table. This...
authorTim Starling <tstarling@users.mediawiki.org>
Wed, 11 Jan 2006 02:19:41 +0000 (02:19 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Wed, 11 Jan 2006 02:19:41 +0000 (02:19 +0000)
includes/Parser.php

index 8a301b4..0030dac 100644 (file)
@@ -2514,15 +2514,12 @@ class Parser
                                                        $this->disableCache();
                                                }
                                        } else {
-                                               $article = new Article( $title );
-                                               $articleContent = $article->fetchContent(0, false);
+                                               $articleContent = $this->fetchTemplate( $title );
                                                if ( $articleContent !== false ) {
                                                        $found = true;
                                                        $text = $articleContent;
                                                        $replaceHeadings = true;
                                                }
-                                               # Register a template reference whether or not the template exists
-                                               $this->mOutput->addTemplate( $title, $article->getID() );
                                        }
                                }
 
@@ -2645,6 +2642,28 @@ class Parser
                }
        }
 
+       /**
+        * Fetch the unparsed text of a template and register a reference to it. 
+        */
+       function fetchTemplate( $title ) {
+               $text = false;
+               // Loop to fetch the article, with up to 1 redirect
+               for ( $i = 0; $i < 2 && is_object( $title ); $i++ ) {
+                       $rev = Revision::newFromTitle( $title );
+                       $this->mOutput->addTemplate( $title, $title->getArticleID() );
+                       if ( !$rev ) {
+                               break;
+                       }
+                       $text = $rev->getText();
+                       if ( $text === false ) {
+                               break;
+                       }
+                       // Redirect?
+                       $title = Title::newFromRedirect( $text );
+               }
+               return $text;
+       }
+
        /**
         * Translude an interwiki link.
         */