Merge "Reduced some master queries by adding flags to Revision functions."
[lhc/web/wiklou.git] / languages / classes / LanguageKu.php
1 <?php
2 /**
3 * Kurdish specific code.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 * @ingroup Language
22 */
23
24 require_once( dirname( __FILE__ ) . '/../LanguageConverter.php' );
25 require_once( dirname( __FILE__ ) . '/LanguageKu_ku.php' );
26
27 /**
28 * Kurdish converter routines
29 *
30 * @ingroup Language
31 */
32 class KuConverter extends LanguageConverter {
33 var $mArabicToLatin = array(
34 'ب' => 'b', 'ج' => 'c', 'چ' => 'ç', 'د' => 'd', 'ف' => 'f', 'گ' => 'g', 'ھ' => 'h',
35 'ہ' => 'h', 'ه' => 'h', 'ح' => 'h', 'ژ' => 'j', 'ك' => 'k', 'ک' => 'k', 'ل' => 'l',
36 'م' => 'm', 'ن' => 'n', 'پ' => 'p', 'ق' => 'q', 'ر' => 'r', 'س' => 's', 'ش' => 'ş',
37 'ت' => 't', 'ڤ' => 'v', 'خ' => 'x', 'غ' => 'x', 'ز' => 'z',
38
39 // ک و => ku -- ist richtig
40 // و ك=> ku -- ist auch richtig
41
42 /* Doppel- und Halbvokale */
43 'ڵ' => 'll', # ll
44 'ڕ' => 'rr', # rr
45 'ا' => 'a',
46 # 'ئێ' => 'ê', # initial e
47 'ە' => 'e',
48 'ه‌' => 'e', # with one non-joiner
49 'ه‌‌' => 'e', # with two non-joiner
50 'ة' => 'e',
51 'ێ' => 'ê',
52 'ي' => 'î',
53 'ی' => 'î', # U+06CC db 8c ARABIC LETTER FARSI YEH
54 'ى' => 'î', # U+0649 d9 89 ARABIC LETTER ALEF MAKSURA
55 'ۆ' => 'o',
56 'و' => 'w',
57 'ئ' => '', # initial hemze should not be shown
58 '،' => ',',
59 'ع' => '\'', # ayn
60 '؟' => '?',
61
62 # digits
63 '٠' => '0', # &#x0660;
64 '١' => '1', # &#x0661;
65 '٢' => '2', # &#x0662;
66 '٣' => '3', # &#x0663;
67 '٤' => '4', # &#x0664;
68 '٥' => '5', # &#x0665;
69 '٦' => '6', # &#x0666;
70 '٧' => '7', # &#x0667;
71 '٨' => '8', # &#x0668;
72 '٩' => '9', # &#x0669;
73 );
74
75 var $mLatinToArabic = array(
76 'b' => 'ب', 'c' => 'ج', 'ç' => 'چ', 'd' => 'د', 'f' => 'ف', 'g' => 'گ',
77 'h' => 'ه', 'j' => 'ژ', 'k' => 'ک', 'l' => 'ل',
78 'm' => 'م', 'n' => 'ن', 'p' => 'پ', 'q' => 'ق', 'r' => 'ر', 's' => 'س', 'ş' => 'ش',
79 't' => 'ت', 'v' => 'ڤ',
80 'x' => 'خ', 'y' => 'ی', 'z' => 'ز',
81
82 'B' => 'ب', 'C' => 'ج', 'Ç' => 'چ', 'D' => 'د', 'F' => 'ف', 'G' => 'گ', 'H' => 'ھ',
83 'H' => 'ہ', 'H' => 'ه', 'H' => 'ح', 'J' => 'ژ', 'K' => 'ك', 'K' => 'ک', 'L' => 'ل',
84 'M' => 'م', 'N' => 'ن', 'P' => 'پ', 'Q' => 'ق', 'R' => 'ر', 'S' => 'س', 'Ş' => 'ش',
85 'T' => 'ت', 'V' => 'ڤ', 'W' => 'و', 'X' => 'خ',
86 'Y' => 'ی', 'Z' => 'ز',
87
88 /* Doppelkonsonanten */
89 # 'll' => 'ڵ', # wenn es geht, doppel-l und l getrennt zu behandeln
90 # 'rr' => 'ڕ', # selbiges für doppel-r
91
92 /* Einzelne Großbuchstaben */
93 // ' C' => 'ج',
94
95 /* Vowels */
96 'a' => 'ا',
97 'e' => 'ە',
98 'ê' => 'ێ',
99 'i' => '',
100 'î' => 'ی',
101 'o' => 'ۆ',
102 'u' => 'و',
103 'û' => 'وو',
104 'w' => 'و',
105 ',' => '،',
106 '?' => '؟',
107
108 # Try to replace the leading vowel
109 ' a' => 'ئا ',
110 ' e' => 'ئە ',
111 ' ê' => 'ئێ ',
112 ' î' => 'ئی ',
113 ' o' => 'ئۆ ',
114 ' u' => 'ئو ',
115 ' û' => 'ئوو ',
116 'A' => 'ئا',
117 'E' => 'ئە',
118 'Ê' => 'ئێ',
119 'Î' => 'ئی',
120 'O' => 'ئۆ',
121 'U' => 'ئو',
122 'Û' => 'ئوو',
123 ' A' => 'ئا ',
124 ' E' => 'ئە ',
125 ' Ê' => 'ئێ ',
126 ' Î' => 'ئی ',
127 ' O' => 'ئۆ ',
128 ' U' => 'ئو ',
129 ' Û' => 'ئوو ',
130 # eyn erstmal deaktivieren, einfache Anführungsstriche sind einfach zu häufig, um sie als eyn zu interpretieren
131 # '\'' => 'ع',
132
133 /* # deactivated for now, breaks links i.e. in header of Special:Recentchanges :-(
134 # digits
135 '0' => '٠', # &#x0660;
136 '1' => '١', # &#x0661;
137 '2' => '٢', # &#x0662;
138 '3' => '٣', # &#x0663;
139 '4' => '٤', # &#x0664;
140 '5' => '٥', # &#x0665;
141 '6' => '٦', # &#x0666;
142 '7' => '٧', # &#x0667;
143 '8' => '٨', # &#x0668;
144 '9' => '٩', # &#x0669;
145 */
146 );
147
148 function loadDefaultTables() {
149 $this->mTables = array(
150 'ku-latn' => new ReplacementArray( $this->mArabicToLatin ),
151 'ku-arab' => new ReplacementArray( $this->mLatinToArabic ),
152 'ku' => new ReplacementArray()
153 );
154 }
155
156 /**
157 * A function wrapper:
158 * - if there is no selected variant, leave the link
159 * names as they were
160 * - do not try to find variants for usernames
161 *
162 * @param $link string
163 * @param $nt Title
164 * @param $ignoreOtherCond bool
165 */
166 function findVariantLink( &$link, &$nt, $ignoreOtherCond = false ) {
167 // check for user namespace
168 if ( is_object( $nt ) ) {
169 $ns = $nt->getNamespace();
170 if ( $ns == NS_USER || $ns == NS_USER_TALK )
171 return;
172 }
173
174 $oldlink = $link;
175 parent::findVariantLink( $link, $nt, $ignoreOtherCond );
176 if ( $this->getPreferredVariant() == $this->mMainLanguageCode )
177 $link = $oldlink;
178 }
179
180 /**
181 * We want our external link captions to be converted in variants,
182 * so we return the original text instead -{$text}-, except for URLs
183 *
184 * @param $text string
185 * @param $noParse bool
186 *
187 * @return string
188 */
189 function markNoConversion( $text, $noParse = false ) {
190 if ( $noParse || preg_match( "/^https?:\/\/|ftp:\/\/|irc:\/\//", $text ) )
191 return parent::markNoConversion( $text );
192 return $text;
193 }
194
195 /**
196 * An ugly function wrapper for parsing Image titles
197 * (to prevent image name conversion)
198 *
199 * @param $text string
200 * @param $toVariant bool
201 *
202 * @return string
203 */
204 function autoConvert( $text, $toVariant = false ) {
205 global $wgTitle;
206 if ( is_object( $wgTitle ) && $wgTitle->getNameSpace() == NS_FILE ) {
207 $imagename = $wgTitle->getNsText();
208 if ( preg_match( "/^$imagename:/", $text ) ) return $text;
209 }
210 return parent::autoConvert( $text, $toVariant );
211 }
212
213 /**
214 * It translates text into variant, specials:
215 * - ommiting roman numbers
216 *
217 * @param $text string
218 * @param $toVariant bool
219 *
220 * @throws MWException
221 * @return string
222 */
223 function translate( $text, $toVariant ) {
224 /* From Kazakh interface, maybe we need it later
225 $breaks = '[^\w\x80-\xff]';
226 // regexp for roman numbers
227 $roman = 'M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})';
228 $roman = '';
229
230 $reg = '/^'.$roman.'$|^'.$roman.$breaks.'|'.$breaks.$roman.'$|'.$breaks.$roman.$breaks.'/';
231
232 $matches = preg_split($reg, $text, -1, PREG_SPLIT_OFFSET_CAPTURE);
233
234 $m = array_shift($matches);
235 if( !isset( $this->mTables[$toVariant] ) ) {
236 throw new MWException( "Broken variant table: " . implode( ',', array_keys( $this->mTables ) ) );
237 }
238 $ret = $this->mTables[$toVariant]->replace( $m[0] );
239 $mstart = $m[1]+strlen($m[0]);
240 foreach($matches as $m) {
241 $ret .= substr($text, $mstart, $m[1]-$mstart);
242 $ret .= parent::translate($m[0], $toVariant);
243 $mstart = $m[1] + strlen($m[0]);
244 }
245
246 return $ret;
247 */
248
249 if ( !isset( $this->mTables[$toVariant] ) ) {
250 throw new MWException( "Broken variant table: " . implode( ',', array_keys( $this->mTables ) ) );
251 }
252
253 return parent::translate( $text, $toVariant );
254 }
255 }
256
257 /**
258 * Kurdish (Kurdî / كوردی)
259 *
260 * @ingroup Language
261 */
262 class LanguageKu extends LanguageKu_ku {
263
264 function __construct() {
265 global $wgHooks;
266 parent::__construct();
267
268 $variants = array( 'ku', 'ku-arab', 'ku-latn' );
269 $variantfallbacks = array(
270 'ku' => 'ku-latn',
271 'ku-arab' => 'ku-latn',
272 'ku-latn' => 'ku-arab',
273 );
274
275 $this->mConverter = new KuConverter( $this, 'ku', $variants, $variantfallbacks );
276 $wgHooks['ArticleSaveComplete'][] = $this->mConverter;
277 }
278 }