X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=includes%2FZhClient.php;h=6dacdc5d3cab8ffef974d67080e121cae17d9c54;hb=69e546c19c017cd268ede1ed1fc679394b37357b;hp=fb0d826123cf96caca8f668d8c38efe02c4203b2;hpb=63d232acf4ddb2b2b5da215ac95a50584cbd4b77;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/ZhClient.php b/includes/ZhClient.php index fb0d826123..6dacdc5d3c 100644 --- a/includes/ZhClient.php +++ b/includes/ZhClient.php @@ -1,10 +1,13 @@ mFP); } } - - -class ZhClientFake { - function ZhClientFake() { - global $wgMemc, $wgDBname; - $this->mZh2TW = $wgMemc->get($key1 = "$wgDBname:zhConvert:tw"); - $this->mZh2CN = $wgMemc->get($key2 = "$wgDBname:zhConvert:cn"); - $this->mZh2SG = $wgMemc->get($key3 = "$wgDBname:zhConvert:sg"); - $this->mZh2HK = $wgMemc->get($key4 = "$wgDBname:zhConvert:hk"); - if(empty($this->mZh2TW) || empty($this->mZh2CN) || empty($this->mZh2SG) || empty($this->mZh2HK)) { - require("includes/ZhConversion.php"); - $this->mZh2TW = $zh2TW; - $this->mZh2CN = $zh2CN; - $this->mZh2HK = $zh2HK; - $this->mZh2SG = $zh2SG; - $wgMemc->set($key1, $this->mZh2TW); - $wgMemc->set($key2, $this->mZh2CN); - $wgMemc->set($key3, $this->mZh2SG); - $wgMemc->set($key4, $this->mZh2HK); - } - } - - function isconnected() { - return true; - } - - /** - * Convert to zh-tw - * - * @access private - */ - function zh2tw($text) { - return strtr($text, $this->mZh2TW); - } - - /** - * Convert to zh-cn - * - * @access private - */ - function zh2cn($text) { - return strtr($text, $this->mZh2CN); - } - - /** - * Convert to zh-sg - * - * @access private - */ - function zh2sg($text) { - return strtr(strtr($text, $this->mZh2CN), $this->mZh2SG); - } - - /** - * Convert to zh-hk - * - * @access private - */ - function zh2hk($text) { - return strtr(strtr($text, $this->mZh2TW), $this->mZh2HK); - } - - /** - * Convert the input to a different language variant - * - * @param string $text input text - * @param string $tolang language variant - * @return string the converted text - * @access public - */ - function convert($text, $tolang) { - $t = ''; - switch($tolang) { - case 'zh-cn': - $t = $this->zh2cn($text); - break; - case 'zh-tw': - $t = $this->zh2tw($text); - break; - case 'zh-sg': - $t = $this->zh2sg($text); - break; - case 'zh-hk': - $t = $this->zh2hk($text); - break; - default: - $t = $text; - } - return $t; - } - - function convertToAllVariants($text) { - $ret = array(); - $ret['zh-cn'] = $this->zh2cn($text); - $ret['zh-tw'] = $this->zh2tw($text); - $ret['zh-sg'] = $this->zh2sg($text); - $ret['zh-hk'] = $this->zh2hk($text); - return $ret; - } - - /** - * Perform "fake" word segmentation, i.e. treating each character as a word - * - * @param string $text input text - * @return string segmented text - * @access public - */ - function segment($text) { - /* adapted from LanguageZh_cn::stripForSearch() - here we will first separate the single characters, - and let the caller conver it to hex - */ - if( function_exists( 'mb_strtolower' ) ) { - return preg_replace( - "/([\\xc0-\\xff][\\x80-\\xbf]*)/e", - "' ' .\"$1\"", - mb_strtolower( $text ) ); - } else { - global $wikiLowerChars; - return preg_replace( - "/([\\xc0-\\xff][\\x80-\\xbf]*)/e", - "' ' . strtr( \"\$1\", \$wikiLowerChars )", - $text ); - } - } - - /** - * Close the fake connection - * - * @access public - */ - function close() { } -} - ?> \ No newline at end of file