Index: trunk/extensions/ArticleFeedbackv5/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.special.js |
— | — | @@ -650,8 +650,8 @@ |
651 | 651 | 'format': 'json', |
652 | 652 | 'aafeedbackid': id, |
653 | 653 | }; |
654 | | - if( continueId > 0 ) { |
655 | | - data['aacontinue'] = continueId; |
| 654 | + if( continueId ) { |
| 655 | + data['aacontinue'] = continueId; |
656 | 656 | } |
657 | 657 | $.ajax( { |
658 | 658 | 'url': $.articleFeedbackv5special.apiUrl, |
— | — | @@ -659,15 +659,15 @@ |
660 | 660 | 'dataType': 'json', |
661 | 661 | 'data': data, |
662 | 662 | 'success': function( data ) { |
663 | | - if( 0 == continueId ) { |
| 663 | + if( data['articlefeedbackv5-view-activity'].hasHeader ) { |
664 | 664 | $( '#articlefeedbackv5-activity-log' ).html( data['articlefeedbackv5-view-activity'].activity ); |
665 | 665 | } else { |
666 | 666 | $( '#articlefeedbackv5-activity-log' ) |
667 | 667 | .find( '.articleFeedbackv5-activity-more' ).replaceWith( data['articlefeedbackv5-view-activity'].activity ); |
668 | 668 | } |
669 | | - if( data['articlefeedbackv5-view-activity'].continue ) { |
| 669 | + if( data['query-continue']['articlefeedbackv5-view-activity'] ) { |
670 | 670 | $( '#articlefeedbackv5-activity-log' ).find( '.articleFeedbackv5-activity-more' ) |
671 | | - .attr( 'rel', data['articlefeedbackv5-view-activity'].continue ) |
| 671 | + .attr( 'rel', data['query-continue']['articlefeedbackv5-view-activity'].aacontinue ) |
672 | 672 | .click( function( e ) { |
673 | 673 | $.articleFeedbackv5special.loadActivityLog( |
674 | 674 | $( '#' + $.articleFeedbackv5special.currentPanelHostId ).closest( '.articleFeedbackv5-feedback' ).attr( 'rel' ), |
Index: trunk/extensions/ArticleFeedbackv5/api/ApiViewActivityArticleFeedbackv5.php |
— | — | @@ -45,6 +45,7 @@ |
46 | 46 | $feedbackId = $params['feedbackid']; |
47 | 47 | $limit = $params['limit']; |
48 | 48 | $continue = $params['continue']; |
| 49 | + $result = $this->getResult(); |
49 | 50 | |
50 | 51 | // fetch our activity database information |
51 | 52 | $feedback = $this->fetchFeedback( $feedbackId ); |
— | — | @@ -62,16 +63,14 @@ |
63 | 64 | |
64 | 65 | // get our activities |
65 | 66 | $activities = $this->fetchActivity( $title, $feedbackId, $limit, $continue); |
66 | | - $old_continue = $continue; |
67 | 67 | |
68 | | - // overwrite previous continue for new value |
69 | | - $continue = null; |
70 | | - |
71 | 68 | // generate our html |
72 | 69 | $html = ''; |
73 | 70 | |
74 | | - // only do this if continue < 1 |
75 | | - if ($old_continue < 1) { |
| 71 | + // only do this if continue is not null |
| 72 | + if ( !$continue ) { |
| 73 | + $result->addValue( $this->getModuleName(), 'hasHeader', true ); |
| 74 | + |
76 | 75 | // <div class="articleFeedbackv5-activity-pane"> |
77 | 76 | $html .= Html::openElement( 'div', array( |
78 | 77 | 'class' => 'articleFeedbackv5-activity-pane' |
— | — | @@ -124,6 +123,8 @@ |
125 | 124 | ) ); |
126 | 125 | } |
127 | 126 | |
| 127 | + $count = 0; |
| 128 | + |
128 | 129 | // divs of activity items |
129 | 130 | foreach($activities as $item) { |
130 | 131 | |
— | — | @@ -132,6 +133,13 @@ |
133 | 134 | continue; |
134 | 135 | } |
135 | 136 | |
| 137 | + $count++; |
| 138 | + |
| 139 | + // figure out if we have more if we have another row past our limit |
| 140 | + if($count > $limit) { |
| 141 | + break; |
| 142 | + } |
| 143 | + |
136 | 144 | // <div class="articleFeedbackv5-activity-item"> |
137 | 145 | $html .= Html::openElement( 'div', array( |
138 | 146 | 'class' => 'articleFeedbackv5-activity-item' |
— | — | @@ -155,16 +163,10 @@ |
156 | 164 | |
157 | 165 | // </div> for class="articleFeedbackv5-activity-item" |
158 | 166 | $html .= Html::closeElement( 'div' ); |
159 | | - |
160 | | - // the last item's log_id should be the continue; |
161 | | - $continue = $item->log_id; |
162 | 167 | } |
163 | 168 | |
164 | | - // figure out if we have more based on our new continue value |
165 | | - $more = $this->fetchHasMore($title, $feedbackId, $continue); |
166 | | - |
167 | 169 | //optional <a href="#" class="articleFeedbackv5-activity-more">Show more Activity</a> |
168 | | - if ($more) { |
| 170 | + if ($count > $limit) { |
169 | 171 | $html .= Html::element( 'a', array( |
170 | 172 | 'class' => "articleFeedbackv5-activity-more", |
171 | 173 | 'href' => '#', |
— | — | @@ -175,50 +177,16 @@ |
176 | 178 | $html .= Html::closeElement( 'div' ); |
177 | 179 | |
178 | 180 | // finally add our generated html data |
179 | | - $result = $this->getResult(); |
180 | 181 | $result->addValue( $this->getModuleName(), 'limit', $limit ); |
181 | 182 | $result->addValue( $this->getModuleName(), 'activity', $html ); |
182 | 183 | |
183 | 184 | // continue only goes in if it's not empty |
184 | | - if ($continue > 0) { |
185 | | - $result->addValue( $this->getModuleName(), 'continue', $continue ); |
| 185 | + if ($count > $limit) { |
| 186 | + $this->setContinueEnumParameter( 'continue', $this->getContinue( $item ) ); |
186 | 187 | } |
187 | | - |
188 | | - // more only goes in if there are more entries |
189 | | - if ($more) { |
190 | | - $result->addValue( $this->getModuleName(), 'more', $more ); |
191 | | - } |
192 | 188 | } |
193 | 189 | |
194 | 190 | /** |
195 | | - * Sees if there are additional activity rows to view |
196 | | - * |
197 | | - * @param string $title the title of the page |
198 | | - * @param int $feedbackId identifier for the feedback item we are fetching activity for |
199 | | - * @param mixed $continue used for offsets |
200 | | - * @return bool true if there are more rows, or false |
201 | | - */ |
202 | | - protected function fetchHasMore( $title, $feedbackId, $continue = null ) { |
203 | | - $dbr = wfGetDB( DB_SLAVE ); |
204 | | - |
205 | | - $feedback = $dbr->selectField( |
206 | | - array( 'logging' ), |
207 | | - array( 'log_id'), |
208 | | - array( |
209 | | - 'log_type' => 'articlefeedbackv5', |
210 | | - 'log_title' => "ArticleFeedbackv5/$title/$feedbackId", |
211 | | - 'log_id < ' . intval($continue) |
212 | | - ), |
213 | | - __METHOD__, |
214 | | - array( |
215 | | - 'LIMIT' => 1 |
216 | | - ) |
217 | | - ); |
218 | | - |
219 | | - return ( (bool) $feedback ); |
220 | | - } |
221 | | - |
222 | | - /** |
223 | 191 | * Gets some base feedback information |
224 | 192 | * |
225 | 193 | * @param int $feedbackId identifier for the feedback item we are fetching activity for |
— | — | @@ -264,9 +232,7 @@ |
265 | 233 | 'log_title' => "ArticleFeedbackv5/$title/$feedbackId" |
266 | 234 | ); |
267 | 235 | |
268 | | - if ( null !== $continue ) { |
269 | | - $where[] = 'log_id < ' . intval($continue); |
270 | | - } |
| 236 | + $where = $this->applyContinue( $continue, $where ); |
271 | 237 | |
272 | 238 | $dbr = wfGetDB( DB_SLAVE ); |
273 | 239 | $activity = $dbr->select( |
— | — | @@ -281,8 +247,8 @@ |
282 | 248 | $where, |
283 | 249 | __METHOD__, |
284 | 250 | array( |
285 | | - 'LIMIT' => $limit, |
286 | | - 'ORDER BY' => 'log_id DESC' |
| 251 | + 'LIMIT' => $limit + 1, |
| 252 | + 'ORDER BY' => 'log_timestamp DESC, log_id ASC' |
287 | 253 | ) |
288 | 254 | ); |
289 | 255 | |
— | — | @@ -376,5 +342,34 @@ |
377 | 343 | ); |
378 | 344 | return $element; |
379 | 345 | } |
| 346 | + |
| 347 | + /** |
| 348 | + * Creates a timestamp/id tuple for continue |
| 349 | + */ |
| 350 | + protected function getContinue( $row ) { |
| 351 | + $ts = wfTimestamp( TS_MW, $row->log_timestamp ); |
| 352 | + return "$ts|{$row->log_id}"; |
| 353 | + } |
| 354 | + |
| 355 | + /** |
| 356 | + * gets timestamp and id pair for continue |
| 357 | + */ |
| 358 | + protected function applyContinue( $continue, $where ) { |
| 359 | + if ( !$continue ) { |
| 360 | + return $where; |
| 361 | + } |
| 362 | + |
| 363 | + $vals = explode( '|', $continue, 3 ); |
| 364 | + if ( count( $vals ) !== 2 ) { |
| 365 | + $this->dieUsage( 'Invalid continue param. You should pass the original value returned by the previous query', 'badcontinue' ); |
| 366 | + } |
| 367 | + |
| 368 | + $db = $this->getDB(); |
| 369 | + $ts = $db->addQuotes( $db->timestamp( $vals[0] ) ); |
| 370 | + $id = intval( $vals[1] ); |
| 371 | + $where[] = '(log_id = ' . $id . ' AND log_timestamp = ' . $ts . ') OR log_timestamp < ' . $ts; |
| 372 | + |
| 373 | + return $where; |
| 374 | + } |
380 | 375 | } |
381 | 376 | |