favicon fix
[lhc/web/wiklou.git] / languages / LanguageSr.php
1 <?php
2 /**
3 * @package MediaWiki
4 * @subpackage Language
5 */
6
7 /*
8 There are two levels of conversion for Serbian: the script level
9 (Cyrillics <-> Latin), and the variant level (ekavian
10 <->iyekavian). The two are orthogonal. So we really only need two
11 dictionaries: one for Cyrillics and Latin, and one for ekavian and
12 iyekavian.
13 */
14 require_once( dirname(__FILE__).'/LanguageConverter.php' );
15 require_once( dirname(__FILE__).'/LanguageSr_ec.php' );
16 require_once( dirname(__FILE__).'/LanguageSr_el.php' );
17
18 class SrConverter extends LanguageConverter {
19 var $mToLatin = array(
20 'а' => 'a', 'б' => 'b', 'в' => 'v', 'г' => 'g', 'д' => 'd',
21 'ђ' => 'đ', 'е' => 'e', 'ж' => 'ž', 'з' => 'z', 'и' => 'i',
22 'ј' => 'j', 'к' => 'k', 'л' => 'l', 'љ' => 'lj', 'м' => 'm',
23 'н' => 'n', 'њ' => 'nj', 'о' => 'o', 'п' => 'p', 'р' => 'r',
24 'с' => 's', 'т' => 't', 'ћ' => 'ć', 'у' => 'u', 'ф' => 'f',
25 'х' => 'h', 'ц' => 'c', 'ч' => 'č', 'џ' => 'dž', 'ш' => 'š',
26
27 'А' => 'A', 'Б' => 'B', 'В' => 'V', 'Г' => 'G', 'Д' => 'D',
28 'Ђ' => 'Đ', 'Е' => 'E', 'Ж' => 'Ž', 'З' => 'Z', 'И' => 'I',
29 'Ј' => 'J', 'К' => 'K', 'Л' => 'L', 'Љ' => 'Lj', 'М' => 'M',
30 'Н' => 'N', 'Њ' => 'Nj', 'О' => 'O', 'П' => 'P', 'Р' => 'R',
31 'С' => 'S', 'Т' => 'T', 'Ћ' => 'Ć', 'У' => 'U', 'Ф' => 'F',
32 'Х' => 'H', 'Ц' => 'C', 'Ч' => 'Č', 'Џ' => 'Dž', 'Ш' => 'Š',
33 );
34
35 var $mToCyrillics = array(
36 'a' => 'а', 'b' => 'б', 'c' => 'ц', 'č' => 'ч', 'ć' => 'ћ',
37 'd' => 'д', 'dž' => 'џ', 'đ' => 'ђ', 'e' => 'е', 'f' => 'ф',
38 'g' => 'г', 'h' => 'х', 'i' => 'и', 'j' => 'ј', 'k' => 'к',
39 'l' => 'л', 'lj' => 'љ', 'm' => 'м', 'n' => 'н', 'nj' => 'њ',
40 'o' => 'о', 'p' => 'п', 'r' => 'р', 's' => 'с', 'š' => 'ш',
41 't' => 'т', 'u' => 'у', 'v' => 'в', 'z' => 'з', 'ž' => 'ж',
42
43 'A' => 'А', 'B' => 'Б', 'C' => 'Ц', 'Č' => 'Ч', 'Ć' => 'Ћ',
44 'D' => 'Д', 'Dž' => 'Џ', 'Đ' => 'Ђ', 'E' => 'Е', 'F' => 'Ф',
45 'G' => 'Г', 'H' => 'Х', 'I' => 'И', 'J' => 'Ј', 'K' => 'К',
46 'L' => 'Л', 'LJ' => 'Љ', 'M' => 'М', 'N' => 'Н', 'NJ' => 'Њ',
47 'O' => 'О', 'P' => 'П', 'R' => 'Р', 'S' => 'С', 'Š' => 'Ш',
48 'T' => 'Т', 'U' => 'У', 'V' => 'В', 'Z' => 'З', 'Ž' => 'Ж',
49
50 'DŽ' => 'Џ', 'd!ž' => 'дж', 'D!ž'=> 'Дж', 'D!Ž'=> 'ДЖ',
51 'Lj' => 'Љ', 'l!j' => 'лј', 'L!j'=> 'Лј', 'L!J'=> 'ЛЈ',
52 'Nj' => 'Њ', 'n!j' => 'нј', 'N!j'=> 'Нј', 'N!J'=> 'НЈ'
53 );
54
55 function loadDefaultTables() {
56 $this->mTables = array();
57 $this->mTables['sr-ec'] = $this->mToCyrillics;
58 $this->mTables['sr-jc'] = $this->mToCyrillics;
59 $this->mTables['sr-el'] = $this->mToLatin;
60 $this->mTables['sr-jl'] = $this->mToLatin;
61 $this->mTables['sr'] = array();
62 }
63
64 /* rules should be defined as -{ekavian | iyekavian-} -or-
65 -{code:text | code:text | ...}-
66 */
67 function parseManualRule($rule, $flags=array()) {
68
69 $echoices = preg_split("/(<[^>]+>)/",$rule,-1,PREG_SPLIT_DELIM_CAPTURE);
70 $choices = array();
71
72 // check if we did a split across an HTML tag
73 // if so, glue them back together
74
75 $ctold = '';
76 foreach($echoices as $ct){
77 if($ct=='');
78 else if(preg_match('/<[^>]+>/',$ct)){
79 $ctold.=$ct;
80 }
81 else{
82 $c = explode($this->mMarkup['varsep'],$ct);
83 if(count($c)>1){
84 $choices[]=$ctold.array_shift($c);
85 $ctold=array_pop($c);
86 $choices=array_merge($choices,$c);
87 }
88 else $ctold.=array_pop($c);
89 }
90 }
91 if($ctold!='') $choices[]=$ctold;
92
93 $carray = array();
94 if(sizeof($choices) == 1) {
95 if(in_array('W', $flags)) {
96 $carray['sr'] = $this->autoConvert($choices[0], 'sr-ec');
97 $carray['sr-ec'] = $this->autoConvert($choices[0], 'sr-ec');
98 $carray['sr-jc'] = $this->autoConvert($choices[0], 'sr-jc');
99 $carray['sr-el'] = $this->autoConvert($choices[0], 'sr-el');
100 $carray['sr-jl'] = $this->autoConvert($choices[0], 'sr-jl');
101 }
102 foreach($this->mVariants as $v) {
103 $carray[$v] = $choices[0];
104 }
105 return $carray;
106 }
107
108 /* detect which format is used, also trim the choices*/
109 $n=0;
110 foreach($choices as $c=>$t) {
111 if(strpos($t, $this->mMarkup['codesep']) !== false) { $n++; }
112 $choices[$c] = trim($t);
113 }
114 /* the -{code:text | ...}- format */
115 if($n == sizeof($choices)) {
116 foreach($choices as $c) {
117 list($code, $text) = explode($this->mMarkup['codesep'], $c);
118 $carray[trim($code)] = trim($text);
119 }
120 return $carray;
121 }
122
123 /* the two choice format -{choice1; choice2}-*/
124 if(sizeof($choices == 2) && $n==0) {
125 if(in_array('S', $flags)) {
126 // conversion between Cyrillics and Latin
127 $carray['sr'] = $carray['sr-ec'] =$carray['sr-jc'] = $choices[0];
128 $carray['sr-el'] =$carray['sr-jl'] = $choices[1];
129 }
130 else {
131 $carray['sr'] = $this->autoConvert($choices[0], 'sr-ec');
132 $carray['sr-ec'] = $this->autoConvert($choices[0], 'sr-ec');
133 $carray['sr-jc'] = $this->autoConvert($choices[1], 'sr-jc');
134 $carray['sr-el'] = $this->autoConvert($choices[0], 'sr-el');
135 $carray['sr-jl'] = $this->autoConvert($choices[1], 'sr-jl');
136 }
137 return $carray;
138 }
139 return $carray;
140 }
141
142 /*
143 * Override function from LanguageConvertor
144 * Additional checks:
145 * - There should be no conversion for Talk pages
146 */
147 function getPreferredVariant(){
148 global $wgTitle;
149 if($wgTitle!=NULL && $wgTitle->isTalkPage()){
150 return $this->mMainLanguageCode;
151 }
152 return parent::getPreferredVariant();
153 }
154
155
156 /*
157 * A function wrapper, if there is no selected variant,
158 * leave the link names as they were
159 */
160 function findVariantLink( &$link, &$nt ) {
161 $oldlink=$link;
162 parent::findVariantLink($link,$nt);
163 if($this->getPreferredVariant()==$this->mMainLanguageCode)
164 $link=$oldlink;
165 }
166
167
168 /*
169 * We want our external link captions to be converted in variants,
170 * so we return the original text instead -{$text}-, except for URLs
171 */
172 function markNoConversion($text) {
173 if(preg_match("/^https?:\/\/|ftp:\/\/|irc:\/\//",$text))
174 return parent::markNoConversion($text);
175 return $text;
176 }
177
178 /*
179 * An ugly function wrapper for parsing Image titles
180 * (to prevent image name conversion)
181 */
182 function autoConvert($text, $toVariant=false) {
183 global $wgTitle;
184 if($wgTitle->getNameSpace()==NS_IMAGE){
185 $imagename = $wgTitle->getNsText();
186 if(preg_match("/^$imagename:/",$text)) return $text;
187 }
188 return parent::autoConvert($text,$toVariant);
189 }
190
191
192 }
193
194 class LanguageSr extends LanguageSr_ec {
195 function __construct() {
196 global $wgHooks;
197 parent::__construct();
198
199 $variants = array('sr', 'sr-ec', 'sr-jc', 'sr-el', 'sr-jl');
200 $variantfallbacks = array(
201 'sr' => 'sr-ec',
202 'sr-ec' => 'sr-jc',
203 'sr-jc' => 'sr-ec',
204 'sr-el' => 'sr-jl',
205 'sr-jl' => 'sr-el'
206 );
207 $marker = array();//don't mess with these, leave them as they are
208 $flags = array(
209 'S' => 'S', 'писмо' => 'S', 'pismo' => 'S',
210 'W' => 'W', 'реч' => 'W', 'reč' => 'W', 'ријеч' => 'W', 'riječ' => 'W'
211 );
212 $this->mConverter = new SrConverter($this, 'sr', $variants, $variantfallbacks, $marker, $flags);
213 $wgHooks['ArticleSaveComplete'][] = $this->mConverter;
214 }
215 }
216 ?>