Index: trunk/extensions/ArticleFeedback/SpecialArticleFeedback.php |
— | — | @@ -20,7 +20,21 @@ |
21 | 21 | $wgOut->addModules( 'ext.articleFeedback.dashboard' ); |
22 | 22 | $this->setHeaders(); |
23 | 23 | if ( $wgArticleFeedbackDashboard ) { |
24 | | - $this->renderDailyHighsAndLows(); |
| 24 | + // fetch the highest and lowest rated articles |
| 25 | + $highs_lows = $this->getDailyHighsAndLows(); |
| 26 | + |
| 27 | + // determine the highest rated articles |
| 28 | + $highs = $this->getDailyHighs( $highs_lows ); |
| 29 | + |
| 30 | + // .. and the lowest rated articles |
| 31 | + $lows = $this->getDailyLows( $highs_lows ); |
| 32 | + |
| 33 | + //render daily highs table |
| 34 | + $this->renderDailyHighsAndLows( $highs, wfMsg( 'articleFeedback-table-caption-dailyhighs' )); |
| 35 | + |
| 36 | + //render daily lows table |
| 37 | + $this->renderDailyHighsAndLows( $lows, wfMsg( 'articleFeedback-table-caption-dailylows' )); |
| 38 | + |
25 | 39 | /* |
26 | 40 | This functionality does not exist yet. |
27 | 41 | $this->renderWeeklyMostChanged(); |
— | — | @@ -91,11 +105,10 @@ |
92 | 106 | * |
93 | 107 | * @return String: HTML table of daily highs and lows |
94 | 108 | */ |
95 | | - protected function renderDailyHighsAndLows() { |
| 109 | + protected function renderDailyHighsAndLows( $pages, $caption ) { |
96 | 110 | global $wgOut, $wgUser; |
97 | 111 | |
98 | 112 | $rows = array(); |
99 | | - $pages = $this->getDailyHighsAndLows(); |
100 | 113 | if ( $pages ) { |
101 | 114 | foreach ( $pages as $page ) { |
102 | 115 | $row = array(); |
— | — | @@ -120,8 +133,9 @@ |
121 | 134 | $rows[] = $row; |
122 | 135 | } |
123 | 136 | } |
| 137 | + |
124 | 138 | $this->renderTable( |
125 | | - wfMsg( 'articleFeedback-table-caption-dailyhighsandlows' ), |
| 139 | + $caption, |
126 | 140 | array_merge( |
127 | 141 | array( wfMsg( 'articleFeedback-table-heading-page' ) ), |
128 | 142 | self::getCategories(), |
— | — | @@ -259,6 +273,35 @@ |
260 | 274 | } |
261 | 275 | |
262 | 276 | /** |
| 277 | + * Determine the 'highest' rated articles |
| 278 | + * |
| 279 | + * Divides the number of ratings in half to determine the range of |
| 280 | + * articles to consider 'highest'. In the event of an odd number |
| 281 | + * of articles, round up, giving preference to the 'highs' so |
| 282 | + * everyone feels warm and fuzzy about having more 'highs', as |
| 283 | + * it were... |
| 284 | + * |
| 285 | + * @param array Pre-orderd from lowest to highest |
| 286 | + * @return array Containing the... highest rated article data |
| 287 | + */ |
| 288 | + protected function getDailyHighs( $highs_lows ) { |
| 289 | + $num_ratings = round( count( $highs_lows ) / 2 ); |
| 290 | + return array_slice( $highs_lows, -$num_ratings, $num_ratings ); |
| 291 | + } |
| 292 | + |
| 293 | + /** |
| 294 | + * Determine the 'lowest' rated articles |
| 295 | + * |
| 296 | + * @see $this->getDailyHighs() |
| 297 | + * @param array Pre-orderd from lowest to highest |
| 298 | + * @return array Containing the... lowest rated article data |
| 299 | + */ |
| 300 | + protected function getDailyLows( $highs_lows ) { |
| 301 | + $num_ratings = round( count( $highs_lows ) / 2, 0, PHP_ROUND_HALF_DOWN); |
| 302 | + return array_slice( $highs_lows, 0, $num_ratings ); |
| 303 | + } |
| 304 | + |
| 305 | + /** |
263 | 306 | * Build data store of highs/lows for use when rendering table |
264 | 307 | * @param object Database result |
265 | 308 | * @return array |
Index: trunk/extensions/ArticleFeedback/ArticleFeedback.i18n.php |
— | — | @@ -76,6 +76,8 @@ |
77 | 77 | Please try again later.', |
78 | 78 | /* Special:ArticleFeedback */ |
79 | 79 | 'articleFeedback-table-caption-dailyhighsandlows' => 'Today\'s highs and lows', |
| 80 | + 'articleFeedback-table-caption-dailyhighs' => 'Today\'s highs', |
| 81 | + 'articleFeedback-table-caption-dailylows' => 'Today\'s lows', |
80 | 82 | 'articleFeedback-table-caption-weeklymostchanged' => 'This week\'s most changed', |
81 | 83 | 'articleFeedback-table-caption-recentlows' => 'Recent lows', |
82 | 84 | 'articleFeedback-table-heading-page' => 'Page', |