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