r95311 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r95310‎ | r95311 | r95312 >
Date:15:47, 23 August 2011
Author:catrope
Status:ok
Tags:
Comment:
ArticleFeedback: Don't count zero-value ratings in the statistics used for the ArticleFeedback dashboard, and change the UI code for the fun issues that occur when ratings can be missing. I had to change the decoded JSON data from an object to an array because of https://bugs.php.net/bug.php?id=55495 , which I discovered and filed while writing this code
Modified paths:
  • /trunk/extensions/ArticleFeedback/ArticleFeedback.i18n.php (modified) (history)
  • /trunk/extensions/ArticleFeedback/SpecialArticleFeedback.php (modified) (history)
  • /trunk/extensions/ArticleFeedback/populateAFStatistics.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ArticleFeedback/SpecialArticleFeedback.php
@@ -119,6 +119,8 @@
120120 $ids[] = $page['page'];
121121 }
122122 self::populateTitleCache( $ids );
 123+
 124+ $categories = self::getCategories();
123125
124126 $rows = array();
125127 if ( $pages ) {
@@ -129,12 +131,19 @@
130132 continue;
131133 }
132134 $row['page'] = $wgUser->getSkin()->link( $pageTitle, $pageTitle->getPrefixedText() );
133 - foreach ( $page['ratings'] as $value ) {
 135+ foreach ( $categories as $catid => $catmsg ) {
 136+ if ( isset( $page['ratings'][$catid] ) ) {
 137+ $number = $this->formatNumber( $page['ratings'][$catid] );
 138+ $class = round( $page['ratings'][$catid] );
 139+ } else {
 140+ $number = wfMsg( 'articlefeedback-table-noratings' );
 141+ $class = 'none';
 142+ }
134143 $row[] = array(
135 - 'text' => $this->formatNumber( $value ),
 144+ 'text' => $number,
136145 'attr' => array(
137146 'class' => 'articleFeedback-table-column-rating ' .
138 - 'articleFeedback-table-column-score-' . round( $value )
 147+ 'articleFeedback-table-column-score-' . $class
139148 )
140149 );
141150 }
@@ -153,7 +162,7 @@
154163 $caption,
155164 array_merge(
156165 array( wfMsg( 'articleFeedback-table-heading-page' ) ),
157 - self::getCategories(),
 166+ $categories,
158167 array( wfMsg( 'articleFeedback-table-heading-average' ) )
159168 ),
160169 $rows,
@@ -168,15 +177,22 @@
169178 */
170179 protected function renderWeeklyMostChanged() {
171180 global $wgUser;
 181+
 182+ $categories = self::getCategories();
172183
173184 $rows = array();
174185 foreach ( $this->getWeeklyMostChanged() as $page ) {
175186 $row = array();
176187 $pageTitle = Title::newFromText( $page['page'] );
177188 $row['page'] = $wgUser->getSkin()->link( $pageTitle, $pageTitle->getPrefixedText() );
178 - foreach ( $page['changes'] as $id => $value ) {
 189+ foreach ( $categories as $catid => $catmsg ) {
 190+ if ( isset( $page['changes'][$catid] ) ) {
 191+ $number = $this->formatNumber( $page['changes'][$catid] );
 192+ } else {
 193+ $number = wfMsg( 'articlefeedback-table-noratings' );
 194+ }
179195 $row[] = array(
180 - 'text' => $this->formatNumber( $value ),
 196+ 'text' => $number,
181197 'attr' => array(
182198 'class' => 'articleFeedback-table-column-changes'
183199 )
@@ -188,7 +204,7 @@
189205 wfMsg( 'articleFeedback-table-caption-weeklymostchanged' ),
190206 array_merge(
191207 array( wfMsg( 'articleFeedback-table-heading-page' ) ),
192 - self::getCategories()
 208+ $categories
193209 ),
194210 $rows,
195211 'articleFeedback-table-weeklymostchanged'
@@ -204,6 +220,7 @@
205221 global $wgUser;
206222
207223 $problems = $this->getProblems();
 224+ $categories = self::getCategories();
208225
209226 // Pre-fill page ID cache
210227 $ids = array();
@@ -220,12 +237,19 @@
221238 continue;
222239 }
223240 $row['page'] = $wgUser->getSkin()->link( $pageTitle, $pageTitle->getPrefixedText() );
224 - foreach ( $page['ratings'] as $value ) {
 241+ foreach ( $categories as $catid => $catmsg ) {
 242+ if ( isset( $page['ratings'][$catid] ) ) {
 243+ $number = $this->formatNumber( $page['ratings'][$catid] );
 244+ $class = round( $page['ratings'][$catid] );
 245+ } else {
 246+ $number = wfMsg( 'articlefeedback-table-noratings' );
 247+ $class = 'none';
 248+ }
225249 $row[] = array(
226 - 'text' => $this->formatNumber( $value ),
 250+ 'text' => $number,
227251 'attr' => array(
228252 'class' => 'articleFeedback-table-column-rating ' .
229 - 'articleFeedback-table-column-score-' . round( $value )
 253+ 'articleFeedback-table-column-score-' . $class
230254 )
231255 );
232256 }
@@ -242,7 +266,7 @@
243267 wfMsg( 'articleFeedback-table-caption-recentlows' ),
244268 array_merge(
245269 array( wfMsg( 'articleFeedback-table-heading-page' ) ),
246 - self::getCategories(),
 270+ $categories,
247271 array( wfMsg( 'articleFeedback-table-heading-average' ) )
248272 ),
249273 $rows,
@@ -414,7 +438,7 @@
415439 }
416440 $highs_lows[] = array(
417441 'page' => $row->afs_page_id,
418 - 'ratings' => FormatJson::decode( $row->afs_data ),
 442+ 'ratings' => FormatJson::decode( $row->afs_data, true ),
419443 'average' => $row->afs_orderable_data
420444 );
421445 }
@@ -434,7 +458,7 @@
435459 }
436460 $problems[] = array(
437461 'page' => $row->afs_page_id,
438 - 'ratings' => FormatJson::decode( $row->afs_data ),
 462+ 'ratings' => FormatJson::decode( $row->afs_data, true ),
439463 'average' => $row->afs_orderable_data
440464 );
441465 }
Index: trunk/extensions/ArticleFeedback/populateAFStatistics.php
@@ -498,6 +498,11 @@
499499 * @param string $rating_set_hash
500500 */
501501 public function addRating( $rating_id, $rating_value, $rating_set_hash = null ) {
 502+ if ( intval( $rating_value ) == 0 ) {
 503+ // Ignore zero ratings
 504+ return;
 505+ }
 506+
502507 $this->ratings[ $rating_id ][] = $rating_value;
503508
504509 if ( $rating_set_hash ) {
Index: trunk/extensions/ArticleFeedback/ArticleFeedback.i18n.php
@@ -106,6 +106,7 @@
107107 'articleFeedback-table-caption-recentlows' => 'Recent lows',
108108 'articleFeedback-table-heading-page' => 'Page',
109109 'articleFeedback-table-heading-average' => 'Average',
 110+ 'articlefeedback-table-noratings' => '-',
110111 'articleFeedback-copy-above-highlow-tables' => 'This is an experimental feature. Please provide feedback on the [$1 discussion page].',
111112 'articlefeedback-dashboard-bottom' => "'''Note''': We will continue to experiment with different ways of surfacing articles in these dashboards. At present, the dashboards include the following articles:
112113 * Pages with highest/lowest ratings: articles that have received at least 10 ratings within the last 24 hours. Averages are calculated by taking the mean of all ratings submitted within the last 24 hours.
@@ -180,6 +181,7 @@
181182 'articlefeedback-pitch-join-login' => '{{Identical|Log in}}',
182183 'articleFeedback-table-heading-page' => '{{Identical|Page}}',
183184 'articleFeedback-table-heading-average' => '{{Identical|Average}}',
 185+ 'articlefeedback-table-noratings' => 'Text to display in a table cell if there is no number to be shown',
184186 'articleFeedback-copy-above-highlow-tables' => 'The variable $1 will contain a full URL to a discussion page where the dashboard can be discussed - since the dashboard is powered by a special page, we can not rely on the built-in MediaWiki talk page.',
185187 );
186188

Follow-up revisions

RevisionCommit summaryAuthorDate
r95312fu r95311: Make new message optional for translatewiki.netraymond16:44, 23 August 2011
r964651.17wmf1: MFT r94135, r95260, r95311, r95601, r95790, r96434catrope18:33, 7 September 2011

Status & tagging log