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.
|
|
|
|
*
|
2010-06-06 15:12:22 +00:00
|
|
|
* @ingroup Extensions
|
2007-08-26 14:39:17 +00:00
|
|
|
* @author Tim Laqua <t.laqua@gmail.com>
|
|
|
|
*/
|
2010-09-11 14:31:16 +00:00
|
|
|
class ContributionScores extends IncludableSpecialPage {
|
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' ) {
|
2011-11-28 16:34:58 +00:00
|
|
|
global $wgContribScoreIgnoreBots, $wgContribScoreIgnoreBlockedUsers, $wgUser, $wgLang;
|
2007-11-27 13:38:37 +00:00
|
|
|
|
2011-11-28 16:34:58 +00:00
|
|
|
$opts = explode( ',', strtolower( $options ) );
|
2007-12-19 15:45:09 +00:00
|
|
|
|
2007-12-20 22:37:18 +00:00
|
|
|
$dbr = wfGetDB( DB_SLAVE );
|
2007-11-27 13:38:37 +00:00
|
|
|
|
|
|
|
$userTable = $dbr->tableName('user');
|
|
|
|
$userGroupTable = $dbr->tableName('user_groups');
|
|
|
|
$revTable = $dbr->tableName('revision');
|
2008-04-17 17:31:22 +00:00
|
|
|
$ipBlocksTable = $dbr->tableName('ipblocks');
|
2007-12-19 15:45:09 +00:00
|
|
|
|
|
|
|
$sqlWhere = "";
|
2008-04-17 17:31:22 +00:00
|
|
|
$nextPrefix = "WHERE";
|
2007-12-19 15:45:09 +00:00
|
|
|
|
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);
|
2008-04-17 17:31:22 +00:00
|
|
|
$sqlWhere .= " {$nextPrefix} rev_timestamp > '$dateString'";
|
|
|
|
$nextPrefix = "AND";
|
2007-11-27 13:38:37 +00:00
|
|
|
}
|
|
|
|
|
2008-04-17 17:31:22 +00:00
|
|
|
if ( $wgContribScoreIgnoreBlockedUsers ) {
|
|
|
|
$sqlWhere .= " {$nextPrefix} rev_user NOT IN (SELECT ipb_user FROM {$ipBlocksTable} WHERE ipb_user <> 0)";
|
|
|
|
$nextPrefix = "AND";
|
2007-11-27 13:38:37 +00:00
|
|
|
}
|
|
|
|
|
2008-04-17 17:31:22 +00:00
|
|
|
if ( $wgContribScoreIgnoreBots ) {
|
|
|
|
$sqlWhere .= " {$nextPrefix} rev_user NOT IN (SELECT ug_user FROM {$userGroupTable} WHERE ug_group='bot')";
|
|
|
|
$nextPrefix = "AND";
|
|
|
|
}
|
|
|
|
|
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}";
|
|
|
|
|
2010-10-29 21:55:29 +00:00
|
|
|
$sql = "SELECT user_id, " .
|
2007-12-19 15:45:09 +00:00
|
|
|
"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
|
|
|
|
2011-11-28 16:34:58 +00:00
|
|
|
$res = $dbr->query( $sql );
|
2007-12-19 15:45:09 +00:00
|
|
|
|
2011-11-28 16:34:58 +00:00
|
|
|
$sortable = in_array( 'nosort', $opts ) ? '' : ' sortable';
|
2007-12-19 15:45:09 +00:00
|
|
|
|
2008-04-14 17:22:51 +00:00
|
|
|
$output = "<table class=\"wikitable contributionscores plainlinks{$sortable}\" >\n".
|
|
|
|
"<tr class='header'>\n".
|
2011-11-28 16:34:58 +00:00
|
|
|
"<th>" . wfMsgHtml( 'contributionscores-score' ) . "</th>\n" .
|
|
|
|
"<th>" . wfMsgHtml( 'contributionscores-pages' ) . "</th>\n" .
|
|
|
|
"<th>" . wfMsgHtml( 'contributionscores-changes' ) . "</th>\n" .
|
|
|
|
"<th>" . wfMsgHtml( 'contributionscores-username' ) . "</th>\n";
|
2007-11-27 13:38:37 +00:00
|
|
|
|
2010-09-11 14:31:16 +00:00
|
|
|
$skin = $wgUser->getSkin();
|
2007-12-19 01:24:52 +00:00
|
|
|
$altrow = '';
|
2010-10-29 21:30:20 +00:00
|
|
|
foreach ( $res as $row ) {
|
2008-04-14 17:22:51 +00:00
|
|
|
$output .= "</tr><tr class='{$altrow}'>\n<td class='content'>" .
|
2011-11-28 16:34:58 +00:00
|
|
|
$wgLang->formatNum( round( $row->wiki_rank, 0 ) ) . "\n</td><td class='content'>" .
|
|
|
|
$wgLang->formatNum( $row->page_count ) . "\n</td><td class='content'>" .
|
|
|
|
$wgLang->formatNum( $row->rev_count ) . "\n</td><td class='content'>" .
|
2007-12-19 15:45:09 +00:00
|
|
|
$skin->userLink( $row->user_id, $row->user_name );
|
|
|
|
|
2007-12-20 22:37:18 +00:00
|
|
|
# Option to not display user tools
|
2007-12-19 15:45:09 +00:00
|
|
|
if ( !in_array( 'notools', $opts ) )
|
|
|
|
$output .= $skin->userToolLinks( $row->user_id, $row->user_name );
|
|
|
|
|
|
|
|
$output .= "</td>\n";
|
2008-04-14 17:22:51 +00:00
|
|
|
|
2011-11-28 16:34:58 +00:00
|
|
|
if ( $altrow == '' && empty( $sortable ) )
|
2008-04-14 17:22:51 +00:00
|
|
|
$altrow = 'odd ';
|
2007-12-19 01:24:52 +00:00
|
|
|
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 ) )
|
2011-11-28 16:34:58 +00:00
|
|
|
$output = Html::rawElement( 'table', array( 'cellspacing' => 0, 'cellpadding' => 0,
|
|
|
|
'class' => 'contributionscores-wrapper', 'lang' => $wgLang->getCode(), 'dir' => $wgLang->getDir() ),
|
|
|
|
"\n".
|
2007-12-19 01:24:52 +00:00
|
|
|
"<tr>\n".
|
|
|
|
"<td style='padding: 0px;'>{$title}</td>\n".
|
|
|
|
"</tr>\n".
|
|
|
|
"<tr>\n".
|
|
|
|
"<td style='padding: 0px;'>{$output}</td>\n".
|
2011-11-28 16:34:58 +00:00
|
|
|
"</tr>\n" );
|
2007-12-19 01:24:52 +00:00
|
|
|
|
2007-11-27 13:38:37 +00:00
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
|
2010-10-29 21:55:29 +00:00
|
|
|
function execute( $par ) {
|
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;
|
|
|
|
}
|
2007-12-20 22:37:18 +00:00
|
|
|
|
2011-11-28 16:34:58 +00:00
|
|
|
/**
|
|
|
|
* Called when being included on a normal wiki page.
|
|
|
|
* Cache is disabled so it can depend on the user language.
|
|
|
|
* @param $par
|
|
|
|
*/
|
2007-12-19 01:24:52 +00:00
|
|
|
function showInclude( $par ) {
|
2011-11-28 16:34:58 +00:00
|
|
|
global $wgOut, $wgLang;
|
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';
|
2011-11-28 16:34:58 +00:00
|
|
|
|
2007-12-19 01:24:52 +00:00
|
|
|
if ( !empty( $par ) ) {
|
2011-11-28 16:34:58 +00:00
|
|
|
$params = explode('/', $par );
|
|
|
|
|
2007-12-19 01:24:52 +00:00
|
|
|
$limit = intval( $params[0] );
|
2011-11-28 16:34:58 +00:00
|
|
|
|
|
|
|
if ( isset( $params[1] ) ) {
|
2007-12-19 01:24:52 +00:00
|
|
|
$days = intval( $params[1] );
|
2011-11-28 16:34:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( isset( $params[2] ) ) {
|
2007-12-19 15:45:09 +00:00
|
|
|
$options = $params[2];
|
2011-11-28 16:34:58 +00:00
|
|
|
}
|
2007-12-19 01:24:52 +00:00
|
|
|
}
|
2011-11-28 16:34:58 +00:00
|
|
|
|
|
|
|
if ( empty( $limit ) || $limit < 1 || $limit > CONTRIBUTIONSCORES_MAXINCLUDELIMIT ) {
|
2007-12-19 01:24:52 +00:00
|
|
|
$limit = 10;
|
2011-11-28 16:34:58 +00:00
|
|
|
}
|
|
|
|
if ( is_null( $days ) || $days < 0 ) {
|
2007-12-19 01:24:52 +00:00
|
|
|
$days = 7;
|
2011-11-28 16:34:58 +00:00
|
|
|
}
|
2009-04-14 18:46:43 +00:00
|
|
|
|
2007-12-19 01:24:52 +00:00
|
|
|
if ( $days > 0 ) {
|
2011-11-28 16:52:50 +00:00
|
|
|
$reportTitle = wfMsgExt( 'contributionscores-days', 'parsemag', $wgLang->formatNum( $days ) );
|
2007-12-19 01:24:52 +00:00
|
|
|
} else {
|
|
|
|
$reportTitle = wfMsg( 'contributionscores-allrevisions' );
|
|
|
|
}
|
2011-11-28 16:34:58 +00:00
|
|
|
$reportTitle .= " " . wfMsgExt( 'contributionscores-top', 'parsemag', $wgLang->formatNum( $limit ) );
|
2007-12-20 22:37:18 +00:00
|
|
|
$title = Xml::element( 'h4', array( 'class' => 'contributionscores-title' ), $reportTitle ) . "\n";
|
2008-11-06 22:20:29 +00:00
|
|
|
$wgOut->addHTML( $this->genContributionScoreTable( $days, $limit, $title, $options ) );
|
2007-12-19 01:24:52 +00:00
|
|
|
}
|
2011-11-28 16:34:58 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the special page
|
|
|
|
*/
|
2007-12-19 01:24:52 +00:00
|
|
|
function showPage() {
|
2011-11-28 16:34:58 +00:00
|
|
|
global $wgOut, $wgLang, $wgContribScoreReports;
|
|
|
|
|
|
|
|
if ( !is_array( $wgContribScoreReports ) ) {
|
2008-04-17 17:31:22 +00:00
|
|
|
$wgContribScoreReports = array(
|
2011-11-28 16:34:58 +00:00
|
|
|
array( 7, 50 ),
|
|
|
|
array( 30, 50 ),
|
|
|
|
array( 0, 50 )
|
|
|
|
);
|
2007-11-27 13:38:37 +00:00
|
|
|
}
|
|
|
|
|
2010-09-11 14:31:16 +00:00
|
|
|
$wgOut->addWikiMsg( 'contributionscores-info' );
|
2007-11-27 13:38:37 +00:00
|
|
|
|
2011-11-28 16:34:58 +00:00
|
|
|
foreach ( $wgContribScoreReports as $scoreReport ) {
|
2011-12-04 13:20:26 +00:00
|
|
|
list( $days, $revs ) = $scoreReport;
|
2011-11-28 16:34:58 +00:00
|
|
|
if ( $days > 0 ) {
|
2011-11-28 16:52:50 +00:00
|
|
|
$reportTitle = wfMsgExt( 'contributionscores-days', 'parsemag', $wgLang->formatNum( $days ) );
|
2007-11-27 13:38:37 +00:00
|
|
|
} else {
|
2007-12-20 22:37:18 +00:00
|
|
|
$reportTitle = wfMsg( 'contributionscores-allrevisions' );
|
2007-11-27 13:38:37 +00:00
|
|
|
}
|
2011-11-28 16:34:58 +00:00
|
|
|
$reportTitle .= " " . wfMsgExt('contributionscores-top', 'parsemag', $wgLang->formatNum( $revs ) );
|
2007-12-20 22:37:18 +00:00
|
|
|
$title = Xml::element( 'h2', array( 'class' => 'contributionscores-title' ), $reportTitle ) . "\n";
|
2008-11-06 22:20:29 +00:00
|
|
|
$wgOut->addHTML( $title );
|
2011-11-28 16:34:58 +00:00
|
|
|
$wgOut->addHTML( $this->genContributionScoreTable( $days, $revs ) );
|
2007-11-27 13:38:37 +00:00
|
|
|
}
|
|
|
|
}
|
2007-08-22 19:25:22 +00:00
|
|
|
}
|