mediawiki-extensions-Contri.../ContributionScores.php

94 lines
3 KiB
PHP
Raw Normal View History

2007-12-10 15:01:29 +00:00
<?php
/** \file
* \brief Contains setup code for the Contribution Scores Extension.
*/
2007-08-22 19:25:22 +00:00
# Not a valid entry point, skip unless MEDIAWIKI is defined
2012-01-05 09:45:01 +00:00
if ( !defined( 'MEDIAWIKI' ) ) {
echo 'Contribution Scores extension';
2012-01-05 09:45:01 +00:00
exit( 1 );
2007-08-22 19:25:22 +00:00
}
2007-08-22 19:25:22 +00:00
$wgExtensionCredits['specialpage'][] = array(
'path' => __FILE__,
'name' => 'Contribution Scores',
'url' => 'https://www.mediawiki.org/wiki/Extension:Contribution_Scores',
'author' => 'Tim Laqua',
'descriptionmsg' => 'contributionscores-desc',
'version' => '1.23.0'
2007-08-22 19:25:22 +00:00
);
define( 'CONTRIBUTIONSCORES_MAXINCLUDELIMIT', 50 );
$wgContribScoreReports = null;
// These settings can be overridden in LocalSettings.php.
// Set to true to exclude bots from the reporting.
$wgContribScoreIgnoreBlockedUsers = false;
// Set to true to exclude blocked users from the reporting.
$wgContribScoreIgnoreBots = false;
// Set to true to use real user names when available. Only for MediaWiki 1.19 and later.
$wgContribScoresUseRealName = false;
// Set to true to disable cache for parser function and inclusion of table.
$wgContribScoreDisableCache = false;
$wgAutoloadClasses['ContributionScores'] = __DIR__ . '/ContributionScores_body.php';
2007-08-22 19:25:22 +00:00
$wgSpecialPages['ContributionScores'] = 'ContributionScores';
$wgMessagesDirs['ContributionScores'] = __DIR__ . '/i18n';
$wgExtensionMessagesFiles['ContributionScoresAlias'] = __DIR__ . '/ContributionScores.alias.php';
$wgExtensionMessagesFiles['ContributionScoresMagic'] =
__DIR__ . '/ContributionScores.i18n.magic.php';
2008-05-25 21:09:41 +00:00
$wgHooks['ParserFirstCallInit'][] = 'efContributionScores_Setup';
function efContributionScores_Setup( &$parser ) {
$parser->setFunctionHook( 'cscore', 'efContributionScores_Render' );
return true;
2008-01-04 01:40:33 +00:00
}
2012-01-05 09:45:01 +00:00
function efContributionScores_Render( &$parser, $usertext, $metric = 'score' ) {
global $wgContribScoreDisableCache;
2012-01-05 09:45:01 +00:00
if ( $wgContribScoreDisableCache ) {
$parser->disableCache();
}
2012-01-05 09:45:01 +00:00
$user = User::newFromName( $usertext );
$dbr = wfGetDB( DB_SLAVE );
if ( $user instanceof User && $user->isLoggedIn() ) {
global $wgLang;
2012-01-05 09:45:01 +00:00
if ( $metric == 'score' ) {
$res = $dbr->select( 'revision',
'COUNT(DISTINCT rev_page)+SQRT(COUNT(rev_id)-COUNT(DISTINCT rev_page))*2 AS wiki_rank',
array( 'rev_user' => $user->getID() ) );
2012-01-05 09:45:01 +00:00
$row = $dbr->fetchObject( $res );
$output = $wgLang->formatNum( round( $row->wiki_rank, 0 ) );
} elseif ( $metric == 'changes' ) {
$res = $dbr->select( 'revision',
'COUNT(rev_id) AS rev_count',
array( 'rev_user' => $user->getID() ) );
2012-01-05 09:45:01 +00:00
$row = $dbr->fetchObject( $res );
$output = $wgLang->formatNum( $row->rev_count );
2012-01-05 09:45:01 +00:00
} elseif ( $metric == 'pages' ) {
$res = $dbr->select( 'revision',
'COUNT(DISTINCT rev_page) AS page_count',
array( 'rev_user' => $user->getID() ) );
2012-01-05 09:45:01 +00:00
$row = $dbr->fetchObject( $res );
$output = $wgLang->formatNum( $row->page_count );
} else {
$output = wfMessage( 'contributionscores-invalidmetric' )->text();
}
} else {
$output = wfMessage( 'contributionscores-invalidusername' )->text();
}
2012-01-05 09:45:01 +00:00
return $parser->insertStripItem( $output, $parser->mStripState );
}