r108127 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r108126‎ | r108127 | r108128 >
Date:09:43, 5 January 2012
Author:siebrand
Status:resolved (Comments)
Tags:
Comment:
* 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
Modified paths:
  • /trunk/extensions/ContributionScores/ContributionScores.php (modified) (history)
  • /trunk/extensions/ContributionScores/ContributionScores_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ContributionScores/ContributionScores_body.php
@@ -27,20 +27,20 @@
2828 * @return HTML Table representing the requested Contribution Scores.
2929 */
3030 function genContributionScoreTable( $days, $limit, $title = null, $options = 'none' ) {
31 - global $wgContribScoreIgnoreBots, $wgContribScoreIgnoreBlockedUsers, $wgLang;
 31+ global $wgContribScoreIgnoreBots, $wgContribScoreIgnoreBlockedUsers, $wgContribScoresUseRealName, $wgLang;
3232
3333 $opts = explode( ',', strtolower( $options ) );
34 -
 34+
3535 $dbr = wfGetDB( DB_SLAVE );
3636
3737 $userTable = $dbr->tableName('user');
3838 $userGroupTable = $dbr->tableName('user_groups');
3939 $revTable = $dbr->tableName('revision');
4040 $ipBlocksTable = $dbr->tableName('ipblocks');
41 -
 41+
4242 $sqlWhere = "";
4343 $nextPrefix = "WHERE";
44 -
 44+
4545 if ( $days > 0 ) {
4646 $date = time() - (60*60*24*$days);
4747 $dateString = $dbr->timestamp($date);
@@ -57,38 +57,39 @@
5858 $sqlWhere .= " {$nextPrefix} rev_user NOT IN (SELECT ug_user FROM {$userGroupTable} WHERE ug_group='bot')";
5959 $nextPrefix = "AND";
6060 }
61 -
62 - $sqlMostPages = "SELECT rev_user,
63 - COUNT(DISTINCT rev_page) AS page_count,
64 - COUNT(rev_id) AS rev_count
65 - FROM {$revTable}
 61+
 62+ $sqlMostPages = "SELECT rev_user,
 63+ COUNT(DISTINCT rev_page) AS page_count,
 64+ COUNT(rev_id) AS rev_count
 65+ FROM {$revTable}
6666 {$sqlWhere}
67 - GROUP BY rev_user
 67+ GROUP BY rev_user
6868 ORDER BY page_count DESC
6969 LIMIT {$limit}";
7070
71 - $sqlMostRevs = "SELECT rev_user,
72 - COUNT(DISTINCT rev_page) AS page_count,
73 - COUNT(rev_id) AS rev_count
74 - FROM {$revTable}
 71+ $sqlMostRevs = "SELECT rev_user,
 72+ COUNT(DISTINCT rev_page) AS page_count,
 73+ COUNT(rev_id) AS rev_count
 74+ FROM {$revTable}
7575 {$sqlWhere}
76 - GROUP BY rev_user
77 - ORDER BY rev_count DESC
 76+ GROUP BY rev_user
 77+ ORDER BY rev_count DESC
7878 LIMIT {$limit}";
79 -
 79+
8080 $sql = "SELECT user_id, " .
8181 "user_name, " .
 82+ "user_real_name" .
8283 "page_count, " .
8384 "rev_count, " .
8485 "page_count+SQRT(rev_count-page_count)*2 AS wiki_rank " .
8586 "FROM $userTable u JOIN (($sqlMostPages) UNION ($sqlMostRevs)) s ON (user_id=rev_user) " .
8687 "ORDER BY wiki_rank DESC " .
8788 "LIMIT $limit";
88 -
 89+
8990 $res = $dbr->query( $sql );
90 -
 91+
9192 $sortable = in_array( 'nosort', $opts ) ? '' : ' sortable';
92 -
 93+
9394 $output = "<table class=\"wikitable contributionscores plainlinks{$sortable}\" >\n".
9495 "<tr class='header'>\n".
9596 Html::element( 'th', array(), wfMsg( 'contributionscores-score' ) ) .
@@ -97,21 +98,36 @@
9899 Html::element( 'th', array(), wfMsg( 'contributionscores-username' ) );
99100
100101 $altrow = '';
 102+
101103 foreach ( $res as $row ) {
 104+ // Use real name if option used and real name present.
 105+ if( $wgContribScoresUseRealName && $row->user_real_name !== '' ) {
 106+ $userLink = Linker::userLink(
 107+ $row->user_id,
 108+ $row->user_name,
 109+ $row->user_real_name
 110+ );
 111+ } else {
 112+ $userLink = Linker::userLink(
 113+ $row->user_id,
 114+ $row->user_name
 115+ );
 116+ }
 117+
102118 $output .= Html::closeElement( 'tr' );
103119 $output .= "<tr class='{$altrow}'>\n<td class='content'>" .
104120 $wgLang->formatNum( round( $row->wiki_rank, 0 ) ) . "\n</td><td class='content'>" .
105121 $wgLang->formatNum( $row->page_count ) . "\n</td><td class='content'>" .
106122 $wgLang->formatNum( $row->rev_count ) . "\n</td><td class='content'>" .
107 - Linker::userLink( $row->user_id, $row->user_name );
108 -
 123+ $userLink;
 124+
109125 # Option to not display user tools
110126 if ( !in_array( 'notools', $opts ) ) {
111127 $output .= Linker::userToolLinks( $row->user_id, $row->user_name );
112128 }
113 -
 129+
114130 $output .= Html::closeElement( 'td' ) . "\n";
115 -
 131+
116132 if ( $altrow == '' && empty( $sortable ) ) {
117133 $altrow = 'odd ';
118134 } else {
@@ -122,7 +138,7 @@
123139 $output .= Html::closeElement( 'table' );
124140
125141 $dbr->freeResult( $res );
126 -
 142+
127143 if ( !empty( $title ) )
128144 $output = Html::rawElement( 'table', array( 'cellspacing' => 0, 'cellpadding' => 0,
129145 'class' => 'contributionscores-wrapper', 'lang' => $wgLang->getCode(), 'dir' => $wgLang->getDir() ),
@@ -133,11 +149,11 @@
134150 "<tr>\n".
135151 "<td style='padding: 0px;'>{$output}</td>\n".
136152 "</tr>\n" );
137 -
 153+
138154 return $output;
139155 }
140156
141 - function execute( $par ) {
 157+ function execute( $par ) {
142158 $this->setHeaders();
143159
144160 if( $this->including() ) {
Index: trunk/extensions/ContributionScores/ContributionScores.php
@@ -15,7 +15,7 @@
1616 'url' => 'https://www.mediawiki.org/wiki/Extension:Contribution_Scores',
1717 'author' => 'Tim Laqua',
1818 'descriptionmsg' => 'contributionscores-desc',
19 - 'version' => '1.13'
 19+ 'version' => '1.14'
2020 );
2121
2222 $dir = dirname( __FILE__ ) . '/';
@@ -24,6 +24,7 @@
2525 $wgContribScoreReports = null;
2626 $wgContribScoreIgnoreBlockedUsers = false;
2727 $wgContribScoreIgnoreBots = false;
 28+$wgContribScoresUseRealName = false;
2829 $wgContribScoreDisableCache = false;
2930
3031 $wgAutoloadClasses['ContributionScores'] = $dir . 'ContributionScores_body.php';
@@ -58,25 +59,27 @@
5960 $dbr = wfGetDB( DB_SLAVE );
6061
6162 if ( $user instanceof User && $user->isLoggedIn() ) {
 63+ global $wgLang;
 64+
6265 if ($metric=='score') {
6366 $res = $dbr->select('revision',
6467 'COUNT(DISTINCT rev_page)+SQRT(COUNT(rev_id)-COUNT(DISTINCT rev_page))*2 AS wiki_rank',
6568 array('rev_user' => $user->getID()));
6669 $row = $dbr->fetchObject($res);
67 - $output = round($row->wiki_rank,0);
 70+ $output = $wgLang->formatNum( round($row->wiki_rank,0) );
6871 } elseif ($metric=='changes') {
6972 $res = $dbr->select('revision',
7073 'COUNT(rev_id) AS rev_count',
7174 array('rev_user' => $user->getID()));
7275 $row = $dbr->fetchObject($res);
73 - $output = $row->rev_count;
 76+ $output = $wgLang->formatNum( $row->rev_count );
7477
7578 } elseif ($metric=='pages') {
7679 $res = $dbr->select('revision',
7780 'COUNT(DISTINCT rev_page) AS page_count',
7881 array('rev_user' => $user->getID()));
7982 $row = $dbr->fetchObject($res);
80 - $output = $row->page_count;
 83+ $output = $wgLang->formatNum( $row->page_count );
8184 } else {
8285 $output = wfMsg('contributionscores-invalidmetric');
8386 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r108129Fix typo in r108127.siebrand09:49, 5 January 2012
r108131Add some documentation for settings per CR on r108127.siebrand10:07, 5 January 2012

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r108126Add additional parameter $altUserName to Linker::userLink to make it possible...siebrand09:33, 5 January 2012

Comments

#Comment by Nikerabbit (talk | contribs)   10:03, 5 January 2012

The new variable could use some docs.

#Comment by Siebrand (talk | contribs)   10:04, 5 January 2012

I kind of followed the way the original author worked, by doing that on the extension documentation page. Will follow-up.

Status & tagging log