Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 27 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
| ApiLanguageSearch | |
0.00% |
0 / 27 |
|
0.00% |
0 / 5 |
30 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| execute | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
| getAllowedParams | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
2 | |||
| getExamplesMessages | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
2 | |||
| getHelpUrls | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | declare( strict_types = 1 ); |
| 3 | |
| 4 | namespace MediaWiki\Api; |
| 5 | |
| 6 | use MediaWiki\Language\LanguageNameSearch; |
| 7 | use Wikimedia\ParamValidator\ParamValidator; |
| 8 | |
| 9 | /** |
| 10 | * Language name search API |
| 11 | * |
| 12 | * Copyright (C) 2012 Alolita Sharma, Amir Aharoni, Arun Ganesh, Brandon Harris, |
| 13 | * Niklas Laxström, Pau Giner, Santhosh Thottingal, Siebrand Mazeland and other |
| 14 | * contributors. |
| 15 | * |
| 16 | * @license GPL-2.0-or-later |
| 17 | * @ingroup API |
| 18 | */ |
| 19 | class ApiLanguageSearch extends ApiBase { |
| 20 | private LanguageNameSearch $languageNameSearch; |
| 21 | |
| 22 | public function __construct( |
| 23 | ApiMain $main, |
| 24 | string $action, |
| 25 | LanguageNameSearch $languageNameSearch |
| 26 | ) { |
| 27 | parent::__construct( $main, $action ); |
| 28 | $this->languageNameSearch = $languageNameSearch; |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * @inheritDoc |
| 33 | */ |
| 34 | public function execute() { |
| 35 | $params = $this->extractRequestParams(); |
| 36 | $search = $params['search']; |
| 37 | $typos = $params['typos']; |
| 38 | $searches = $this->languageNameSearch->doSearch( $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(): array { |
| 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(): array { |
| 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(): string { |
| 77 | return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Languagesearch'; |
| 78 | } |
| 79 | } |