- $db = $this->getDB();
- $this->addTables(array('page', $this->bl_table));
- $this->addWhere("{$this->bl_from}=page_id");
- if(is_null($resultPageSet))
- $this->addFields(array('page_id', 'page_title', 'page_namespace'));
- else
- $this->addFields($resultPageSet->getPageTableFields());
- $this->addFields('page_is_redirect');
- $this->addWhereFld($this->bl_title, $this->rootTitle->getDBKey());
- if($this->hasNS)
- $this->addWhereFld($this->bl_ns, $this->rootTitle->getNamespace());
- $this->addWhereFld('page_namespace', $this->params['namespace']);
- if(!is_null($this->contID))
- $this->addWhere("{$this->bl_from}>={$this->contID}");
- if($this->params['filterredir'] == 'redirects')
- $this->addWhereFld('page_is_redirect', 1);
- if($this->params['filterredir'] == 'nonredirects')
- $this->addWhereFld('page_is_redirect', 0);
- $this->addOption('LIMIT', $this->params['limit'] + 1);
- $this->addOption('ORDER BY', $this->bl_from);
+ $this->addTables( array( $this->bl_table, 'page' ) );
+ $this->addWhere( "{$this->bl_from}=page_id" );
+ if ( is_null( $resultPageSet ) ) {
+ $this->addFields( array( 'page_id', 'page_title', 'page_namespace' ) );
+ } else {
+ $this->addFields( $resultPageSet->getPageTableFields() );
+ }
+
+ $this->addFields( 'page_is_redirect' );
+ $this->addWhereFld( $this->bl_title, $this->rootTitle->getDBkey() );
+
+ if ( $this->hasNS ) {
+ $this->addWhereFld( $this->bl_ns, $this->rootTitle->getNamespace() );
+ }
+ $this->addWhereFld( 'page_namespace', $this->params['namespace'] );
+
+ if ( !is_null( $this->contID ) ) {
+ $this->addWhere( "{$this->bl_from}>={$this->contID}" );
+ }
+
+ if ( $this->params['filterredir'] == 'redirects' ) {
+ $this->addWhereFld( 'page_is_redirect', 1 );
+ } elseif ( $this->params['filterredir'] == 'nonredirects' && !$this->redirect ) {
+ // bug 22245 - Check for !redirect, as filtering nonredirects, when getting what links to them is contradictory
+ $this->addWhereFld( 'page_is_redirect', 0 );
+ }
+
+ $this->addOption( 'LIMIT', $this->params['limit'] + 1 );
+ $this->addOption( 'ORDER BY', $this->bl_from );
+ $this->addOption( 'STRAIGHT_JOIN' );