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

帮助:解析函数/protectionlevel

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

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

PROTECTIONLEVEL

查询页面保护级别。MediaWiki原生支持。

查询非当前页面时,是【高开销】函数。

语法

  • {{PROTECTIONLEVEL: 操作 }}
    • 操作:如move、edit。查询当前页面的保护级别
  • {{PROTECTIONLEVEL: 操作 | 页面名 }}
    • 页面名:查询指定页面的保护级别【高开销】

返回结果为autoconfirmedsysop或空字符串(未受保护)。超过高开销函数次数限制后,其返回结果是空字符串。

在BWiki中,Lv2以上的B站用户会被自动授予 autoconfirmed 用户组,因此只有“仅允许管理员”的页面保护是有意义的。

示例

  • {{PROTECTIONLEVEL: edit }}
  • {{PROTECTIONLEVEL: move }}
  • {{PROTECTIONLEVEL: edit | 保护页面示例 }} → sysop(这是个被永久保护的页面)
  • {{PROTECTIONLEVEL: move | 保护页面示例 }} → sysop

底层代码

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

/** mediawiki-1.37.0\includes\parser\CoreParserFunctions.php
 * Returns the requested protection level for the current page. This
 * is an expensive parser function and can't be called too many times
 * per page, unless the protection levels/expiries for the given title
 * have already been retrieved
 *
 * @param Parser $parser
 * @param string $type
 * @param string $title
 *
 * @return string
 */
public static function protectionlevel( $parser, $type = '', $title = '' ) {
	$titleObject = Title::newFromText( $title ) ?? $parser->getTitle();
	if ( $titleObject->areRestrictionsLoaded() || $parser->incrementExpensiveFunctionCount() ) {
		$restrictions = $titleObject->getRestrictions( strtolower( $type ) );
		# Title::getRestrictions returns an array, its possible it may have
		# multiple values in the future
		return implode( ',', $restrictions );
	}
	return '';
}
代码逻辑:
  • 根据标题查询保护级别
  • 超过高开销函数次数限制,或未保护的页面返回空字符串

实际用例

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