2007-12-10 15:01:29 +00:00
|
|
|
<?php
|
2007-08-26 14:39:17 +00:00
|
|
|
/** \file
|
2008-08-10 19:29:02 +00: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
|
|
|
|
if (!defined('MEDIAWIKI')) {
|
2007-11-27 13:38:37 +00:00
|
|
|
echo "Contribution Scores extension";
|
|
|
|
exit(1);
|
2007-08-22 19:25:22 +00:00
|
|
|
}
|
2007-11-27 13:38:37 +00:00
|
|
|
|
2007-08-22 19:25:22 +00:00
|
|
|
$wgExtensionCredits['specialpage'][] = array(
|
2009-04-27 03:15:19 +00:00
|
|
|
'path' => __FILE__,
|
2011-11-28 16:34:58 +00:00
|
|
|
'name' => 'Contribution Scores',
|
|
|
|
'url' => 'http://www.mediawiki.org/wiki/Extension:Contribution_Scores',
|
|
|
|
'author' => 'Tim Laqua',
|
2008-02-05 14:54:15 +00:00
|
|
|
'descriptionmsg' => 'contributionscores-desc',
|
2011-11-28 16:34:58 +00:00
|
|
|
'version' => '1.12'
|
2007-08-22 19:25:22 +00:00
|
|
|
);
|
2007-11-27 13:38:37 +00:00
|
|
|
|
2007-12-19 01:24:52 +00:00
|
|
|
define( 'CONTRIBUTIONSCORES_PATH', dirname( __FILE__ ) );
|
|
|
|
define( 'CONTRIBUTIONSCORES_EXTPATH', str_replace( $_SERVER['DOCUMENT_ROOT'], '/', CONTRIBUTIONSCORES_PATH ) );
|
|
|
|
define( 'CONTRIBUTIONSCORES_MAXINCLUDELIMIT', 50 );
|
2008-04-17 17:31:22 +00:00
|
|
|
$wgContribScoreReports = null;
|
|
|
|
$wgContribScoreIgnoreBlockedUsers = false;
|
|
|
|
$wgContribScoreIgnoreBots = false;
|
2008-05-16 01:59:42 +00:00
|
|
|
$wgContribScoreDisableCache = false;
|
2007-12-19 01:24:52 +00:00
|
|
|
|
|
|
|
$wgAutoloadClasses['ContributionScores'] = CONTRIBUTIONSCORES_PATH . '/ContributionScores_body.php';
|
2007-08-22 19:25:22 +00:00
|
|
|
$wgSpecialPages['ContributionScores'] = 'ContributionScores';
|
2008-07-19 13:48:50 +00:00
|
|
|
$wgSpecialPageGroups['ContributionScores'] = 'wiki';
|
2007-11-27 20:29:24 +00:00
|
|
|
|
2011-02-13 23:25:59 +00:00
|
|
|
$wgExtensionMessagesFiles['ContributionScores'] = CONTRIBUTIONSCORES_PATH . '/ContributionScores.i18n.php';
|
|
|
|
$wgExtensionAliasesFiles['ContributionScores'] = CONTRIBUTIONSCORES_PATH . '/ContributionScores.alias.php';
|
|
|
|
$wgExtensionMessagesFiles['ContributionScores'] = CONTRIBUTIONSCORES_PATH . '/ContributionScores.i18n.php';
|
2007-11-27 20:29:24 +00:00
|
|
|
|
2008-05-16 01:51:28 +00:00
|
|
|
$wgHooks['LanguageGetMagic'][] = 'efContributionScores_LanguageGetMagic';
|
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' );
|
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
|
|
|
|
|
|
|
function efContributionScores_LanguageGetMagic( &$magicWords, $langCode ) {
|
|
|
|
$magicWords['cscore'] = array( 0, 'cscore' );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2008-05-16 01:59:42 +00:00
|
|
|
if ($wgContribScoreDisableCache) {
|
2008-05-16 01:51:28 +00:00
|
|
|
$parser->disableCache();
|
|
|
|
}
|
2008-08-10 19:29:02 +00:00
|
|
|
|
2008-05-16 01:51:28 +00:00
|
|
|
$user = User::newFromName($usertext);
|
|
|
|
$dbr = wfGetDB( DB_SLAVE );
|
2008-08-10 19:29:02 +00:00
|
|
|
|
2008-05-28 14:54:19 +00:00
|
|
|
if ( $user instanceof User && $user->isLoggedIn() ) {
|
2008-05-16 01:51:28 +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()));
|
|
|
|
$row = $dbr->fetchObject($res);
|
2008-05-16 01:59:42 +00:00
|
|
|
$output = round($row->wiki_rank,0);
|
2008-05-16 01:51:28 +00:00
|
|
|
} elseif ($metric=='changes') {
|
|
|
|
$res = $dbr->select('revision',
|
|
|
|
'COUNT(rev_id) AS rev_count',
|
|
|
|
array('rev_user' => $user->getID()));
|
|
|
|
$row = $dbr->fetchObject($res);
|
|
|
|
$output = $row->rev_count;
|
2008-08-10 19:29:02 +00:00
|
|
|
|
2008-05-16 01:51:28 +00:00
|
|
|
} elseif ($metric=='pages') {
|
|
|
|
$res = $dbr->select('revision',
|
|
|
|
'COUNT(DISTINCT rev_page) AS page_count',
|
|
|
|
array('rev_user' => $user->getID()));
|
|
|
|
$row = $dbr->fetchObject($res);
|
|
|
|
$output = $row->page_count;
|
|
|
|
} else {
|
|
|
|
$output = wfMsg('contributionscores-invalidmetric');
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$output = wfMsg('contributionscores-invalidusername');
|
|
|
|
}
|
2008-08-10 19:29:02 +00:00
|
|
|
|
2008-05-16 01:51:28 +00:00
|
|
|
return $parser->insertStripItem($output, $parser->mStripState);
|
2008-08-10 19:29:02 +00:00
|
|
|
}
|