MediaWiki REL1_39
TrivialLanguageConverter.php
Go to the documentation of this file.
1<?php
23
38
42 protected $language;
43
47 private $titleFormatter;
48
58 public function __construct(
59 $langobj,
60 TitleFormatter $titleFormatter = null
61 ) {
62 $this->language = $langobj;
63 $this->titleFormatter = $titleFormatter ?? MediaWikiServices::getInstance()->getTitleFormatter();
64 }
65
66 public function autoConvert( $text, $variant = false ) {
67 return $text;
68 }
69
70 public function autoConvertToAllVariants( $text ) {
71 return [ $this->language->getCode() => $text ];
72 }
73
74 public function convert( $t ) {
75 return $t;
76 }
77
78 public function convertTo( $text, $variant ) {
79 return $text;
80 }
81
87 public function convertSplitTitle( $title ) {
88 $mainText = $this->titleFormatter->getText( $title );
89
90 $index = $title->getNamespace();
91 try {
92 $nsWithUnderscores = $this->titleFormatter->getNamespaceName( $index, $mainText );
93 } catch ( InvalidArgumentException $e ) {
94 // T165149: see MediaWikiTitleCodec::formatTitle()
95 $nsWithUnderscores = $this->language->getNsText( NS_SPECIAL );
96 $mainText = "Badtitle/NS$index:$mainText";
97 }
98 $nsText = str_replace( '_', ' ', $nsWithUnderscores );
99
100 return [ $nsText, ':', $mainText ];
101 }
102
107 public function convertTitle( $title ) {
108 return $this->titleFormatter->getPrefixedText( $title );
109 }
110
111 public function convertNamespace( $index, $variant = null ) {
112 return $this->language->getFormattedNsText( $index );
113 }
114
118 public function getVariants() {
119 return [ $this->language->getCode() ];
120 }
121
122 public function getVariantFallbacks( $variant ) {
123 return $this->language->getCode();
124 }
125
126 public function getPreferredVariant() {
127 return $this->language->getCode();
128 }
129
130 public function getDefaultVariant() {
131 return $this->language->getCode();
132 }
133
134 public function getURLVariant() {
135 return '';
136 }
137
138 public function getConvRuleTitle() {
139 return false;
140 }
141
142 public function findVariantLink( &$l, &$n, $ignoreOtherCond = false ) {
143 }
144
145 public function getExtraHashOptions() {
146 return '';
147 }
148
149 public function guessVariant( $text, $variant ) {
150 return false;
151 }
152
153 public function markNoConversion( $text, $noParse = false ) {
154 return $text;
155 }
156
157 public function convertCategoryKey( $key ) {
158 return $key;
159 }
160
161 public function validateVariant( $variant = null ) {
162 if ( $variant === null ) {
163 return null;
164 }
165 $variant = strtolower( $variant );
166 return $variant === $this->language->getCode() ? $variant : null;
167 }
168
169 public function translate( $text, $variant ) {
170 return $text;
171 }
172
173 public function updateConversionTable( LinkTarget $linkTarget ) {
174 }
175
181 private function reloadTables() {
182 }
183
191 public function hasVariants() {
192 return count( $this->getVariants() ) > 1;
193 }
194
205 public function hasVariant( $variant ) {
206 return $variant && ( $variant === $this->validateVariant( $variant ) );
207 }
208
217 public function convertHtml( $text ) {
218 return htmlspecialchars( $this->convert( $text ) );
219 }
220}
const NS_SPECIAL
Definition Defines.php:53
Base class for language-specific code.
Definition Language.php:53
Service locator for MediaWiki core services.
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.
convertTo( $text, $variant)
Same as convert() except a extra parameter to custom variant.
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.
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.