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).
|
|
|
|
*/
|
|
|
|
|
2012-01-05 09:45:01 +00:00
|
|
|
/// Special page class for the Contribution Scores extension
|
2007-08-26 14:39:17 +00:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
}
|
|
|
|
|
2012-01-05 09:45:01 +00:00
|
|
|
/// Generates a "Contribution Scores" table for a given LIMIT and date range
|
2007-11-27 13:38:37 +00:00
|
|
|
/**
|
|
|
|
* 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)
|
2012-08-16 14:19:19 +02:00
|
|
|
* @param $title Title (default null)
|
|
|
|
* @param $options array of options (default none; nosort/notools)
|
|
|
|
* @return Html Table representing the requested Contribution Scores.
|
2007-11-27 13:38:37 +00:00
|
|
|
*/
|
2007-12-19 15:45:09 +00:00
|
|
|
function genContributionScoreTable( $days, $limit, $title = null, $options = 'none' ) {
|
2012-08-16 14:19:19 +02:00
|
|
|
global $wgContribScoreIgnoreBots, $wgContribScoreIgnoreBlockedUsers, $wgContribScoresUseRealName;
|
2007-11-27 13:38:37 +00:00
|
|
|
|
2011-11-28 16:34:58 +00:00
|
|
|
$opts = explode( ',', strtolower( $options ) );
|
2012-01-05 09:43:51 +00:00
|
|
|
|
2007-12-20 22:37:18 +00:00
|
|
|
$dbr = wfGetDB( DB_SLAVE );
|
2007-11-27 13:38:37 +00:00
|
|
|
|
2012-01-05 09:45:01 +00:00
|
|
|
$userTable = $dbr->tableName( 'user' );
|
|
|
|
$userGroupTable = $dbr->tableName( 'user_groups' );
|
|
|
|
$revTable = $dbr->tableName( 'revision' );
|
|
|
|
$ipBlocksTable = $dbr->tableName( 'ipblocks' );
|
2012-01-05 09:43:51 +00:00
|
|
|
|
2007-12-19 15:45:09 +00:00
|
|
|
$sqlWhere = "";
|
2008-04-17 17:31:22 +00:00
|
|
|
$nextPrefix = "WHERE";
|
2012-01-05 09:43:51 +00:00
|
|
|
|
2007-11-27 13:38:37 +00:00
|
|
|
if ( $days > 0 ) {
|
2012-01-05 09:45:01 +00:00
|
|
|
$date = time() - ( 60 * 60 * 24 * $days );
|
|
|
|
$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')";
|
|
|
|
}
|
2012-01-05 09:43:51 +00:00
|
|
|
|
|
|
|
$sqlMostPages = "SELECT rev_user,
|
|
|
|
COUNT(DISTINCT rev_page) AS page_count,
|
|
|
|
COUNT(rev_id) AS rev_count
|
|
|
|
FROM {$revTable}
|
2007-12-19 15:45:09 +00:00
|
|
|
{$sqlWhere}
|
2012-01-05 09:43:51 +00:00
|
|
|
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}";
|
|
|
|
|
2012-01-05 09:43:51 +00:00
|
|
|
$sqlMostRevs = "SELECT rev_user,
|
|
|
|
COUNT(DISTINCT rev_page) AS page_count,
|
|
|
|
COUNT(rev_id) AS rev_count
|
|
|
|
FROM {$revTable}
|
2007-12-19 15:45:09 +00:00
|
|
|
{$sqlWhere}
|
2012-01-05 09:43:51 +00:00
|
|
|
GROUP BY rev_user
|
|
|
|
ORDER BY rev_count DESC
|
2007-12-19 15:45:09 +00:00
|
|
|
LIMIT {$limit}";
|
2012-01-05 09:43:51 +00:00
|
|
|
|
2010-10-29 21:55:29 +00:00
|
|
|
$sql = "SELECT user_id, " .
|
2007-12-19 15:45:09 +00:00
|
|
|
"user_name, " .
|
2012-01-05 09:49:29 +00:00
|
|
|
"user_real_name, " .
|
2007-12-19 15:45:09 +00:00
|
|
|
"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";
|
2012-01-05 09:43:51 +00:00
|
|
|
|
2011-11-28 16:34:58 +00:00
|
|
|
$res = $dbr->query( $sql );
|
2012-01-05 09:43:51 +00:00
|
|
|
|
2011-11-28 16:34:58 +00:00
|
|
|
$sortable = in_array( 'nosort', $opts ) ? '' : ' sortable';
|
2012-01-05 09:43:51 +00:00
|
|
|
|
2012-01-05 09:45:01 +00:00
|
|
|
$output = "<table class=\"wikitable contributionscores plainlinks{$sortable}\" >\n" .
|
|
|
|
"<tr class='header'>\n" .
|
2013-09-22 22:54:28 -05:00
|
|
|
Html::element( 'th', array(), $this->msg( 'contributionscores-rank' )->text() ) .
|
2012-08-16 14:19:19 +02:00
|
|
|
Html::element( 'th', array(), $this->msg( 'contributionscores-score' )->text() ) .
|
|
|
|
Html::element( 'th', array(), $this->msg( 'contributionscores-pages' )->text() ) .
|
|
|
|
Html::element( 'th', array(), $this->msg( 'contributionscores-changes' )->text() ) .
|
|
|
|
Html::element( 'th', array(), $this->msg( 'contributionscores-username' )->text() );
|
2007-11-27 13:38:37 +00:00
|
|
|
|
2007-12-19 01:24:52 +00:00
|
|
|
$altrow = '';
|
2013-09-22 22:54:28 -05:00
|
|
|
$user_rank = 1;
|
2012-01-05 09:43:51 +00:00
|
|
|
|
2012-10-23 14:09:05 +02:00
|
|
|
$lang = $this->getLanguage();
|
2010-10-29 21:30:20 +00:00
|
|
|
foreach ( $res as $row ) {
|
2012-01-05 09:43:51 +00:00
|
|
|
// Use real name if option used and real name present.
|
2012-01-05 09:45:01 +00:00
|
|
|
if ( $wgContribScoresUseRealName && $row->user_real_name !== '' ) {
|
2012-01-05 09:43:51 +00:00
|
|
|
$userLink = Linker::userLink(
|
|
|
|
$row->user_id,
|
|
|
|
$row->user_name,
|
|
|
|
$row->user_real_name
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$userLink = Linker::userLink(
|
|
|
|
$row->user_id,
|
|
|
|
$row->user_name
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2012-01-05 09:04:02 +00:00
|
|
|
$output .= Html::closeElement( 'tr' );
|
2013-09-22 22:54:28 -05:00
|
|
|
$output .= "<tr class='{$altrow}'>\n<td class='content' style='padding-right:10px;text-align:right;'>" .
|
|
|
|
$lang->formatNum( round( $user_rank, 0 ) ) . "\n</td><td class='content' style='padding-right:10px;text-align:right;'>" .
|
|
|
|
$lang->formatNum( round( $row->wiki_rank, 0 ) ) . "\n</td><td class='content' style='padding-right:10px;text-align:right;'>" .
|
|
|
|
$lang->formatNum( $row->page_count ) . "\n</td><td class='content' style='padding-right:10px;text-align:right;'>" .
|
2012-08-16 14:19:19 +02:00
|
|
|
$lang->formatNum( $row->rev_count ) . "\n</td><td class='content'>" .
|
2012-01-05 09:43:51 +00:00
|
|
|
$userLink;
|
|
|
|
|
2007-12-20 22:37:18 +00:00
|
|
|
# Option to not display user tools
|
2012-01-05 09:04:02 +00:00
|
|
|
if ( !in_array( 'notools', $opts ) ) {
|
|
|
|
$output .= Linker::userToolLinks( $row->user_id, $row->user_name );
|
|
|
|
}
|
2012-01-05 09:43:51 +00:00
|
|
|
|
2012-01-05 09:04:02 +00:00
|
|
|
$output .= Html::closeElement( 'td' ) . "\n";
|
2012-01-05 09:43:51 +00:00
|
|
|
|
2012-01-05 09:04:02 +00:00
|
|
|
if ( $altrow == '' && empty( $sortable ) ) {
|
2008-04-14 17:22:51 +00:00
|
|
|
$altrow = 'odd ';
|
2012-01-05 09:04:02 +00:00
|
|
|
} else {
|
2007-12-19 01:24:52 +00:00
|
|
|
$altrow = '';
|
2012-01-05 09:04:02 +00:00
|
|
|
}
|
2013-09-22 22:54:28 -05:00
|
|
|
|
|
|
|
$user_rank++;
|
2007-11-27 13:38:37 +00:00
|
|
|
}
|
2012-01-05 09:04:02 +00:00
|
|
|
$output .= Html::closeElement( 'tr' );
|
|
|
|
$output .= Html::closeElement( 'table' );
|
|
|
|
|
2007-11-27 13:38:37 +00:00
|
|
|
$dbr->freeResult( $res );
|
2012-01-05 09:43:51 +00:00
|
|
|
|
2007-12-19 01:24:52 +00:00
|
|
|
if ( !empty( $title ) )
|
2012-10-23 14:09:05 +02:00
|
|
|
$output = Html::rawElement( 'table',
|
|
|
|
array(
|
|
|
|
'style' => 'border-spacing: 0; padding: 0',
|
|
|
|
'class' => 'contributionscores-wrapper',
|
|
|
|
'lang' => htmlspecialchars( $lang->getCode()),
|
|
|
|
'dir' => $lang->getDir()
|
|
|
|
),
|
|
|
|
"\n" .
|
|
|
|
"<tr>\n" .
|
|
|
|
"<td style='padding: 0px;'>{$title}</td>\n" .
|
|
|
|
"</tr>\n" .
|
|
|
|
"<tr>\n" .
|
|
|
|
"<td style='padding: 0px;'>{$output}</td>\n" .
|
|
|
|
"</tr>\n"
|
|
|
|
);
|
2012-01-05 09:43:51 +00:00
|
|
|
|
2007-11-27 13:38:37 +00:00
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
|
2012-01-05 09:43:51 +00:00
|
|
|
function execute( $par ) {
|
2007-11-27 13:38:37 +00:00
|
|
|
$this->setHeaders();
|
|
|
|
|
2012-01-05 09:45:01 +00:00
|
|
|
if ( $this->including() ) {
|
2007-12-19 01:24:52 +00:00
|
|
|
$this->showInclude( $par );
|
|
|
|
} else {
|
|
|
|
$this->showPage();
|
|
|
|
}
|
2012-01-05 09:04:02 +00:00
|
|
|
|
2007-12-19 01:24:52 +00:00
|
|
|
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 ) {
|
|
|
|
$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 ) ) {
|
2012-01-05 09:45:01 +00:00
|
|
|
$params = explode( '/', $par );
|
2011-11-28 16:34:58 +00:00
|
|
|
|
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 ) {
|
2012-08-16 14:19:19 +02:00
|
|
|
$reportTitle = $this->msg( 'contributionscores-days' )->numParams( $days )->text();
|
2007-12-19 01:24:52 +00:00
|
|
|
} else {
|
2012-08-16 14:19:19 +02:00
|
|
|
$reportTitle = $this->msg( 'contributionscores-allrevisions' )->text();
|
2007-12-19 01:24:52 +00:00
|
|
|
}
|
2012-08-16 14:19:19 +02:00
|
|
|
$reportTitle .= " " . $this->msg( 'contributionscores-top' )->numParams( $limit )->text();
|
2007-12-20 22:37:18 +00:00
|
|
|
$title = Xml::element( 'h4', array( 'class' => 'contributionscores-title' ), $reportTitle ) . "\n";
|
2012-08-16 14:19:19 +02:00
|
|
|
$this->getOutput()->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() {
|
2012-08-16 14:19:19 +02:00
|
|
|
global $wgContribScoreReports;
|
2011-11-28 16:34:58 +00:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-08-16 14:19:19 +02:00
|
|
|
$out = $this->getOutput();
|
|
|
|
$out->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 ) {
|
2012-08-16 14:19:19 +02:00
|
|
|
$reportTitle = $this->msg( 'contributionscores-days' )->numParams( $days )->text();
|
2007-11-27 13:38:37 +00:00
|
|
|
} else {
|
2012-08-16 14:19:19 +02:00
|
|
|
$reportTitle = $this->msg( 'contributionscores-allrevisions' )->text();
|
2007-11-27 13:38:37 +00:00
|
|
|
}
|
2012-08-16 14:19:19 +02:00
|
|
|
$reportTitle .= " " . $this->msg( 'contributionscores-top' )->numParams( $revs )->text();
|
2007-12-20 22:37:18 +00:00
|
|
|
$title = Xml::element( 'h2', array( 'class' => 'contributionscores-title' ), $reportTitle ) . "\n";
|
2012-08-16 14:19:19 +02:00
|
|
|
$out->addHTML( $title );
|
|
|
|
$out->addHTML( $this->genContributionScoreTable( $days, $revs ) );
|
2007-11-27 13:38:37 +00:00
|
|
|
}
|
|
|
|
}
|
2007-08-22 19:25:22 +00:00
|
|
|
}
|