+ if ( is_null( $resultPageSet ) )
+ $this->addFields( array( 'page_id', 'page_title', 'page_namespace', 'page_is_redirect' ) );
+ else
+ $this->addFields( $resultPageSet->getPageTableFields() );
+
+ $this->addFields( $this->bl_title );
+ if ( $this->hasNS )
+ $this->addFields( $this->bl_ns );
+
+ // We can't use LinkBatch here because $this->hasNS may be false
+ $titleWhere = array();
+ foreach ( $this->redirTitles as $t )
+ $titleWhere[] = "{$this->bl_title} = " . $db->addQuotes( $t->getDBkey() ) .
+ ( $this->hasNS ? " AND {$this->bl_ns} = '{$t->getNamespace()}'" : "" );
+ $this->addWhere( $db->makeList( $titleWhere, LIST_OR ) );
+ $this->addWhereFld( 'page_namespace', $this->params['namespace'] );
+
+ if ( !is_null( $this->redirID ) )
+ {
+ $first = $this->redirTitles[0];
+ $title = $db->strencode( $first->getDBkey() );
+ $ns = $first->getNamespace();
+ $from = $this->redirID;
+ if ( $this->hasNS )
+ $this->addWhere( "{$this->bl_ns} > $ns OR " .
+ "({$this->bl_ns} = $ns AND " .
+ "({$this->bl_title} > '$title' OR " .
+ "({$this->bl_title} = '$title' AND " .
+ "{$this->bl_from} >= $from)))" );
+ else
+ $this->addWhere( "{$this->bl_title} > '$title' OR " .
+ "({$this->bl_title} = '$title' AND " .
+ "{$this->bl_from} >= $from)" );
+
+ }
+ if ( $this->params['filterredir'] == 'redirects' )
+ $this->addWhereFld( 'page_is_redirect', 1 );
+ else if ( $this->params['filterredir'] == 'nonredirects' )
+ $this->addWhereFld( 'page_is_redirect', 0 );
+
+ $this->addOption( 'LIMIT', $this->params['limit'] + 1 );
+ $this->addOption( 'ORDER BY', $this->bl_sort );
+ $this->addOption( 'USE INDEX', array( 'page' => 'PRIMARY' ) );
+ }
+
+ private function run( $resultPageSet = null ) {
+ $this->params = $this->extractRequestParams( false );
+ $this->redirect = isset( $this->params['redirect'] ) && $this->params['redirect'];
+ $userMax = ( $this->redirect ? ApiBase::LIMIT_BIG1 / 2 : ApiBase::LIMIT_BIG1 );
+ $botMax = ( $this->redirect ? ApiBase::LIMIT_BIG2 / 2 : ApiBase::LIMIT_BIG2 );
+ if ( $this->params['limit'] == 'max' ) {
+ $this->params['limit'] = $this->getMain()->canApiHighLimits() ? $botMax : $userMax;
+ $this->getResult()->addValue( 'limits', $this->getModuleName(), $this->params['limit'] );