Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 23 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
ApiCollection | |
0.00% |
0 / 23 |
|
0.00% |
0 / 6 |
56 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
6 | |||
getModuleManager | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getAllowedParams | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
getExamplesMessages | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
isInternal | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\Collection\Api; |
4 | |
5 | use ApiBase; |
6 | use ApiMain; |
7 | use ApiModuleManager; |
8 | use MediaWiki\MediaWikiServices; |
9 | use Wikimedia\ParamValidator\ParamValidator; |
10 | |
11 | /** |
12 | * API parent module. |
13 | * Each operation is implemented as a submodule. This module just performs some |
14 | * basic checks and dispatches to execute() call. |
15 | */ |
16 | class ApiCollection extends ApiBase { |
17 | /** @var array Module name => module class */ |
18 | private const SUBMODULES = [ |
19 | 'addarticle' => ApiAddArticle::class, |
20 | 'addcategory' => ApiAddCategory::class, |
21 | 'addchapter' => ApiAddChapter::class, |
22 | 'clearcollection' => ApiClearCollection::class, |
23 | 'getcollection' => ApiGetCollection::class, |
24 | 'getbookcreatorboxcontent' => ApiGetBookCreatorBoxContent::class, |
25 | 'getpopupdata' => [ |
26 | 'class' => ApiGetPopupData::class, |
27 | 'services' => [ |
28 | 'TitleFactory', |
29 | 'WikiPageFactory', |
30 | ] |
31 | ], |
32 | 'postcollection' => ApiPostCollection::class, |
33 | 'removearticle' => ApiRemoveArticle::class, |
34 | 'removeitem' => ApiRemoveItem::class, |
35 | 'renamechapter' => ApiRenameChapter::class, |
36 | 'setsorting' => ApiSetSorting::class, |
37 | 'settitles' => ApiSetTitles::class, |
38 | 'sortitems' => ApiSortItems::class, |
39 | 'suggestarticleaction' => ApiSuggestArticleAction::class, |
40 | 'suggestundoarticleaction' => ApiSuggestUndoArticleAction::class, |
41 | ]; |
42 | |
43 | /** @var ApiModuleManager */ |
44 | private $moduleManager; |
45 | |
46 | /** |
47 | * @param ApiMain $main |
48 | * @param string $action |
49 | */ |
50 | public function __construct( ApiMain $main, $action ) { |
51 | parent::__construct( $main, $action ); |
52 | |
53 | $this->moduleManager = new ApiModuleManager( |
54 | $this, |
55 | MediaWikiServices::getInstance()->getObjectFactory() |
56 | ); |
57 | $this->moduleManager->addModules( self::SUBMODULES, 'submodule' ); |
58 | } |
59 | |
60 | /** |
61 | * Entry point for executing the module |
62 | * @inheritDoc |
63 | */ |
64 | public function execute() { |
65 | $submodule = $this->getParameter( 'submodule' ); |
66 | $module = $this->getModuleManager()->getModule( $submodule, 'submodule' ); |
67 | |
68 | if ( $module === null ) { |
69 | $this->dieWithError( 'apihelp-no-such-module' ); |
70 | } |
71 | |
72 | $module->extractRequestParams(); |
73 | $module->execute(); |
74 | } |
75 | |
76 | /** |
77 | * @inheritDoc |
78 | */ |
79 | public function getModuleManager(): ApiModuleManager { |
80 | return $this->moduleManager; |
81 | } |
82 | |
83 | /** @inheritDoc */ |
84 | protected function getAllowedParams(): array { |
85 | return [ |
86 | 'submodule' => [ |
87 | ParamValidator::PARAM_TYPE => 'submodule', |
88 | ParamValidator::PARAM_REQUIRED => true, |
89 | ], |
90 | ]; |
91 | } |
92 | |
93 | /** @inheritDoc */ |
94 | public function getExamplesMessages(): array { |
95 | return [ |
96 | 'action=collection&submodule=getcollection' => 'apihelp-collection-param-submodule', |
97 | ]; |
98 | } |
99 | |
100 | /** @inheritDoc */ |
101 | public function isInternal() { |
102 | return true; |
103 | } |
104 | |
105 | } |