MediaWiki  1.23.2
LanguageSr.php
Go to the documentation of this file.
1 <?php
24 require_once __DIR__ . '/../LanguageConverter.php';
25 
35 class SrConverter extends LanguageConverter {
36  public $mToLatin = array(
37  'а' => 'a', 'б' => 'b', 'в' => 'v', 'г' => 'g', 'д' => 'd',
38  'ђ' => 'đ', 'е' => 'e', 'ж' => 'ž', 'з' => 'z', 'и' => 'i',
39  'ј' => 'j', 'к' => 'k', 'л' => 'l', 'љ' => 'lj', 'м' => 'm',
40  'н' => 'n', 'њ' => 'nj', 'о' => 'o', 'п' => 'p', 'р' => 'r',
41  'с' => 's', 'т' => 't', 'ћ' => 'ć', 'у' => 'u', 'ф' => 'f',
42  'х' => 'h', 'ц' => 'c', 'ч' => 'č', 'џ' => 'dž', 'ш' => 'š',
43 
44  'А' => 'A', 'Б' => 'B', 'В' => 'V', 'Г' => 'G', 'Д' => 'D',
45  'Ђ' => 'Đ', 'Е' => 'E', 'Ж' => 'Ž', 'З' => 'Z', 'И' => 'I',
46  'Ј' => 'J', 'К' => 'K', 'Л' => 'L', 'Љ' => 'Lj', 'М' => 'M',
47  'Н' => 'N', 'Њ' => 'Nj', 'О' => 'O', 'П' => 'P', 'Р' => 'R',
48  'С' => 'S', 'Т' => 'T', 'Ћ' => 'Ć', 'У' => 'U', 'Ф' => 'F',
49  'Х' => 'H', 'Ц' => 'C', 'Ч' => 'Č', 'Џ' => 'Dž', 'Ш' => 'Š',
50  );
51 
52  public $mToCyrillics = array(
53  'a' => 'а', 'b' => 'б', 'c' => 'ц', 'č' => 'ч', 'ć' => 'ћ',
54  'd' => 'д', 'dž' => 'џ', 'đ' => 'ђ', 'e' => 'е', 'f' => 'ф',
55  'g' => 'г', 'h' => 'х', 'i' => 'и', 'j' => 'ј', 'k' => 'к',
56  'l' => 'л', 'lj' => 'љ', 'm' => 'м', 'n' => 'н', 'nj' => 'њ',
57  'o' => 'о', 'p' => 'п', 'r' => 'р', 's' => 'с', 'š' => 'ш',
58  't' => 'т', 'u' => 'у', 'v' => 'в', 'z' => 'з', 'ž' => 'ж',
59 
60  'A' => 'А', 'B' => 'Б', 'C' => 'Ц', 'Č' => 'Ч', 'Ć' => 'Ћ',
61  'D' => 'Д', 'Dž' => 'Џ', 'Đ' => 'Ђ', 'E' => 'Е', 'F' => 'Ф',
62  'G' => 'Г', 'H' => 'Х', 'I' => 'И', 'J' => 'Ј', 'K' => 'К',
63  'L' => 'Л', 'LJ' => 'Љ', 'M' => 'М', 'N' => 'Н', 'NJ' => 'Њ',
64  'O' => 'О', 'P' => 'П', 'R' => 'Р', 'S' => 'С', 'Š' => 'Ш',
65  'T' => 'Т', 'U' => 'У', 'V' => 'В', 'Z' => 'З', 'Ž' => 'Ж',
66 
67  'DŽ' => 'Џ', 'd!ž' => 'дж', 'D!ž' => 'Дж', 'D!Ž' => 'ДЖ',
68  'Lj' => 'Љ', 'l!j' => 'лј', 'L!j' => 'Лј', 'L!J' => 'ЛЈ',
69  'Nj' => 'Њ', 'n!j' => 'нј', 'N!j' => 'Нј', 'N!J' => 'НЈ'
70  );
71 
72  function loadDefaultTables() {
73  $this->mTables = array(
74  'sr-ec' => new ReplacementArray( $this->mToCyrillics ),
75  'sr-el' => new ReplacementArray( $this->mToLatin ),
76  'sr' => new ReplacementArray()
77  );
78  }
79 
91  function parseManualRule( $rule, $flags = array() ) {
92  if ( in_array( 'T', $flags ) ) {
93  return parent::parseManualRule( $rule, $flags );
94  }
95 
96  $carray = array();
97  // otherwise ignore all formatting
98  foreach ( $this->mVariants as $v ) {
99  $carray[$v] = $rule;
100  }
101 
102  return $carray;
103  }
104 
115  function findVariantLink( &$link, &$nt, $ignoreOtherCond = false ) {
116  // check for user namespace
117  if ( is_object( $nt ) ) {
118  $ns = $nt->getNamespace();
119  if ( $ns == NS_USER || $ns == NS_USER_TALK ) {
120  return;
121  }
122  }
123 
124  $oldlink = $link;
125  parent::findVariantLink( $link, $nt, $ignoreOtherCond );
126  if ( $this->getPreferredVariant() == $this->mMainLanguageCode ) {
127  $link = $oldlink;
128  }
129  }
130 
140  function autoConvert( $text, $toVariant = false ) {
142  if ( is_object( $wgTitle ) && $wgTitle->getNamespace() == NS_FILE ) {
143  $imagename = $wgTitle->getNsText();
144  if ( preg_match( "/^$imagename:/", $text ) ) {
145  return $text;
146  }
147  }
148  return parent::autoConvert( $text, $toVariant );
149  }
150 
161  function translate( $text, $toVariant ) {
162  $breaks = '[^\w\x80-\xff]';
163 
164  // regexp for roman numbers
165  $roman = 'M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})';
166 
167  $reg = '/^' . $roman . '$|^' . $roman . $breaks . '|' . $breaks
168  . $roman . '$|' . $breaks . $roman . $breaks . '/';
169 
170  $matches = preg_split( $reg, $text, -1, PREG_SPLIT_OFFSET_CAPTURE );
171 
172  $m = array_shift( $matches );
173  $this->loadTables();
174  if ( !isset( $this->mTables[$toVariant] ) ) {
175  throw new MWException( "Broken variant table: "
176  . implode( ',', array_keys( $this->mTables ) ) );
177  }
178  $ret = $this->mTables[$toVariant]->replace( $m[0] );
179  $mstart = $m[1] + strlen( $m[0] );
180  foreach ( $matches as $m ) {
181  $ret .= substr( $text, $mstart, $m[1] -$mstart );
182  $ret .= parent::translate( $m[0], $toVariant );
183  $mstart = $m[1] + strlen( $m[0] );
184  }
185 
186  return $ret;
187  }
188 
200  public function guessVariant( $text, $variant ) {
201  $numCyrillic = preg_match_all( "/[шђчћжШЂЧЋЖ]/u", $text, $dummy );
202  $numLatin = preg_match_all( "/[šđč枊ĐČĆŽ]/u", $text, $dummy );
203 
204  if ( $variant == 'sr-ec' ) {
205  return $numCyrillic > $numLatin;
206  } elseif ( $variant == 'sr-el' ) {
207  return $numLatin > $numCyrillic;
208  } else {
209  return false;
210  }
211 
212  }
213 
214 }
215 
221 class LanguageSr extends Language {
222  function __construct() {
224 
225  parent::__construct();
226 
227  $variants = array( 'sr', 'sr-ec', 'sr-el' );
228  $variantfallbacks = array(
229  'sr' => 'sr-ec',
230  'sr-ec' => 'sr',
231  'sr-el' => 'sr',
232  );
233 
234  $flags = array(
235  'S' => 'S', 'писмо' => 'S', 'pismo' => 'S',
236  'W' => 'W', 'реч' => 'W', 'reč' => 'W', 'ријеч' => 'W', 'riječ' => 'W'
237  );
238  $this->mConverter = new SrConverter( $this, 'sr', $variants, $variantfallbacks, $flags );
239  $wgHooks['PageContentSaveComplete'][] = $this->mConverter;
240  }
241 }
SrConverter\guessVariant
guessVariant( $text, $variant)
Guess if a text is written in Cyrillic or Latin.
Definition: LanguageSr.php:200
SrConverter\findVariantLink
findVariantLink(&$link, &$nt, $ignoreOtherCond=false)
A function wrapper:
Definition: LanguageSr.php:115
LanguageSr\__construct
__construct()
Definition: LanguageSr.php:222
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
SrConverter
There are two levels of conversion for Serbian: the script level (Cyrillics <-> Latin),...
Definition: LanguageSr.php:35
$ret
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses & $ret
Definition: hooks.txt:1530
Language\$mConverter
LanguageConverter $mConverter
Definition: Language.php:78
NS_FILE
const NS_FILE
Definition: Defines.php:85
SrConverter\parseManualRule
parseManualRule( $rule, $flags=array())
rules should be defined as -{ekavian | iyekavian-} -or- -{code:text | code:text | ....
Definition: LanguageSr.php:91
$wgHooks
$wgHooks['ArticleShow'][]
Definition: hooks.txt:110
$flags
it s the revision text itself In either if gzip is the revision text is gzipped $flags
Definition: hooks.txt:2113
$link
set to $title object and return false for a match for latest after cache objects are set use the ContentHandler facility to handle CSS and JavaScript for highlighting & $link
Definition: hooks.txt:2149
MWException
MediaWiki exception.
Definition: MWException.php:26
SrConverter\loadDefaultTables
loadDefaultTables()
Definition: LanguageSr.php:72
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
LanguageSr
Serbian (Српски / Srpski)
Definition: LanguageSr.php:221
NS_USER_TALK
const NS_USER_TALK
Definition: Defines.php:82
ReplacementArray
Replacement array for FSS with fallback to strtr() Supports lazy initialisation of FSS resource.
Definition: StringUtils.php:411
$matches
if(!defined( 'MEDIAWIKI')) if(!isset( $wgVersion)) $matches
Definition: NoLocalSettings.php:33
SrConverter\$mToLatin
$mToLatin
Definition: LanguageSr.php:36
Makefile.translate
def translate(text, conv_table)
Definition: Makefile.py:216
as
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
NS_USER
const NS_USER
Definition: Defines.php:81
SrConverter\translate
translate( $text, $toVariant)
It translates text into variant, specials:
Definition: LanguageSr.php:161
SrConverter\autoConvert
autoConvert( $text, $toVariant=false)
An ugly function wrapper for parsing Image titles (to prevent image name conversion)
Definition: LanguageSr.php:140
SrConverter\$mToCyrillics
$mToCyrillics
Definition: LanguageSr.php:52
Language
Internationalisation code.
Definition: Language.php:74
$wgTitle
if(! $wgRequest->checkUrlExtension()) if(! $wgEnableAPI) $wgTitle
Definition: api.php:63