r87525 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r87524‎ | r87525 | r87526 >
Date:01:19, 6 May 2011
Author:awjrichards
Status:ok
Tags:
Comment:
Made it possible to display a separate table for highs and for lows rather than one monolithic table (though you can do that too if you want).

* Added messages for highs/lows table captions
* Added methods for determining the highs as well as the lows from an array of combined highs/lows
Modified paths:
  • /trunk/extensions/ArticleFeedback/ArticleFeedback.i18n.php (modified) (history)
  • /trunk/extensions/ArticleFeedback/SpecialArticleFeedback.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ArticleFeedback/SpecialArticleFeedback.php
@@ -20,7 +20,21 @@
2121 $wgOut->addModules( 'ext.articleFeedback.dashboard' );
2222 $this->setHeaders();
2323 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+
2539 /*
2640 This functionality does not exist yet.
2741 $this->renderWeeklyMostChanged();
@@ -91,11 +105,10 @@
92106 *
93107 * @return String: HTML table of daily highs and lows
94108 */
95 - protected function renderDailyHighsAndLows() {
 109+ protected function renderDailyHighsAndLows( $pages, $caption ) {
96110 global $wgOut, $wgUser;
97111
98112 $rows = array();
99 - $pages = $this->getDailyHighsAndLows();
100113 if ( $pages ) {
101114 foreach ( $pages as $page ) {
102115 $row = array();
@@ -120,8 +133,9 @@
121134 $rows[] = $row;
122135 }
123136 }
 137+
124138 $this->renderTable(
125 - wfMsg( 'articleFeedback-table-caption-dailyhighsandlows' ),
 139+ $caption,
126140 array_merge(
127141 array( wfMsg( 'articleFeedback-table-heading-page' ) ),
128142 self::getCategories(),
@@ -259,6 +273,35 @@
260274 }
261275
262276 /**
 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+ /**
263306 * Build data store of highs/lows for use when rendering table
264307 * @param object Database result
265308 * @return array
Index: trunk/extensions/ArticleFeedback/ArticleFeedback.i18n.php
@@ -76,6 +76,8 @@
7777 Please try again later.',
7878 /* Special:ArticleFeedback */
7979 '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',
8082 'articleFeedback-table-caption-weeklymostchanged' => 'This week\'s most changed',
8183 'articleFeedback-table-caption-recentlows' => 'Recent lows',
8284 'articleFeedback-table-heading-page' => 'Page',

Follow-up revisions

RevisionCommit summaryAuthorDate
r87547Followup r87525, Adjusting how rounding of values for getting daily highs and...awjrichards16:29, 6 May 2011

Status & tagging log