r64271 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r64270‎ | r64271 | r64272 >
Date:20:46, 27 March 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Fixed continue parameter for ApiQueryStories
Modified paths:
  • /trunk/extensions/Storyboard/api/ApiQueryStories.php (modified) (history)
  • /trunk/extensions/Storyboard/storyboard.sql (modified) (history)

Diff [purge]

Index: trunk/extensions/Storyboard/storyboard.sql
@@ -19,4 +19,6 @@
2020 ) /*$wgDBTableOptions*/;
2121
2222 CREATE INDEX story_published_modified ON /*$wgDBprefix*/storyboard (story_is_published, story_modified);
23 -CREATE INDEX story_title ON /*$wgDBprefix*/storyboard (story_title);
\ No newline at end of file
 23+CREATE INDEX story_modified_id ON /*$wgDBprefix*/storyboard (story_modified, story_id);
 24+CREATE INDEX story_title ON /*$wgDBprefix*/storyboard (story_title);
 25+ALTER TABLE /*$wgDBprefix*/storyboard ADD UNIQUE (story_title)
\ No newline at end of file
Index: trunk/extensions/Storyboard/api/ApiQueryStories.php
@@ -57,9 +57,25 @@
5858 $this->addWhere( array(
5959 'story_is_published' => 1
6060 ) );
61 - $this->addOption( 'LIMIT', $params['limit'] );
62 - $this->addOption( 'ORDER BY', 'story_modified DESC' );
 61+ $this->addOption( 'LIMIT', $params['limit'] + 1 );
 62+ $this->addOption( 'ORDER BY', 'story_modified, story_id DESC' );
6363
 64+ if ( !is_null( $params['continue'] ) ) {
 65+ $continueParams = explode( '|', $params['continue'] );
 66+ if ( count( $continueParams ) != 2 ) {
 67+ $this->dieUsage( 'Invalid continue param. You should pass the ' .
 68+ 'original value returned by the previous query', '_badcontinue' );
 69+ }
 70+
 71+ $storyModified = $continueParams[0];
 72+ $storyId = intval( $continueParams[1] );
 73+
 74+ $this->addWhere(
 75+ "story_modified < $storyModified OR " .
 76+ "(story_modified = $storyId AND story_id <= $storyModified)"
 77+ );
 78+ }
 79+
6480 $stories = $this->select( __METHOD__ );
6581 $count = 0;
6682
@@ -67,7 +83,7 @@
6884 if ( ++$count > $params['limit'] ) {
6985 // We've reached the one extra which shows that
7086 // there are additional pages to be had. Stop here...
71 - $this->setContinueEnumParameter( 'continue', "" ); // TODO: add some weird stuff here
 87+ $this->setContinueEnumParameter( 'continue', wfTimestamp(TS_MW, $row->story_modified) . '|' . $row->story_id ); // TODO: add some weird stuff here
7288 break;
7389 }
7490 $res = array(
@@ -126,8 +142,8 @@
127143 protected function getExamples() {
128144 return array (
129145 'api.php?action=query&list=stories',
130 - 'api.php?action=query&list=stories&stcontinue=42',
131 - 'api.php?action=query&list=stories&stcontinue=4&stlimit=2',
 146+ 'api.php?action=query&list=stories&stlimit=42',
 147+ 'api.php?action=query&list=stories&stcontinue=20100319202223|4&stlimit=2',
132148 );
133149 }
134150

Status & tagging log