| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
use MediaWiki\Language\ILanguageConverter; |
| 21 |
use MediaWiki\Language\Language; |
| 22 |
use MediaWiki\Linker\LinkTarget; |
| 23 |
use MediaWiki\MediaWikiServices; |
| 24 |
use MediaWiki\StubObject\StubUserLang; |
| 25 |
use MediaWiki\Title\TitleFormatter; |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
class TrivialLanguageConverter implements ILanguageConverter { |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
protected $language; |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
private $titleFormatter; |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
public function __construct( |
| 62 |
$langobj, |
| 63 |
?TitleFormatter $titleFormatter = null |
| 64 |
) { |
| 65 |
$this->language = $langobj; |
| 66 |
$this->titleFormatter = $titleFormatter ?? MediaWikiServices::getInstance()->getTitleFormatter(); |
| 67 |
} |
| 68 |
|
| 69 |
public function autoConvert( $text, $variant = false ) { |
| 70 |
return $text; |
| 71 |
} |
| 72 |
|
| 73 |
public function autoConvertToAllVariants( $text ) { |
| 74 |
return [ $this->language->getCode() => $text ]; |
| 75 |
} |
| 76 |
|
| 77 |
public function convert( $t ) { |
| 78 |
return $t; |
| 79 |
} |
| 80 |
|
| 81 |
public function convertTo( $text, $variant, bool $clearState = true ) { |
| 82 |
return $text; |
| 83 |
} |
| 84 |
|
| 85 |
public function convertSplitTitle( $title ) { |
| 86 |
$mainText = $this->titleFormatter->getText( $title ); |
| 87 |
|
| 88 |
$index = $title->getNamespace(); |
| 89 |
try { |
| 90 |
$nsWithUnderscores = $this->titleFormatter->getNamespaceName( $index, $mainText ); |
| 91 |
} catch ( InvalidArgumentException $e ) { |
| 92 |
|
| 93 |
$nsWithUnderscores = $this->language->getNsText( NS_SPECIAL ); |
| 94 |
$mainText = "Badtitle/NS$index:$mainText"; |
| 95 |
} |
| 96 |
$nsText = str_replace( '_', ' ', $nsWithUnderscores ); |
| 97 |
|
| 98 |
return [ $nsText, ':', $mainText ]; |
| 99 |
} |
| 100 |
|
| 101 |
public function convertTitle( $title ) { |
| 102 |
return $this->titleFormatter->getPrefixedText( $title ); |
| 103 |
} |
| 104 |
|
| 105 |
public function convertNamespace( $index, $variant = null ) { |
| 106 |
return $this->language->getFormattedNsText( $index ); |
| 107 |
} |
| 108 |
|
| 109 |
public function getVariants() { |
| 110 |
return [ $this->language->getCode() ]; |
| 111 |
} |
| 112 |
|
| 113 |
public function getVariantFallbacks( $variant ) { |
| 114 |
return $this->language->getCode(); |
| 115 |
} |
| 116 |
|
| 117 |
public function getPreferredVariant() { |
| 118 |
return $this->language->getCode(); |
| 119 |
} |
| 120 |
|
| 121 |
public function getDefaultVariant() { |
| 122 |
return $this->language->getCode(); |
| 123 |
} |
| 124 |
|
| 125 |
public function getURLVariant() { |
| 126 |
return ''; |
| 127 |
} |
| 128 |
|
| 129 |
public function getConvRuleTitle() { |
| 130 |
return false; |
| 131 |
} |
| 132 |
|
| 133 |
public function findVariantLink( &$l, &$n, $ignoreOtherCond = false ) { |
| 134 |
} |
| 135 |
|
| 136 |
public function getExtraHashOptions() { |
| 137 |
return ''; |
| 138 |
} |
| 139 |
|
| 140 |
public function guessVariant( $text, $variant ) { |
| 141 |
return false; |
| 142 |
} |
| 143 |
|
| 144 |
public function markNoConversion( $text, $noParse = false ) { |
| 145 |
return $text; |
| 146 |
} |
| 147 |
|
| 148 |
public function convertCategoryKey( $key ) { |
| 149 |
return $key; |
| 150 |
} |
| 151 |
|
| 152 |
public function validateVariant( $variant = null ) { |
| 153 |
if ( $variant === null ) { |
| 154 |
return null; |
| 155 |
} |
| 156 |
$variant = strtolower( $variant ); |
| 157 |
return $variant === $this->language->getCode() ? $variant : null; |
| 158 |
} |
| 159 |
|
| 160 |
public function translate( $text, $variant ) { |
| 161 |
return $text; |
| 162 |
} |
| 163 |
|
| 164 |
public function updateConversionTable( LinkTarget $linkTarget ) { |
| 165 |
} |
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
private function reloadTables() { |
| 173 |
} |
| 174 |
|
| 175 |
public function hasVariants() { |
| 176 |
return count( $this->getVariants() ) > 1; |
| 177 |
} |
| 178 |
|
| 179 |
public function hasVariant( $variant ) { |
| 180 |
return $variant && ( $variant === $this->validateVariant( $variant ) ); |
| 181 |
} |
| 182 |
|
| 183 |
public function convertHtml( $text ) { |
| 184 |
return htmlspecialchars( $this->convert( $text ) ); |
| 185 |
} |
| 186 |
} |