3 * Copyright © 2006 Yuri Astrakhan "<Firstname><Lastname>@gmail.com"
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
26 abstract class ApiQueryGeneratorBase
extends ApiQueryBase
{
28 private $mGeneratorPageSet = null;
31 * Switch this module to generator mode. By default, generator mode is
32 * switched off and the module acts like a normal query module.
33 * @since 1.21 requires pageset parameter
34 * @param ApiPageSet $generatorPageSet ApiPageSet object that the module will get
35 * by calling getPageSet() when in generator mode.
37 public function setGeneratorMode( ApiPageSet
$generatorPageSet ) {
38 if ( $generatorPageSet === null ) {
39 ApiBase
::dieDebug( __METHOD__
, 'Required parameter missing - $generatorPageSet' );
41 $this->mGeneratorPageSet
= $generatorPageSet;
45 * Indicate whether the module is in generator mode
49 public function isInGeneratorMode() {
50 return $this->mGeneratorPageSet
!== null;
54 * Get the PageSet object to work on.
55 * If this module is generator, the pageSet object is different from other module's
58 protected function getPageSet() {
59 if ( $this->mGeneratorPageSet
!== null ) {
60 return $this->mGeneratorPageSet
;
63 return parent
::getPageSet();
67 * Overrides ApiBase to prepend 'g' to every generator parameter
68 * @param string $paramName Parameter name
69 * @return string Prefixed parameter name
71 public function encodeParamName( $paramName ) {
72 if ( $this->mGeneratorPageSet
!== null ) {
73 return 'g' . parent
::encodeParamName( $paramName );
75 return parent
::encodeParamName( $paramName );
80 * Overridden to set the generator param if in generator mode
81 * @param string $paramName Parameter name
82 * @param string|array $paramValue Parameter value
84 protected function setContinueEnumParameter( $paramName, $paramValue ) {
85 if ( $this->mGeneratorPageSet
!== null ) {
86 $this->getContinuationManager()->addGeneratorContinueParam( $this, $paramName, $paramValue );
88 parent
::setContinueEnumParameter( $paramName, $paramValue );
93 protected function getHelpFlags() {
94 // Corresponding messages: api-help-flag-generator
95 $flags = parent
::getHelpFlags();
96 $flags[] = 'generator';
101 * Execute this module as a generator
102 * @param ApiPageSet $resultPageSet All output should be appended to this object
104 abstract public function executeGenerator( $resultPageSet );