MediaWiki  master
TrivialLanguageConverter.php
Go to the documentation of this file.
1 <?php
23 
38 
42  protected $language;
43 
47  private $titleFormatter;
48 
57  public function __construct( $langobj ) {
58  $this->language = $langobj;
59  $this->titleFormatter = MediaWikiServices::getInstance()->getTitleFormatter();
60  }
61 
62  public function autoConvert( $text, $variant = false ) {
63  return $text;
64  }
65 
66  public function autoConvertToAllVariants( $text ) {
67  return [ $this->language->getCode() => $text ];
68  }
69 
70  public function convert( $t ) {
71  return $t;
72  }
73 
74  public function convertTo( $text, $variant ) {
75  return $text;
76  }
77 
82  public function convertTitle( $title ) {
83  return $this->titleFormatter->getPrefixedText( $title );
84  }
85 
86  public function convertNamespace( $index, $variant = null ) {
87  return $this->language->getFormattedNsText( $index );
88  }
89 
93  public function getVariants() {
94  return [ $this->language->getCode() ];
95  }
96 
97  public function getVariantFallbacks( $variant ) {
98  return $this->language->getCode();
99  }
100 
101  public function getPreferredVariant() {
102  return $this->language->getCode();
103  }
104 
105  public function getDefaultVariant() {
106  return $this->language->getCode();
107  }
108 
109  public function getURLVariant() {
110  return '';
111  }
112 
113  public function getConvRuleTitle() {
114  return false;
115  }
116 
117  public function findVariantLink( &$l, &$n, $ignoreOtherCond = false ) {
118  }
119 
120  public function getExtraHashOptions() {
121  return '';
122  }
123 
124  public function guessVariant( $text, $variant ) {
125  return false;
126  }
127 
128  public function markNoConversion( $text, $noParse = false ) {
129  return $text;
130  }
131 
132  public function convertCategoryKey( $key ) {
133  return $key;
134  }
135 
136  public function validateVariant( $variant = null ) {
137  if ( $variant === null ) {
138  return null;
139  }
140  $variant = strtolower( $variant );
141  return $variant === $this->language->getCode() ? $variant : null;
142  }
143 
144  public function translate( $text, $variant ) {
145  return $text;
146  }
147 
148  public function updateConversionTable( LinkTarget $linkTarget ) {
149  }
150 
156  private function reloadTables() {
157  }
158 
166  public function hasVariants() {
167  return count( $this->getVariants() ) > 1;
168  }
169 
180  public function hasVariant( $variant ) {
181  return $variant && ( $variant === $this->validateVariant( $variant ) );
182  }
183 
192  public function convertHtml( $text ) {
193  return htmlspecialchars( $this->convert( $text ) );
194  }
195 }
196 
200 class_alias( TrivialLanguageConverter::class, 'FakeConverter' );
TrivialLanguageConverter\getExtraHashOptions
getExtraHashOptions()
Returns language specific hash options.
Definition: TrivialLanguageConverter.php:120
TrivialLanguageConverter\updateConversionTable
updateConversionTable(LinkTarget $linkTarget)
Refresh the cache of conversion tables when MediaWiki:Conversiontable* is updated.
Definition: TrivialLanguageConverter.php:148
TrivialLanguageConverter\getURLVariant
getURLVariant()
Get the variant specified in the URL.
Definition: TrivialLanguageConverter.php:109
TrivialLanguageConverter\getVariants
getVariants()
Definition: TrivialLanguageConverter.php:93
TrivialLanguageConverter\getVariantFallbacks
getVariantFallbacks( $variant)
In case some variant is not defined in the markup, we need to have some fallback.
Definition: TrivialLanguageConverter.php:97
TrivialLanguageConverter\getPreferredVariant
getPreferredVariant()
Get preferred language variant.
Definition: TrivialLanguageConverter.php:101
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:193
TrivialLanguageConverter\convertHtml
convertHtml( $text)
Perform output conversion on a string, and encode for safe HTML output.
Definition: TrivialLanguageConverter.php:192
TrivialLanguageConverter\convert
convert( $t)
Convert text to different variants of a language.
Definition: TrivialLanguageConverter.php:70
Page\PageReference
Interface for objects (potentially) representing a page that can be viewable and linked to on a wiki.
Definition: PageReference.php:49
TrivialLanguageConverter\autoConvert
autoConvert( $text, $variant=false)
Dictionary-based conversion.
Definition: TrivialLanguageConverter.php:62
TrivialLanguageConverter\getDefaultVariant
getDefaultVariant()
This function would not be affected by user's settings.
Definition: TrivialLanguageConverter.php:105
TrivialLanguageConverter\$language
Language $language
Definition: TrivialLanguageConverter.php:42
TrivialLanguageConverter\$titleFormatter
TitleFormatter $titleFormatter
Definition: TrivialLanguageConverter.php:47
$title
$title
Definition: testCompression.php:38
TrivialLanguageConverter\autoConvertToAllVariants
autoConvertToAllVariants( $text)
Call translate() to convert text to all valid variants.
Definition: TrivialLanguageConverter.php:66
TrivialLanguageConverter\hasVariants
hasVariants()
Check if this is a language with variants.
Definition: TrivialLanguageConverter.php:166
ILanguageConverter
The shared interface for all language converters.
Definition: ILanguageConverter.php:29
TrivialLanguageConverter\convertNamespace
convertNamespace( $index, $variant=null)
Get the namespace display name in the preferred variant.
Definition: TrivialLanguageConverter.php:86
TrivialLanguageConverter\markNoConversion
markNoConversion( $text, $noParse=false)
Enclose a string with the "no conversion" tag.
Definition: TrivialLanguageConverter.php:128
TrivialLanguageConverter\getConvRuleTitle
getConvRuleTitle()
Get the title produced by the conversion rule.
Definition: TrivialLanguageConverter.php:113
TrivialLanguageConverter\__construct
__construct( $langobj)
Creates a converter for languages that don't have variants.
Definition: TrivialLanguageConverter.php:57
TrivialLanguageConverter\convertTo
convertTo( $text, $variant)
Same as convert() except a extra parameter to custom variant.
Definition: TrivialLanguageConverter.php:74
TitleFormatter
A title formatter service for MediaWiki.
Definition: TitleFormatter.php:35
TrivialLanguageConverter\guessVariant
guessVariant( $text, $variant)
Guess if a text is written in a variant.
Definition: TrivialLanguageConverter.php:124
TrivialLanguageConverter\convertTitle
convertTitle( $title)
Definition: TrivialLanguageConverter.php:82
TrivialLanguageConverter\hasVariant
hasVariant( $variant)
Strict check if the language has the specific variant.
Definition: TrivialLanguageConverter.php:180
TrivialLanguageConverter\translate
translate( $text, $variant)
Translate a string to a variant.
Definition: TrivialLanguageConverter.php:144
TrivialLanguageConverter\convertCategoryKey
convertCategoryKey( $key)
Convert the sorting key for category links.
Definition: TrivialLanguageConverter.php:132
$t
$t
Definition: testCompression.php:74
MediaWiki\Linker\LinkTarget
Definition: LinkTarget.php:26
TrivialLanguageConverter
A trivial language converter.
Definition: TrivialLanguageConverter.php:37
TrivialLanguageConverter\reloadTables
reloadTables()
Used by test suites which need to reset the converter state.
Definition: TrivialLanguageConverter.php:156
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:117
Language
Internationalisation code See https://www.mediawiki.org/wiki/Special:MyLanguage/Localisation for more...
Definition: Language.php:42
TrivialLanguageConverter\validateVariant
validateVariant( $variant=null)
Validate the variant and return an appropriate strict internal variant code if one exists.
Definition: TrivialLanguageConverter.php:136