-
-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() { }
-}
-