Merge "Special:Upload should not crash on failing previews"
[mediawiki.git] / includes / api / ApiQueryGeneratorBase.php
blobf7b94c7c015650fa6b821bd6991f017347eea7fd
1 <?php
2 /**
5 * Created on Sep 7, 2006
7 * Copyright © 2006 Yuri Astrakhan "<Firstname><Lastname>@gmail.com"
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 * http://www.gnu.org/copyleft/gpl.html
24 * @file
27 /**
28 * @ingroup API
30 abstract class ApiQueryGeneratorBase extends ApiQueryBase {
32 private $mGeneratorPageSet = null;
34 /**
35 * Switch this module to generator mode. By default, generator mode is
36 * switched off and the module acts like a normal query module.
37 * @since 1.21 requires pageset parameter
38 * @param ApiPageSet $generatorPageSet ApiPageSet object that the module will get
39 * by calling getPageSet() when in generator mode.
41 public function setGeneratorMode( ApiPageSet $generatorPageSet ) {
42 if ( $generatorPageSet === null ) {
43 ApiBase::dieDebug( __METHOD__, 'Required parameter missing - $generatorPageSet' );
45 $this->mGeneratorPageSet = $generatorPageSet;
48 /**
49 * Indicate whether the module is in generator mode
50 * @since 1.28
51 * @return bool
53 public function isInGeneratorMode() {
54 return $this->mGeneratorPageSet !== null;
57 /**
58 * Get the PageSet object to work on.
59 * If this module is generator, the pageSet object is different from other module's
60 * @return ApiPageSet
62 protected function getPageSet() {
63 if ( $this->mGeneratorPageSet !== null ) {
64 return $this->mGeneratorPageSet;
67 return parent::getPageSet();
70 /**
71 * Overrides ApiBase to prepend 'g' to every generator parameter
72 * @param string $paramName Parameter name
73 * @return string Prefixed parameter name
75 public function encodeParamName( $paramName ) {
76 if ( $this->mGeneratorPageSet !== null ) {
77 return 'g' . parent::encodeParamName( $paramName );
78 } else {
79 return parent::encodeParamName( $paramName );
83 /**
84 * Overridden to set the generator param if in generator mode
85 * @param string $paramName Parameter name
86 * @param string|array $paramValue Parameter value
88 protected function setContinueEnumParameter( $paramName, $paramValue ) {
89 if ( $this->mGeneratorPageSet !== null ) {
90 $this->getContinuationManager()->addGeneratorContinueParam( $this, $paramName, $paramValue );
91 } else {
92 parent::setContinueEnumParameter( $paramName, $paramValue );
96 /**
97 * @see ApiBase::getHelpFlags()
99 * Corresponding messages: api-help-flag-generator
101 protected function getHelpFlags() {
102 $flags = parent::getHelpFlags();
103 $flags[] = 'generator';
104 return $flags;
108 * Execute this module as a generator
109 * @param ApiPageSet $resultPageSet All output should be appended to this object
111 abstract public function executeGenerator( $resultPageSet );