r87547 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r87546‎ | r87547 | r87548 >
Date:16:29, 6 May 2011
Author:awjrichards
Status:ok
Tags:
Comment:
Followup r87525, Adjusting how rounding of values for getting daily highs and lows works for compatibility with PHP < 5.3
Modified paths:
  • /trunk/extensions/ArticleFeedback/ArticleFeedback.php (modified) (history)
  • /trunk/extensions/ArticleFeedback/SpecialArticleFeedback.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ArticleFeedback/SpecialArticleFeedback.php
@@ -277,7 +277,8 @@
278278 *
279279 * Divides the number of ratings in half to determine the range of
280280 * articles to consider 'highest'. In the event of an odd number
281 - * of articles, round up, giving preference to the 'highs' so
 281+ * of articles, (determined by checking for modulus of # of ratings / 2),
 282+ * round up, giving preference to the 'highs' so
282283 * everyone feels warm and fuzzy about having more 'highs', as
283284 * it were...
284285 *
@@ -285,20 +286,32 @@
286287 * @return array Containing the... highest rated article data
287288 */
288289 protected function getDailyHighs( $highs_lows ) {
289 - $num_ratings = round( count( $highs_lows ) / 2 );
290 - return array_slice( $highs_lows, -$num_ratings, $num_ratings );
 290+ $num_ratings = count( $highs_lows );
 291+ if ( $num_ratings % 2 ) {
 292+ $num_highs = round( $num_ratings / 2 );
 293+ } else {
 294+ $num_highs = $num_ratings / 2;
 295+ }
 296+ return array_slice( $highs_lows, -$num_highs, $num_highs );
291297 }
292298
293299 /**
294300 * Determine the 'lowest' rated articles
295 - *
296 - * @see $this->getDailyHighs()
 301+ *
 302+ * @see getDailyHighs() However, if we are dealing with an odd number of
 303+ * ratings, round up and then subtract 1 since we are giving preference
 304+ * to the 'highs' when dealing with an odd number of ratings.
297305 * @param array Pre-orderd from lowest to highest
298306 * @return array Containing the... lowest rated article data
299307 */
300308 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 );
 309+ $num_ratings = count( $highs_lows );
 310+ if ( $num_ratings % 2 ) {
 311+ $num_lows = round( $num_ratings / 2 ) - 1;
 312+ } else {
 313+ $num_lows = $num_ratings / 2;
 314+ }
 315+ return array_slice( $highs_lows, 0, $num_lows );
303316 }
304317
305318 /**

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r87525Made it possible to display a separate table for highs and for lows rather th...awjrichards01:19, 6 May 2011

Status & tagging log