include_once -> require_once
[lhc/web/wiklou.git] / languages / LanguageUtf8.php
1 <?php
2
3 $wgInputEncoding = "utf-8";
4 $wgOutputEncoding = "utf-8";
5
6 $wikiUpperChars = $wgMemc->get( $key1 = "$wgDBname:utf8:upper" );
7 $wikiLowerChars = $wgMemc->get( $key2 = "$wgDBname:utf8:lower" );
8
9 if(empty( $wikiUpperChars) || empty($wikiLowerChars )) {
10 require_once( "Utf8Case.php" );
11 $wgMemc->set( $key1, $wikiUpperChars );
12 $wgMemc->set( $key2, $wikiLowerChars );
13 }
14
15 # Base stuff useful to all UTF-8 based language files
16 class LanguageUtf8 extends Language {
17
18 function ucfirst( $string ) {
19 # For most languages, this is a wrapper for ucfirst()
20 # But that doesn't work right in a UTF-8 locale
21 global $wikiUpperChars, $wikiLowerChars;
22 return preg_replace (
23 "/^([\\x00-\\x7f]|[\\xc0-\\xff][\\x80-\\xbf]*)/e",
24 "strtr ( \"\$1\" , \$wikiUpperChars )",
25 $string );
26 }
27
28 function lcfirst( $string ) {
29 global $wikiUpperChars, $wikiLowerChars;
30 return preg_replace (
31 "/^([\\x00-\\x7f]|[\\xc0-\\xff][\\x80-\\xbf]*)/e",
32 "strtr ( \"\$1\" , \$wikiLowerChars )",
33 $string );
34 }
35
36 function stripForSearch( $string ) {
37 # MySQL fulltext index doesn't grok utf-8, so we
38 # need to fold cases and convert to hex
39 global $wikiLowerChars;
40 return preg_replace(
41 "/([\\xc0-\\xff][\\x80-\\xbf]*)/e",
42 "'U8' . bin2hex( strtr( \"\$1\", \$wikiLowerChars ) )",
43 $string );
44 }
45
46 function fallback8bitEncoding() {
47 # Windows codepage 1252 is a superset of iso 8859-1
48 # override this to use difference source encoding to
49 # translate incoming 8-bit URLs.
50 return "windows-1252";
51 }
52
53 function checkTitleEncoding( $s ) {
54 global $wgInputEncoding;
55
56 # Check for non-UTF-8 URLs
57 $ishigh = preg_match( '/[\x80-\xff]/', $s);
58 if(!$ishigh) return $s;
59
60 $isutf8 = preg_match( '/^([\x00-\x7f]|[\xc0-\xdf][\x80-\xbf]|' .
61 '[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xf7][\x80-\xbf]{3})+$/', $s );
62 if( $isutf8 ) return $s;
63
64 return $this->iconv( $this->fallback8bitEncoding(), "utf-8", $s );
65 }
66 }
67
68 ?>