r87416 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r87415‎ | r87416 | r87417 >
Date:17:33, 4 May 2011
Author:krinkle
Status:ok
Tags:
Comment:
Fixing broken output in case there are no rows in article_feedback_stats_highs_lows (eg. right after install/update). maybe false, thus it can't access a object property. In these cases getDailyHighsAndLows returns early. In the foreach() of renderDailyHighsAndLows, make sure getDailyHighsAndLows finished, it that returned early (null/false), don't go into foreach (Warning: Invalid argument supplied for foreach())
Modified paths:
  • /trunk/extensions/ArticleFeedback/SpecialArticleFeedback.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ArticleFeedback/SpecialArticleFeedback.php
@@ -96,15 +96,18 @@
9797 global $wgOut, $wgArticleFeedbackRatings;
9898
9999 $rows = array();
100 - foreach ( $this->getDailyHighsAndLows() as $page ) {
101 - $row = array();
102 - $pageTitle = Title::newFromId( $page['page'] );
103 - $row['page'] = Linker::link( $pageTitle, $pageTitle->getPrefixedText() );
104 - foreach ( $page['ratings'] as $id => $value ) {
105 - $row['rating-' . $id] = $value;
 100+ $pages = $this->getDailyHighsAndLows();
 101+ if ( $pages ) {
 102+ foreach ( $pages as $page ) {
 103+ $row = array();
 104+ $pageTitle = Title::newFromId( $page['page'] );
 105+ $row['page'] = Linker::link( $pageTitle, $pageTitle->getPrefixedText() );
 106+ foreach ( $page['ratings'] as $id => $value ) {
 107+ $row['rating-' . $id] = $value;
 108+ }
 109+ $row['average articleFeedback-table-cell-score-' . round( $page['average'] )] = $page['average'];
 110+ $rows[] = $row;
106111 }
107 - $row['average articleFeedback-table-cell-score-' . round( $page['average'] )] = $page['average'];
108 - $rows[] = $row;
109112 }
110113 $this->renderTable(
111114 wfMsg( 'articleFeedback-table-caption-dailyhighsandlows' ),
@@ -216,7 +219,7 @@
217220 );
218221
219222 // if we have no results, just return
220 - if ( !$row->afshl_ts ) {
 223+ if ( !$row || !$row->afshl_ts ) {
221224 return;
222225 }
223226

Status & tagging log