r86001, now with less scariness :P I took out the delete action and did purge instea...
[lhc/web/wiklou.git] / includes / api / ApiQuery.php
index 6027818..19a6d92 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * API for MediaWiki 1.8+
+ *
  *
  * Created on Sep 7, 2006
  *
@@ -43,7 +43,12 @@ if ( !defined( 'MEDIAWIKI' ) ) {
 class ApiQuery extends ApiBase {
 
        private $mPropModuleNames, $mListModuleNames, $mMetaModuleNames;
+
+       /**
+        * @var ApiPageSet
+        */
        private $mPageSet;
+
        private $params, $redirects, $convertTitles;
 
        private $mQueryPropModules = array(
@@ -54,6 +59,7 @@ class ApiQuery extends ApiBase {
                'langlinks' => 'ApiQueryLangLinks',
                'images' => 'ApiQueryImages',
                'imageinfo' => 'ApiQueryImageInfo',
+               'stashimageinfo' => 'ApiQueryStashImageInfo',
                'templates' => 'ApiQueryLinks',
                'categories' => 'ApiQueryCategories',
                'extlinks' => 'ApiQueryExternalLinks',
@@ -87,6 +93,7 @@ class ApiQuery extends ApiBase {
                'users' => 'ApiQueryUsers',
                'random' => 'ApiQueryRandom',
                'protectedtitles' => 'ApiQueryProtectedTitles',
+               'querypage' => 'ApiQueryQueryPage',
        );
 
        private $mQueryMetaModules = array(
@@ -183,15 +190,15 @@ class ApiQuery extends ApiBase {
         * @return mixed string or null
         */
        function getModuleType( $moduleName ) {
-               if ( array_key_exists ( $moduleName, $this->mQueryPropModules ) ) {
+               if ( isset( $this->mQueryPropModules[$moduleName] ) ) {
                        return 'prop';
                }
 
-               if ( array_key_exists ( $moduleName, $this->mQueryListModules ) ) {
+               if ( isset( $this->mQueryListModules[$moduleName] ) ) {
                        return 'list';
                }
 
-               if ( array_key_exists ( $moduleName, $this->mQueryMetaModules ) ) {
+               if ( isset( $this->mQueryMetaModules[$moduleName] ) ) {
                        return 'meta';
                }
 
@@ -301,9 +308,9 @@ class ApiQuery extends ApiBase {
 
        /**
         * Create instances of all modules requested by the client
-        * @param $modules array to append instatiated modules to
+        * @param $modules Array to append instantiated modules to
         * @param $param string Parameter name to read modules from
-        * @param $moduleList array(modulename => classname)
+        * @param $moduleList Array array(modulename => classname)
         */
        private function instantiateModules( &$modules, $param, $moduleList ) {
                $list = @$this->params[$param];
@@ -383,9 +390,7 @@ class ApiQuery extends ApiBase {
                        $result->addValue( 'query', 'redirects', $redirValues );
                }
 
-               //
                // Missing revision elements
-               //
                $missingRevIDs = $pageSet->getMissingRevisionIDs();
                if ( count( $missingRevIDs ) ) {
                        $revids = array();
@@ -398,9 +403,7 @@ class ApiQuery extends ApiBase {
                        $result->addValue( 'query', 'badrevids', $revids );
                }
 
-               //
                // Page elements
-               //
                $pages = array();
 
                // Report any missing titles
@@ -427,7 +430,7 @@ class ApiQuery extends ApiBase {
                        ApiQueryBase::addTitleInfo( $vals, $title );
                        $vals['special'] = '';
                        if ( $title->getNamespace() == NS_SPECIAL &&
-                                       !SpecialPage::exists( $title->getText() ) ) {
+                                       !SpecialPage::exists( $title->getDbKey() ) ) {
                                $vals['missing'] = '';
                        } elseif ( $title->getNamespace() == NS_MEDIA &&
                                        !wfFindFile( $title ) ) {
@@ -457,36 +460,56 @@ class ApiQuery extends ApiBase {
                        $result->addValue( 'query', 'pages', $pages );
                }
                if ( $this->params['export'] ) {
-                       $exporter = new WikiExporter( $this->getDB() );
-                       // WikiExporter writes to stdout, so catch its
-                       // output with an ob
-                       ob_start();
-                       $exporter->openStream();
-                       foreach ( @$pageSet->getGoodTitles() as $title ) {
+                       $this->doExport( $pageSet, $result );
+               }
+       }
+
+       /**
+        * @param  $pageSet ApiPageSet Pages to be exported
+        * @param  $result ApiResult Result to output to
+        */
+       private function doExport( $pageSet, $result )  {
+               $exportTitles = array();
+               $titles = $pageSet->getGoodTitles();
+               if ( count( $titles ) ) {
+                       foreach ( $titles as $title ) {
                                if ( $title->userCanRead() ) {
-                                       $exporter->pageByTitle( $title );
+                                       $exportTitles[] = $title;
                                }
                        }
-                       $exporter->closeStream();
-                       $exportxml = ob_get_contents();
-                       ob_end_clean();
-
-                       // Don't check the size of exported stuff
-                       // It's not continuable, so it would cause more
-                       // problems than it'd solve
-                       $result->disableSizeCheck();
-                       if ( $this->params['exportnowrap'] ) {
-                               $result->reset();
-                               // Raw formatter will handle this
-                               $result->addValue( null, 'text', $exportxml );
-                               $result->addValue( null, 'mime', 'text/xml' );
-                       } else {
-                               $r = array();
-                               ApiResult::setContent( $r, $exportxml );
-                               $result->addValue( 'query', 'export', $r );
-                       }
-                       $result->enableSizeCheck();
                }
+               // only export when there are titles
+               if ( !count( $exportTitles ) ) {
+                       return;
+               }
+
+               $exporter = new WikiExporter( $this->getDB() );
+               // WikiExporter writes to stdout, so catch its
+               // output with an ob
+               ob_start();
+               $exporter->openStream();
+               foreach ( $exportTitles as $title ) {
+                       $exporter->pageByTitle( $title );
+               }
+               $exporter->closeStream();
+               $exportxml = ob_get_contents();
+               ob_end_clean();
+
+               // Don't check the size of exported stuff
+               // It's not continuable, so it would cause more
+               // problems than it'd solve
+               $result->disableSizeCheck();
+               if ( $this->params['exportnowrap'] ) {
+                       $result->reset();
+                       // Raw formatter will handle this
+                       $result->addValue( null, 'text', $exportxml );
+                       $result->addValue( null, 'mime', 'text/xml' );
+               } else {
+                       $r = array();
+                       ApiResult::setContent( $r, $exportxml );
+                       $result->addValue( 'query', 'export', $r );
+               }
+               $result->enableSizeCheck();
        }
 
        /**
@@ -576,15 +599,15 @@ class ApiQuery extends ApiBase {
                $this->mPageSet = null;
                $this->mAllowedGenerators = array(); // Will be repopulated
 
-               $astriks = str_repeat( '--- ', 8 );
-               $astriks2 = str_repeat( '*** ', 10 );
-               $msg .= "\n$astriks Query: Prop  $astriks\n\n";
+               $querySeparator = str_repeat( '--- ', 12 );
+               $moduleSeparator = str_repeat( '*** ', 14 );
+               $msg .= "\n$querySeparator Query: Prop  $querySeparator\n\n";
                $msg .= $this->makeHelpMsgHelper( $this->mQueryPropModules, 'prop' );
-               $msg .= "\n$astriks Query: List  $astriks\n\n";
+               $msg .= "\n$querySeparator Query: List  $querySeparator\n\n";
                $msg .= $this->makeHelpMsgHelper( $this->mQueryListModules, 'list' );
-               $msg .= "\n$astriks Query: Meta  $astriks\n\n";
+               $msg .= "\n$querySeparator Query: Meta  $querySeparator\n\n";
                $msg .= $this->makeHelpMsgHelper( $this->mQueryMetaModules, 'meta' );
-               $msg .= "\n\n$astriks2 Modules: continuation  $astriks2\n\n";
+               $msg .= "\n\n$moduleSeparator Modules: continuation  $moduleSeparator\n\n";
 
                // Perform the base call last because the $this->mAllowedGenerators
                // will be updated inside makeHelpMsgHelper()
@@ -596,7 +619,7 @@ class ApiQuery extends ApiBase {
 
        /**
         * For all modules in $moduleList, generate help messages and join them together
-        * @param $moduleList array(modulename => classname)
+        * @param $moduleList Array array(modulename => classname)
         * @param $paramName string Parameter name
         * @return string
         */
@@ -604,7 +627,7 @@ class ApiQuery extends ApiBase {
                $moduleDescriptions = array();
 
                foreach ( $moduleList as $moduleName => $moduleClass ) {
-                       $module = new $moduleClass ( $this, $moduleName, null );
+                       $module = new $moduleClass( $this, $moduleName, null );
 
                        $msg = ApiMain::makeHelpMsgHeader( $module, $paramName );
                        $msg2 = $module->makeHelpMsg();