r110611 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r110610‎ | r110611 | r110612 >
Date:20:37, 2 February 2012
Author:gregchiasson
Status:ok (Comments)
Tags:aft 
Comment:
AFT5: Use wgExtensionAssetsPath, which refs r109971, and make the more button only display when there're actually more records to load.
Modified paths:
  • /trunk/extensions/ArticleFeedbackv5/api/ApiViewFeedbackArticleFeedbackv5.php (modified) (history)
  • /trunk/extensions/ArticleFeedbackv5/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.special.js (modified) (history)

Diff [purge]

Index: trunk/extensions/ArticleFeedbackv5/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.special.js
@@ -268,7 +268,7 @@
269269
270270 $( '#articleFeedbackv5-sort-arrow-' + id ).show();
271271 $( '#articleFeedbackv5-sort-arrow-' + id ).attr(
272 - 'src', '/extensions/ArticleFeedbackv5/modules/jquery.articleFeedbackv5/images/sort-' + dir + 'ending.png'
 272+ 'src', mw.config.get('wgExtensionAssetsPath') + '/ArticleFeedbackv5/modules/jquery.articleFeedbackv5/images/sort-' + dir + 'ending.png'
273273 );
274274 $( '#articleFeedbackv5-special-sort-' + id).addClass( 'sort-active' );
275275 };
@@ -624,6 +624,11 @@
625625 $( '#articleFeedbackv5-feedback-count-total' ).text( data['articlefeedbackv5-view-feedback'].count );
626626 $.articleFeedbackv5special.listControls.continue = data['articlefeedbackv5-view-feedback'].continue;
627627 $.articleFeedbackv5special.listControls.continueId = data['articlefeedbackv5-view-feedback'].continueid;
 628+ if( data['articlefeedbackv5-view-feedback'].more ) {
 629+ $( '#articleFeedbackv5-show-more').show();
 630+ } else {
 631+ $( '#articleFeedbackv5-show-more').hide();
 632+ }
628633 } else {
629634 $( '#articleFeedbackv5-show-feedback' ).text( mw.msg( 'articlefeedbackv5-error-loading-feedback' ) );
630635 }
Index: trunk/extensions/ArticleFeedbackv5/api/ApiViewFeedbackArticleFeedbackv5.php
@@ -16,6 +16,7 @@
1717 class ApiViewFeedbackArticleFeedbackv5 extends ApiQueryBase {
1818 private $continue = null;
1919 private $continueId = null;
 20+ private $showMore = false;
2021
2122 /**
2223 * Constructor
@@ -51,6 +52,7 @@
5253
5354 $result->addValue( $this->getModuleName(), 'length', $length );
5455 $result->addValue( $this->getModuleName(), 'count', $count );
 56+ $result->addValue( $this->getModuleName(), 'more', $this->showMore );
5557 if ( $this->continue !== null ) {
5658 $result->addValue( $this->getModuleName(), 'continue', $this->continue );
5759 }
@@ -125,7 +127,7 @@
126128 default:
127129 $sortField = 'af_id';
128130 $order = "af_id $direction";
129 - $continueSql = "af_id < ".intVal( $continue );
 131+ $continueSql = "af_id $continueDirection ".intVal( $continue );
130132 break;
131133 }
132134
@@ -161,7 +163,7 @@
162164 $where,
163165 __METHOD__,
164166 array(
165 - 'LIMIT' => $limit,
 167+ 'LIMIT' => ($limit + 1),
166168 'ORDER BY' => $order
167169 ),
168170 array(
@@ -178,15 +180,24 @@
179181
180182 foreach ( $id_query as $id ) {
181183 $ids[] = $id->af_id;
182 - $this->continue = $id->$sortField;
183 - $this->continueId = $id->af_id;
 184+ // Get the continue values from the last counted item.
 185+ if( count( $ids ) == $limit ) {
 186+ $this->continue = $id->$sortField;
 187+ $this->continueId = $id->af_id;
 188+ }
184189 }
185 -
186190
187191 if ( !count( $ids ) ) {
188192 return array();
189193 }
190194
 195+ // Returned an extra row, meaning there's more to show.
 196+ // Also, pop that extra one off, so we don't render it.
 197+ if ( count( $ids ) > $limit ) {
 198+ $this->showMore = true;
 199+ array_pop( $ids );
 200+ }
 201+
191202 $rows = $dbr->select(
192203 array( 'aft_article_feedback',
193204 'rating' => 'aft_article_answer',

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r109971ATF5 - fix image links on sort arrows, and a couple of the queries for buildi...gregchiasson00:28, 25 January 2012

Comments

#Comment by Catrope (talk | contribs)   00:08, 28 February 2012
+ if( count( $ids ) == $limit ) {

Instead of counting the number of ids every time, just keep a counter variable. If the limit is something like 500 and you're counting the array at every iteration, you're counting 1+2+3+...+500 = 125,250 things.

+ array_pop( $ids );

You could've decided to just not add it in the first place, no use adding an element to an array and removing it right after.

Status & tagging log