Move ApiQueryGeneratorBase to it's own file
[lhc/web/wiklou.git] / includes / api / ApiQueryGeneratorBase.php
1 <?php
2 /**
3 *
4 *
5 * Created on Sep 7, 2006
6 *
7 * Copyright © 2006 Yuri Astrakhan "<Firstname><Lastname>@gmail.com"
8 *
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.
13 *
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.
18 *
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
23 *
24 * @file
25 */
26
27 /**
28 * @ingroup API
29 */
30 abstract class ApiQueryGeneratorBase extends ApiQueryBase {
31
32 private $mGeneratorPageSet = null;
33
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.
40 */
41 public function setGeneratorMode( ApiPageSet $generatorPageSet ) {
42 if ( $generatorPageSet === null ) {
43 ApiBase::dieDebug( __METHOD__, 'Required parameter missing - $generatorPageSet' );
44 }
45 $this->mGeneratorPageSet = $generatorPageSet;
46 }
47
48 /**
49 * Get the PageSet object to work on.
50 * If this module is generator, the pageSet object is different from other module's
51 * @return ApiPageSet
52 */
53 protected function getPageSet() {
54 if ( $this->mGeneratorPageSet !== null ) {
55 return $this->mGeneratorPageSet;
56 }
57
58 return parent::getPageSet();
59 }
60
61 /**
62 * Overrides ApiBase to prepend 'g' to every generator parameter
63 * @param string $paramName Parameter name
64 * @return string Prefixed parameter name
65 */
66 public function encodeParamName( $paramName ) {
67 if ( $this->mGeneratorPageSet !== null ) {
68 return 'g' . parent::encodeParamName( $paramName );
69 } else {
70 return parent::encodeParamName( $paramName );
71 }
72 }
73
74 /**
75 * Overridden to set the generator param if in generator mode
76 * @param string $paramName Parameter name
77 * @param string|array $paramValue Parameter value
78 */
79 protected function setContinueEnumParameter( $paramName, $paramValue ) {
80 if ( $this->mGeneratorPageSet !== null ) {
81 $this->getContinuationManager()->addGeneratorContinueParam( $this, $paramName, $paramValue );
82 } else {
83 parent::setContinueEnumParameter( $paramName, $paramValue );
84 }
85 }
86
87 /**
88 * @see ApiBase::getHelpFlags()
89 *
90 * Corresponding messages: api-help-flag-generator
91 */
92 protected function getHelpFlags() {
93 $flags = parent::getHelpFlags();
94 $flags[] = 'generator';
95 return $flags;
96 }
97
98 /**
99 * Execute this module as a generator
100 * @param ApiPageSet $resultPageSet All output should be appended to this object
101 */
102 abstract public function executeGenerator( $resultPageSet );
103 }