2007-12-10 15:01:29 +00:00
|
|
|
<?php
|
2007-08-26 14:39:17 +00:00
|
|
|
/** \file
|
2015-10-01 15:20:36 +02:00
|
|
|
* \brief Contains setup code for the Contribution Scores Extension.
|
|
|
|
*/
|
2007-08-26 14:39:17 +00:00
|
|
|
|
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' ) ) {
|
2015-10-01 15:20:36 +02:00
|
|
|
echo 'Contribution Scores extension';
|
2012-01-05 09:45:01 +00:00
|
|
|
exit( 1 );
|
2007-08-22 19:25:22 +00:00
|
|
|
}
|
2007-11-27 13:38:37 +00:00
|
|
|
|
2016-02-17 15:57:15 +01:00
|
|
|
$wgExtensionCredits['specialpage'][] = [
|
2009-04-27 03:15:19 +00:00
|
|
|
'path' => __FILE__,
|
2011-11-28 16:34:58 +00:00
|
|
|
'name' => 'Contribution Scores',
|
2011-12-13 23:49:33 +00:00
|
|
|
'url' => 'https://www.mediawiki.org/wiki/Extension:Contribution_Scores',
|
2011-11-28 16:34:58 +00:00
|
|
|
'author' => 'Tim Laqua',
|
2008-02-05 14:54:15 +00:00
|
|
|
'descriptionmsg' => 'contributionscores-desc',
|
2016-02-17 15:57:15 +01:00
|
|
|
'version' => '1.25.0'
|
|
|
|
];
|
2007-11-27 13:38:37 +00:00
|
|
|
|
2007-12-19 01:24:52 +00:00
|
|
|
define( 'CONTRIBUTIONSCORES_MAXINCLUDELIMIT', 50 );
|
2008-04-17 17:31:22 +00:00
|
|
|
$wgContribScoreReports = null;
|
2012-01-05 10:07:48 +00:00
|
|
|
|
|
|
|
// These settings can be overridden in LocalSettings.php.
|
2007-12-19 01:24:52 +00:00
|
|
|
|
2015-10-01 15:20:36 +02:00
|
|
|
// 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';
|
2007-11-27 20:29:24 +00:00
|
|
|
|
2014-03-27 11:53:16 +01:00
|
|
|
$wgMessagesDirs['ContributionScores'] = __DIR__ . '/i18n';
|
2015-10-01 15:20:36 +02:00
|
|
|
$wgExtensionMessagesFiles['ContributionScoresAlias'] = __DIR__ . '/ContributionScores.alias.php';
|
|
|
|
$wgExtensionMessagesFiles['ContributionScoresMagic'] =
|
|
|
|
__DIR__ . '/ContributionScores.i18n.magic.php';
|
2008-05-25 21:09:41 +00:00
|
|
|
|
2009-09-04 22:22:12 +00:00
|
|
|
$wgHooks['ParserFirstCallInit'][] = 'efContributionScores_Setup';
|
2008-05-16 01:51:28 +00:00
|
|
|
|
2009-09-04 22:22:12 +00:00
|
|
|
function efContributionScores_Setup( &$parser ) {
|
|
|
|
$parser->setFunctionHook( 'cscore', 'efContributionScores_Render' );
|
2015-10-01 15:20:36 +02:00
|
|
|
|
2008-05-16 01:51:28 +00:00
|
|
|
return true;
|
2008-01-04 01:40:33 +00:00
|
|
|
}
|
2008-05-16 01:51:28 +00:00
|
|
|
|
2012-01-05 09:45:01 +00:00
|
|
|
function efContributionScores_Render( &$parser, $usertext, $metric = 'score' ) {
|
2010-08-06 23:40:27 +00:00
|
|
|
global $wgContribScoreDisableCache;
|
2010-05-27 15:56:53 +00:00
|
|
|
|
2012-01-05 09:45:01 +00:00
|
|
|
if ( $wgContribScoreDisableCache ) {
|
2019-11-04 15:14:56 -05:00
|
|
|
$parser->getOutput()->updateCacheExpiry( 0 );
|
2008-05-16 01:51:28 +00:00
|
|
|
}
|
2008-08-10 19:29:02 +00:00
|
|
|
|
2012-01-05 09:45:01 +00:00
|
|
|
$user = User::newFromName( $usertext );
|
2017-09-24 05:22:25 +00:00
|
|
|
$dbr = wfGetDB( DB_REPLICA );
|
2008-08-10 19:29:02 +00:00
|
|
|
|
2008-05-28 14:54:19 +00:00
|
|
|
if ( $user instanceof User && $user->isLoggedIn() ) {
|
2012-01-05 09:43:51 +00:00
|
|
|
global $wgLang;
|
|
|
|
|
2012-01-05 09:45:01 +00:00
|
|
|
if ( $metric == 'score' ) {
|
|
|
|
$res = $dbr->select( 'revision',
|
2015-10-01 15:20:36 +02:00
|
|
|
'COUNT(DISTINCT rev_page)+SQRT(COUNT(rev_id)-COUNT(DISTINCT rev_page))*2 AS wiki_rank',
|
2016-02-17 15:57:15 +01:00
|
|
|
[ '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',
|
2015-10-01 15:20:36 +02:00
|
|
|
'COUNT(rev_id) AS rev_count',
|
2016-02-17 15:57:15 +01:00
|
|
|
[ 'rev_user' => $user->getID() ] );
|
2012-01-05 09:45:01 +00:00
|
|
|
$row = $dbr->fetchObject( $res );
|
2012-01-05 09:43:51 +00:00
|
|
|
$output = $wgLang->formatNum( $row->rev_count );
|
2012-01-05 09:45:01 +00:00
|
|
|
} elseif ( $metric == 'pages' ) {
|
|
|
|
$res = $dbr->select( 'revision',
|
2015-10-01 15:20:36 +02:00
|
|
|
'COUNT(DISTINCT rev_page) AS page_count',
|
2016-02-17 15:57:15 +01:00
|
|
|
[ 'rev_user' => $user->getID() ] );
|
2012-01-05 09:45:01 +00:00
|
|
|
$row = $dbr->fetchObject( $res );
|
2012-01-05 09:43:51 +00:00
|
|
|
$output = $wgLang->formatNum( $row->page_count );
|
2008-05-16 01:51:28 +00:00
|
|
|
} else {
|
2012-08-16 14:19:19 +02:00
|
|
|
$output = wfMessage( 'contributionscores-invalidmetric' )->text();
|
2008-05-16 01:51:28 +00:00
|
|
|
}
|
|
|
|
} else {
|
2012-08-16 14:19:19 +02:00
|
|
|
$output = wfMessage( 'contributionscores-invalidusername' )->text();
|
2008-05-16 01:51:28 +00:00
|
|
|
}
|
2008-08-10 19:29:02 +00:00
|
|
|
|
2012-01-05 09:45:01 +00:00
|
|
|
return $parser->insertStripItem( $output, $parser->mStripState );
|
2008-08-10 19:29:02 +00:00
|
|
|
}
|