- if ( count( $cont ) != 2 )
- $this->dieUsage( "Invalid continue param. You should pass the " .
- "original value returned by the previous query", "_badcontinue" );
- $orig = $this->getDB()->strencode( $this->titleTokey( $cont[0] ) );
- $dup = $this->getDB()->strencode( $this->titleToKey( $cont[1] ) );
- $this->addWhere( "i1.img_name > '$orig' OR " .
- "(i1.img_name = '$orig' AND " .
- "i2.img_name >= '$dup')" );
+ if ( count( $cont ) != 2 ) {
+ $this->dieUsage( 'Invalid continue param. You should pass the ' .
+ 'original value returned by the previous query', '_badcontinue' );
+ }
+ $op = $params['dir'] == 'descending' ? '<' : '>';
+ $db = $this->getDB();
+ $orig = $db->addQuotes( $this->titleTokey( $cont[0] ) );
+ $dup = $db->addQuotes( $this->titleToKey( $cont[1] ) );
+ $this->addWhere(
+ "i1.img_name $op $orig OR " .
+ "(i1.img_name = $orig AND " .
+ "i2.img_name $op= $dup)"
+ );
+ }
+
+ $sort = ( $params['dir'] == 'descending' ? ' DESC' : '' );
+ // Don't order by i1.img_name if it's constant in the WHERE clause
+ if ( count( $this->getPageSet()->getGoodTitles() ) == 1 ) {
+ $this->addOption( 'ORDER BY', 'i2.img_name' . $sort );
+ } else {
+ $this->addOption( 'ORDER BY', array(
+ 'i1.img_name' . $sort,
+ 'i2.img_name' . $sort
+ ));