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
23 namespace MediaWiki\Api
;
30 abstract class ApiQueryGeneratorBase
extends ApiQueryBase
{
32 /** @var ApiPageSet|null */
33 private $mGeneratorPageSet = null;
36 * Switch this module to generator mode. By default, generator mode is
37 * switched off and the module acts like a normal query module.
38 * @since 1.21 requires pageset parameter
39 * @param ApiPageSet $generatorPageSet ApiPageSet object that the module will get
40 * by calling getPageSet() when in generator mode.
42 public function setGeneratorMode( ApiPageSet
$generatorPageSet ) {
43 $this->mGeneratorPageSet
= $generatorPageSet;
47 * Indicate whether the module is in generator mode
51 public function isInGeneratorMode() {
52 return $this->mGeneratorPageSet
!== null;
56 * Get the PageSet object to work on.
57 * If this module is generator, the pageSet object is different from other module's
60 protected function getPageSet() {
61 return $this->mGeneratorPageSet ?? parent
::getPageSet();
65 * Overrides ApiBase to prepend 'g' to every generator parameter
66 * @param string $paramName Parameter name
67 * @return string Prefixed parameter name
69 public function encodeParamName( $paramName ) {
70 if ( $this->mGeneratorPageSet
!== null ) {
71 return 'g' . parent
::encodeParamName( $paramName );
73 return parent
::encodeParamName( $paramName );
78 * Overridden to set the generator param if in generator mode
79 * @param string $paramName Parameter name
80 * @param int|string|array $paramValue Parameter value
82 protected function setContinueEnumParameter( $paramName, $paramValue ) {
83 if ( $this->mGeneratorPageSet
!== null ) {
84 $this->getContinuationManager()->addGeneratorContinueParam( $this, $paramName, $paramValue );
86 parent
::setContinueEnumParameter( $paramName, $paramValue );
91 protected function getHelpFlags() {
92 // Corresponding messages: api-help-flag-generator
93 $flags = parent
::getHelpFlags();
94 $flags[] = 'generator';
99 * Execute this module as a generator
100 * @param ApiPageSet $resultPageSet All output should be appended to this object
102 abstract public function executeGenerator( $resultPageSet );
105 /** @deprecated class alias since 1.43 */
106 class_alias( ApiQueryGeneratorBase
::class, 'ApiQueryGeneratorBase' );