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

帮助:解析函数/fullurle

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

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

fullurle

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

可附加查询参数,与fullurl一致。但url中的部分特殊字符会被转换为 HTML 实体。

语法

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

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

会被转换为HTML实体的符号:&&amp;"&quot;<&lt;>&gt; (见PHP函数htmlspecialchars 文档)

示例

  • 基本 {{fullurle:帮助:解析函数}}https://wiki.biligame.com/tools/%E5%B8%AE%E5%8A%A9:%E8%A7%A3%E6%9E%90%E5%87%BD%E6%95%B0
  • 带参数 {{fullurle:Test|action=edit}}https://wiki.biligame.com/tools/index.php?title=Test&amp;action=edit
  • 带参数 {{fullurle:Test|a=1<2>1&b=2"2&c=3'3}}https://wiki.biligame.com/tools/index.php?title=Test&amp;a=1&lt;2&gt;1&amp;b=2&quot;2&amp;c=3'3
  • 分类页 {{fullurle:分类:模板}}https://wiki.biligame.com/tools/%E5%88%86%E7%B1%BB:%E6%A8%A1%E6%9D%BF
  • 跨wiki {{fullurle:arxiv:2501.12948}}https://www.arxiv.org/abs/2501.12948

底层代码

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

// mediawiki-1.37.0\includes\parser\CoreParserFunctions.php
public static function fullurle( $parser, $s = '', $arg = null ) {
	$temp = self::urlFunction( 'getFullURL', $s, $arg );
	if ( !is_string( $temp ) ) {
		return $temp;
	} else {
		return htmlspecialchars( $temp );
	}
}

// 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类自动解析
  • 使用php函数htmlspecialchars处理部分特殊字符(&"<>

实际用例

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