Tools 是非官方社区Wiki。社区文档正在编写中,欢迎参与。 Wiki编辑答疑群:717421103
版本250722.2
全站通知:

帮助:解析函数/fullpagename

来自WIKI实验室WIKI_BWIKI_哔哩哔哩
跳到导航 跳到搜索

FULLPAGENAME是一个解析函数。帮助:解析函数页列出了所有解析函数的说明。

FULLPAGENAME

带命名空间的完整页面名MediaWiki原生支持。

根据输入返回包含命名空间前缀的完整页面名称,保留原始格式和大小写。

语法

{{FULLPAGENAME}}

{{FULLPAGENAME: 页面名 }}

  • 页面名(可选):任意文本(支持伪页面名和特殊字符)

无效输入(无法创建有效标题)时返回空字符串

示例

  • 当前页面 {{FULLPAGENAME}} → 帮助:解析函数/fullpagename
  • 带命名空间 {{FULLPAGENAME: 帮助:Fullpagename }} → 帮助:Fullpagename
  • 保留空格 {{FULLPAGENAME: a b c }} → A b c
  • 特殊字符 {{FULLPAGENAME: /a_b/c }} → /a b/c
  • 无效输入 {{FULLPAGENAME: 特殊:所有页面 }}


底层代码

来自MediaWiki及其扩展的源代码,运行在服务端。此处仅供快速查阅,便于更充分的挖掘其“特性”。

// mediawiki-1.37.0\includes\parser\CoreParserFunctions.php
public static function fullpagename( $parser, $title = null ) {
    $t = Title::newFromText( $title );
    if ( $t === null || !$t->canHaveTalkPage() ) {
        return '';
    }
    return wfEscapeWikiText( $t->getPrefixedText() );
}

/** mediawiki-1.37.0\includes\Title.php
  * Get the prefixed title with spaces.
  * This is the form usually used for display
  *
  * @return string The prefixed title, with spaces
  */
public function getPrefixedText() {
    if ( $this->prefixedText === null ) {
        $s = $this->prefix( $this->mTextform );
        $s = strtr( $s, '_', ' ' );
        $this->prefixedText = $s;
    }
    return $this->prefixedText;
}

/** mediawiki-1.37.0\includes\Title.php
  * @deprecated since 1.37 directly accessing this member,
  *   use the ::getText() method instead.
  * @var string Text form (spaces not underscores) of the main part
  */
public $mTextform = '';


/** mediawiki-1.37.0\includes\Title.php
  * Prefix some arbitrary text with the namespace or interwiki prefix
  * of this object
  *
  * @param string $name The text
  * @return string The prefixed text
  */
private function prefix( $name ) {
    $p = '';
    if ( $this->isExternal() ) {
        $p = $this->mInterwiki . ':';
    }

    if ( $this->mNamespace != 0 ) {
        $nsText = $this->getNsText();

        if ( $nsText === false ) {
            // See T165149. Awkward, but better than erroneously linking to the main namespace.
            $nsText = MediaWikiServices::getInstance()->getContentLanguage()->
                getNsText( NS_SPECIAL ) . ":Badtitle/NS{$this->mNamespace}";
        }

        $p .= $nsText . ':';
    }
    return $p . $name;
}
代码逻辑:
  • 将输入文本解析为MediaWiki标题对象
  • 检查标题有效性(是否可创建讨论页)
  • 获取命名空间前缀
  • 返回带命名空间的页面名(自动转换下划线为空格)

实际用例

一些Wiki使用了相关特性,如下所示这个静态列表可能在下列页面更改后过时仅供批判性参考