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

88 lines
3.1 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.15'
2007-08-22 19:25:22 +00:00
);
$dir = dirname( __FILE__ ) . '/';
define( 'CONTRIBUTIONSCORES_MAXINCLUDELIMIT', 50 );
$wgContribScoreReports = null;
// These settings can be overridden in LocalSettings.php.
$wgContribScoreIgnoreBlockedUsers = false; // Set to true to exclude bots from the reporting.
$wgContribScoreIgnoreBots = false; // Set to true to exclude blocked users from the reporting.
$wgContribScoresUseRealName = false; // Set to true to use real user names when available. Only for MediaWiki 1.19 and later.
$wgContribScoreDisableCache = false; // Set to true to disable cache for parser function and inclusion of table.
$wgAutoloadClasses['ContributionScores'] = $dir . 'ContributionScores_body.php';
2007-08-22 19:25:22 +00:00
$wgSpecialPages['ContributionScores'] = 'ContributionScores';
$wgSpecialPageGroups['ContributionScores'] = 'wiki';
$wgExtensionMessagesFiles['ContributionScores'] = $dir . 'ContributionScores.i18n.php';
$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',
2012-01-05 09:45:01 +00:00
array( 'rev_user' => $user->getID() ) );
$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',
2012-01-05 09:45:01 +00:00
array( 'rev_user' => $user->getID() ) );
$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',
2012-01-05 09:45:01 +00:00
array( 'rev_user' => $user->getID() ) );
$row = $dbr->fetchObject( $res );
$output = $wgLang->formatNum( $row->page_count );
} else {
2012-01-05 09:45:01 +00:00
$output = wfMsg( 'contributionscores-invalidmetric' );
}
} else {
2012-01-05 09:45:01 +00:00
$output = wfMsg( 'contributionscores-invalidusername' );
}
2012-01-05 09:45:01 +00:00
return $parser->insertStripItem( $output, $parser->mStripState );
}