2007-08-22 19:25:22 +00:00
|
|
|
<?php
|
2007-08-26 14:39:17 +00:00
|
|
|
/** \file
|
|
|
|
* \brief Contains code for the ContributionScores Class (extends SpecialPage).
|
|
|
|
*/
|
|
|
|
|
|
|
|
///Special page class for the Contribution Scores extension
|
|
|
|
/**
|
|
|
|
* Special page that generates a list of wiki contributors based
|
2007-11-27 13:38:37 +00:00
|
|
|
* on edit diversity (unique pages edited) and edit volume (total
|
2007-08-26 14:39:17 +00:00
|
|
|
* number of edits.
|
|
|
|
*
|
|
|
|
* @addtogroup Extensions
|
|
|
|
* @author Tim Laqua <t.laqua@gmail.com>
|
|
|
|
*/
|
2007-12-19 01:24:52 +00:00
|
|
|
class ContributionScores extends IncludableSpecialPage
|
2007-08-22 19:25:22 +00:00
|
|
|
{
|
2007-11-27 13:38:37 +00:00
|
|
|
public function __construct() {
|
2007-12-19 01:24:52 +00:00
|
|
|
parent::__construct( 'ContributionScores' );
|
2007-11-27 13:38:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getDescription() {
|
|
|
|
return wfMsg( 'contributionscores' );
|
|
|
|
}
|
|
|
|
|
|
|
|
///Generates a "Contribution Scores" table for a given LIMIT and date range
|
|
|
|
/**
|
|
|
|
* Function generates Contribution Scores tables in HTML format (not wikiText)
|
|
|
|
*
|
|
|
|
* @param $days int Days in the past to run report for
|
|
|
|
* @param $limit int Maximum number of users to return (default 50)
|
|
|
|
*
|
|
|
|
* @return HTML Table representing the requested Contribution Scores.
|
|
|
|
*/
|
2007-12-19 15:45:09 +00:00
|
|
|
function genContributionScoreTable( $days, $limit, $title = null, $options = 'none' ) {
|
2007-11-27 13:38:37 +00:00
|
|
|
global $contribScoreIgnoreBots, $wgUser;
|
|
|
|
|
2007-12-19 15:45:09 +00:00
|
|
|
$opts = explode(',', strtolower($options));
|
|
|
|
|
2007-11-27 13:38:37 +00:00
|
|
|
$dbr =& wfGetDB( DB_SLAVE );
|
|
|
|
|
|
|
|
$userTable = $dbr->tableName('user');
|
|
|
|
$userGroupTable = $dbr->tableName('user_groups');
|
|
|
|
$revTable = $dbr->tableName('revision');
|
2007-12-19 15:45:09 +00:00
|
|
|
|
|
|
|
$sqlWhere = "";
|
|
|
|
|
2007-11-27 13:38:37 +00:00
|
|
|
if ( $days > 0 ) {
|
2007-11-27 13:56:23 +00:00
|
|
|
$date = time() - (60*60*24*$days);
|
2007-11-27 13:38:37 +00:00
|
|
|
$dateString = $dbr->timestamp($date);
|
2007-12-19 15:45:09 +00:00
|
|
|
$sqlWhere .= " WHERE rev_timestamp > '$dateString' ";
|
2007-11-27 13:38:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( $contribScoreIgnoreBots ) {
|
2007-12-19 15:45:09 +00:00
|
|
|
if (preg_match("/where/i", $sqlWhere)) {
|
|
|
|
$sqlWhere .= "AND ";
|
2007-11-27 13:38:37 +00:00
|
|
|
} else {
|
2007-12-19 15:45:09 +00:00
|
|
|
$sqlWhere .= "WHERE ";
|
2007-11-27 13:38:37 +00:00
|
|
|
}
|
2007-12-19 15:45:09 +00:00
|
|
|
$sqlWhere .= "rev_user NOT IN (SELECT ug_user FROM {$userGroupTable} WHERE ug_group='bot') ";
|
2007-11-27 13:38:37 +00:00
|
|
|
}
|
|
|
|
|
2007-12-19 15:45:09 +00:00
|
|
|
$sqlMostPages = "SELECT rev_user,
|
|
|
|
COUNT(DISTINCT rev_page) AS page_count,
|
|
|
|
COUNT(rev_id) AS rev_count
|
|
|
|
FROM {$revTable}
|
|
|
|
{$sqlWhere}
|
|
|
|
GROUP BY rev_user
|
2007-12-19 17:23:43 +00:00
|
|
|
ORDER BY page_count DESC
|
2007-12-19 15:45:09 +00:00
|
|
|
LIMIT {$limit}";
|
|
|
|
|
|
|
|
$sqlMostRevs = "SELECT rev_user,
|
|
|
|
COUNT(DISTINCT rev_page) AS page_count,
|
|
|
|
COUNT(rev_id) AS rev_count
|
|
|
|
FROM {$revTable}
|
|
|
|
{$sqlWhere}
|
2007-12-19 17:23:43 +00:00
|
|
|
GROUP BY rev_user
|
|
|
|
ORDER BY rev_count DESC
|
2007-12-19 15:45:09 +00:00
|
|
|
LIMIT {$limit}";
|
|
|
|
|
|
|
|
$sql = "SELECT user_id, " .
|
|
|
|
"user_name, " .
|
|
|
|
"page_count, " .
|
|
|
|
"rev_count, " .
|
|
|
|
"page_count+SQRT(rev_count-page_count)*2 AS wiki_rank " .
|
|
|
|
"FROM $userTable u JOIN (($sqlMostPages) UNION ($sqlMostRevs)) s ON (user_id=rev_user) " .
|
2007-11-27 13:38:37 +00:00
|
|
|
"ORDER BY wiki_rank DESC " .
|
|
|
|
"LIMIT $limit";
|
2007-12-19 15:45:09 +00:00
|
|
|
|
2007-11-27 13:38:37 +00:00
|
|
|
$res = $dbr->query($sql);
|
2007-12-19 15:45:09 +00:00
|
|
|
|
|
|
|
$sortable = in_array('nosort', $opts) ? '' : ' sortable';
|
|
|
|
|
|
|
|
$output = "<table class=\"wikitable plainlinks{$sortable}\" >\n".
|
2007-12-19 01:24:52 +00:00
|
|
|
"<tr class='contributionscores-tableheadings'>\n".
|
2007-12-19 15:45:09 +00:00
|
|
|
"<td class=\"contributionscores-headercell\">" . wfMsg( 'contributionscores-score' ) . "</td>\n" .
|
|
|
|
"<td class=\"contributionscores-headercell\">" . wfMsg( 'contributionscores-pages' ) . "</td>\n" .
|
|
|
|
"<td class=\"contributionscores-headercell\">" . wfMsg( 'contributionscores-changes' ) . "</td>\n" .
|
|
|
|
"<td class=\"contributionscores-headercell\">" . wfMsg( 'contributionscores-username' ) . "</td>\n";
|
2007-11-27 13:38:37 +00:00
|
|
|
|
|
|
|
$skin =& $wgUser->getSkin();
|
2007-12-19 01:24:52 +00:00
|
|
|
$altrow = '';
|
2007-11-27 13:38:37 +00:00
|
|
|
while ( $row = $dbr->fetchObject( $res ) ) {
|
2007-12-19 15:45:09 +00:00
|
|
|
$output .= "</tr><tr class='{$altrow}'>\n<td class='contributionscores-contentcell'>" .
|
|
|
|
round($row->wiki_rank,0) . "\n</td><td class='contributionscores-contentcell'>" .
|
|
|
|
$row->page_count . "\n</td><td class='contributionscores-contentcell'>" .
|
|
|
|
$row->rev_count . "\n</td><td class='contributionscores-contentcell'>" .
|
|
|
|
$skin->userLink( $row->user_id, $row->user_name );
|
|
|
|
|
|
|
|
# Option to not display user tools
|
|
|
|
if ( !in_array( 'notools', $opts ) )
|
|
|
|
$output .= $skin->userToolLinks( $row->user_id, $row->user_name );
|
|
|
|
|
|
|
|
$output .= "</td>\n";
|
2007-12-19 01:24:52 +00:00
|
|
|
|
|
|
|
if ($altrow == '')
|
|
|
|
$altrow = 'contributionscores-altrow ';
|
|
|
|
else
|
|
|
|
$altrow = '';
|
2007-11-27 13:38:37 +00:00
|
|
|
}
|
|
|
|
$output .= "</tr></table>";
|
|
|
|
$dbr->freeResult( $res );
|
2007-12-19 01:24:52 +00:00
|
|
|
|
|
|
|
if ( !empty( $title ) )
|
|
|
|
$output = "<table cellspacing='0' cellpadding='0' class='contributionscores-wrapper'>\n".
|
|
|
|
"<tr>\n".
|
|
|
|
"<td style='padding: 0px;'>{$title}</td>\n".
|
|
|
|
"</tr>\n".
|
|
|
|
"<tr>\n".
|
|
|
|
"<td style='padding: 0px;'>{$output}</td>\n".
|
|
|
|
"</tr>\n".
|
|
|
|
"</table>";
|
|
|
|
|
2007-11-27 13:38:37 +00:00
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
|
|
|
|
function execute( $par ) {
|
2007-12-19 02:15:35 +00:00
|
|
|
global $wgRequest, $wgVersion, $wgOut, $wgHooks;
|
|
|
|
|
|
|
|
$wgHooks['BeforePageDisplay'][] = 'efContributionScores_addHeadScripts';
|
2007-11-27 20:29:24 +00:00
|
|
|
|
2007-11-28 14:28:20 +00:00
|
|
|
if( version_compare( $wgVersion, '1.11', '>=' ) )
|
2007-11-27 20:29:24 +00:00
|
|
|
wfLoadExtensionMessages( 'ContributionScores' );
|
|
|
|
|
2007-11-27 13:38:37 +00:00
|
|
|
$this->setHeaders();
|
|
|
|
|
2007-12-19 01:24:52 +00:00
|
|
|
if( $this->including() ) {
|
|
|
|
$this->showInclude( $par );
|
|
|
|
} else {
|
|
|
|
$this->showPage();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
function showInclude( $par ) {
|
|
|
|
global $wgOut;
|
2007-11-27 13:38:37 +00:00
|
|
|
|
2007-12-19 01:24:52 +00:00
|
|
|
$days = null;
|
|
|
|
$limit = null;
|
2007-12-19 15:45:09 +00:00
|
|
|
$options = 'none';
|
2007-12-19 01:24:52 +00:00
|
|
|
|
|
|
|
if ( !empty( $par ) ) {
|
|
|
|
$params = explode('/', $par);
|
|
|
|
|
|
|
|
$limit = intval( $params[0] );
|
|
|
|
|
|
|
|
if ( isset( $params[1] ) )
|
|
|
|
$days = intval( $params[1] );
|
2007-12-19 15:45:09 +00:00
|
|
|
|
|
|
|
if ( isset( $params[2] ) )
|
|
|
|
$options = $params[2];
|
2007-12-19 01:24:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( empty( $limit ) || $limit < 1 || $limit > CONTRIBUTIONSCORES_MAXINCLUDELIMIT )
|
|
|
|
$limit = 10;
|
|
|
|
if ( is_null( $days ) || $days < 0 )
|
|
|
|
$days = 7;
|
|
|
|
|
|
|
|
if ( $days > 0 ) {
|
|
|
|
$reportTitle = wfMsg( 'contributionscores-days', $days );
|
|
|
|
} else {
|
|
|
|
$reportTitle = wfMsg( 'contributionscores-allrevisions' );
|
|
|
|
}
|
|
|
|
$reportTitle .= " " . wfMsg( 'contributionscores-top', $limit );
|
|
|
|
$title = "<h4 class='contributionscores-title'> $reportTitle </h4>\n";
|
2007-12-19 15:45:09 +00:00
|
|
|
$wgOut->addHtml( $this->genContributionScoreTable( $days, $limit, $title, $options ) );
|
2007-12-19 01:24:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function showPage() {
|
|
|
|
global $wgOut, $contribScoreReports;
|
|
|
|
|
2007-11-27 13:38:37 +00:00
|
|
|
if (!is_array($contribScoreReports)) {
|
|
|
|
$contribScoreReports = array(
|
|
|
|
array(7,50),
|
|
|
|
array(30,50),
|
|
|
|
array(0,50));
|
|
|
|
}
|
|
|
|
|
|
|
|
$wgOut->addWikiText (wfMsg('contributionscores-info'));
|
|
|
|
|
|
|
|
foreach ( $contribScoreReports as $scoreReport) {
|
|
|
|
if ( $scoreReport[0] > 0 ) {
|
|
|
|
$reportTitle = wfMsg('contributionscores-days', $scoreReport[0]);
|
|
|
|
} else {
|
|
|
|
$reportTitle = wfMsg('contributionscores-allrevisions');
|
|
|
|
}
|
|
|
|
$reportTitle .= " " . wfMsg('contributionscores-top', $scoreReport[1]);
|
2007-12-19 01:24:52 +00:00
|
|
|
$wgOut->addHtml ("<h2 class='contributionscores-title'>$reportTitle</h2>\n");
|
2007-11-27 13:38:37 +00:00
|
|
|
$wgOut->addHtml( $this->genContributionScoreTable($scoreReport[0],$scoreReport[1]));
|
|
|
|
}
|
|
|
|
}
|
2007-08-22 19:25:22 +00:00
|
|
|
}
|