Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
0.00%
0 / 6
CRAP
0.00% covered (danger)
0.00%
0 / 1
ApiQueryGeneratorBase
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
0.00%
0 / 6
72
0.00% covered (danger)
0.00%
0 / 1
 setGeneratorMode
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 isInGeneratorMode
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getPageSet
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 encodeParamName
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
 setContinueEnumParameter
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
 getHelpFlags
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 executeGenerator
n/a
0 / 0
n/a
0 / 0
0
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 * @stable to extend
25 *
26 * @ingroup API
27 */
28abstract class ApiQueryGeneratorBase extends ApiQueryBase {
29
30    private $mGeneratorPageSet = null;
31
32    /**
33     * Switch this module to generator mode. By default, generator mode is
34     * switched off and the module acts like a normal query module.
35     * @since 1.21 requires pageset parameter
36     * @param ApiPageSet $generatorPageSet ApiPageSet object that the module will get
37     *        by calling getPageSet() when in generator mode.
38     */
39    public function setGeneratorMode( ApiPageSet $generatorPageSet ) {
40        $this->mGeneratorPageSet = $generatorPageSet;
41    }
42
43    /**
44     * Indicate whether the module is in generator mode
45     * @since 1.28
46     * @return bool
47     */
48    public function isInGeneratorMode() {
49        return $this->mGeneratorPageSet !== null;
50    }
51
52    /**
53     * Get the PageSet object to work on.
54     * If this module is generator, the pageSet object is different from other module's
55     * @return ApiPageSet
56     */
57    protected function getPageSet() {
58        return $this->mGeneratorPageSet ?? 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 int|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    /** @inheritDoc */
88    protected function getHelpFlags() {
89        // Corresponding messages: api-help-flag-generator
90        $flags = parent::getHelpFlags();
91        $flags[] = 'generator';
92        return $flags;
93    }
94
95    /**
96     * Execute this module as a generator
97     * @param ApiPageSet $resultPageSet All output should be appended to this object
98     */
99    abstract public function executeGenerator( $resultPageSet );
100}