MediaWiki  1.28.1
LanguageShi.php
Go to the documentation of this file.
1 <?php
37  protected $mDoContentConvert;
38 
39  public $mToLatin = [
40  'ⴰ' => 'a', 'ⴱ' => 'b', 'ⴳ' => 'g', 'ⴷ' => 'd', 'ⴹ' => 'ḍ', 'ⴻ' => 'e',
41  'ⴼ' => 'f', 'ⴽ' => 'k', 'ⵀ' => 'h', 'ⵃ' => 'ḥ', 'ⵄ' => 'ε', 'ⵅ' => 'x',
42  'ⵇ' => 'q', 'ⵉ' => 'i', 'ⵊ' => 'j', 'ⵍ' => 'l', 'ⵎ' => 'm', 'ⵏ' => 'n',
43  'ⵓ' => 'u', 'ⵔ' => 'r', 'ⵕ' => 'ṛ', 'ⵖ' => 'γ', 'ⵙ' => 's', 'ⵚ' => 'ṣ',
44  'ⵛ' => 'š', 'ⵜ' => 't', 'ⵟ' => 'ṭ', 'ⵡ' => 'w', 'ⵢ' => 'y', 'ⵣ' => 'z',
45  'ⵥ' => 'ẓ', 'ⵯ' => 'ʷ', 'ⵖ' => 'ɣ', 'ⵠ' => 'v', 'ⵒ' => 'p',
46  ];
47 
49  'A' => 'a', 'B' => 'b', 'C' => 'c', 'D' => 'd', 'E' => 'e',
50  'F' => 'f', 'G' => 'g', 'H' => 'h', 'I' => 'i', 'J' => 'j',
51  'K' => 'k', 'L' => 'l', 'M' => 'm', 'N' => 'n', 'O' => 'o',
52  'P' => 'p', 'Q' => 'q', 'R' => 'r', 'S' => 's', 'T' => 't',
53  'U' => 'u', 'V' => 'v', 'W' => 'w', 'X' => 'x', 'Y' => 'y',
54  'Z' => 'z', 'Ɣ' => 'ɣ',
55  ];
56 
57  public $mToTifinagh = [
58  'a' => 'ⴰ', 'b' => 'ⴱ', 'g' => 'ⴳ', 'd' => 'ⴷ', 'ḍ' => 'ⴹ', 'e' => 'ⴻ',
59  'f' => 'ⴼ', 'k' => 'ⴽ', 'h' => 'ⵀ', 'ḥ' => 'ⵃ', 'ε' => 'ⵄ', 'x' => 'ⵅ',
60  'q' => 'ⵇ', 'i' => 'ⵉ', 'j' => 'ⵊ', 'l' => 'ⵍ', 'm' => 'ⵎ', 'n' => 'ⵏ',
61  'u' => 'ⵓ', 'r' => 'ⵔ', 'ṛ' => 'ⵕ', 'γ' => 'ⵖ', 's' => 'ⵙ', 'ṣ' => 'ⵚ',
62  'š' => 'ⵛ', 't' => 'ⵜ', 'ṭ' => 'ⵟ', 'w' => 'ⵡ', 'y' => 'ⵢ', 'z' => 'ⵣ',
63  'ẓ' => 'ⵥ', 'ʷ' => 'ⵯ', 'ɣ' => 'ⵖ', 'v' => 'ⵠ', 'p' => 'ⵒ',
64  ];
65 
66  function loadDefaultTables() {
67  $this->mTables = [
68  'lowercase' => new ReplacementArray( $this->mUpperToLowerCaseLatin ),
69  'shi-tfng' => new ReplacementArray( $this->mToTifinagh ),
70  'shi-latn' => new ReplacementArray( $this->mToLatin ),
71  'shi' => new ReplacementArray()
72  ];
73  }
74 
85  function parseManualRule( $rule, $flags = [] ) {
86  if ( in_array( 'T', $flags ) ) {
87  return parent::parseManualRule( $rule, $flags );
88  }
89 
90  $carray = [];
91  // otherwise ignore all formatting
92  foreach ( $this->mVariants as $v ) {
93  $carray[$v] = $rule;
94  }
95 
96  return $carray;
97  }
98 
106  function parserConvert( $text, &$parser ) {
107  $this->mDoContentConvert = !( is_object( $parser->getTitle() )
108  && $parser->getTitle()->isTalkPage() );
109 
110  return parent::parserConvert( $text, $parser );
111  }
112 
123  function findVariantLink( &$link, &$nt, $ignoreOtherCond = false ) {
124  // check for user namespace
125  if ( is_object( $nt ) ) {
126  $ns = $nt->getNamespace();
127  if ( $ns == NS_USER || $ns == NS_USER_TALK ) {
128  return;
129  }
130  }
131 
132  $oldlink = $link;
133  parent::findVariantLink( $link, $nt, $ignoreOtherCond );
134  if ( $this->getPreferredVariant() == $this->mMainLanguageCode ) {
135  $link = $oldlink;
136  }
137  }
138 
147  function translate( $text, $toVariant ) {
148  // If $text is empty or only includes spaces, do nothing
149  // Otherwise translate it
150  if ( trim( $text ) ) {
151  $this->loadTables();
152  // To Tifinagh, first translate uppercase to lowercase Latin
153  if ( $toVariant == 'shi-tfng' ) {
154  $text = $this->mTables['lowercase']->replace( $text );
155  }
156  $text = $this->mTables[$toVariant]->replace( $text );
157  }
158  return $text;
159  }
160 }
161 
167 class LanguageShi extends Language {
168  function __construct() {
169  parent::__construct();
170 
171  $variants = [ 'shi', 'shi-tfng', 'shi-latn' ];
172  $variantfallbacks = [
173  'shi' => 'shi-tfng',
174  'shi-tfng' => 'shi',
175  'shi-latn' => 'shi',
176  ];
177 
178  $flags = [];
179  $this->mConverter = new ShiConverter( $this, 'shi', $variants, $variantfallbacks, $flags );
180  }
181 }
parseManualRule($rule, $flags=[])
rules should be defined as -{Tifinagh | Latin-} -or- -{code:text | code:text | ...}- update: delete all rule parsing because it's not used currently, and just produces a couple of bugs
Definition: LanguageShi.php:85
it s the revision text itself In either if gzip is the revision text is gzipped $flags
Definition: hooks.txt:2703
Base class for language conversion.
loadTables($fromCache=true)
Load conversion tables either from the cache or the disk.
Tachelhit.
magic word & $parser
Definition: hooks.txt:2487
usually copyright or history_copyright This message must be in HTML not wikitext & $link
Definition: hooks.txt:2889
parserConvert($text, &$parser)
Do not convert content on talk pages.
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
Conversion script between Latin and Tifinagh for Tachelhit.
Definition: LanguageShi.php:36
translate($text, $toVariant)
It translates text into variant.
const NS_USER_TALK
Definition: Defines.php:59
getPreferredVariant()
Get preferred language variant.
findVariantLink(&$link, &$nt, $ignoreOtherCond=false)
A function wrapper: