Merge "Making listToText() not break if passed a 1-item list."
[lhc/web/wiklou.git] / includes / api / ApiQueryInfo.php
index 87fd58b..4a85b0b 100644 (file)
@@ -4,7 +4,7 @@
  *
  * Created on Sep 25, 2006
  *
- * 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
@@ -57,7 +57,10 @@ class ApiQueryInfo extends ApiQueryBase {
                global $wgDisableCounters;
 
                $pageSet->requestField( 'page_restrictions' );
-               $pageSet->requestField( 'page_is_redirect' );
+               // when resolving redirects, no page will have this field
+               if( !$pageSet->isResolvingRedirects() ) {
+                       $pageSet->requestField( 'page_is_redirect' );
+               }
                $pageSet->requestField( 'page_is_new' );
                if ( !$wgDisableCounters ) {
                        $pageSet->requestField( 'page_counter' );
@@ -280,7 +283,10 @@ class ApiQueryInfo extends ApiQueryBase {
                }
 
                $this->pageRestrictions = $pageSet->getCustomField( 'page_restrictions' );
-               $this->pageIsRedir = $pageSet->getCustomField( 'page_is_redirect' );
+               // when resolving redirects, no page will have this field
+               $this->pageIsRedir = !$pageSet->isResolvingRedirects()
+                       ? $pageSet->getCustomField( 'page_is_redirect' )
+                       : array();
                $this->pageIsNew = $pageSet->getCustomField( 'page_is_new' );
 
                global $wgDisableCounters;
@@ -346,7 +352,7 @@ class ApiQueryInfo extends ApiQueryBase {
                                : intval( $this->pageCounter[$pageid] );
                        $pageInfo['length'] = intval( $this->pageLength[$pageid] );
 
-                       if ( $this->pageIsRedir[$pageid] ) {
+                       if ( isset( $this->pageIsRedir[$pageid] ) && $this->pageIsRedir[$pageid] ) {
                                $pageInfo['redirect'] = '';
                        }
                        if ( $this->pageIsNew[$pageid] ) {
@@ -429,15 +435,14 @@ class ApiQueryInfo extends ApiQueryBase {
                // Get normal protections for existing titles
                if ( count( $this->titles ) ) {
                        $this->resetQueryParams();
-                       $this->addTables( array( 'page_restrictions', 'page' ) );
-                       $this->addWhere( 'page_id=pr_page' );
+                       $this->addTables( 'page_restrictions' );
                        $this->addFields( array( 'pr_page', 'pr_type', 'pr_level',
-                                       'pr_expiry', 'pr_cascade', 'page_namespace',
-                                       'page_title' ) );
+                                       'pr_expiry', 'pr_cascade' ) );
                        $this->addWhereFld( 'pr_page', array_keys( $this->titles ) );
 
                        $res = $this->select( __METHOD__ );
                        foreach ( $res as $row ) {
+                               $title = $this->titles[$row->pr_page];
                                $a = array(
                                        'type' => $row->pr_type,
                                        'level' => $row->pr_level,
@@ -446,11 +451,14 @@ class ApiQueryInfo extends ApiQueryBase {
                                if ( $row->pr_cascade ) {
                                        $a['cascade'] = '';
                                }
-                               $this->protections[$row->page_namespace][$row->page_title][] = $a;
-
-                               // Also check old restrictions
-                               if ( $this->pageRestrictions[$row->pr_page] ) {
-                                       $restrictions = explode( ':', trim( $this->pageRestrictions[$row->pr_page] ) );
+                               $this->protections[$title->getNamespace()][$title->getDBkey()][] = $a;
+                       }
+                       // Also check old restrictions
+                       foreach( $this->titles as $pageId => $title ) {
+                               if ( $this->pageRestrictions[$pageId] ) {
+                                       $namespace = $title->getNamespace();
+                                       $dbKey = $title->getDBkey();
+                                       $restrictions = explode( ':', trim( $this->pageRestrictions[$pageId] ) );
                                        foreach ( $restrictions as $restrict ) {
                                                $temp = explode( '=', trim( $restrict ) );
                                                if ( count( $temp ) == 1 ) {
@@ -460,12 +468,12 @@ class ApiQueryInfo extends ApiQueryBase {
                                                        if ( $restriction == '' ) {
                                                                continue;
                                                        }
-                                                       $this->protections[$row->page_namespace][$row->page_title][] = array(
+                                                       $this->protections[$namespace][$dbKey][] = array(
                                                                'type' => 'edit',
                                                                'level' => $restriction,
                                                                'expiry' => 'infinity',
                                                        );
-                                                       $this->protections[$row->page_namespace][$row->page_title][] = array(
+                                                       $this->protections[$namespace][$dbKey][] = array(
                                                                'type' => 'move',
                                                                'level' => $restriction,
                                                                'expiry' => 'infinity',
@@ -475,7 +483,7 @@ class ApiQueryInfo extends ApiQueryBase {
                                                        if ( $restriction == '' ) {
                                                                continue;
                                                        }
-                                                       $this->protections[$row->page_namespace][$row->page_title][] = array(
+                                                       $this->protections[$namespace][$dbKey][] = array(
                                                                'type' => $temp[0],
                                                                'level' => $restriction,
                                                                'expiry' => 'infinity',