Ссылка из шаблона на заголовок шаблона в который он вставлен

Нам требуется возможность сослаться на название страницы в которую непосредственновставлен шаблон и которая сама по себе трансклудится в другую страницу.

Требуется как минимум чтобы вставить в Template:ContextBox название категории когда сама категория инклудится в статью или другую категории для контекстного бара.

В Help:Page_name такого не нашел. Все ссылки ведут к основной генеримой странице.

Можно сделать было официально как MediaWiki extension но было лень т.к. все равно не нашел способа перехватить стек вложенных шаблонов. Добавил в код:

1) Запоминаю стек вложения шаблонов (глобально, в надежде что прерывания не помешают и вики использует натуральный стек PHP для парсинга всех вложенностей)

2) Ввожу magic words ссылающиеся на предпоследний темплейт в стеке (это можно было сделать более официально, но зачем если все равно хак нужен)

		# SUBST
		wfProfileIn( __METHOD__.'-modifiers' );
		if ( !$found ) {
			$mwSubst = MagicWord::get( 'subst' );
			if ( $mwSubst->matchStartAndRemove( $part1 ) xor $this->ot['wiki'] ) {
				# One of two possibilities is true:
				# 1) Found SUBST but not in the PST phase
				# 2) Didn't find SUBST and in the PST phase
				# In either case, return without further processing
				$text = $frame->virtualBracketedImplode( '{{', '|', '}}', $titleWithSpaces, $args );
				$isLocalObj = true;
				$found = true;
			}
		}
 
//VL: 2010-09-08 
        // our magics - too lazy to register because I have to fix this file anyways
        global $g_asParentTitle;
		$sIncluder = $g_asParentTitle[count($g_asParentTitle) - 2];
		$sTemplate = $g_asParentTitle[count($g_asParentTitle) - 1];
 
        if (!$found)
        {
            if ($part1 == "INCLUDER_FULLPAGENAME")
            {
                $text = $sIncluder;
			    $found = true;
            }
 
            /* can be done with #if:
            if ($part1 == "INCLUDERORTHIS_FULLPAGENAME")
            {
                $text = $sIncluder;
                if ($text == "")
                {
                    // resort to normal macro
                    $text = wfEscapeWikiText( $this->mTitle->getPrefixedText() );
                }
 
			    $found = true;
            }
            */
 
            if ($part1 == "INCLUDER_PAGENAME")
            {
                // remove namespace
                $text = preg_replace('/^[^:]+\:/', '', $sIncluder);
			    $found = true;
            }
 
            if ($part1 == "TEMPLATE_FULLPAGENAME")
            {
                // remove namespace
                $text = $sTemplate;
			    $found = true;
            }
 
            if ($part1 == "TEMPLATE_PAGENAME")
            {
                // remove namespace
                $text = preg_replace('/^[^:]+\:/', '', $sTemplate);
			    $found = true;
            }
        }
//VL.
 
		# Variables
		if ( !$found && $args->getLength() == 0 ) {
			$id = $this->mVariables->matchStartToEnd( $part1 );
			if ( $id !== false ) {
				$text = $this->getVariableValue( $id );
				if (MagicWord::getCacheTTL($id)>-1)
					$this->mOutput->mContainsOldMagic = true;
				$found = true;
			}
		}
# If we haven't found text to substitute by now, we're done
		# Recover the source wikitext and return it
		if ( !$found ) {
			$text = $frame->virtualBracketedImplode( '{{', '|', '}}', $titleWithSpaces, $args );
			wfProfileOut( __METHOD__ );
			return array( 'object' => $text );
		}
 
//VL: 2010-09-08 
        global $g_asParentTitle;
        $g_asParentTitle[] = $part1;
//VL.
 
		# Expand DOM-style return values in a child frame
		if ( $isChildObj ) {
			# Clean up argument array
			$newFrame = $frame->newChild( $args, $title );
 
			if ( $nowiki ) {
				$text = $newFrame->expand( $text, PPFrame::RECOVER_ORIG );
			} elseif ( $titleText !== false && $newFrame->isEmpty() ) {
				# Expansion is eligible for the empty-frame cache
				if ( isset( $this->mTplExpandCache[$titleText] ) ) {
					$text = $this->mTplExpandCache[$titleText];
				} else {
					$text = $newFrame->expand( $text );
					$this->mTplExpandCache[$titleText] = $text;
				}
			} else {
				# Uncached expansion
				$text = $newFrame->expand( $text );
			}
		}
		if ( $isLocalObj && $nowiki ) {
			$text = $frame->expand( $text, PPFrame::RECOVER_ORIG );
			$isLocalObj = false;
		}
 
//VL: 2010-09-08 
        // template expanded here
        array_pop($g_asParentTitle);
//VL.
 
		# Replace raw HTML by a placeholder
		# Add a blank line preceding, to prevent it from mucking up
		# immediately preceding headings

(экаж табы перекосило)