Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 33
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
ApiSupportedProgrammingLanguages
0.00% covered (danger)
0.00%
0 / 33
0.00% covered (danger)
0.00%
0 / 3
42
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 run
0.00% covered (danger)
0.00%
0 / 30
0.00% covered (danger)
0.00%
0 / 1
12
 getAllowedParams
n/a
0 / 0
n/a
0 / 0
1
 isInternal
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2/**
3 * WikiLambda function call API
4 *
5 * @file
6 * @ingroup Extensions
7 * @copyright 2020– Abstract Wikipedia team; see AUTHORS.txt
8 * @license MIT
9 */
10
11namespace MediaWiki\Extension\WikiLambda\ActionAPI;
12
13use GuzzleHttp\Exception\ClientException;
14use GuzzleHttp\Exception\ConnectException;
15use GuzzleHttp\Exception\ServerException;
16use MediaWiki\Api\ApiMain;
17use MediaWiki\Extension\WikiLambda\ZErrorFactory;
18use MediaWiki\Extension\WikiLambda\ZObjects\ZResponseEnvelope;
19use MediaWiki\PoolCounter\PoolCounterWorkViaCallback;
20use MediaWiki\Status\Status;
21
22class ApiSupportedProgrammingLanguages extends WikiLambdaApiBase {
23
24    public function __construct( ApiMain $mainModule, string $moduleName ) {
25        parent::__construct( $mainModule, $moduleName, 'wikilambda_supported_programming_languages_' );
26
27        $this->setUp();
28    }
29
30    /**
31     * TODO (T338251): Factor out some commonality with WikiLambdaApiBase::executeFunctionCall()
32     * rather than rolling our own. (But note different end-point and error messages.)
33     *
34     * @inheritDoc
35     */
36    protected function run() {
37        $pageResult = $this->getResult();
38
39        $work = new PoolCounterWorkViaCallback(
40            'WikiLambdaSupportedProgrammingLanguages',
41            $this->getUser()->getName(),
42            [
43                'doWork' => function () {
44                    return $this->orchestrator->getSupportedProgrammingLanguages();
45                },
46                'error' => function ( Status $status ) {
47                    $this->dieWithError(
48                        [ "apierror-wikilambda_supported_programming_languages-concurrency-limit" ],
49                        null, null, 429
50                    );
51                } ] );
52
53        try {
54            $response = $work->execute();
55            $result = [ 'success' => true, 'data' => $response->getBody() ];
56        } catch ( ConnectException $exception ) {
57            $this->dieWithError(
58                [
59                    "apierror-wikilambda_supported_programming_languages-not-connected",
60                    $this->orchestratorHost
61                ],
62                null, null, 500
63            );
64        } catch ( ClientException | ServerException $exception ) {
65            $zError = ZErrorFactory::wrapMessageInZError( $exception->getResponse()->getReasonPhrase(), '' );
66            $zResponseMap = ZResponseEnvelope::wrapErrorInResponseMap( $zError );
67            $zResponseObject = new ZResponseEnvelope( null, $zResponseMap );
68            $result = [ 'data' => $zResponseObject->getSerialized() ];
69        }
70        $pageResult->addValue( [ 'query' ], $this->getModuleName(), $result );
71    }
72
73    /**
74     * @inheritDoc
75     * @codeCoverageIgnore
76     */
77    protected function getAllowedParams(): array {
78        return [];
79    }
80
81    /**
82     * Mark as internal. This isn't meant to be user-facing, and can change at any time.
83     * @return bool
84     */
85    public function isInternal() {
86        return true;
87    }
88
89}