- $this->addTables('page');
- $this->addOption('LIMIT', $limit);
- $this->addWhereFld('page_namespace', $namespace);
- $this->addWhereRange('page_random', 'newer', $randstr, null);
- $this->addWhereFld('page_is_redirect', $redirect);
- $this->addOption('USE INDEX', 'page_random');
- if(is_null($resultPageSet))
- $this->addFields(array('page_id', 'page_title', 'page_namespace'));
- else
- $this->addFields($resultPageSet->getPageTableFields());
- }
+ $this->addTables( 'page' );
+ $this->addFields( [ 'page_id', 'page_random' ] );
+ if ( is_null( $resultPageSet ) ) {
+ $this->addFields( [ 'page_title', 'page_namespace' ] );
+ } else {
+ $this->addFields( $resultPageSet->getPageTableFields() );
+ }
+ $this->addWhereFld( 'page_namespace', $params['namespace'] );
+ if ( $params['redirect'] || $params['filterredir'] === 'redirects' ) {
+ $this->addWhereFld( 'page_is_redirect', 1 );
+ } elseif ( $params['filterredir'] === 'nonredirects' ) {
+ $this->addWhereFld( 'page_is_redirect', 0 );
+ } elseif ( is_null( $resultPageSet ) ) {
+ $this->addFields( [ 'page_is_redirect' ] );
+ }
+ $this->addOption( 'LIMIT', $limit + 1 );
+
+ if ( $start !== null ) {
+ $start = $this->getDB()->addQuotes( $start );
+ if ( $startId > 0 ) {
+ $startId = (int)$startId; // safety
+ $this->addWhere( "page_random = $start AND page_id >= $startId OR page_random > $start" );
+ } else {
+ $this->addWhere( "page_random >= $start" );
+ }
+ }
+ if ( $end !== null ) {
+ $this->addWhere( 'page_random < ' . $this->getDB()->addQuotes( $end ) );
+ }
+ $this->addOption( 'ORDER BY', [ 'page_random', 'page_id' ] );
+
+ $result = $this->getResult();
+ $path = [ 'query', $this->getModuleName() ];