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

帮助:解析函数/fullurl

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

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

fullurl

获取指定页面的完整URL。MediaWiki原生支持。

可附加查询参数。支持本地和跨wiki页面,自动处理URL编码。

  • 官方文档:[1]

语法

{{fullurl: 页面名称 | 查询参数 }}

  • 页面名称:支持命名空间、跨wiki链接
  • 查询参数(可选):以key=value形式添加,多个参数用&连接

示例


底层代码

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

// mediawiki-1.37.0\includes\parser\CoreParserFunctions.php
public static function fullurl( $parser, $s = '', $arg = null ) {
    return self::urlFunction( 'getFullURL', $s, $arg );
}

// mediawiki-1.37.0\includes\parser\CoreParserFunctions.php
public static function urlFunction( $func, $s = '', $arg = null ) {
	$title = Title::newFromText( $s );
	# Due to order of execution of a lot of bits, the values might be encoded
	# before arriving here; if that's true, then the title can't be created
	# and the variable will fail. If we can't get a decent title from the first
	# attempt, url-decode and try for a second.
	if ( $title === null ) {
		$title = Title::newFromURL( urldecode( $s ) );
	}
	if ( $title !== null ) {
		# Convert NS_MEDIA -> NS_FILE
		if ( $title->inNamespace( NS_MEDIA ) ) {
			$title = Title::makeTitle( NS_FILE, $title->getDBkey() );
		}
		if ( $arg !== null ) {
			$text = $title->$func( $arg );
		} else {
			$text = $title->$func();
		}
		return $text;
	} else {
		return [ 'found' => false ];
	}
}
代码逻辑:
  • 优先尝试解析原始页面名称,失败时自动进行URL解码后重试
  • 媒体文件(NS_MEDIA)会自动转换为文件命名空间(NS_FILE)
  • 当提供查询参数时,会附加到URL的查询字符串中
  • 跨wiki链接通过Title类自动解析

实际用例

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

恋与深空 - lysk

第五人格 - dwrg

坎特伯雷公主与骑士唤醒冠军之剑的奇幻冒险 - gt

黑神话:悟空 - wukong

WIKI实验室 - tools

地下城堡2 - dxcb2

东方归言录 - touhoulostword

卡拉彼丘 - klbq

白荆回廊 - bjhl

女神转生 - persona

赛尔计划 - seerplan

幻塔 - ht