社区文档构建进行中,欢迎编辑。社区答疑群(非官方):717421103

全站通知:

帮助:解析函数/cscore

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

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

cscore

获取用户贡献,如贡献分数、编辑数、编辑页面数。出自扩展 Contribution Scores

语法

贡献分数:{{#cscore:用户名|score}}
编辑次数:{{#cscore:用户名|changes}}
编辑页面:{{#cscore:用户名|pages}}
  • 注意,此处的用户名是B站用户的bid。

示例

以Lu(bid 39886146)为例

贡献分数:{{#cscore:39886146|score}} → 1,887
编辑次数:{{#cscore:39886146|changes}} → 7,772
编辑页面数量:{{#cscore:39886146|pages}} → 1,732

底层代码

/* mediawiki-extensions-ContributionScores-REL1_37/src/ContributionScores.php */
public static function efContributionScoresRender( $parser, $usertext, $metric = 'score' ) {
	global $wgContribScoreDisableCache;

	if ( $wgContribScoreDisableCache ) {
		$parser->getOutput()->updateCacheExpiry( 0 );
	}

	$user = User::newFromName( $usertext );
	$dbr = wfGetDB( DB_REPLICA );

	if ( $user instanceof User && $user->isRegistered() ) {
		global $wgLang;

		$revWhere = ActorMigration::newMigration()->getWhere( $dbr, 'rev_user', $user );
		if ( $metric == 'score' ) {
			$res = $dbr->select(
				[ 'revision' ] + $revWhere['tables'],
				'COUNT(DISTINCT rev_page)+SQRT(COUNT(rev_id)-COUNT(DISTINCT rev_page))*2 AS wiki_rank',
				$revWhere['conds'],
				__METHOD__,
				[],
				$revWhere['joins']
			);
			$row = $dbr->fetchObject( $res );
			$output = $wgLang->formatNum( round( $row->wiki_rank, 0 ) );
		} elseif ( $metric == 'changes' ) {
			$res = $dbr->select(
				[ 'revision' ] + $revWhere['tables'],
				'COUNT(rev_id) AS rev_count',
				$revWhere['conds'],
				__METHOD__,
				[],
				$revWhere['joins']
			);
			$row = $dbr->fetchObject( $res );
			$output = $wgLang->formatNum( $row->rev_count );
		} elseif ( $metric == 'pages' ) {
			$res = $dbr->select(
				[ 'revision' ] + $revWhere['tables'],
				'COUNT(DISTINCT rev_page) AS page_count',
				$revWhere['conds'],
				__METHOD__,
				[],
				$revWhere['joins']
			);
			$row = $dbr->fetchObject( $res );
			$output = $wgLang->formatNum( $row->page_count );
		} else {
			$output = wfMessage( 'contributionscores-invalidmetric' )->text();
		}
	} else {
		$output = wfMessage( 'contributionscores-invalidusername' )->text();
	}
	return $parser->insertStripItem( $output, $parser->mStripState );
}
代码逻辑:
  • 根据用户名和模式从数据库查询对应数据

实际用例

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