*
* Created on July 7, 2007
*
- * Copyright © 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
+ * Copyright © 2006 Yuri Astrakhan "<Firstname><Lastname>@gmail.com"
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
}
if ( !is_null( $params['continue'] ) ) {
$continueArr = explode( '|', $params['continue'] );
- if ( count( $continueArr ) != 2 ) {
- $this->dieUsage( 'Invalid continue parameter', 'badcontinue' );
+ $op = $params['dir'] == 'descending' ? '<' : '>';
+ if ( $params['unique'] ) {
+ if ( count( $continueArr ) != 1 ) {
+ $this->dieUsage( 'Invalid continue parameter', 'badcontinue' );
+ }
+ $continueTitle = $db->addQuotes( $continueArr[0] );
+ $this->addWhere( "pl_title $op= $continueTitle" );
+ } else {
+ if ( count( $continueArr ) != 2 ) {
+ $this->dieUsage( 'Invalid continue parameter', 'badcontinue' );
+ }
+ $continueTitle = $db->addQuotes( $continueArr[0] );
+ $continueFrom = intval( $continueArr[1] );
+ $this->addWhere(
+ "pl_title $op $continueTitle OR " .
+ "(pl_title = $continueTitle AND " .
+ "pl_from $op= $continueFrom)"
+ );
}
- $continueTitle = $db->addQuotes( $this->titleToKey( $continueArr[0] ) );
- $continueFrom = intval( $continueArr[1] );
- $this->addWhere(
- "pl_title > $continueTitle OR " .
- "(pl_title = $continueTitle AND " .
- "pl_from > $continueFrom)"
- );
}
$from = ( is_null( $params['from'] ) ? null : $this->titlePartToKey( $params['from'] ) );
$limit = $params['limit'];
$this->addOption( 'LIMIT', $limit + 1 );
+ $sort = ( $params['dir'] == 'descending' ? ' DESC' : '' );
+ $orderBy = array();
+ $orderBy[] = 'pl_title' . $sort;
if ( !$params['unique'] ) {
- $this->addOption( 'ORDER BY', array(
- 'pl_title',
- 'pl_from'
- ));
+ $orderBy[] = 'pl_from' . $sort;
}
+ $this->addOption( 'ORDER BY', $orderBy );
$res = $this->select( __METHOD__ );
foreach ( $res as $row ) {
if ( ++ $count > $limit ) {
// We've reached the one extra which shows that there are additional pages to be had. Stop here...
- // TODO: Security issue - if the user has no right to view next title, it will still be shown
if ( $params['unique'] ) {
- $this->setContinueEnumParameter( 'from', $this->keyToTitle( $row->pl_title ) );
+ $this->setContinueEnumParameter( 'continue', $row->pl_title );
} else {
- $this->setContinueEnumParameter( 'continue', $this->keyToTitle( $row->pl_title ) . "|" . $row->pl_from );
+ $this->setContinueEnumParameter( 'continue', $row->pl_title . "|" . $row->pl_from );
}
break;
}
$fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $vals );
if ( !$fit ) {
if ( $params['unique'] ) {
- $this->setContinueEnumParameter( 'from', $this->keyToTitle( $row->pl_title ) );
+ $this->setContinueEnumParameter( 'continue', $row->pl_title );
} else {
- $this->setContinueEnumParameter( 'continue', $this->keyToTitle( $row->pl_title ) . "|" . $row->pl_from );
+ $this->setContinueEnumParameter( 'continue', $row->pl_title . "|" . $row->pl_from );
}
break;
}
ApiBase::PARAM_MIN => 1,
ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1,
ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
- )
+ ),
+ 'dir' => array(
+ ApiBase::PARAM_DFLT => 'ascending',
+ ApiBase::PARAM_TYPE => array(
+ 'ascending',
+ 'descending'
+ )
+ ),
);
}
'namespace' => 'The namespace to enumerate',
'limit' => 'How many total links to return',
'continue' => 'When more results are available, use this to continue',
+ 'dir' => 'The direction in which to list',
);
}