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

帮助:解析函数/fullpagenamee

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

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

FULLPAGENAMEE

带命名空间的完整页面名,使用URL编码。MediaWiki原生支持。

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

语法

{{FULLPAGENAMEE}}

{{FULLPAGENAMEE: 页面名 }}

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

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

示例

  • 当前页面 {{FULLPAGENAMEE}} → %E5%B8%AE%E5%8A%A9:%E8%A7%A3%E6%9E%90%E5%87%BD%E6%95%B0/fullpagenamee
  • 带命名空间 {{FULLPAGENAMEE: 帮助:Fullpagename }} → %E5%B8%AE%E5%8A%A9:Fullpagename
  • 保留空格 {{FULLPAGENAMEE: a b c }} → A_b_c
  • 特殊字符 {{FULLPAGENAMEE: /a_b/c }} → /a_b/c
  • 无效输入 {{FULLPAGENAMEE: 特殊:所有页面 }}


底层代码

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

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

/** 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标题对象
  • 检查标题有效性(是否可创建讨论页)
  • 获取命名空间前缀
  • 返回带命名空间的页面名(自动转换下划线为空格,并进行URL编码)

实际用例

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