Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 13 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
| ApiQueryGeneratorBase | |
0.00% |
0 / 12 |
|
0.00% |
0 / 6 |
72 | |
0.00% |
0 / 1 |
| setGeneratorMode | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| isInGeneratorMode | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getPageSet | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| encodeParamName | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| setContinueEnumParameter | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| getHelpFlags | |
0.00% |
0 / 3 |
|
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 | * @license GPL-2.0-or-later |
| 6 | * @file |
| 7 | */ |
| 8 | |
| 9 | namespace MediaWiki\Api; |
| 10 | |
| 11 | /** |
| 12 | * @stable to extend |
| 13 | * |
| 14 | * @ingroup API |
| 15 | */ |
| 16 | abstract class ApiQueryGeneratorBase extends ApiQueryBase { |
| 17 | |
| 18 | /** @var ApiPageSet|null */ |
| 19 | private $mGeneratorPageSet = null; |
| 20 | |
| 21 | /** |
| 22 | * Switch this module to generator mode. By default, generator mode is |
| 23 | * switched off and the module acts like a normal query module. |
| 24 | * @since 1.21 requires pageset parameter |
| 25 | * @param ApiPageSet $generatorPageSet ApiPageSet object that the module will get |
| 26 | * by calling getPageSet() when in generator mode. |
| 27 | */ |
| 28 | public function setGeneratorMode( ApiPageSet $generatorPageSet ) { |
| 29 | $this->mGeneratorPageSet = $generatorPageSet; |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * Indicate whether the module is in generator mode |
| 34 | * @since 1.28 |
| 35 | * @return bool |
| 36 | */ |
| 37 | public function isInGeneratorMode() { |
| 38 | return $this->mGeneratorPageSet !== null; |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Get the PageSet object to work on. |
| 43 | * If this module is generator, the pageSet object is different from other module's |
| 44 | * @return ApiPageSet |
| 45 | */ |
| 46 | protected function getPageSet() { |
| 47 | return $this->mGeneratorPageSet ?? parent::getPageSet(); |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Overrides ApiBase to prepend 'g' to every generator parameter |
| 52 | * @param string $paramName Parameter name |
| 53 | * @return string Prefixed parameter name |
| 54 | */ |
| 55 | public function encodeParamName( $paramName ) { |
| 56 | if ( $this->mGeneratorPageSet !== null ) { |
| 57 | return 'g' . parent::encodeParamName( $paramName ); |
| 58 | } else { |
| 59 | return parent::encodeParamName( $paramName ); |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Overridden to set the generator param if in generator mode |
| 65 | * @param string $paramName Parameter name |
| 66 | * @param int|string|array $paramValue Parameter value |
| 67 | */ |
| 68 | protected function setContinueEnumParameter( $paramName, $paramValue ) { |
| 69 | if ( $this->mGeneratorPageSet !== null ) { |
| 70 | $this->getContinuationManager()->addGeneratorContinueParam( $this, $paramName, $paramValue ); |
| 71 | } else { |
| 72 | parent::setContinueEnumParameter( $paramName, $paramValue ); |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | /** @inheritDoc */ |
| 77 | protected function getHelpFlags() { |
| 78 | // Corresponding messages: api-help-flag-generator |
| 79 | $flags = parent::getHelpFlags(); |
| 80 | $flags[] = 'generator'; |
| 81 | return $flags; |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * Execute this module as a generator |
| 86 | * @param ApiPageSet $resultPageSet All output should be appended to this object |
| 87 | */ |
| 88 | abstract public function executeGenerator( $resultPageSet ); |
| 89 | } |
| 90 | |
| 91 | /** @deprecated class alias since 1.43 */ |
| 92 | class_alias( ApiQueryGeneratorBase::class, 'ApiQueryGeneratorBase' ); |