Index: trunk/extensions/ContributionScores/ContributionScores_body.php |
— | — | @@ -27,20 +27,20 @@ |
28 | 28 | * @return HTML Table representing the requested Contribution Scores. |
29 | 29 | */ |
30 | 30 | function genContributionScoreTable( $days, $limit, $title = null, $options = 'none' ) { |
31 | | - global $wgContribScoreIgnoreBots, $wgContribScoreIgnoreBlockedUsers, $wgLang; |
| 31 | + global $wgContribScoreIgnoreBots, $wgContribScoreIgnoreBlockedUsers, $wgContribScoresUseRealName, $wgLang; |
32 | 32 | |
33 | 33 | $opts = explode( ',', strtolower( $options ) ); |
34 | | - |
| 34 | + |
35 | 35 | $dbr = wfGetDB( DB_SLAVE ); |
36 | 36 | |
37 | 37 | $userTable = $dbr->tableName('user'); |
38 | 38 | $userGroupTable = $dbr->tableName('user_groups'); |
39 | 39 | $revTable = $dbr->tableName('revision'); |
40 | 40 | $ipBlocksTable = $dbr->tableName('ipblocks'); |
41 | | - |
| 41 | + |
42 | 42 | $sqlWhere = ""; |
43 | 43 | $nextPrefix = "WHERE"; |
44 | | - |
| 44 | + |
45 | 45 | if ( $days > 0 ) { |
46 | 46 | $date = time() - (60*60*24*$days); |
47 | 47 | $dateString = $dbr->timestamp($date); |
— | — | @@ -57,38 +57,39 @@ |
58 | 58 | $sqlWhere .= " {$nextPrefix} rev_user NOT IN (SELECT ug_user FROM {$userGroupTable} WHERE ug_group='bot')"; |
59 | 59 | $nextPrefix = "AND"; |
60 | 60 | } |
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} |
66 | 66 | {$sqlWhere} |
67 | | - GROUP BY rev_user |
| 67 | + GROUP BY rev_user |
68 | 68 | ORDER BY page_count DESC |
69 | 69 | LIMIT {$limit}"; |
70 | 70 | |
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} |
75 | 75 | {$sqlWhere} |
76 | | - GROUP BY rev_user |
77 | | - ORDER BY rev_count DESC |
| 76 | + GROUP BY rev_user |
| 77 | + ORDER BY rev_count DESC |
78 | 78 | LIMIT {$limit}"; |
79 | | - |
| 79 | + |
80 | 80 | $sql = "SELECT user_id, " . |
81 | 81 | "user_name, " . |
| 82 | + "user_real_name" . |
82 | 83 | "page_count, " . |
83 | 84 | "rev_count, " . |
84 | 85 | "page_count+SQRT(rev_count-page_count)*2 AS wiki_rank " . |
85 | 86 | "FROM $userTable u JOIN (($sqlMostPages) UNION ($sqlMostRevs)) s ON (user_id=rev_user) " . |
86 | 87 | "ORDER BY wiki_rank DESC " . |
87 | 88 | "LIMIT $limit"; |
88 | | - |
| 89 | + |
89 | 90 | $res = $dbr->query( $sql ); |
90 | | - |
| 91 | + |
91 | 92 | $sortable = in_array( 'nosort', $opts ) ? '' : ' sortable'; |
92 | | - |
| 93 | + |
93 | 94 | $output = "<table class=\"wikitable contributionscores plainlinks{$sortable}\" >\n". |
94 | 95 | "<tr class='header'>\n". |
95 | 96 | Html::element( 'th', array(), wfMsg( 'contributionscores-score' ) ) . |
— | — | @@ -97,21 +98,36 @@ |
98 | 99 | Html::element( 'th', array(), wfMsg( 'contributionscores-username' ) ); |
99 | 100 | |
100 | 101 | $altrow = ''; |
| 102 | + |
101 | 103 | 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 | + |
102 | 118 | $output .= Html::closeElement( 'tr' ); |
103 | 119 | $output .= "<tr class='{$altrow}'>\n<td class='content'>" . |
104 | 120 | $wgLang->formatNum( round( $row->wiki_rank, 0 ) ) . "\n</td><td class='content'>" . |
105 | 121 | $wgLang->formatNum( $row->page_count ) . "\n</td><td class='content'>" . |
106 | 122 | $wgLang->formatNum( $row->rev_count ) . "\n</td><td class='content'>" . |
107 | | - Linker::userLink( $row->user_id, $row->user_name ); |
108 | | - |
| 123 | + $userLink; |
| 124 | + |
109 | 125 | # Option to not display user tools |
110 | 126 | if ( !in_array( 'notools', $opts ) ) { |
111 | 127 | $output .= Linker::userToolLinks( $row->user_id, $row->user_name ); |
112 | 128 | } |
113 | | - |
| 129 | + |
114 | 130 | $output .= Html::closeElement( 'td' ) . "\n"; |
115 | | - |
| 131 | + |
116 | 132 | if ( $altrow == '' && empty( $sortable ) ) { |
117 | 133 | $altrow = 'odd '; |
118 | 134 | } else { |
— | — | @@ -122,7 +138,7 @@ |
123 | 139 | $output .= Html::closeElement( 'table' ); |
124 | 140 | |
125 | 141 | $dbr->freeResult( $res ); |
126 | | - |
| 142 | + |
127 | 143 | if ( !empty( $title ) ) |
128 | 144 | $output = Html::rawElement( 'table', array( 'cellspacing' => 0, 'cellpadding' => 0, |
129 | 145 | 'class' => 'contributionscores-wrapper', 'lang' => $wgLang->getCode(), 'dir' => $wgLang->getDir() ), |
— | — | @@ -133,11 +149,11 @@ |
134 | 150 | "<tr>\n". |
135 | 151 | "<td style='padding: 0px;'>{$output}</td>\n". |
136 | 152 | "</tr>\n" ); |
137 | | - |
| 153 | + |
138 | 154 | return $output; |
139 | 155 | } |
140 | 156 | |
141 | | - function execute( $par ) { |
| 157 | + function execute( $par ) { |
142 | 158 | $this->setHeaders(); |
143 | 159 | |
144 | 160 | if( $this->including() ) { |
Index: trunk/extensions/ContributionScores/ContributionScores.php |
— | — | @@ -15,7 +15,7 @@ |
16 | 16 | 'url' => 'https://www.mediawiki.org/wiki/Extension:Contribution_Scores', |
17 | 17 | 'author' => 'Tim Laqua', |
18 | 18 | 'descriptionmsg' => 'contributionscores-desc', |
19 | | - 'version' => '1.13' |
| 19 | + 'version' => '1.14' |
20 | 20 | ); |
21 | 21 | |
22 | 22 | $dir = dirname( __FILE__ ) . '/'; |
— | — | @@ -24,6 +24,7 @@ |
25 | 25 | $wgContribScoreReports = null; |
26 | 26 | $wgContribScoreIgnoreBlockedUsers = false; |
27 | 27 | $wgContribScoreIgnoreBots = false; |
| 28 | +$wgContribScoresUseRealName = false; |
28 | 29 | $wgContribScoreDisableCache = false; |
29 | 30 | |
30 | 31 | $wgAutoloadClasses['ContributionScores'] = $dir . 'ContributionScores_body.php'; |
— | — | @@ -58,25 +59,27 @@ |
59 | 60 | $dbr = wfGetDB( DB_SLAVE ); |
60 | 61 | |
61 | 62 | if ( $user instanceof User && $user->isLoggedIn() ) { |
| 63 | + global $wgLang; |
| 64 | + |
62 | 65 | if ($metric=='score') { |
63 | 66 | $res = $dbr->select('revision', |
64 | 67 | 'COUNT(DISTINCT rev_page)+SQRT(COUNT(rev_id)-COUNT(DISTINCT rev_page))*2 AS wiki_rank', |
65 | 68 | array('rev_user' => $user->getID())); |
66 | 69 | $row = $dbr->fetchObject($res); |
67 | | - $output = round($row->wiki_rank,0); |
| 70 | + $output = $wgLang->formatNum( round($row->wiki_rank,0) ); |
68 | 71 | } elseif ($metric=='changes') { |
69 | 72 | $res = $dbr->select('revision', |
70 | 73 | 'COUNT(rev_id) AS rev_count', |
71 | 74 | array('rev_user' => $user->getID())); |
72 | 75 | $row = $dbr->fetchObject($res); |
73 | | - $output = $row->rev_count; |
| 76 | + $output = $wgLang->formatNum( $row->rev_count ); |
74 | 77 | |
75 | 78 | } elseif ($metric=='pages') { |
76 | 79 | $res = $dbr->select('revision', |
77 | 80 | 'COUNT(DISTINCT rev_page) AS page_count', |
78 | 81 | array('rev_user' => $user->getID())); |
79 | 82 | $row = $dbr->fetchObject($res); |
80 | | - $output = $row->page_count; |
| 83 | + $output = $wgLang->formatNum( $row->page_count ); |
81 | 84 | } else { |
82 | 85 | $output = wfMsg('contributionscores-invalidmetric'); |
83 | 86 | } |