Index: trunk/extensions/MoodBar/include/MoodBarUtil.php |
— | — | @@ -65,5 +65,76 @@ |
66 | 66 | } |
67 | 67 | |
68 | 68 | } |
| 69 | + |
| 70 | + /** |
| 71 | + * Get the top responders for feedback in past week, default is top 5 |
| 72 | + * @param $num int - the number of top responders we want to get |
| 73 | + * @return array |
| 74 | + */ |
| 75 | + public static function getTopResponders( $num = 5 ) { |
| 76 | + |
| 77 | + global $wgMemc; |
69 | 78 | |
| 79 | + $timestamp = wfTimestamp( TS_UNIX ) - 7 * 24 * 60 * 60; // 1 week ago |
| 80 | + |
| 81 | + // Try cache first |
| 82 | + $key = wfMemcKey( 'moodbar_feedback_response', 'top_responders', 'past_week' ); |
| 83 | + $topResponders = $wgMemc->get( $key ); |
| 84 | + |
| 85 | + if ( $topResponders === false ) { |
| 86 | + $dbr = wfGetDB( DB_SLAVE ); |
| 87 | + $res = $dbr->select( array( 'moodbar_feedback_response', 'user' ), |
| 88 | + array( 'COUNT(*) AS number', 'user_id', 'user_name', 'user_real_name' ), |
| 89 | + array( 'mbfr_user_id = user_id', 'mbfr_timestamp > ' . $dbr->addQuotes( $dbr->timestamp( $timestamp ) ) ), |
| 90 | + __METHOD__, |
| 91 | + array( 'GROUP BY' => 'user_id', 'ORDER BY' => 'number DESC', 'LIMIT' => $num ) |
| 92 | + ); |
| 93 | + |
| 94 | + $topResponders = iterator_to_array( $res ); |
| 95 | + |
| 96 | + // Cache the results in cache for 12 hour |
| 97 | + $wgMemc->set( $key, $topResponders, 12 * 60 * 60 ); |
| 98 | + } |
| 99 | + |
| 100 | + return $topResponders; |
| 101 | + |
| 102 | + } |
| 103 | + |
| 104 | + /** |
| 105 | + * Get the stats for the moodbar type in the last 24 hours |
| 106 | + * @return array - count of number for each moodbar type |
| 107 | + */ |
| 108 | + public function getMoodBarTypeStats() { |
| 109 | + |
| 110 | + global $wgMemc; |
| 111 | + |
| 112 | + $timestamp = wfTimestamp( TS_UNIX ) - 24 * 60 * 60; // 24 hours ago |
| 113 | + |
| 114 | + // Try cache first |
| 115 | + $key = wfMemcKey( 'moodbar_feedback', 'type_stats', 'last_day' ); |
| 116 | + $moodbarStat = $wgMemc->get( $key ); |
| 117 | + |
| 118 | + if ( $moodbarStat === false ) { |
| 119 | + $dbr = wfGetDB( DB_SLAVE ); |
| 120 | + $res = $dbr->select( array( 'moodbar_feedback' ), |
| 121 | + array( 'mbf_type', 'COUNT(*) AS number' ), |
| 122 | + array( 'mbf_hidden_state' => 0, 'mbf_timestamp > ' . $dbr->addQuotes( $dbr->timestamp( $timestamp ) ) ), |
| 123 | + __METHOD__, |
| 124 | + array( 'GROUP BY' => 'mbf_type' ) |
| 125 | + ); |
| 126 | + |
| 127 | + $moodbarStat = array( 'happy' => 0, 'sad' => 0, 'confused' => 0 ); |
| 128 | + |
| 129 | + foreach ( $res as $row ) { |
| 130 | + $moodbarStat[$row->mbf_type] = $row->number; |
| 131 | + } |
| 132 | + |
| 133 | + // Cache the results in cache for 1 hour |
| 134 | + $wgMemc->set( $key, $moodbarStat, 60 * 60 ); |
| 135 | + } |
| 136 | + |
| 137 | + return $moodbarStat; |
| 138 | + |
| 139 | + } |
| 140 | + |
70 | 141 | } |
\ No newline at end of file |
Index: trunk/extensions/MoodBar/SpecialFeedbackDashboard.php |
— | — | @@ -70,43 +70,6 @@ |
71 | 71 | } |
72 | 72 | |
73 | 73 | /** |
74 | | - * Get the stats for the moodbar type in the last 24 hours |
75 | | - * @return array - count of number for each moodbar type |
76 | | - */ |
77 | | - public function getMoodBarTypeStats( ) { |
78 | | - |
79 | | - global $wgMemc; |
80 | | - |
81 | | - $timestamp = wfTimestamp( TS_UNIX ) - 24 * 60 * 60; // 24 hours ago |
82 | | - |
83 | | - // Try cache first |
84 | | - $key = wfMemcKey( 'moodbar_feedback', 'type_stats', 'last_day' ); |
85 | | - $moodbarStat = $wgMemc->get( $key ); |
86 | | - |
87 | | - if ( $moodbarStat === false ) { |
88 | | - $dbr = wfGetDB( DB_SLAVE ); |
89 | | - $res = $dbr->select( array( 'moodbar_feedback' ), |
90 | | - array( 'mbf_type', 'COUNT(*) AS number' ), |
91 | | - array( 'mbf_hidden_state' => 0, 'mbf_timestamp > ' . $dbr->addQuotes( $dbr->timestamp( $timestamp ) ) ), |
92 | | - __METHOD__, |
93 | | - array( 'GROUP BY' => 'mbf_type' ) |
94 | | - ); |
95 | | - |
96 | | - $moodbarStat = array( 'happy' => 0, 'sad' => 0, 'confused' => 0 ); |
97 | | - |
98 | | - foreach ( $res as $row ) { |
99 | | - $moodbarStat[$row->mbf_type] = $row->number; |
100 | | - } |
101 | | - |
102 | | - // Cache the results in cache for 1 hour |
103 | | - $wgMemc->set( $key, $moodbarStat, 60 * 60 ); |
104 | | - } |
105 | | - |
106 | | - return $moodbarStat; |
107 | | - |
108 | | - } |
109 | | - |
110 | | - /** |
111 | 74 | * Build the filter form. The state of each form element is preserved |
112 | 75 | * using data in $wgRequest. |
113 | 76 | * @param $filterType string Value to pass in the <form>'s data-filtertype attribute |
— | — | @@ -137,7 +100,7 @@ |
138 | 101 | $filterType = htmlspecialchars( $filterType ); |
139 | 102 | |
140 | 103 | |
141 | | - $moodbarStat = $this->getMoodBarTypeStats(); |
| 104 | + $moodbarStat = MoodBarUtil::getMoodBarTypeStats(); |
142 | 105 | $moodbarStatMsg = wfMessage( 'moodbar-type-stats' )->params( $moodbarStat['happy'], $moodbarStat['sad'], $moodbarStat['confused'] )->escaped(); |
143 | 106 | $feedbackDashboardDescription = wfMessage( 'moodbar-feedback-description' )->params( $wgSitename ); // don't escape because there is html |
144 | 107 | |
— | — | @@ -159,7 +122,9 @@ |
160 | 123 | |
161 | 124 | $showUnansweredFilter = '<label for="fbd-filters-show-unanswered" id="fbd-filters-type-show-unanswered-label" class="fbd-filters-label">' . |
162 | 125 | $showUnansweredCheckbox . $showUnansweredMsg . '</label>'; |
163 | | - |
| 126 | + |
| 127 | + $leaderBoardElement = self::buildLeaderBoardElement(); |
| 128 | + |
164 | 129 | return <<<HTML |
165 | 130 | <div id="fbd-description"> |
166 | 131 | <div id="fbd-description-text"> |
— | — | @@ -196,6 +161,7 @@ |
197 | 162 | <button type="submit" id="fbd-filters-set">$setFiltersMsg</button> |
198 | 163 | </form> |
199 | 164 | <a href="$whatIsURL" id="fbd-about">$whatIsMsg</a> |
| 165 | + $leaderBoardElement |
200 | 166 | </div> |
201 | 167 | HTML; |
202 | 168 | } |
— | — | @@ -296,6 +262,44 @@ |
297 | 263 | HTML; |
298 | 264 | } |
299 | 265 | |
| 266 | + /** |
| 267 | + * Build the HTML for leaderboard |
| 268 | + * @return html string |
| 269 | + */ |
| 270 | + protected static function buildLeaderBoardElement() { |
| 271 | + |
| 272 | + $topResponders = MoodBarUtil::getTopResponders(); |
| 273 | + |
| 274 | + $html = ''; |
| 275 | + |
| 276 | + if ( $topResponders ) { |
| 277 | + foreach ( $topResponders as $row ) { |
| 278 | + $user = User::newFromRow( $row ); |
| 279 | + if ( $user && !$user->isAnon() ) { |
| 280 | + $html .= '<li>' . Linker::userLink( $user->getId(), htmlspecialchars( $user->getName() ) ) . |
| 281 | + '<span>' . $row->number . '</span></li>'; |
| 282 | + } |
| 283 | + } |
| 284 | + } |
| 285 | + |
| 286 | + if ( $html ) { |
| 287 | + $topRespondersTitle = wfMessage( 'moodbar-feedback-top-responders-title' )->escaped(); |
| 288 | + |
| 289 | + return <<<HTML |
| 290 | + <div class="fbd-leaderboard-top-responders"> |
| 291 | + $topRespondersTitle |
| 292 | + <hr /> |
| 293 | + <ul class="fbd-leaderboard"> |
| 294 | + $html |
| 295 | + </ul> |
| 296 | + </div> |
| 297 | +HTML; |
| 298 | + } |
| 299 | + |
| 300 | + return $html; |
| 301 | + |
| 302 | + } |
| 303 | + |
300 | 304 | protected static function buildResponseElement( $feedbackItem, $response ) { |
301 | 305 | global $wgLang, $wgUser; |
302 | 306 | |
Index: trunk/extensions/MoodBar/MoodBar.i18n.php |
— | — | @@ -141,6 +141,7 @@ |
142 | 142 | 'moodbar-feedback-action-error' => 'An error occurred when trying to perform this action.', |
143 | 143 | 'moodbar-feedback-response-summary' => '[[$1|$2]] [[$3|responded]] $4 ago', |
144 | 144 | 'moodbar-feedback-edit-summary' => 'Response to [[Special:FeedbackDashboard/$1|user feedback]]: $2', |
| 145 | + 'moodbar-feedback-top-responders-title' => 'Top Responders', |
145 | 146 | // Mood types |
146 | 147 | 'moodbar-type-happy' => '{{GENDER:$1|Happy}}', |
147 | 148 | 'moodbar-type-sad' => '{{GENDER:$1|Sad}}', |
— | — | @@ -310,6 +311,7 @@ |
311 | 312 | 'moodbar-action-reason-required' => 'Text explaining admin action reason is required', |
312 | 313 | 'moodbar-feedback-response-summary' => 'Text providing a summary of a user response, $1 is user page, $2 is user name, $3 is user talk page, $4 is time', |
313 | 314 | 'moodbar-feedback-edit-summary' => 'Auto generated Edit summary for feedback response, $1 is the feedback id and $2 is the response text', |
| 315 | + 'moodbar-feedback-top-responders-title' => 'The title for Top Responders, which is located below feedback dashboard filter', |
314 | 316 | 'moodbar-type-happy' => '$1 is the username that can be used for GENDER. Message is used on Special:FeedbackDashboard.', |
315 | 317 | 'moodbar-type-sad' => '$1 is the username that can be used for GENDER. Message is used on Special:FeedbackDashboard.', |
316 | 318 | 'moodbar-type-confused' => '$1 is the username that can be used for GENDER. Message is used on Special:FeedbackDashboard.', |