Merge "Added deprecation comment to constant that when used throws deprecation exception"
[lhc/web/wiklou.git] / includes / api / ApiQueryBase.php
index 02d071b..59e6652 100644 (file)
@@ -351,7 +351,7 @@ abstract class ApiQueryBase extends ApiBase {
                }
                $result = $this->getResult();
                $fit = $result->addValue( array( 'query', 'pages', $pageId,
-                                        $this->getModuleName() ), null, $item );
+                       $this->getModuleName() ), null, $item );
                if ( !$fit ) {
                        return false;
                }
@@ -393,8 +393,7 @@ abstract class ApiQueryBase extends ApiBase {
         */
        protected function getDB() {
                if ( is_null( $this->mDb ) ) {
-                       $apiQuery = $this->getQuery();
-                       $this->mDb = $apiQuery->getDB();
+                       $this->mDb = $this->getQuery()->getDB();
                }
                return $this->mDb;
        }
@@ -585,24 +584,32 @@ abstract class ApiQueryBase extends ApiBase {
  */
 abstract class ApiQueryGeneratorBase extends ApiQueryBase {
 
-       private $mIsGenerator;
+       private $mGeneratorPageSet = null;
 
        /**
-        * @param $query ApiBase
-        * @param $moduleName string
-        * @param $paramPrefix string
+        * Switch this module to generator mode. By default, generator mode is
+        * switched off and the module acts like a normal query module.
+        * @since 1.21 requires pageset parameter
+        * @param $generatorPageSet ApiPageSet object that the module will get
+        *        by calling getPageSet() when in generator mode.
         */
-       public function __construct( $query, $moduleName, $paramPrefix = '' ) {
-               parent::__construct( $query, $moduleName, $paramPrefix );
-               $this->mIsGenerator = false;
+       public function setGeneratorMode( ApiPageSet $generatorPageSet ) {
+               if ( $generatorPageSet === null ) {
+                       ApiBase::dieDebug( __METHOD__, 'Required parameter missing - $generatorPageSet' );
+               }
+               $this->mGeneratorPageSet = $generatorPageSet;
        }
 
        /**
-        * Switch this module to generator mode. By default, generator mode is
-        * switched off and the module acts like a normal query module.
+        * Get the PageSet object to work on.
+        * If this module is generator, the pageSet object is different from other module's
+        * @return ApiPageSet
         */
-       public function setGeneratorMode() {
-               $this->mIsGenerator = true;
+       protected function getPageSet() {
+               if ( $this->mGeneratorPageSet !== null ) {
+                       return $this->mGeneratorPageSet;
+               }
+               return parent::getPageSet();
        }
 
        /**
@@ -611,7 +618,7 @@ abstract class ApiQueryGeneratorBase extends ApiQueryBase {
         * @return string Prefixed parameter name
         */
        public function encodeParamName( $paramName ) {
-               if ( $this->mIsGenerator ) {
+               if ( $this->mGeneratorPageSet !== null ) {
                        return 'g' . parent::encodeParamName( $paramName );
                } else {
                        return parent::encodeParamName( $paramName );
@@ -623,5 +630,5 @@ abstract class ApiQueryGeneratorBase extends ApiQueryBase {
         * @param $resultPageSet ApiPageSet: All output should be appended to
         *  this object
         */
-       public abstract function executeGenerator( $resultPageSet );
+       abstract public function executeGenerator( $resultPageSet );
 }