Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 20
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
ApiQueryContentTranslationConfig
0.00% covered (danger)
0.00%
0 / 20
0.00% covered (danger)
0.00%
0 / 3
30
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 execute
0.00% covered (danger)
0.00%
0 / 15
0.00% covered (danger)
0.00%
0 / 1
12
 getExamplesMessages
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2declare( strict_types = 1 );
3
4namespace ContentTranslation\ActionApi;
5
6use Exception;
7use MediaWiki\Api\ApiQuery;
8use MediaWiki\Api\ApiQueryBase;
9use MediaWiki\Config\Config;
10use MediaWiki\WikiMap\WikiMap;
11
12/**
13 * API module to query ContentTranslation configuration
14 */
15class ApiQueryContentTranslationConfig extends ApiQueryBase {
16    public function __construct(
17        ApiQuery $query,
18        string $moduleName,
19        private readonly Config $communityConfig
20    ) {
21        parent::__construct( $query, $moduleName );
22    }
23
24    public function execute() {
25        try {
26            $featuredCollection = $this->communityConfig->get( 'ContentTranslationFeaturedCollection' );
27            $featuredCollectionDescription =
28                $this->communityConfig->get( 'ContentTranslationFeaturedCollectionDescription' );
29            $featuredCollectionLink = $this->communityConfig->get( 'ContentTranslationFeaturedCollectionLink' );
30
31            $communityNameMsg = $this->msg( 'project-localized-name-' . WikiMap::getCurrentWikiId() );
32            $communityName = $communityNameMsg->IsDisabled() ? null : $communityNameMsg->text();
33
34            $responseData = [
35                'featuredcollectionname' => $featuredCollection,
36                'featuredcollectioncommunityname' => $communityName,
37                'featuredcollectiondescription' => $featuredCollectionDescription,
38                'featuredcollectionlink' => $featuredCollectionLink
39            ];
40
41            $this->getResult()->addValue( [ 'query' ], $this->getModuleName(), $responseData );
42        } catch ( Exception ) {
43            $this->dieWithError( 'apierror-contenttranslationconfig-load-error' );
44        }
45    }
46
47    /** @inheritDoc */
48    protected function getExamplesMessages() {
49        return [
50            'action=query&meta=cxconfig'
51                => 'apihelp-query+cxconfig-example-simple',
52        ];
53    }
54}