Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 37 |
|
0.00% |
0 / 26 |
CRAP | |
0.00% |
0 / 1 |
TrivialLanguageConverter | |
0.00% |
0 / 37 |
|
0.00% |
0 / 26 |
930 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
autoConvert | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
autoConvertToAllVariants | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
convert | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
convertTo | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
convertSplitTitle | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
6 | |||
convertTitle | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
convertNamespace | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getVariants | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getVariantFallbacks | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getPreferredVariant | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getDefaultVariant | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getURLVariant | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getConvRuleTitle | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
findVariantLink | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getExtraHashOptions | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
guessVariant | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
markNoConversion | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
convertCategoryKey | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
validateVariant | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
12 | |||
translate | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
updateConversionTable | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
reloadTables | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
hasVariants | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
hasVariant | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
6 | |||
convertHtml | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * This program is free software; you can redistribute it and/or modify |
4 | * it under the terms of the GNU General Public License as published by |
5 | * the Free Software Foundation; either version 2 of the License, or |
6 | * (at your option) any later version. |
7 | * |
8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. |
12 | * |
13 | * You should have received a copy of the GNU General Public License along |
14 | * with this program; if not, write to the Free Software Foundation, Inc., |
15 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
16 | * http://www.gnu.org/copyleft/gpl.html |
17 | * |
18 | * @file |
19 | */ |
20 | use MediaWiki\Linker\LinkTarget; |
21 | use MediaWiki\MediaWikiServices; |
22 | use MediaWiki\StubObject\StubUserLang; |
23 | use MediaWiki\Title\TitleFormatter; |
24 | |
25 | /** |
26 | * A trivial language converter. |
27 | * |
28 | * For Languages which do not implement variant |
29 | * conversion, for example, German, TrivialLanguageConverter is provided rather than a |
30 | * LanguageConverter when asked for their converter. The TrivialLanguageConverter just |
31 | * returns text unchanged, i.e., it doesn't do any conversion. |
32 | * |
33 | * See https://www.mediawiki.org/wiki/Writing_systems#LanguageConverter. |
34 | * |
35 | * @since 1.35 |
36 | * @ingroup Language |
37 | */ |
38 | class TrivialLanguageConverter implements ILanguageConverter { |
39 | |
40 | /** |
41 | * @var Language |
42 | */ |
43 | protected $language; |
44 | |
45 | /** |
46 | * @var TitleFormatter |
47 | */ |
48 | private $titleFormatter; |
49 | |
50 | /** |
51 | * Creates a converter for languages that don't have variants. This method is internal |
52 | * and should be called for LanguageConverterFactory only |
53 | * |
54 | * @param Language|StubUserLang $langobj |
55 | * @param TitleFormatter|null $titleFormatter |
56 | * |
57 | * @internal |
58 | */ |
59 | public function __construct( |
60 | $langobj, |
61 | TitleFormatter $titleFormatter = null |
62 | ) { |
63 | $this->language = $langobj; |
64 | $this->titleFormatter = $titleFormatter ?? MediaWikiServices::getInstance()->getTitleFormatter(); |
65 | } |
66 | |
67 | public function autoConvert( $text, $variant = false ) { |
68 | return $text; |
69 | } |
70 | |
71 | public function autoConvertToAllVariants( $text ) { |
72 | return [ $this->language->getCode() => $text ]; |
73 | } |
74 | |
75 | public function convert( $t ) { |
76 | return $t; |
77 | } |
78 | |
79 | public function convertTo( $text, $variant, bool $clearState = true ) { |
80 | return $text; |
81 | } |
82 | |
83 | public function convertSplitTitle( $title ) { |
84 | $mainText = $this->titleFormatter->getText( $title ); |
85 | |
86 | $index = $title->getNamespace(); |
87 | try { |
88 | $nsWithUnderscores = $this->titleFormatter->getNamespaceName( $index, $mainText ); |
89 | } catch ( InvalidArgumentException $e ) { |
90 | // T165149: see MediaWikiTitleCodec::formatTitle() |
91 | $nsWithUnderscores = $this->language->getNsText( NS_SPECIAL ); |
92 | $mainText = "Badtitle/NS$index:$mainText"; |
93 | } |
94 | $nsText = str_replace( '_', ' ', $nsWithUnderscores ); |
95 | |
96 | return [ $nsText, ':', $mainText ]; |
97 | } |
98 | |
99 | public function convertTitle( $title ) { |
100 | return $this->titleFormatter->getPrefixedText( $title ); |
101 | } |
102 | |
103 | public function convertNamespace( $index, $variant = null ) { |
104 | return $this->language->getFormattedNsText( $index ); |
105 | } |
106 | |
107 | public function getVariants() { |
108 | return [ $this->language->getCode() ]; |
109 | } |
110 | |
111 | public function getVariantFallbacks( $variant ) { |
112 | return $this->language->getCode(); |
113 | } |
114 | |
115 | public function getPreferredVariant() { |
116 | return $this->language->getCode(); |
117 | } |
118 | |
119 | public function getDefaultVariant() { |
120 | return $this->language->getCode(); |
121 | } |
122 | |
123 | public function getURLVariant() { |
124 | return ''; |
125 | } |
126 | |
127 | public function getConvRuleTitle() { |
128 | return false; |
129 | } |
130 | |
131 | public function findVariantLink( &$l, &$n, $ignoreOtherCond = false ) { |
132 | } |
133 | |
134 | public function getExtraHashOptions() { |
135 | return ''; |
136 | } |
137 | |
138 | public function guessVariant( $text, $variant ) { |
139 | return false; |
140 | } |
141 | |
142 | public function markNoConversion( $text, $noParse = false ) { |
143 | return $text; |
144 | } |
145 | |
146 | public function convertCategoryKey( $key ) { |
147 | return $key; |
148 | } |
149 | |
150 | public function validateVariant( $variant = null ) { |
151 | if ( $variant === null ) { |
152 | return null; |
153 | } |
154 | $variant = strtolower( $variant ); |
155 | return $variant === $this->language->getCode() ? $variant : null; |
156 | } |
157 | |
158 | public function translate( $text, $variant ) { |
159 | return $text; |
160 | } |
161 | |
162 | public function updateConversionTable( LinkTarget $linkTarget ) { |
163 | } |
164 | |
165 | /** |
166 | * Used by test suites which need to reset the converter state. |
167 | * |
168 | * Called by ParserTestRunner with the help of TestingAccessWrapper |
169 | */ |
170 | private function reloadTables() { |
171 | } |
172 | |
173 | public function hasVariants() { |
174 | return count( $this->getVariants() ) > 1; |
175 | } |
176 | |
177 | public function hasVariant( $variant ) { |
178 | return $variant && ( $variant === $this->validateVariant( $variant ) ); |
179 | } |
180 | |
181 | public function convertHtml( $text ) { |
182 | return htmlspecialchars( $this->convert( $text ) ); |
183 | } |
184 | } |