+
+ # NS
+ if ( !$found ) {
+ # Check for NS: (namespace expansion)
+ $mwNs = MagicWord::get( MAG_NS );
+ if ( $mwNs->matchStartAndRemove( $text ) ) {
+ if ( intval( $text ) ) {
+ $text = $wgLang->getNsText( intval( $text ) );
+ $found = true;
+ } else {
+ $index = Namespace::getCanonicalIndex( strtolower( $text ) );
+ if ( !is_null( $index ) ) {
+ $text = $wgLang->getNsText( $index );
+ $found = true;
+ }
+ }
+ }
+ }
+
+ # LOCALURL and LOCALURLE
+ if ( !$found ) {
+ $mwLocal = MagicWord::get( MAG_LOCALURL );
+ $mwLocalE = MagicWord::get( MAG_LOCALURLE );
+
+ if ( $mwLocal->matchStartAndRemove( $text ) ) {
+ $func = 'getLocalURL';
+ } elseif ( $mwLocalE->matchStartAndRemove( $text ) ) {
+ $func = 'escapeLocalURL';
+ } else {
+ $func = '';
+ }
+
+ if ( $func !== '' ) {
+ $args = explode( "|", $text );
+ $n = count( $args );
+ if ( $n > 0 ) {
+ $title = Title::newFromText( $args[0] );
+ if ( !is_null( $title ) ) {
+ if ( $n > 1 ) {
+ $text = $title->$func( $args[1] );
+ } else {
+ $text = $title->$func();
+ }
+ $found = true;
+ }
+ }
+ }
+ }
+
+ # Check for a match against internal variables
+ if ( !$found && array_key_exists( $text, $this->mVariables ) ) {
+ $text = $this->mVariables[$text];
+ $found = true;
+ $this->mOutput->mContainsOldMagic = true;
+ }
+
+ # Load from database
+ if ( !$found ) {
+ $title = Title::newFromText( $text, NS_TEMPLATE );
+ if ( is_object( $title ) && !$title->isExternal() ) {
+ # Check for excessive inclusion
+ $dbk = $title->getPrefixedDBkey();
+ if ( !array_key_exists( $dbk, $this->mIncludeCount ) ) {
+ $this->mIncludeCount[$dbk] = 0;
+ }
+ if ( ++$this->mIncludeCount[$dbk] <= MAX_INCLUDE_REPEAT ) {
+ $article = new Article( $title );
+ $articleContent = $article->getContentWithoutUsingSoManyDamnGlobals();
+ if ( $articleContent !== false ) {
+ $found = true;
+ $text = $articleContent;
+
+ # Escaping and link table handling
+ # Not required for preSaveTransform()
+ if ( $this->mOutputType == OT_HTML ) {
+ if ( $nowiki ) {
+ $text = wfEscapeWikiText( $text );
+ } else {
+ $text = $this->removeHTMLtags( $text );
+ }
+ $wgLinkCache->suspend();
+ $text = $this->doTokenizedParser( $text );
+ $wgLinkCache->resume();
+ $wgLinkCache->addLinkObj( $title );