MediaWiki  master
TrivialLanguageConverter.php
Go to the documentation of this file.
1 <?php
22 
37 
41  protected $language;
42 
46  private $titleFormatter;
47 
48  public function __construct( $langobj ) {
49  $this->language = $langobj;
50  $this->titleFormatter = MediaWikiServices::getInstance()->getTitleFormatter();
51  }
52 
53  public function autoConvert( $text, $variant = false ) {
54  return $text;
55  }
56 
57  public function autoConvertToAllVariants( $text ) {
58  return [ $this->language->getCode() => $text ];
59  }
60 
61  public function convert( $t ) {
62  return $t;
63  }
64 
65  public function convertTo( $text, $variant ) {
66  return $text;
67  }
68 
73  public function convertTitle( LinkTarget $linkTarget ) {
74  return $this->titleFormatter->getPrefixedText( $linkTarget );
75  }
76 
77  public function convertNamespace( $index, $variant = null ) {
78  return $this->language->getFormattedNsText( $index );
79  }
80 
84  public function getVariants() {
85  return [ $this->language->getCode() ];
86  }
87 
88  public function getVariantFallbacks( $variant ) {
89  return $this->language->getCode();
90  }
91 
92  public function getPreferredVariant() {
93  return $this->language->getCode();
94  }
95 
96  public function getDefaultVariant() {
97  return $this->language->getCode();
98  }
99 
100  public function getURLVariant() {
101  return '';
102  }
103 
104  public function getConvRuleTitle() {
105  return false;
106  }
107 
108  public function findVariantLink( &$l, &$n, $ignoreOtherCond = false ) {
109  }
110 
111  public function getExtraHashOptions() {
112  return '';
113  }
114 
115  public function guessVariant( $text, $variant ) {
116  return false;
117  }
118 
119  public function markNoConversion( $text, $noParse = false ) {
120  return $text;
121  }
122 
123  public function convertCategoryKey( $key ) {
124  return $key;
125  }
126 
127  public function validateVariant( $variant = null ) {
128  if ( $variant === null ) {
129  return null;
130  }
131  $variant = strtolower( $variant );
132  return $variant === $this->language->getCode() ? $variant : null;
133  }
134 
135  public function translate( $text, $variant ) {
136  return $text;
137  }
138 
139  public function updateConversionTable( LinkTarget $linkTarget ) {
140  }
141 
147  private function reloadTables() {
148  }
149 
157  public function hasVariants() {
158  return count( $this->getVariants() ) > 1;
159  }
160 
171  public function hasVariant( $variant ) {
172  return $variant && ( $variant === $this->validateVariant( $variant ) );
173  }
174 
183  public function convertHtml( $text ) {
184  return htmlspecialchars( $this->convert( $text ) );
185  }
186 }
187 
191 class_alias( TrivialLanguageConverter::class, 'FakeConverter' );
TrivialLanguageConverter\getExtraHashOptions
getExtraHashOptions()
Returns language specific hash options.
Definition: TrivialLanguageConverter.php:111
TrivialLanguageConverter\updateConversionTable
updateConversionTable(LinkTarget $linkTarget)
Refresh the cache of conversion tables when MediaWiki:Conversiontable* is updated.
Definition: TrivialLanguageConverter.php:139
TrivialLanguageConverter\getURLVariant
getURLVariant()
Get the variant specified in the URL.
Definition: TrivialLanguageConverter.php:100
TrivialLanguageConverter\getVariants
getVariants()
Definition: TrivialLanguageConverter.php:84
TrivialLanguageConverter\getVariantFallbacks
getVariantFallbacks( $variant)
In case some variant is not defined in the markup, we need to have some fallback.
Definition: TrivialLanguageConverter.php:88
TrivialLanguageConverter\getPreferredVariant
getPreferredVariant()
Get preferred language variant.
Definition: TrivialLanguageConverter.php:92
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:149
TrivialLanguageConverter\convertHtml
convertHtml( $text)
Perform output conversion on a string, and encode for safe HTML output.
Definition: TrivialLanguageConverter.php:183
TrivialLanguageConverter\convert
convert( $t)
Convert text to different variants of a language.
Definition: TrivialLanguageConverter.php:61
TrivialLanguageConverter\autoConvert
autoConvert( $text, $variant=false)
Dictionary-based conversion.
Definition: TrivialLanguageConverter.php:53
TrivialLanguageConverter\getDefaultVariant
getDefaultVariant()
Get default variant.
Definition: TrivialLanguageConverter.php:96
TrivialLanguageConverter\$language
Language $language
Definition: TrivialLanguageConverter.php:41
TrivialLanguageConverter\$titleFormatter
TitleFormatter $titleFormatter
Definition: TrivialLanguageConverter.php:46
TrivialLanguageConverter\autoConvertToAllVariants
autoConvertToAllVariants( $text)
Call translate() to convert text to all valid variants.
Definition: TrivialLanguageConverter.php:57
TrivialLanguageConverter\hasVariants
hasVariants()
Check if this is a language with variants.
Definition: TrivialLanguageConverter.php:157
ILanguageConverter
The shared interface for all language converters.
Definition: ILanguageConverter.php:28
TrivialLanguageConverter\convertNamespace
convertNamespace( $index, $variant=null)
Get the namespace display name in the preferred variant.
Definition: TrivialLanguageConverter.php:77
TrivialLanguageConverter\markNoConversion
markNoConversion( $text, $noParse=false)
Enclose a string with the "no conversion" tag.
Definition: TrivialLanguageConverter.php:119
TrivialLanguageConverter\getConvRuleTitle
getConvRuleTitle()
Get the title produced by the conversion rule.
Definition: TrivialLanguageConverter.php:104
TrivialLanguageConverter\__construct
__construct( $langobj)
Definition: TrivialLanguageConverter.php:48
TrivialLanguageConverter\convertTo
convertTo( $text, $variant)
Same as convert() except a extra parameter to custom variant.
Definition: TrivialLanguageConverter.php:65
TitleFormatter
A title formatter service for MediaWiki.
Definition: TitleFormatter.php:34
TrivialLanguageConverter\guessVariant
guessVariant( $text, $variant)
Guess if a text is written in a variant.
Definition: TrivialLanguageConverter.php:115
TrivialLanguageConverter\convertTitle
convertTitle(LinkTarget $linkTarget)
Definition: TrivialLanguageConverter.php:73
TrivialLanguageConverter\hasVariant
hasVariant( $variant)
Strict check if the language has the specific variant.
Definition: TrivialLanguageConverter.php:171
TrivialLanguageConverter\translate
translate( $text, $variant)
Translate a string to a variant.
Definition: TrivialLanguageConverter.php:135
TrivialLanguageConverter\convertCategoryKey
convertCategoryKey( $key)
Convert the sorting key for category links.
Definition: TrivialLanguageConverter.php:123
$t
$t
Definition: testCompression.php:74
MediaWiki\Linker\LinkTarget
Definition: LinkTarget.php:26
TrivialLanguageConverter
A trivial language converter.
Definition: TrivialLanguageConverter.php:36
TrivialLanguageConverter\reloadTables
reloadTables()
Used by test suites which need to reset the converter state.
Definition: TrivialLanguageConverter.php:147
TrivialLanguageConverter\findVariantLink
findVariantLink(&$l, &$n, $ignoreOtherCond=false)
If a language supports multiple variants, it is possible that non-existing link in one variant actual...
Definition: TrivialLanguageConverter.php:108
Language
Internationalisation code See https://www.mediawiki.org/wiki/Special:MyLanguage/Localisation for more...
Definition: Language.php:41
TrivialLanguageConverter\validateVariant
validateVariant( $variant=null)
Validate the variant and return an appropriate strict internal variant code if one exists.
Definition: TrivialLanguageConverter.php:127