Merge "Move some FileBackend related classes to /libs"
[lhc/web/wiklou.git] / includes / api / ApiQuery.php
index 3ca4c08..5e3c709 100644 (file)
@@ -443,16 +443,13 @@ class ApiQuery extends ApiBase {
                }
 
                $exporter = new WikiExporter( $this->getDB() );
-               // WikiExporter writes to stdout, so catch its
-               // output with an ob
-               ob_start();
+               $sink = new DumpStringOutput;
+               $exporter->setOutputSink( $sink );
                $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
@@ -460,10 +457,10 @@ class ApiQuery extends ApiBase {
                if ( $this->mParams['exportnowrap'] ) {
                        $result->reset();
                        // Raw formatter will handle this
-                       $result->addValue( null, 'text', $exportxml, ApiResult::NO_SIZE_CHECK );
+                       $result->addValue( null, 'text', $sink, ApiResult::NO_SIZE_CHECK );
                        $result->addValue( null, 'mime', 'text/xml', ApiResult::NO_SIZE_CHECK );
                } else {
-                       $result->addValue( 'query', 'export', $exportxml, ApiResult::NO_SIZE_CHECK );
+                       $result->addValue( 'query', 'export', $sink, ApiResult::NO_SIZE_CHECK );
                        $result->addValue( 'query', ApiResult::META_BC_SUBELEMENTS, [ 'export' ] );
                }
        }
@@ -498,79 +495,35 @@ class ApiQuery extends ApiBase {
                return $result;
        }
 
-       /**
-        * Override the parent to generate help messages for all available query modules.
-        * @deprecated since 1.25
-        * @return string
-        */
-       public function makeHelpMsg() {
-               wfDeprecated( __METHOD__, '1.25' );
-
-               // Use parent to make default message for the query module
-               $msg = parent::makeHelpMsg();
-
-               $querySeparator = str_repeat( '--- ', 12 );
-               $moduleSeparator = str_repeat( '*** ', 14 );
-               $msg .= "\n$querySeparator Query: Prop  $querySeparator\n\n";
-               $msg .= $this->makeHelpMsgHelper( 'prop' );
-               $msg .= "\n$querySeparator Query: List  $querySeparator\n\n";
-               $msg .= $this->makeHelpMsgHelper( 'list' );
-               $msg .= "\n$querySeparator Query: Meta  $querySeparator\n\n";
-               $msg .= $this->makeHelpMsgHelper( 'meta' );
-               $msg .= "\n\n$moduleSeparator Modules: continuation  $moduleSeparator\n\n";
-
-               return $msg;
-       }
-
-       /**
-        * For all modules of a given group, generate help messages and join them together
-        * @deprecated since 1.25
-        * @param string $group Module group
-        * @return string
-        */
-       private function makeHelpMsgHelper( $group ) {
-               $moduleDescriptions = [];
-
-               $moduleNames = $this->mModuleMgr->getNames( $group );
-               sort( $moduleNames );
-               foreach ( $moduleNames as $name ) {
-                       /**
-                        * @var $module ApiQueryBase
-                        */
-                       $module = $this->mModuleMgr->getModule( $name );
-
-                       $msg = ApiMain::makeHelpMsgHeader( $module, $group );
-                       $msg2 = $module->makeHelpMsg();
-                       if ( $msg2 !== false ) {
-                               $msg .= $msg2;
-                       }
-                       if ( $module instanceof ApiQueryGeneratorBase ) {
-                               $msg .= "Generator:\n  This module may be used as a generator\n";
-                       }
-                       $moduleDescriptions[] = $msg;
-               }
-
-               return implode( "\n", $moduleDescriptions );
-       }
-
        public function isReadMode() {
-               // We need to make an exception for ApiQueryTokens so login tokens can
-               // be fetched on private wikis. Restrict that exception as much as
-               // possible: no other modules allowed, and no pageset parameters
-               // either. We do allow the 'rawcontinue' and 'indexpageids' parameters
-               // since frameworks might add these unconditionally and they can't
-               // expose anything here.
+               // We need to make an exception for certain meta modules that should be
+               // accessible even without the 'read' right. Restrict the exception as
+               // much as possible: no other modules allowed, and no pageset
+               // parameters either. We do allow the 'rawcontinue' and 'indexpageids'
+               // parameters since frameworks might add these unconditionally and they
+               // can't expose anything here.
+               $this->mParams = $this->extractRequestParams();
                $params = array_filter(
                        array_diff_key(
-                               $this->extractRequestParams() + $this->getPageSet()->extractRequestParams(),
+                               $this->mParams + $this->getPageSet()->extractRequestParams(),
                                [ 'rawcontinue' => 1, 'indexpageids' => 1 ]
                        )
                );
-               if ( $params === [ 'meta' => [ 'tokens' ] ] ) {
-                       return false;
+               if ( array_keys( $params ) !== [ 'meta' ] ) {
+                       return true;
+               }
+
+               // Ask each module if it requires read mode. Any true => this returns
+               // true.
+               $modules = [];
+               $this->instantiateModules( $modules, 'meta' );
+               foreach ( $modules as $module ) {
+                       if ( $module->isReadMode() ) {
+                               return true;
+                       }
                }
 
-               return true;
+               return false;
        }
 
        protected function getExamplesMessages() {