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
|
|
|
* Indicate whether the module is in generator mode |
50
|
|
|
* @since 1.28 |
51
|
|
|
* @return bool |
52
|
|
|
*/ |
53
|
|
|
public function isInGeneratorMode() { |
54
|
|
|
return $this->mGeneratorPageSet !== null; |
55
|
|
|
} |
56
|
|
|
|
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 |
61
|
|
|
*/ |
62
|
|
|
protected function getPageSet() { |
63
|
|
|
if ( $this->mGeneratorPageSet !== null ) { |
64
|
|
|
return $this->mGeneratorPageSet; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
return parent::getPageSet(); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Overrides ApiBase to prepend 'g' to every generator parameter |
72
|
|
|
* @param string $paramName Parameter name |
73
|
|
|
* @return string Prefixed parameter name |
74
|
|
|
*/ |
75
|
|
|
public function encodeParamName( $paramName ) { |
76
|
|
|
if ( $this->mGeneratorPageSet !== null ) { |
77
|
|
|
return 'g' . parent::encodeParamName( $paramName ); |
78
|
|
|
} else { |
79
|
|
|
return parent::encodeParamName( $paramName ); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
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 |
87
|
|
|
*/ |
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 ); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @see ApiBase::getHelpFlags() |
98
|
|
|
* |
99
|
|
|
* Corresponding messages: api-help-flag-generator |
100
|
|
|
*/ |
101
|
|
|
protected function getHelpFlags() { |
102
|
|
|
$flags = parent::getHelpFlags(); |
103
|
|
|
$flags[] = 'generator'; |
104
|
|
|
return $flags; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Execute this module as a generator |
109
|
|
|
* @param ApiPageSet $resultPageSet All output should be appended to this object |
110
|
|
|
*/ |
111
|
|
|
abstract public function executeGenerator( $resultPageSet ); |
112
|
|
|
} |
113
|
|
|
|