Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 23
0.00% covered (danger)
0.00%
0 / 6
CRAP
0.00% covered (danger)
0.00%
0 / 1
ApiCollection
0.00% covered (danger)
0.00%
0 / 23
0.00% covered (danger)
0.00%
0 / 6
56
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
2
 execute
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
6
 getModuleManager
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getAllowedParams
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
2
 getExamplesMessages
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 isInternal
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace MediaWiki\Extension\Collection\Api;
4
5use MediaWiki\Api\ApiBase;
6use MediaWiki\Api\ApiMain;
7use MediaWiki\Api\ApiModuleManager;
8use MediaWiki\MediaWikiServices;
9use 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 */
16class ApiCollection extends ApiBase {
17    /** 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    private ApiModuleManager $moduleManager;
44
45    public function __construct(
46        ApiMain $main,
47        string $action
48    ) {
49        parent::__construct( $main, $action );
50
51        $this->moduleManager = new ApiModuleManager(
52            $this,
53            MediaWikiServices::getInstance()->getObjectFactory()
54        );
55        $this->moduleManager->addModules( self::SUBMODULES, 'submodule' );
56    }
57
58    /**
59     * Entry point for executing the module
60     * @inheritDoc
61     */
62    public function execute() {
63        $submodule = $this->getParameter( 'submodule' );
64        $module = $this->getModuleManager()->getModule( $submodule, 'submodule' );
65
66        if ( $module === null ) {
67            $this->dieWithError( 'apihelp-no-such-module' );
68        }
69
70        $module->extractRequestParams();
71        $module->execute();
72    }
73
74    /**
75     * @inheritDoc
76     */
77    public function getModuleManager(): ApiModuleManager {
78        return $this->moduleManager;
79    }
80
81    /** @inheritDoc */
82    protected function getAllowedParams(): array {
83        return [
84            'submodule' => [
85                ParamValidator::PARAM_TYPE => 'submodule',
86                ParamValidator::PARAM_REQUIRED => true,
87            ],
88        ];
89    }
90
91    /** @inheritDoc */
92    public function getExamplesMessages(): array {
93        return [
94            'action=collection&submodule=getcollection' => 'apihelp-collection-param-submodule',
95        ];
96    }
97
98    /** @inheritDoc */
99    public function isInternal() {
100        return true;
101    }
102
103}