- $where = array (
- 'page_namespace' => $apnamespace
- );
- if (isset ($apfrom))
- $where[] = 'page_title>=' . $db->addQuotes(ApiQueryBase :: titleToKey($apfrom));
-
- if ($apfilterredir === 'redirects')
- $where['page_is_redirect'] = 1;
- elseif ($apfilterredir === 'nonredirects') $where['page_is_redirect'] = 0;
-
- $this->profileDBIn();
- $res = $db->select('page', array (
- 'page_id',
- 'page_namespace',
- 'page_title'
- ), $where, __CLASS__ . '::' . __METHOD__, array (
- 'USE INDEX' => 'name_title',
- 'LIMIT' => $aplimit +1,
- 'ORDER BY' => 'page_namespace, page_title'
- ));
- $this->profileDBOut();
-
- $data = array ();
- if(!$this->isGenerator())
- ApiResult :: setIndexedTagName($data, 'p');
-
+
+ $params = $this->extractRequestParams();
+
+ // Page filters
+ $this->addTables( 'page' );
+
+ if ( $params['filterredir'] == 'redirects' ) {
+ $this->addWhereFld( 'page_is_redirect', 1 );
+ } elseif ( $params['filterredir'] == 'nonredirects' ) {
+ $this->addWhereFld( 'page_is_redirect', 0 );
+ }
+
+ $this->addWhereFld( 'page_namespace', $params['namespace'] );
+ $dir = ( $params['dir'] == 'descending' ? 'older' : 'newer' );
+ $from = ( is_null( $params['from'] ) ? null : $this->titlePartToKey( $params['from'] ) );
+ $to = ( is_null( $params['to'] ) ? null : $this->titlePartToKey( $params['to'] ) );
+ $this->addWhereRange( 'page_title', $dir, $from, $to );
+
+ if ( isset( $params['prefix'] ) ) {
+ $this->addWhere( 'page_title' . $db->buildLike( $this->titlePartToKey( $params['prefix'] ), $db->anyString() ) );
+ }
+
+ if ( is_null( $resultPageSet ) ) {
+ $selectFields = array(
+ 'page_namespace',
+ 'page_title',
+ 'page_id'
+ );
+ } else {
+ $selectFields = $resultPageSet->getPageTableFields();
+ }
+
+ $this->addFields( $selectFields );
+ $forceNameTitleIndex = true;
+ if ( isset( $params['minsize'] ) ) {
+ $this->addWhere( 'page_len>=' . intval( $params['minsize'] ) );
+ $forceNameTitleIndex = false;
+ }
+
+ if ( isset( $params['maxsize'] ) ) {
+ $this->addWhere( 'page_len<=' . intval( $params['maxsize'] ) );
+ $forceNameTitleIndex = false;
+ }
+
+ // Page protection filtering
+ if ( count( $params['prtype'] ) || $params['prexpiry'] != 'all' ) {
+ $this->addTables( 'page_restrictions' );
+ $this->addWhere( 'page_id=pr_page' );
+ $this->addWhere( 'pr_expiry>' . $db->addQuotes( $db->timestamp() ) );
+
+ if ( count( $params['prtype'] ) ) {
+ $this->addWhereFld( 'pr_type', $params['prtype'] );
+
+ if ( isset( $params['prlevel'] ) ) {
+ // Remove the empty string and '*' from the prlevel array
+ $prlevel = array_diff( $params['prlevel'], array( '', '*' ) );
+
+ if ( count( $prlevel ) ) {
+ $this->addWhereFld( 'pr_level', $prlevel );
+ }
+ }
+ if ( $params['prfiltercascade'] == 'cascading' ) {
+ $this->addWhereFld( 'pr_cascade', 1 );
+ } elseif ( $params['prfiltercascade'] == 'noncascading' ) {
+ $this->addWhereFld( 'pr_cascade', 0 );
+ }
+
+ $this->addOption( 'DISTINCT' );
+ }
+ $forceNameTitleIndex = false;
+
+ if ( $params['prexpiry'] == 'indefinite' ) {
+ $this->addWhere( "pr_expiry = {$db->addQuotes( $db->getInfinity() )} OR pr_expiry IS NULL" );
+ } elseif ( $params['prexpiry'] == 'definite' ) {
+ $this->addWhere( "pr_expiry != {$db->addQuotes( $db->getInfinity() )}" );
+ }
+
+ } elseif ( isset( $params['prlevel'] ) ) {
+ $this->dieUsage( 'prlevel may not be used without prtype', 'params' );
+ }
+
+ if ( $params['filterlanglinks'] == 'withoutlanglinks' ) {
+ $this->addTables( 'langlinks' );
+ $this->addJoinConds( array( 'langlinks' => array( 'LEFT JOIN', 'page_id=ll_from' ) ) );
+ $this->addWhere( 'll_from IS NULL' );
+ $forceNameTitleIndex = false;
+ } elseif ( $params['filterlanglinks'] == 'withlanglinks' ) {
+ $this->addTables( 'langlinks' );
+ $this->addWhere( 'page_id=ll_from' );
+ $this->addOption( 'STRAIGHT_JOIN' );
+ // We have to GROUP BY all selected fields to stop
+ // PostgreSQL from whining
+ $this->addOption( 'GROUP BY', implode( ', ', $selectFields ) );
+ $forceNameTitleIndex = false;
+ }
+
+ if ( $forceNameTitleIndex ) {
+ $this->addOption( 'USE INDEX', 'name_title' );
+ }
+
+ $limit = $params['limit'];
+ $this->addOption( 'LIMIT', $limit + 1 );
+ $res = $this->select( __METHOD__ );
+