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

帮助:解析函数/pagesize

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

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

PAGESIZE

获取指定页面的大小。MediaWiki原生支持。

语法

  • {{PAGESIZE: 页面名 }}
    • 页面名:指定一个页面获取其大小(byte size)
  • {{PAGESIZE: 页面名 | R }}
    • 不格式化结果数字(无逗号分隔符)

示例

  • {{PAGESIZE: 帮助:解析函数 }} → 14,024
  • {{PAGESIZE: 帮助:解析函数 | R }} → 14024
  • {{PAGESIZE: 帮助:不存在的页面23333333}} → 0

底层代码

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

/** mediawiki-1.37.0\includes\parser\CoreParserFunctions.php
 * Return the size of the given page, or 0 if it's nonexistent.  This is an
 * expensive parser function and can't be called too many times per page.
 *
 * @param Parser $parser
 * @param string $page Name of page to check (Default: empty string)
 * @param string|null $raw Should number be human readable with commas or just number
 * @return string
 */
public static function pagesize( $parser, $page = '', $raw = null ) {
	$title = Title::newFromText( $page );

	if ( !is_object( $title ) ) {
		return self::formatRaw( 0, $raw, $parser->getFunctionLang() );
	}

	// fetch revision from cache/database and return the value
	$rev = self::getCachedRevisionObject( $parser, $title, 'vary-revision-sha1' );
	$length = $rev ? $rev->getSize() : 0;
	if ( $length === null ) {
		// We've had bugs where rev_len was not being recorded for empty pages, see T135414
		$length = 0;
	}
	return self::formatRaw( $length, $raw, $parser->getFunctionLang() );
}
代码逻辑:
  • 根据给出的标题查询页面大小
  • 非法标题、不存在的页面和空页面均返回 0

实际用例

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