Merge "Added assertArrayEquals method to MediaWikiTestCase to avoid duplicating asort...
[lhc/web/wiklou.git] / includes / api / ApiQueryQueryPage.php
index 5b379d9..2c7ba12 100644 (file)
  * @file
  */
 
-if ( !defined( 'MEDIAWIKI' ) ) {
-       // Eclipse helper - will be ignored in production
-       require_once( 'ApiQueryBase.php' );
-}
-
 /**
  * Query module to get the results of a QueryPage-based special page
  *
@@ -73,15 +68,15 @@ class ApiQueryQueryPage extends ApiQueryGeneratorBase {
 
        /**
         * @param $resultPageSet ApiPageSet
-        * @return void
         */
        public function run( $resultPageSet = null ) {
-               global $wgUser;
+               global $wgQueryCacheLimit;
+
                $params = $this->extractRequestParams();
                $result = $this->getResult();
 
                $qp = new $this->qpMap[$params['page']]();
-               if ( !$qp->userCanExecute( $wgUser ) ) {
+               if ( !$qp->userCanExecute( $this->getUser() ) ) {
                        $this->dieUsageMsg( 'specialpage-cantexecute' );
                }
 
@@ -95,11 +90,17 @@ class ApiQueryQueryPage extends ApiQueryGeneratorBase {
                                if ( $ts ) {
                                        $r['cachedtimestamp'] = wfTimestamp( TS_ISO_8601, $ts );
                                }
+                               $r['maxresults'] = $wgQueryCacheLimit;
                        }
                }
                $result->addValue( array( 'query' ), $this->getModuleName(), $r );
 
-               $res = $qp->doQuery( $params['limit'] + 1, $params['offset'] );
+               if ( $qp->isCached() && !$qp->isCacheable() ) {
+                       // Disabled query page, don't run the query
+                       return;
+               }
+
+               $res = $qp->doQuery( $params['offset'], $params['limit'] + 1 );
                $count = 0;
                $titles = array();
                foreach ( $res as $row ) {
@@ -172,16 +173,49 @@ class ApiQueryQueryPage extends ApiQueryGeneratorBase {
                );
        }
 
+       public function getResultProperties() {
+               return array(
+                       ApiBase::PROP_ROOT => array(
+                               'name' => array(
+                                       ApiBase::PROP_TYPE => 'string',
+                                       ApiBase::PROP_NULLABLE => false
+                               ),
+                               'disabled' => array(
+                                       ApiBase::PROP_TYPE => 'boolean',
+                                       ApiBase::PROP_NULLABLE => false
+                               ),
+                               'cached' => array(
+                                       ApiBase::PROP_TYPE => 'boolean',
+                                       ApiBase::PROP_NULLABLE => false
+                               ),
+                               'cachedtimestamp' => array(
+                                       ApiBase::PROP_TYPE => 'timestamp',
+                                       ApiBase::PROP_NULLABLE => true
+                               )
+                       ),
+                       '' => array(
+                               'value' => 'string',
+                               'timestamp' => array(
+                                       ApiBase::PROP_TYPE => 'timestamp',
+                                       ApiBase::PROP_NULLABLE => true
+                               ),
+                               'ns' => 'namespace',
+                               'title' => 'string'
+                       )
+               );
+       }
+
        public function getDescription() {
                return 'Get a list provided by a QueryPage-based special page';
        }
 
        public function getPossibleErrors() {
                return array_merge( parent::getPossibleErrors(), array(
+                        array( 'specialpage-cantexecute' )
                ) );
        }
 
-       protected function getExamples() {
+       public function getExamples() {
                return array(
                        'api.php?action=query&list=querypage&qppage=Ancientpages'
                );