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