Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 25
0.00% covered (danger)
0.00%
0 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
ApiLanguageSearch
0.00% covered (danger)
0.00%
0 / 25
0.00% covered (danger)
0.00%
0 / 4
20
0.00% covered (danger)
0.00%
0 / 1
 execute
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
2
 getAllowedParams
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
2
 getExamplesMessages
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
2
 getHelpUrls
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2/**
3 * Language name search API
4 *
5 * Copyright (C) 2012 Alolita Sharma, Amir Aharoni, Arun Ganesh, Brandon Harris,
6 * Niklas Laxström, Pau Giner, Santhosh Thottingal, Siebrand Mazeland and other
7 * contributors. See CREDITS for a list.
8 *
9 * UniversalLanguageSelector is dual licensed GPLv2 or later and MIT. You don't
10 * have to do anything special to choose one license or the other and you don't
11 * have to notify anyone which license you are using. You are free to use
12 * UniversalLanguageSelector in commercial projects as long as the copyright
13 * header is left intact. See files GPL-LICENSE and MIT-LICENSE for details.
14 *
15 * @file
16 * @ingroup Extensions
17 * @license GPL-2.0-or-later
18 * @license MIT
19 */
20
21namespace UniversalLanguageSelector\Api;
22
23use ApiBase;
24use LanguageNameSearch;
25use Wikimedia\ParamValidator\ParamValidator;
26
27/**
28 * @ingroup API
29 */
30class ApiLanguageSearch extends ApiBase {
31    /**
32     * @inheritDoc
33     */
34    public function execute() {
35        $params = $this->extractRequestParams();
36        $search = $params['search'];
37        $typos = $params['typos'];
38        $searches = LanguageNameSearch::search( $search, $typos, $this->getLanguage()->getCode() );
39        $result = $this->getResult();
40        $result->addValue( null, $this->getModuleName(), $searches );
41    }
42
43    /**
44     * @inheritDoc
45     */
46    public function getAllowedParams() {
47        return [
48            'search' => [
49                ParamValidator::PARAM_REQUIRED => true
50            ],
51            'typos' => [
52                ParamValidator::PARAM_REQUIRED => false,
53                ParamValidator::PARAM_TYPE => 'integer',
54                ParamValidator::PARAM_DEFAULT => 1
55            ],
56        ];
57    }
58
59    /**
60     * @inheritDoc
61     */
62    protected function getExamplesMessages() {
63        return [
64            'action=languagesearch&search=Te'
65                => 'apihelp-languagesearch-example-1',
66            'action=languagesearch&search=ഫി'
67                => 'apihelp-languagesearch-example-2',
68            'action=languagesearch&search=ഫി&typos=1'
69                => 'apihelp-languagesearch-example-3',
70        ];
71    }
72
73    /**
74     * @inheritDoc
75     */
76    public function getHelpUrls() {
77        return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Languagesearch';
78    }
79}