MediaWiki 1.40.4
TrivialLanguageConverter.php
Go to the documentation of this file.
1<?php
24
39
43 protected $language;
44
48 private $titleFormatter;
49
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
88 public function convertSplitTitle( $title ) {
89 $mainText = $this->titleFormatter->getText( $title );
90
91 $index = $title->getNamespace();
92 try {
93 $nsWithUnderscores = $this->titleFormatter->getNamespaceName( $index, $mainText );
94 } catch ( InvalidArgumentException $e ) {
95 // T165149: see MediaWikiTitleCodec::formatTitle()
96 $nsWithUnderscores = $this->language->getNsText( NS_SPECIAL );
97 $mainText = "Badtitle/NS$index:$mainText";
98 }
99 $nsText = str_replace( '_', ' ', $nsWithUnderscores );
100
101 return [ $nsText, ':', $mainText ];
102 }
103
108 public function convertTitle( $title ) {
109 return $this->titleFormatter->getPrefixedText( $title );
110 }
111
112 public function convertNamespace( $index, $variant = null ) {
113 return $this->language->getFormattedNsText( $index );
114 }
115
119 public function getVariants() {
120 return [ $this->language->getCode() ];
121 }
122
123 public function getVariantFallbacks( $variant ) {
124 return $this->language->getCode();
125 }
126
127 public function getPreferredVariant() {
128 return $this->language->getCode();
129 }
130
131 public function getDefaultVariant() {
132 return $this->language->getCode();
133 }
134
135 public function getURLVariant() {
136 return '';
137 }
138
139 public function getConvRuleTitle() {
140 return false;
141 }
142
143 public function findVariantLink( &$l, &$n, $ignoreOtherCond = false ) {
144 }
145
146 public function getExtraHashOptions() {
147 return '';
148 }
149
150 public function guessVariant( $text, $variant ) {
151 return false;
152 }
153
154 public function markNoConversion( $text, $noParse = false ) {
155 return $text;
156 }
157
158 public function convertCategoryKey( $key ) {
159 return $key;
160 }
161
162 public function validateVariant( $variant = null ) {
163 if ( $variant === null ) {
164 return null;
165 }
166 $variant = strtolower( $variant );
167 return $variant === $this->language->getCode() ? $variant : null;
168 }
169
170 public function translate( $text, $variant ) {
171 return $text;
172 }
173
174 public function updateConversionTable( LinkTarget $linkTarget ) {
175 }
176
182 private function reloadTables() {
183 }
184
192 public function hasVariants() {
193 return count( $this->getVariants() ) > 1;
194 }
195
206 public function hasVariant( $variant ) {
207 return $variant && ( $variant === $this->validateVariant( $variant ) );
208 }
209
218 public function convertHtml( $text ) {
219 return htmlspecialchars( $this->convert( $text ) );
220 }
221}
const NS_SPECIAL
Definition Defines.php:53
Base class for language-specific code.
Definition Language.php:56
Service locator for MediaWiki core services.
Stub object for the user language.
A trivial language converter.
convertHtml( $text)
Perform output conversion on a string, and encode for safe HTML output.
translate( $text, $variant)
Translate a string to a variant.
hasVariants()
Check if this is a language with variants.
convert( $t)
Convert text to different variants of a language.
getURLVariant()
Get the variant specified in the URL.
__construct( $langobj, TitleFormatter $titleFormatter=null)
Creates a converter for languages that don't have variants.
getPreferredVariant()
Get preferred language variant.
markNoConversion( $text, $noParse=false)
Enclose a string with the "no conversion" tag.
autoConvertToAllVariants( $text)
Call translate() to convert text to all valid variants.
getConvRuleTitle()
Get the title produced by the conversion rule.
getDefaultVariant()
This function would not be affected by user's settings.
findVariantLink(&$l, &$n, $ignoreOtherCond=false)
If a language supports multiple variants, it is possible that non-existing link in one variant actual...
autoConvert( $text, $variant=false)
Dictionary-based conversion.
getExtraHashOptions()
Returns language specific hash options.
guessVariant( $text, $variant)
Guess if a text is written in a variant.
updateConversionTable(LinkTarget $linkTarget)
Refresh the cache of conversion tables when MediaWiki:Conversiontable* is updated.
convertTo( $text, $variant, bool $clearState=true)
Same as convert() except a extra parameter to custom variant.
validateVariant( $variant=null)
Validate the variant and return an appropriate strict internal variant code if one exists.
convertCategoryKey( $key)
Convert the sorting key for category links.
convertNamespace( $index, $variant=null)
Get the namespace display name in the preferred variant.
hasVariant( $variant)
Strict check if the language has the specific variant.
getVariantFallbacks( $variant)
In case some variant is not defined in the markup, we need to have some fallback.
The shared interface for all language converters.
Interface for objects (potentially) representing a page that can be viewable and linked to on a wiki.
A title formatter service for MediaWiki.