* format number output of cscore parser function.

* add $wgContribScoresUseRealName to allow display of real user names per request[1]. Requires MediaWiki 1.19 alpha r108126.
* remove trailing whitespace.

[1] https://www.mediawiki.org/wiki/Thread:Extension_talk:Contribution_Scores/Show_real_name_or_e-mail_instead_of_username%3F
This commit is contained in:
Siebrand Mazeland 2012-01-05 09:43:51 +00:00
parent f1e3ad6c82
commit 7467195055
2 changed files with 50 additions and 31 deletions

View file

@ -15,7 +15,7 @@ $wgExtensionCredits['specialpage'][] = array(
'url' => 'https://www.mediawiki.org/wiki/Extension:Contribution_Scores', 'url' => 'https://www.mediawiki.org/wiki/Extension:Contribution_Scores',
'author' => 'Tim Laqua', 'author' => 'Tim Laqua',
'descriptionmsg' => 'contributionscores-desc', 'descriptionmsg' => 'contributionscores-desc',
'version' => '1.13' 'version' => '1.14'
); );
$dir = dirname( __FILE__ ) . '/'; $dir = dirname( __FILE__ ) . '/';
@ -24,6 +24,7 @@ define( 'CONTRIBUTIONSCORES_MAXINCLUDELIMIT', 50 );
$wgContribScoreReports = null; $wgContribScoreReports = null;
$wgContribScoreIgnoreBlockedUsers = false; $wgContribScoreIgnoreBlockedUsers = false;
$wgContribScoreIgnoreBots = false; $wgContribScoreIgnoreBots = false;
$wgContribScoresUseRealName = false;
$wgContribScoreDisableCache = false; $wgContribScoreDisableCache = false;
$wgAutoloadClasses['ContributionScores'] = $dir . 'ContributionScores_body.php'; $wgAutoloadClasses['ContributionScores'] = $dir . 'ContributionScores_body.php';
@ -58,25 +59,27 @@ function efContributionScores_Render(&$parser, $usertext, $metric='score') {
$dbr = wfGetDB( DB_SLAVE ); $dbr = wfGetDB( DB_SLAVE );
if ( $user instanceof User && $user->isLoggedIn() ) { if ( $user instanceof User && $user->isLoggedIn() ) {
global $wgLang;
if ($metric=='score') { if ($metric=='score') {
$res = $dbr->select('revision', $res = $dbr->select('revision',
'COUNT(DISTINCT rev_page)+SQRT(COUNT(rev_id)-COUNT(DISTINCT rev_page))*2 AS wiki_rank', 'COUNT(DISTINCT rev_page)+SQRT(COUNT(rev_id)-COUNT(DISTINCT rev_page))*2 AS wiki_rank',
array('rev_user' => $user->getID())); array('rev_user' => $user->getID()));
$row = $dbr->fetchObject($res); $row = $dbr->fetchObject($res);
$output = round($row->wiki_rank,0); $output = $wgLang->formatNum( round($row->wiki_rank,0) );
} elseif ($metric=='changes') { } elseif ($metric=='changes') {
$res = $dbr->select('revision', $res = $dbr->select('revision',
'COUNT(rev_id) AS rev_count', 'COUNT(rev_id) AS rev_count',
array('rev_user' => $user->getID())); array('rev_user' => $user->getID()));
$row = $dbr->fetchObject($res); $row = $dbr->fetchObject($res);
$output = $row->rev_count; $output = $wgLang->formatNum( $row->rev_count );
} elseif ($metric=='pages') { } elseif ($metric=='pages') {
$res = $dbr->select('revision', $res = $dbr->select('revision',
'COUNT(DISTINCT rev_page) AS page_count', 'COUNT(DISTINCT rev_page) AS page_count',
array('rev_user' => $user->getID())); array('rev_user' => $user->getID()));
$row = $dbr->fetchObject($res); $row = $dbr->fetchObject($res);
$output = $row->page_count; $output = $wgLang->formatNum( $row->page_count );
} else { } else {
$output = wfMsg('contributionscores-invalidmetric'); $output = wfMsg('contributionscores-invalidmetric');
} }

View file

@ -27,20 +27,20 @@ class ContributionScores extends IncludableSpecialPage {
* @return HTML Table representing the requested Contribution Scores. * @return HTML Table representing the requested Contribution Scores.
*/ */
function genContributionScoreTable( $days, $limit, $title = null, $options = 'none' ) { function genContributionScoreTable( $days, $limit, $title = null, $options = 'none' ) {
global $wgContribScoreIgnoreBots, $wgContribScoreIgnoreBlockedUsers, $wgLang; global $wgContribScoreIgnoreBots, $wgContribScoreIgnoreBlockedUsers, $wgContribScoresUseRealName, $wgLang;
$opts = explode( ',', strtolower( $options ) ); $opts = explode( ',', strtolower( $options ) );
$dbr = wfGetDB( DB_SLAVE ); $dbr = wfGetDB( DB_SLAVE );
$userTable = $dbr->tableName('user'); $userTable = $dbr->tableName('user');
$userGroupTable = $dbr->tableName('user_groups'); $userGroupTable = $dbr->tableName('user_groups');
$revTable = $dbr->tableName('revision'); $revTable = $dbr->tableName('revision');
$ipBlocksTable = $dbr->tableName('ipblocks'); $ipBlocksTable = $dbr->tableName('ipblocks');
$sqlWhere = ""; $sqlWhere = "";
$nextPrefix = "WHERE"; $nextPrefix = "WHERE";
if ( $days > 0 ) { if ( $days > 0 ) {
$date = time() - (60*60*24*$days); $date = time() - (60*60*24*$days);
$dateString = $dbr->timestamp($date); $dateString = $dbr->timestamp($date);
@ -57,38 +57,39 @@ class ContributionScores extends IncludableSpecialPage {
$sqlWhere .= " {$nextPrefix} rev_user NOT IN (SELECT ug_user FROM {$userGroupTable} WHERE ug_group='bot')"; $sqlWhere .= " {$nextPrefix} rev_user NOT IN (SELECT ug_user FROM {$userGroupTable} WHERE ug_group='bot')";
$nextPrefix = "AND"; $nextPrefix = "AND";
} }
$sqlMostPages = "SELECT rev_user, $sqlMostPages = "SELECT rev_user,
COUNT(DISTINCT rev_page) AS page_count, COUNT(DISTINCT rev_page) AS page_count,
COUNT(rev_id) AS rev_count COUNT(rev_id) AS rev_count
FROM {$revTable} FROM {$revTable}
{$sqlWhere} {$sqlWhere}
GROUP BY rev_user GROUP BY rev_user
ORDER BY page_count DESC ORDER BY page_count DESC
LIMIT {$limit}"; LIMIT {$limit}";
$sqlMostRevs = "SELECT rev_user, $sqlMostRevs = "SELECT rev_user,
COUNT(DISTINCT rev_page) AS page_count, COUNT(DISTINCT rev_page) AS page_count,
COUNT(rev_id) AS rev_count COUNT(rev_id) AS rev_count
FROM {$revTable} FROM {$revTable}
{$sqlWhere} {$sqlWhere}
GROUP BY rev_user GROUP BY rev_user
ORDER BY rev_count DESC ORDER BY rev_count DESC
LIMIT {$limit}"; LIMIT {$limit}";
$sql = "SELECT user_id, " . $sql = "SELECT user_id, " .
"user_name, " . "user_name, " .
"user_real_name" .
"page_count, " . "page_count, " .
"rev_count, " . "rev_count, " .
"page_count+SQRT(rev_count-page_count)*2 AS wiki_rank " . "page_count+SQRT(rev_count-page_count)*2 AS wiki_rank " .
"FROM $userTable u JOIN (($sqlMostPages) UNION ($sqlMostRevs)) s ON (user_id=rev_user) " . "FROM $userTable u JOIN (($sqlMostPages) UNION ($sqlMostRevs)) s ON (user_id=rev_user) " .
"ORDER BY wiki_rank DESC " . "ORDER BY wiki_rank DESC " .
"LIMIT $limit"; "LIMIT $limit";
$res = $dbr->query( $sql ); $res = $dbr->query( $sql );
$sortable = in_array( 'nosort', $opts ) ? '' : ' sortable'; $sortable = in_array( 'nosort', $opts ) ? '' : ' sortable';
$output = "<table class=\"wikitable contributionscores plainlinks{$sortable}\" >\n". $output = "<table class=\"wikitable contributionscores plainlinks{$sortable}\" >\n".
"<tr class='header'>\n". "<tr class='header'>\n".
Html::element( 'th', array(), wfMsg( 'contributionscores-score' ) ) . Html::element( 'th', array(), wfMsg( 'contributionscores-score' ) ) .
@ -97,21 +98,36 @@ class ContributionScores extends IncludableSpecialPage {
Html::element( 'th', array(), wfMsg( 'contributionscores-username' ) ); Html::element( 'th', array(), wfMsg( 'contributionscores-username' ) );
$altrow = ''; $altrow = '';
foreach ( $res as $row ) { foreach ( $res as $row ) {
// Use real name if option used and real name present.
if( $wgContribScoresUseRealName && $row->user_real_name !== '' ) {
$userLink = Linker::userLink(
$row->user_id,
$row->user_name,
$row->user_real_name
);
} else {
$userLink = Linker::userLink(
$row->user_id,
$row->user_name
);
}
$output .= Html::closeElement( 'tr' ); $output .= Html::closeElement( 'tr' );
$output .= "<tr class='{$altrow}'>\n<td class='content'>" . $output .= "<tr class='{$altrow}'>\n<td class='content'>" .
$wgLang->formatNum( round( $row->wiki_rank, 0 ) ) . "\n</td><td class='content'>" . $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->page_count ) . "\n</td><td class='content'>" .
$wgLang->formatNum( $row->rev_count ) . "\n</td><td class='content'>" . $wgLang->formatNum( $row->rev_count ) . "\n</td><td class='content'>" .
Linker::userLink( $row->user_id, $row->user_name ); $userLink;
# Option to not display user tools # Option to not display user tools
if ( !in_array( 'notools', $opts ) ) { if ( !in_array( 'notools', $opts ) ) {
$output .= Linker::userToolLinks( $row->user_id, $row->user_name ); $output .= Linker::userToolLinks( $row->user_id, $row->user_name );
} }
$output .= Html::closeElement( 'td' ) . "\n"; $output .= Html::closeElement( 'td' ) . "\n";
if ( $altrow == '' && empty( $sortable ) ) { if ( $altrow == '' && empty( $sortable ) ) {
$altrow = 'odd '; $altrow = 'odd ';
} else { } else {
@ -122,7 +138,7 @@ class ContributionScores extends IncludableSpecialPage {
$output .= Html::closeElement( 'table' ); $output .= Html::closeElement( 'table' );
$dbr->freeResult( $res ); $dbr->freeResult( $res );
if ( !empty( $title ) ) if ( !empty( $title ) )
$output = Html::rawElement( 'table', array( 'cellspacing' => 0, 'cellpadding' => 0, $output = Html::rawElement( 'table', array( 'cellspacing' => 0, 'cellpadding' => 0,
'class' => 'contributionscores-wrapper', 'lang' => $wgLang->getCode(), 'dir' => $wgLang->getDir() ), 'class' => 'contributionscores-wrapper', 'lang' => $wgLang->getCode(), 'dir' => $wgLang->getDir() ),
@ -133,11 +149,11 @@ class ContributionScores extends IncludableSpecialPage {
"<tr>\n". "<tr>\n".
"<td style='padding: 0px;'>{$output}</td>\n". "<td style='padding: 0px;'>{$output}</td>\n".
"</tr>\n" ); "</tr>\n" );
return $output; return $output;
} }
function execute( $par ) { function execute( $par ) {
$this->setHeaders(); $this->setHeaders();
if( $this->including() ) { if( $this->including() ) {