The beginnings of HipHop compiled mode support. It works now for parser cache hits.
[lhc/web/wiklou.git] / languages / LanguageConverter.php
1 <?php
2 /**
3 * Contains the LanguageConverter class and ConverterRule class
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 /**
25 * Base class for language conversion.
26 * @ingroup Language
27 *
28 * @author Zhengzhu Feng <zhengzhu@gmail.com>
29 * @maintainers fdcn <fdcn64@gmail.com>, shinjiman <shinjiman@gmail.com>, PhiLiP <philip.npc@gmail.com>
30 */
31 class LanguageConverter {
32 var $mMainLanguageCode;
33 var $mVariants, $mVariantFallbacks, $mVariantNames;
34 var $mTablesLoaded = false;
35 var $mTables;
36 // 'bidirectional' 'unidirectional' 'disable' for each variant
37 var $mManualLevel;
38
39 /**
40 * @var String: memcached key name
41 */
42 var $mCacheKey;
43
44 var $mLangObj;
45 var $mFlags;
46 var $mDescCodeSep = ':', $mDescVarSep = ';';
47 var $mUcfirst = false;
48 var $mConvRuleTitle = false;
49 var $mURLVariant;
50 var $mUserVariant;
51 var $mHeaderVariant;
52 var $mMaxDepth = 10;
53 var $mVarSeparatorPattern;
54
55 const CACHE_VERSION_KEY = 'VERSION 6';
56
57 /**
58 * Constructor
59 *
60 * @param $langobj Language: the Language Object
61 * @param $maincode String: the main language code of this language
62 * @param $variants Array: the supported variants of this language
63 * @param $variantfallbacks Array: the fallback language of each variant
64 * @param $flags Array: defining the custom strings that maps to the flags
65 * @param $manualLevel Array: limit for supported variants
66 */
67 public function __construct( $langobj, $maincode, $variants = array(),
68 $variantfallbacks = array(), $flags = array(),
69 $manualLevel = array() ) {
70 global $wgDisabledVariants;
71 $this->mLangObj = $langobj;
72 $this->mMainLanguageCode = $maincode;
73 $this->mVariants = array_diff( $variants, $wgDisabledVariants );
74 $this->mVariantFallbacks = $variantfallbacks;
75 $this->mVariantNames = Language::getLanguageNames();
76 $this->mCacheKey = wfMemcKey( 'conversiontables', $maincode );
77 $defaultflags = array(
78 // 'S' show converted text
79 // '+' add rules for alltext
80 // 'E' the gave flags is error
81 // these flags above are reserved for program
82 'A' => 'A', // add rule for convert code (all text convert)
83 'T' => 'T', // title convert
84 'R' => 'R', // raw content
85 'D' => 'D', // convert description (subclass implement)
86 '-' => '-', // remove convert (not implement)
87 'H' => 'H', // add rule for convert code
88 // (but no display in placed code)
89 'N' => 'N' // current variant name
90 );
91 $this->mFlags = array_merge( $defaultflags, $flags );
92 foreach ( $this->mVariants as $v ) {
93 if ( array_key_exists( $v, $manualLevel ) ) {
94 $this->mManualLevel[$v] = $manualLevel[$v];
95 } else {
96 $this->mManualLevel[$v] = 'bidirectional';
97 }
98 $this->mFlags[$v] = $v;
99 }
100 }
101
102 /**
103 * Get all valid variants.
104 * Call this instead of using $this->mVariants directly.
105 *
106 * @return Array: contains all valid variants
107 */
108 public function getVariants() {
109 return $this->mVariants;
110 }
111
112 /**
113 * In case some variant is not defined in the markup, we need
114 * to have some fallback. For example, in zh, normally people
115 * will define zh-hans and zh-hant, but less so for zh-sg or zh-hk.
116 * when zh-sg is preferred but not defined, we will pick zh-hans
117 * in this case. Right now this is only used by zh.
118 *
119 * @param $variant String: the language code of the variant
120 * @return String: The code of the fallback language or the
121 * main code if there is no fallback
122 */
123 public function getVariantFallbacks( $variant ) {
124 if ( isset( $this->mVariantFallbacks[$variant] ) ) {
125 return $this->mVariantFallbacks[$variant];
126 }
127 return $this->mMainLanguageCode;
128 }
129
130 /**
131 * Get the title produced by the conversion rule.
132 * @return String: The converted title text
133 */
134 public function getConvRuleTitle() {
135 return $this->mConvRuleTitle;
136 }
137
138 /**
139 * Get preferred language variant.
140 * @return String: the preferred language code
141 */
142 public function getPreferredVariant() {
143 global $wgDefaultLanguageVariant, $wgUser;
144
145 $req = $this->getURLVariant();
146
147 if ( $wgUser->isLoggedIn() && !$req ) {
148 $req = $this->getUserVariant();
149 } elseif ( !$req ) {
150 $req = $this->getHeaderVariant();
151 }
152
153 if ( $wgDefaultLanguageVariant && !$req ) {
154 $req = $this->validateVariant( $wgDefaultLanguageVariant );
155 }
156
157 // This function, unlike the other get*Variant functions, is
158 // not memoized (i.e. there return value is not cached) since
159 // new information might appear during processing after this
160 // is first called.
161 if ( $req ) {
162 return $req;
163 }
164 return $this->mMainLanguageCode;
165 }
166
167 /**
168 * Get default variant.
169 * This function would not be affected by user's settings or headers
170 * @return String: the default variant code
171 */
172 public function getDefaultVariant() {
173 global $wgDefaultLanguageVariant;
174
175 $req = $this->getURLVariant();
176
177 if ( $wgDefaultLanguageVariant && !$req ) {
178 $req = $this->validateVariant( $wgDefaultLanguageVariant );
179 }
180
181 if ( $req ) {
182 return $req;
183 }
184 return $this->mMainLanguageCode;
185 }
186
187 /**
188 * Validate the variant
189 * @param $variant String: the variant to validate
190 * @return Mixed: returns the variant if it is valid, null otherwise
191 */
192 protected function validateVariant( $variant = null ) {
193 if ( $variant !== null && in_array( $variant, $this->mVariants ) ) {
194 return $variant;
195 }
196 return null;
197 }
198
199 /**
200 * Get the variant specified in the URL
201 *
202 * @return Mixed: variant if one found, false otherwise.
203 */
204 public function getURLVariant() {
205 global $wgRequest;
206
207 if ( $this->mURLVariant ) {
208 return $this->mURLVariant;
209 }
210
211 // see if the preference is set in the request
212 $ret = $wgRequest->getText( 'variant' );
213
214 if ( !$ret ) {
215 $ret = $wgRequest->getVal( 'uselang' );
216 }
217
218 return $this->mURLVariant = $this->validateVariant( $ret );
219 }
220
221 /**
222 * Determine if the user has a variant set.
223 *
224 * @return Mixed: variant if one found, false otherwise.
225 */
226 protected function getUserVariant() {
227 global $wgUser;
228
229 // memoizing this function wreaks havoc on parserTest.php
230 /*
231 if ( $this->mUserVariant ) {
232 return $this->mUserVariant;
233 }
234 */
235
236 // Get language variant preference from logged in users
237 // Don't call this on stub objects because that causes infinite
238 // recursion during initialisation
239 if ( $wgUser->isLoggedIn() ) {
240 $ret = $wgUser->getOption( 'variant' );
241 } else {
242 // figure out user lang without constructing wgLang to avoid
243 // infinite recursion
244 $ret = $wgUser->getOption( 'language' );
245 }
246
247 return $this->mUserVariant = $this->validateVariant( $ret );
248 }
249
250 /**
251 * Determine the language variant from the Accept-Language header.
252 *
253 * @return Mixed: variant if one found, false otherwise.
254 */
255 protected function getHeaderVariant() {
256 global $wgRequest;
257
258 if ( $this->mHeaderVariant ) {
259 return $this->mHeaderVariant;
260 }
261
262 // see if some supported language variant is set in the
263 // HTTP header.
264 $languages = array_keys( $wgRequest->getAcceptLang() );
265 if ( empty( $languages ) ) {
266 return null;
267 }
268
269 $fallbackLanguages = array();
270 foreach ( $languages as $language ) {
271 $this->mHeaderVariant = $this->validateVariant( $language );
272 if ( $this->mHeaderVariant ) {
273 break;
274 }
275
276 // To see if there are fallbacks of current language.
277 // We record these fallback variants, and process
278 // them later.
279 $fallbacks = $this->getVariantFallbacks( $language );
280 if ( is_string( $fallbacks ) ) {
281 $fallbackLanguages[] = $fallbacks;
282 } elseif ( is_array( $fallbacks ) ) {
283 $fallbackLanguages =
284 array_merge( $fallbackLanguages, $fallbacks );
285 }
286 }
287
288 if ( !$this->mHeaderVariant ) {
289 // process fallback languages now
290 $fallback_languages = array_unique( $fallbackLanguages );
291 foreach ( $fallback_languages as $language ) {
292 $this->mHeaderVariant = $this->validateVariant( $language );
293 if ( $this->mHeaderVariant ) {
294 break;
295 }
296 }
297 }
298
299 return $this->mHeaderVariant;
300 }
301
302 /**
303 * Dictionary-based conversion.
304 * This function would not parse the conversion rules.
305 * If you want to parse rules, try to use convert() or
306 * convertTo().
307 *
308 * @param $text String: the text to be converted
309 * @param $toVariant String: the target language code
310 * @return String: the converted text
311 */
312 public function autoConvert( $text, $toVariant = false ) {
313 wfProfileIn( __METHOD__ );
314
315 $this->loadTables();
316
317 if ( !$toVariant ) {
318 $toVariant = $this->getPreferredVariant();
319 if ( !$toVariant ) {
320 wfProfileOut( __METHOD__ );
321 return $text;
322 }
323 }
324
325 /* we convert everything except:
326 1. HTML markups (anything between < and >)
327 2. HTML entities
328 3. placeholders created by the parser
329 */
330 global $wgParser;
331 if ( isset( $wgParser ) && $wgParser->UniqPrefix() != '' ) {
332 $marker = '|' . $wgParser->UniqPrefix() . '[\-a-zA-Z0-9]+';
333 } else {
334 $marker = '';
335 }
336
337 // this one is needed when the text is inside an HTML markup
338 $htmlfix = '|<[^>]+$|^[^<>]*>';
339
340 // disable convert to variants between <code></code> tags
341 $codefix = '<code>.+?<\/code>|';
342 // disable convertsion of <script type="text/javascript"> ... </script>
343 $scriptfix = '<script.*?>.*?<\/script>|';
344 // disable conversion of <pre xxxx> ... </pre>
345 $prefix = '<pre.*?>.*?<\/pre>|';
346
347 $reg = '/' . $codefix . $scriptfix . $prefix .
348 '<[^>]+>|&[a-zA-Z#][a-z0-9]+;' . $marker . $htmlfix . '/s';
349 $startPos = 0;
350 $sourceBlob = '';
351 $literalBlob = '';
352
353 // Guard against delimiter nulls in the input
354 $text = str_replace( "\000", '', $text );
355
356 $markupMatches = null;
357 $elementMatches = null;
358 while ( $startPos < strlen( $text ) ) {
359 if ( preg_match( $reg, $text, $markupMatches, PREG_OFFSET_CAPTURE, $startPos ) ) {
360 $elementPos = $markupMatches[0][1];
361 $element = $markupMatches[0][0];
362 } else {
363 $elementPos = strlen( $text );
364 $element = '';
365 }
366
367 // Queue the part before the markup for translation in a batch
368 $sourceBlob .= substr( $text, $startPos, $elementPos - $startPos ) . "\000";
369
370 // Advance to the next position
371 $startPos = $elementPos + strlen( $element );
372
373 // Translate any alt or title attributes inside the matched element
374 if ( $element !== '' && preg_match( '/^(<[^>\s]*)\s([^>]*)(.*)$/', $element,
375 $elementMatches ) )
376 {
377 $attrs = Sanitizer::decodeTagAttributes( $elementMatches[2] );
378 $changed = false;
379 foreach ( array( 'title', 'alt' ) as $attrName ) {
380 if ( !isset( $attrs[$attrName] ) ) {
381 continue;
382 }
383 $attr = $attrs[$attrName];
384 // Don't convert URLs
385 if ( !strpos( $attr, '://' ) ) {
386 $attr = $this->translate( $attr, $toVariant );
387 }
388
389 // Remove HTML tags to avoid disrupting the layout
390 $attr = preg_replace( '/<[^>]+>/', '', $attr );
391 if ( $attr !== $attrs[$attrName] ) {
392 $attrs[$attrName] = $attr;
393 $changed = true;
394 }
395 }
396 if ( $changed ) {
397 $element = $elementMatches[1] . Html::expandAttributes( $attrs ) .
398 $elementMatches[3];
399 }
400 }
401 $literalBlob .= $element . "\000";
402 }
403
404 // Do the main translation batch
405 $translatedBlob = $this->translate( $sourceBlob, $toVariant );
406
407 // Put the output back together
408 $translatedIter = StringUtils::explode( "\000", $translatedBlob );
409 $literalIter = StringUtils::explode( "\000", $literalBlob );
410 $output = '';
411 while ( $translatedIter->valid() && $literalIter->valid() ) {
412 $output .= $translatedIter->current();
413 $output .= $literalIter->current();
414 $translatedIter->next();
415 $literalIter->next();
416 }
417
418 wfProfileOut( __METHOD__ );
419 return $output;
420 }
421
422 /**
423 * Translate a string to a variant.
424 * Doesn't parse rules or do any of that other stuff, for that use
425 * convert() or convertTo().
426 *
427 * @param $text String: text to convert
428 * @param $variant String: variant language code
429 * @return String: translated text
430 */
431 public function translate( $text, $variant ) {
432 wfProfileIn( __METHOD__ );
433 // If $text is empty or only includes spaces, do nothing
434 // Otherwise translate it
435 if ( trim( $text ) ) {
436 $this->loadTables();
437 $text = $this->mTables[$variant]->replace( $text );
438 }
439 wfProfileOut( __METHOD__ );
440 return $text;
441 }
442
443 /**
444 * Call translate() to convert text to all valid variants.
445 *
446 * @param $text String: the text to be converted
447 * @return Array: variant => converted text
448 */
449 public function autoConvertToAllVariants( $text ) {
450 wfProfileIn( __METHOD__ );
451 $this->loadTables();
452
453 $ret = array();
454 foreach ( $this->mVariants as $variant ) {
455 $ret[$variant] = $this->translate( $text, $variant );
456 }
457
458 wfProfileOut( __METHOD__ );
459 return $ret;
460 }
461
462 /**
463 * Convert link text to all valid variants.
464 * In the first, this function only convert text outside the
465 * "-{" "}-" markups. Since the "{" and "}" are not allowed in
466 * titles, the text will get all converted always.
467 * So I removed this feature and deprecated the function.
468 *
469 * @param $text String: the text to be converted
470 * @return Array: variant => converted text
471 * @deprecated Use autoConvertToAllVariants() instead
472 */
473 public function convertLinkToAllVariants( $text ) {
474 return $this->autoConvertToAllVariants( $text );
475 }
476
477 /**
478 * Apply manual conversion rules.
479 *
480 * @param $convRule Object: Object of ConverterRule
481 */
482 protected function applyManualConv( $convRule ) {
483 // Use syntax -{T|zh-cn:TitleCN; zh-tw:TitleTw}- to custom
484 // title conversion.
485 // Bug 24072: $mConvRuleTitle was overwritten by other manual
486 // rule(s) not for title, this breaks the title conversion.
487 $newConvRuleTitle = $convRule->getTitle();
488 if ( $newConvRuleTitle ) {
489 // So I add an empty check for getTitle()
490 $this->mConvRuleTitle = $newConvRuleTitle;
491 }
492
493 // merge/remove manual conversion rules to/from global table
494 $convTable = $convRule->getConvTable();
495 $action = $convRule->getRulesAction();
496 foreach ( $convTable as $variant => $pair ) {
497 if ( !$this->validateVariant( $variant ) ) {
498 continue;
499 }
500
501 if ( $action == 'add' ) {
502 foreach ( $pair as $from => $to ) {
503 // to ensure that $from and $to not be left blank
504 // so $this->translate() could always return a string
505 if ( $from || $to ) {
506 // more efficient than array_merge(), about 2.5 times.
507 $this->mTables[$variant]->setPair( $from, $to );
508 }
509 }
510 } elseif ( $action == 'remove' ) {
511 $this->mTables[$variant]->removeArray( $pair );
512 }
513 }
514 }
515
516 /**
517 * Auto convert a Title object to a readable string in the
518 * preferred variant.
519 *
520 * @param $title Object: a object of Title
521 * @return String: converted title text
522 */
523 public function convertTitle( $title ) {
524 $variant = $this->getPreferredVariant();
525 $index = $title->getNamespace();
526 if ( $index === NS_MAIN ) {
527 $text = '';
528 } else {
529 // first let's check if a message has given us a converted name
530 $nsConvKey = 'conversion-ns' . $index;
531 if ( !wfEmptyMsg( $nsConvKey ) ) {
532 $text = wfMsgForContentNoTrans( $nsConvKey );
533 } else {
534 // the message does not exist, try retrieve it from the current
535 // variant's namespace names.
536 $langObj = $this->mLangObj->factory( $variant );
537 $text = $langObj->getFormattedNsText( $index );
538 }
539 $text .= ':';
540 }
541 $text .= $title->getText();
542 $text = $this->translate( $text, $variant );
543 return $text;
544 }
545
546 /**
547 * Convert text to different variants of a language. The automatic
548 * conversion is done in autoConvert(). Here we parse the text
549 * marked with -{}-, which specifies special conversions of the
550 * text that can not be accomplished in autoConvert().
551 *
552 * Syntax of the markup:
553 * -{code1:text1;code2:text2;...}- or
554 * -{flags|code1:text1;code2:text2;...}- or
555 * -{text}- in which case no conversion should take place for text
556 *
557 * @param $text String: text to be converted
558 * @return String: converted text
559 */
560 public function convert( $text ) {
561 $variant = $this->getPreferredVariant();
562 return $this->convertTo( $text, $variant );
563 }
564
565 /**
566 * Same as convert() except a extra parameter to custom variant.
567 *
568 * @param $text String: text to be converted
569 * @param $variant String: the target variant code
570 * @return String: converted text
571 */
572 public function convertTo( $text, $variant ) {
573 global $wgDisableLangConversion;
574 if ( $wgDisableLangConversion ) {
575 return $text;
576 }
577 return $this->recursiveConvertTopLevel( $text, $variant );
578 }
579
580 /**
581 * Recursively convert text on the outside. Allow to use nested
582 * markups to custom rules.
583 *
584 * @param $text String: text to be converted
585 * @param $variant String: the target variant code
586 * @param $depth Integer: depth of recursion
587 * @return String: converted text
588 */
589 protected function recursiveConvertTopLevel( $text, $variant, $depth = 0 ) {
590 $startPos = 0;
591 $out = '';
592 $length = strlen( $text );
593 while ( $startPos < $length ) {
594 $pos = strpos( $text, '-{', $startPos );
595
596 if ( $pos === false ) {
597 // No more markup, append final segment
598 $out .= $this->autoConvert( substr( $text, $startPos ), $variant );
599 return $out;
600 }
601
602 // Markup found
603 // Append initial segment
604 $out .= $this->autoConvert( substr( $text, $startPos, $pos - $startPos ), $variant );
605
606 // Advance position
607 $startPos = $pos;
608
609 // Do recursive conversion
610 $out .= $this->recursiveConvertRule( $text, $variant, $startPos, $depth + 1 );
611 }
612
613 return $out;
614 }
615
616 /**
617 * Recursively convert text on the inside.
618 *
619 * @param $text String: text to be converted
620 * @param $variant String: the target variant code
621 * @param $depth Integer: depth of recursion
622 * @return String: converted text
623 */
624 protected function recursiveConvertRule( $text, $variant, &$startPos, $depth = 0 ) {
625 // Quick sanity check (no function calls)
626 if ( $text[$startPos] !== '-' || $text[$startPos + 1] !== '{' ) {
627 throw new MWException( __METHOD__ . ': invalid input string' );
628 }
629
630 $startPos += 2;
631 $inner = '';
632 $warningDone = false;
633 $length = strlen( $text );
634
635 while ( $startPos < $length ) {
636 $m = false;
637 preg_match( '/-\{|\}-/', $text, $m, PREG_OFFSET_CAPTURE, $startPos );
638 if ( !$m ) {
639 // Unclosed rule
640 break;
641 }
642
643 $token = $m[0][0];
644 $pos = $m[0][1];
645
646 // Markup found
647 // Append initial segment
648 $inner .= substr( $text, $startPos, $pos - $startPos );
649
650 // Advance position
651 $startPos = $pos;
652
653 switch ( $token ) {
654 case '-{':
655 // Check max depth
656 if ( $depth >= $this->mMaxDepth ) {
657 $inner .= '-{';
658 if ( !$warningDone ) {
659 $inner .= '<span class="error">' .
660 wfMsgForContent( 'language-converter-depth-warning',
661 $this->mMaxDepth ) .
662 '</span>';
663 $warningDone = true;
664 }
665 $startPos += 2;
666 continue;
667 }
668 // Recursively parse another rule
669 $inner .= $this->recursiveConvertRule( $text, $variant, $startPos, $depth + 1 );
670 break;
671 case '}-':
672 // Apply the rule
673 $startPos += 2;
674 $rule = new ConverterRule( $inner, $this );
675 $rule->parse( $variant );
676 $this->applyManualConv( $rule );
677 return $rule->getDisplay();
678 default:
679 throw new MWException( __METHOD__ . ': invalid regex match' );
680 }
681 }
682
683 // Unclosed rule
684 if ( $startPos < $length ) {
685 $inner .= substr( $text, $startPos );
686 }
687 $startPos = $length;
688 return '-{' . $this->autoConvert( $inner, $variant );
689 }
690
691 /**
692 * If a language supports multiple variants, it is possible that
693 * non-existing link in one variant actually exists in another variant.
694 * This function tries to find it. See e.g. LanguageZh.php
695 *
696 * @param $link String: the name of the link
697 * @param $nt Mixed: the title object of the link
698 * @param $ignoreOtherCond Boolean: to disable other conditions when
699 * we need to transclude a template or update a category's link
700 * @return Null, the input parameters may be modified upon return
701 */
702 public function findVariantLink( &$link, &$nt, $ignoreOtherCond = false ) {
703 # If the article has already existed, there is no need to
704 # check it again, otherwise it may cause a fault.
705 if ( is_object( $nt ) && $nt->exists() ) {
706 return;
707 }
708
709 global $wgDisableLangConversion, $wgDisableTitleConversion, $wgRequest,
710 $wgUser;
711 $isredir = $wgRequest->getText( 'redirect', 'yes' );
712 $action = $wgRequest->getText( 'action' );
713 $linkconvert = $wgRequest->getText( 'linkconvert', 'yes' );
714 $disableLinkConversion = $wgDisableLangConversion
715 || $wgDisableTitleConversion;
716 $linkBatch = new LinkBatch();
717
718 $ns = NS_MAIN;
719
720 if ( $disableLinkConversion ||
721 ( !$ignoreOtherCond &&
722 ( $isredir == 'no'
723 || $action == 'edit'
724 || $action == 'submit'
725 || $linkconvert == 'no'
726 || $wgUser->getOption( 'noconvertlink' ) == 1 ) ) ) {
727 return;
728 }
729
730 if ( is_object( $nt ) ) {
731 $ns = $nt->getNamespace();
732 }
733
734 $variants = $this->autoConvertToAllVariants( $link );
735 if ( !$variants ) { // give up
736 return;
737 }
738
739 $titles = array();
740
741 foreach ( $variants as $v ) {
742 if ( $v != $link ) {
743 $varnt = Title::newFromText( $v, $ns );
744 if ( !is_null( $varnt ) ) {
745 $linkBatch->addObj( $varnt );
746 $titles[] = $varnt;
747 }
748 }
749 }
750
751 // fetch all variants in single query
752 $linkBatch->execute();
753
754 foreach ( $titles as $varnt ) {
755 if ( $varnt->getArticleID() > 0 ) {
756 $nt = $varnt;
757 $link = $varnt->getText();
758 break;
759 }
760 }
761 }
762
763 /**
764 * Returns language specific hash options.
765 */
766 public function getExtraHashOptions() {
767 $variant = $this->getPreferredVariant();
768 return '!' . $variant;
769 }
770
771 /**
772 * Load default conversion tables.
773 * This method must be implemented in derived class.
774 *
775 * @private
776 */
777 function loadDefaultTables() {
778 $name = get_class( $this );
779 wfDie( "Must implement loadDefaultTables() method in class $name" );
780 }
781
782 /**
783 * Load conversion tables either from the cache or the disk.
784 * @private
785 * @param $fromCache Boolean: load from memcached? Defaults to true.
786 */
787 function loadTables( $fromCache = true ) {
788 if ( $this->mTablesLoaded ) {
789 return;
790 }
791 global $wgMemc;
792 wfProfileIn( __METHOD__ );
793 $this->mTablesLoaded = true;
794 $this->mTables = false;
795 if ( $fromCache ) {
796 wfProfileIn( __METHOD__ . '-cache' );
797 $this->mTables = $wgMemc->get( $this->mCacheKey );
798 wfProfileOut( __METHOD__ . '-cache' );
799 }
800 if ( !$this->mTables
801 || !array_key_exists( self::CACHE_VERSION_KEY, $this->mTables ) ) {
802 wfProfileIn( __METHOD__ . '-recache' );
803 // not in cache, or we need a fresh reload.
804 // We will first load the default tables
805 // then update them using things in MediaWiki:Conversiontable/*
806 $this->loadDefaultTables();
807 foreach ( $this->mVariants as $var ) {
808 $cached = $this->parseCachedTable( $var );
809 $this->mTables[$var]->mergeArray( $cached );
810 }
811
812 $this->postLoadTables();
813 $this->mTables[self::CACHE_VERSION_KEY] = true;
814
815 $wgMemc->set( $this->mCacheKey, $this->mTables, 43200 );
816 wfProfileOut( __METHOD__ . '-recache' );
817 }
818 wfProfileOut( __METHOD__ );
819 }
820
821 /**
822 * Hook for post processing after conversion tables are loaded.
823 */
824 function postLoadTables() { }
825
826 /**
827 * Reload the conversion tables.
828 *
829 * @private
830 */
831 function reloadTables() {
832 if ( $this->mTables ) {
833 unset( $this->mTables );
834 }
835 $this->mTablesLoaded = false;
836 $this->loadTables( false );
837 }
838
839 /**
840 * Parse the conversion table stored in the cache.
841 *
842 * The tables should be in blocks of the following form:
843 * -{
844 * word => word ;
845 * word => word ;
846 * ...
847 * }-
848 *
849 * To make the tables more manageable, subpages are allowed
850 * and will be parsed recursively if $recursive == true.
851 *
852 * @param $code String: language code
853 * @param $subpage String: subpage name
854 * @param $recursive Boolean: parse subpages recursively? Defaults to true.
855 */
856 function parseCachedTable( $code, $subpage = '', $recursive = true ) {
857 static $parsed = array();
858
859 $key = 'Conversiontable/' . $code;
860 if ( $subpage ) {
861 $key .= '/' . $subpage;
862 }
863 if ( array_key_exists( $key, $parsed ) ) {
864 return array();
865 }
866
867 if ( strpos( $code, '/' ) === false ) {
868 $txt = MessageCache::singleton()->get( 'Conversiontable', true, $code );
869 if ( $txt === false ) {
870 # FIXME: this method doesn't seem to be expecting
871 # this possible outcome...
872 $txt = '&lt;Conversiontable&gt;';
873 }
874 } else {
875 $title = Title::makeTitleSafe(
876 NS_MEDIAWIKI,
877 "Conversiontable/$code"
878 );
879 if ( $title && $title->exists() ) {
880 $article = new Article( $title );
881 $txt = $article->getContents();
882 } else {
883 $txt = '';
884 }
885 }
886
887 // get all subpage links of the form
888 // [[MediaWiki:Conversiontable/zh-xx/...|...]]
889 $linkhead = $this->mLangObj->getNsText( NS_MEDIAWIKI ) .
890 ':Conversiontable';
891 $subs = StringUtils::explode( '[[', $txt );
892 $sublinks = array();
893 foreach ( $subs as $sub ) {
894 $link = explode( ']]', $sub, 2 );
895 if ( count( $link ) != 2 ) {
896 continue;
897 }
898 $b = explode( '|', $link[0], 2 );
899 $b = explode( '/', trim( $b[0] ), 3 );
900 if ( count( $b ) == 3 ) {
901 $sublink = $b[2];
902 } else {
903 $sublink = '';
904 }
905
906 if ( $b[0] == $linkhead && $b[1] == $code ) {
907 $sublinks[] = $sublink;
908 }
909 }
910
911 // parse the mappings in this page
912 $blocks = StringUtils::explode( '-{', $txt );
913 $ret = array();
914 $first = true;
915 foreach ( $blocks as $block ) {
916 if ( $first ) {
917 // Skip the part before the first -{
918 $first = false;
919 continue;
920 }
921 $mappings = explode( '}-', $block, 2 );
922 $stripped = str_replace( array( "'", '"', '*', '#' ), '',
923 $mappings[0] );
924 $table = StringUtils::explode( ';', $stripped );
925 foreach ( $table as $t ) {
926 $m = explode( '=>', $t, 3 );
927 if ( count( $m ) != 2 ) {
928 continue;
929 }
930 // trim any trailling comments starting with '//'
931 $tt = explode( '//', $m[1], 2 );
932 $ret[trim( $m[0] )] = trim( $tt[0] );
933 }
934 }
935 $parsed[$key] = true;
936
937 // recursively parse the subpages
938 if ( $recursive ) {
939 foreach ( $sublinks as $link ) {
940 $s = $this->parseCachedTable( $code, $link, $recursive );
941 $ret = array_merge( $ret, $s );
942 }
943 }
944
945 if ( $this->mUcfirst ) {
946 foreach ( $ret as $k => $v ) {
947 $ret[$this->mLangObj->ucfirst( $k )] = $this->mLangObj->ucfirst( $v );
948 }
949 }
950 return $ret;
951 }
952
953 /**
954 * Enclose a string with the "no conversion" tag. This is used by
955 * various functions in the Parser.
956 *
957 * @param $text String: text to be tagged for no conversion
958 * @param $noParse Boolean: unused
959 * @return String: the tagged text
960 */
961 public function markNoConversion( $text, $noParse = false ) {
962 # don't mark if already marked
963 if ( strpos( $text, '-{' ) || strpos( $text, '}-' ) ) {
964 return $text;
965 }
966
967 $ret = "-{R|$text}-";
968 return $ret;
969 }
970
971 /**
972 * Convert the sorting key for category links. This should make different
973 * keys that are variants of each other map to the same key.
974 */
975 function convertCategoryKey( $key ) {
976 return $key;
977 }
978
979 /**
980 * Hook to refresh the cache of conversion tables when
981 * MediaWiki:Conversiontable* is updated.
982 * @private
983 *
984 * @param $article Object: Article object
985 * @param $user Object: User object for the current user
986 * @param $text String: article text (?)
987 * @param $summary String: edit summary of the edit
988 * @param $isMinor Boolean: was the edit marked as minor?
989 * @param $isWatch Boolean: did the user watch this page or not?
990 * @param $section Unused
991 * @param $flags Bitfield
992 * @param $revision Object: new Revision object or null
993 * @return Boolean: true
994 */
995 function OnArticleSaveComplete( $article, $user, $text, $summary, $isMinor,
996 $isWatch, $section, $flags, $revision ) {
997 $titleobj = $article->getTitle();
998 if ( $titleobj->getNamespace() == NS_MEDIAWIKI ) {
999 $title = $titleobj->getDBkey();
1000 $t = explode( '/', $title, 3 );
1001 $c = count( $t );
1002 if ( $c > 1 && $t[0] == 'Conversiontable' ) {
1003 if ( $this->validateVariant( $t[1] ) ) {
1004 $this->reloadTables();
1005 }
1006 }
1007 }
1008 return true;
1009 }
1010
1011 /**
1012 * Armour rendered math against conversion.
1013 * Escape special chars in parsed math text. (in most cases are img elements)
1014 *
1015 * @param $text String: text to armour against conversion
1016 * @return String: armoured text where { and } have been converted to
1017 * &#123; and &#125;
1018 */
1019 public function armourMath( $text ) {
1020 // convert '-{' and '}-' to '-&#123;' and '&#125;-' to prevent
1021 // any unwanted markup appearing in the math image tag.
1022 $text = strtr( $text, array( '-{' => '-&#123;', '}-' => '&#125;-' ) );
1023 return $text;
1024 }
1025
1026 /**
1027 * Get the cached separator pattern for ConverterRule::parseRules()
1028 */
1029 function getVarSeparatorPattern() {
1030 if ( is_null( $this->mVarSeparatorPattern ) ) {
1031 // varsep_pattern for preg_split:
1032 // text should be splited by ";" only if a valid variant
1033 // name exist after the markup, for example:
1034 // -{zh-hans:<span style="font-size:120%;">xxx</span>;zh-hant:\
1035 // <span style="font-size:120%;">yyy</span>;}-
1036 // we should split it as:
1037 // array(
1038 // [0] => 'zh-hans:<span style="font-size:120%;">xxx</span>'
1039 // [1] => 'zh-hant:<span style="font-size:120%;">yyy</span>'
1040 // [2] => ''
1041 // )
1042 $pat = '/;\s*(?=';
1043 foreach ( $this->mVariants as $variant ) {
1044 // zh-hans:xxx;zh-hant:yyy
1045 $pat .= $variant . '\s*:|';
1046 // xxx=>zh-hans:yyy; xxx=>zh-hant:zzz
1047 $pat .= '[^;]*?=>\s*' . $variant . '\s*:|';
1048 }
1049 $pat .= '\s*$)/';
1050 $this->mVarSeparatorPattern = $pat;
1051 }
1052 return $this->mVarSeparatorPattern;
1053 }
1054 }
1055
1056 /**
1057 * Parser for rules of language conversion , parse rules in -{ }- tag.
1058 * @ingroup Language
1059 * @author fdcn <fdcn64@gmail.com>, PhiLiP <philip.npc@gmail.com>
1060 */
1061 class ConverterRule {
1062 var $mText; // original text in -{text}-
1063 var $mConverter; // LanguageConverter object
1064 var $mManualCodeError = '<strong class="error">code error!</strong>';
1065 var $mRuleDisplay = '';
1066 var $mRuleTitle = false;
1067 var $mRules = '';// string : the text of the rules
1068 var $mRulesAction = 'none';
1069 var $mFlags = array();
1070 var $mVariantFlags = array();
1071 var $mConvTable = array();
1072 var $mBidtable = array();// array of the translation in each variant
1073 var $mUnidtable = array();// array of the translation in each variant
1074
1075 /**
1076 * Constructor
1077 *
1078 * @param $text String: the text between -{ and }-
1079 * @param $converter LanguageConverter object
1080 */
1081 public function __construct( $text, $converter ) {
1082 $this->mText = $text;
1083 $this->mConverter = $converter;
1084 }
1085
1086 /**
1087 * Check if variants array in convert array.
1088 *
1089 * @param $variants Array or string: variant language code
1090 * @return String: translated text
1091 */
1092 public function getTextInBidtable( $variants ) {
1093 $variants = (array)$variants;
1094 if ( !$variants ) {
1095 return false;
1096 }
1097 foreach ( $variants as $variant ) {
1098 if ( isset( $this->mBidtable[$variant] ) ) {
1099 return $this->mBidtable[$variant];
1100 }
1101 }
1102 return false;
1103 }
1104
1105 /**
1106 * Parse flags with syntax -{FLAG| ... }-
1107 * @private
1108 */
1109 function parseFlags() {
1110 $text = $this->mText;
1111 $flags = array();
1112 $variantFlags = array();
1113
1114 $sepPos = strpos( $text, '|' );
1115 if ( $sepPos !== false ) {
1116 $validFlags = $this->mConverter->mFlags;
1117 $f = StringUtils::explode( ';', substr( $text, 0, $sepPos ) );
1118 foreach ( $f as $ff ) {
1119 $ff = trim( $ff );
1120 if ( isset( $validFlags[$ff] ) ) {
1121 $flags[$validFlags[$ff]] = true;
1122 }
1123 }
1124 $text = strval( substr( $text, $sepPos + 1 ) );
1125 }
1126
1127 if ( !$flags ) {
1128 $flags['S'] = true;
1129 } elseif ( isset( $flags['R'] ) ) {
1130 $flags = array( 'R' => true );// remove other flags
1131 } elseif ( isset( $flags['N'] ) ) {
1132 $flags = array( 'N' => true );// remove other flags
1133 } elseif ( isset( $flags['-'] ) ) {
1134 $flags = array( '-' => true );// remove other flags
1135 } elseif ( count( $flags ) == 1 && isset( $flags['T'] ) ) {
1136 $flags['H'] = true;
1137 } elseif ( isset( $flags['H'] ) ) {
1138 // replace A flag, and remove other flags except T
1139 $temp = array( '+' => true, 'H' => true );
1140 if ( isset( $flags['T'] ) ) {
1141 $temp['T'] = true;
1142 }
1143 if ( isset( $flags['D'] ) ) {
1144 $temp['D'] = true;
1145 }
1146 $flags = $temp;
1147 } else {
1148 if ( isset( $flags['A'] ) ) {
1149 $flags['+'] = true;
1150 $flags['S'] = true;
1151 }
1152 if ( isset( $flags['D'] ) ) {
1153 unset( $flags['S'] );
1154 }
1155 // try to find flags like "zh-hans", "zh-hant"
1156 // allow syntaxes like "-{zh-hans;zh-hant|XXXX}-"
1157 $variantFlags = array_intersect( array_keys( $flags ), $this->mConverter->mVariants );
1158 if ( $variantFlags ) {
1159 $variantFlags = array_flip( $variantFlags );
1160 $flags = array();
1161 }
1162 }
1163 $this->mVariantFlags = $variantFlags;
1164 $this->mRules = $text;
1165 $this->mFlags = $flags;
1166 }
1167
1168 /**
1169 * Generate conversion table.
1170 * @private
1171 */
1172 function parseRules() {
1173 $rules = $this->mRules;
1174 $bidtable = array();
1175 $unidtable = array();
1176 $variants = $this->mConverter->mVariants;
1177 $varsep_pattern = $this->mConverter->getVarSeparatorPattern();
1178
1179 $choice = preg_split( $varsep_pattern, $rules );
1180
1181 foreach ( $choice as $c ) {
1182 $v = explode( ':', $c, 2 );
1183 if ( count( $v ) != 2 ) {
1184 // syntax error, skip
1185 continue;
1186 }
1187 $to = trim( $v[1] );
1188 $v = trim( $v[0] );
1189 $u = explode( '=>', $v, 2 );
1190 // if $to is empty, strtr() could return a wrong result
1191 if ( count( $u ) == 1 && $to && in_array( $v, $variants ) ) {
1192 $bidtable[$v] = $to;
1193 } elseif ( count( $u ) == 2 ) {
1194 $from = trim( $u[0] );
1195 $v = trim( $u[1] );
1196 if ( array_key_exists( $v, $unidtable )
1197 && !is_array( $unidtable[$v] )
1198 && $to
1199 && in_array( $v, $variants ) ) {
1200 $unidtable[$v] = array( $from => $to );
1201 } elseif ( $to && in_array( $v, $variants ) ) {
1202 $unidtable[$v][$from] = $to;
1203 }
1204 }
1205 // syntax error, pass
1206 if ( !isset( $this->mConverter->mVariantNames[$v] ) ) {
1207 $bidtable = array();
1208 $unidtable = array();
1209 break;
1210 }
1211 }
1212 $this->mBidtable = $bidtable;
1213 $this->mUnidtable = $unidtable;
1214 }
1215
1216 /**
1217 * @private
1218 */
1219 function getRulesDesc() {
1220 $codesep = $this->mConverter->mDescCodeSep;
1221 $varsep = $this->mConverter->mDescVarSep;
1222 $text = '';
1223 foreach ( $this->mBidtable as $k => $v ) {
1224 $text .= $this->mConverter->mVariantNames[$k] . "$codesep$v$varsep";
1225 }
1226 foreach ( $this->mUnidtable as $k => $a ) {
1227 foreach ( $a as $from => $to ) {
1228 $text .= $from . '⇒' . $this->mConverter->mVariantNames[$k] .
1229 "$codesep$to$varsep";
1230 }
1231 }
1232 return $text;
1233 }
1234
1235 /**
1236 * Parse rules conversion.
1237 * @private
1238 */
1239 function getRuleConvertedStr( $variant ) {
1240 $bidtable = $this->mBidtable;
1241 $unidtable = $this->mUnidtable;
1242
1243 if ( count( $bidtable ) + count( $unidtable ) == 0 ) {
1244 return $this->mRules;
1245 } else {
1246 // display current variant in bidirectional array
1247 $disp = $this->getTextInBidtable( $variant );
1248 // or display current variant in fallbacks
1249 if ( !$disp ) {
1250 $disp = $this->getTextInBidtable(
1251 $this->mConverter->getVariantFallbacks( $variant ) );
1252 }
1253 // or display current variant in unidirectional array
1254 if ( !$disp && array_key_exists( $variant, $unidtable ) ) {
1255 $disp = array_values( $unidtable[$variant] );
1256 $disp = $disp[0];
1257 }
1258 // or display frist text under disable manual convert
1259 if ( !$disp
1260 && $this->mConverter->mManualLevel[$variant] == 'disable' ) {
1261 if ( count( $bidtable ) > 0 ) {
1262 $disp = array_values( $bidtable );
1263 $disp = $disp[0];
1264 } else {
1265 $disp = array_values( $unidtable );
1266 $disp = array_values( $disp[0] );
1267 $disp = $disp[0];
1268 }
1269 }
1270 return $disp;
1271 }
1272 }
1273
1274 /**
1275 * Generate conversion table for all text.
1276 * @private
1277 */
1278 function generateConvTable() {
1279 // Special case optimisation
1280 if ( !$this->mBidtable && !$this->mUnidtable ) {
1281 $this->mConvTable = array();
1282 return;
1283 }
1284
1285 $bidtable = $this->mBidtable;
1286 $unidtable = $this->mUnidtable;
1287 $manLevel = $this->mConverter->mManualLevel;
1288
1289 $vmarked = array();
1290 foreach ( $this->mConverter->mVariants as $v ) {
1291 /* for bidirectional array
1292 fill in the missing variants, if any,
1293 with fallbacks */
1294 if ( !isset( $bidtable[$v] ) ) {
1295 $variantFallbacks =
1296 $this->mConverter->getVariantFallbacks( $v );
1297 $vf = $this->getTextInBidtable( $variantFallbacks );
1298 if ( $vf ) {
1299 $bidtable[$v] = $vf;
1300 }
1301 }
1302
1303 if ( isset( $bidtable[$v] ) ) {
1304 foreach ( $vmarked as $vo ) {
1305 // use syntax: -{A|zh:WordZh;zh-tw:WordTw}-
1306 // or -{H|zh:WordZh;zh-tw:WordTw}-
1307 // or -{-|zh:WordZh;zh-tw:WordTw}-
1308 // to introduce a custom mapping between
1309 // words WordZh and WordTw in the whole text
1310 if ( $manLevel[$v] == 'bidirectional' ) {
1311 $this->mConvTable[$v][$bidtable[$vo]] = $bidtable[$v];
1312 }
1313 if ( $manLevel[$vo] == 'bidirectional' ) {
1314 $this->mConvTable[$vo][$bidtable[$v]] = $bidtable[$vo];
1315 }
1316 }
1317 $vmarked[] = $v;
1318 }
1319 /* for unidirectional array fill to convert tables */
1320 if ( ( $manLevel[$v] == 'bidirectional' || $manLevel[$v] == 'unidirectional' )
1321 && isset( $unidtable[$v] ) )
1322 {
1323 if ( isset( $this->mConvTable[$v] ) ) {
1324 $this->mConvTable[$v] = array_merge( $this->mConvTable[$v], $unidtable[$v] );
1325 } else {
1326 $this->mConvTable[$v] = $unidtable[$v];
1327 }
1328 }
1329 }
1330 }
1331
1332 /**
1333 * Parse rules and flags.
1334 * @param $variant String: variant language code
1335 */
1336 public function parse( $variant = null ) {
1337 if ( !$variant ) {
1338 $variant = $this->mConverter->getPreferredVariant();
1339 }
1340
1341 $this->parseFlags();
1342 $flags = $this->mFlags;
1343
1344 // convert to specified variant
1345 // syntax: -{zh-hans;zh-hant[;...]|<text to convert>}-
1346 if ( $this->mVariantFlags ) {
1347 // check if current variant in flags
1348 if ( isset( $this->mVariantFlags[$variant] ) ) {
1349 // then convert <text to convert> to current language
1350 $this->mRules = $this->mConverter->autoConvert( $this->mRules,
1351 $variant );
1352 } else { // if current variant no in flags,
1353 // then we check its fallback variants.
1354 $variantFallbacks =
1355 $this->mConverter->getVariantFallbacks( $variant );
1356 foreach ( $variantFallbacks as $variantFallback ) {
1357 // if current variant's fallback exist in flags
1358 if ( isset( $this->mVariantFlags[$variantFallback] ) ) {
1359 // then convert <text to convert> to fallback language
1360 $this->mRules =
1361 $this->mConverter->autoConvert( $this->mRules,
1362 $variantFallback );
1363 break;
1364 }
1365 }
1366 }
1367 $this->mFlags = $flags = array( 'R' => true );
1368 }
1369
1370 if ( !isset( $flags['R'] ) && !isset( $flags['N'] ) ) {
1371 // decode => HTML entities modified by Sanitizer::removeHTMLtags
1372 $this->mRules = str_replace( '=&gt;', '=>', $this->mRules );
1373 $this->parseRules();
1374 }
1375 $rules = $this->mRules;
1376
1377 if ( !$this->mBidtable && !$this->mUnidtable ) {
1378 if ( isset( $flags['+'] ) || isset( $flags['-'] ) ) {
1379 // fill all variants if text in -{A/H/-|text} without rules
1380 foreach ( $this->mConverter->mVariants as $v ) {
1381 $this->mBidtable[$v] = $rules;
1382 }
1383 } elseif ( !isset( $flags['N'] ) && !isset( $flags['T'] ) ) {
1384 $this->mFlags = $flags = array( 'R' => true );
1385 }
1386 }
1387
1388 $this->mRuleDisplay = false;
1389 foreach ( $flags as $flag => $unused ) {
1390 switch ( $flag ) {
1391 case 'R':
1392 // if we don't do content convert, still strip the -{}- tags
1393 $this->mRuleDisplay = $rules;
1394 break;
1395 case 'N':
1396 // process N flag: output current variant name
1397 $ruleVar = trim( $rules );
1398 if ( isset( $this->mConverter->mVariantNames[$ruleVar] ) ) {
1399 $this->mRuleDisplay = $this->mConverter->mVariantNames[$ruleVar];
1400 } else {
1401 $this->mRuleDisplay = '';
1402 }
1403 break;
1404 case 'D':
1405 // process D flag: output rules description
1406 $this->mRuleDisplay = $this->getRulesDesc();
1407 break;
1408 case 'H':
1409 // process H,- flag or T only: output nothing
1410 $this->mRuleDisplay = '';
1411 break;
1412 case '-':
1413 $this->mRulesAction = 'remove';
1414 $this->mRuleDisplay = '';
1415 break;
1416 case '+':
1417 $this->mRulesAction = 'add';
1418 $this->mRuleDisplay = '';
1419 break;
1420 case 'S':
1421 $this->mRuleDisplay = $this->getRuleConvertedStr( $variant );
1422 break;
1423 case 'T':
1424 $this->mRuleTitle = $this->getRuleConvertedStr( $variant );
1425 $this->mRuleDisplay = '';
1426 break;
1427 default:
1428 // ignore unknown flags (but see error case below)
1429 }
1430 }
1431 if ( $this->mRuleDisplay === false ) {
1432 $this->mRuleDisplay = $this->mManualCodeError;
1433 }
1434
1435 $this->generateConvTable();
1436 }
1437
1438 /**
1439 * @todo FIXME: code this function :)
1440 */
1441 public function hasRules() {
1442 // TODO:
1443 }
1444
1445 /**
1446 * Get display text on markup -{...}-
1447 */
1448 public function getDisplay() {
1449 return $this->mRuleDisplay;
1450 }
1451
1452 /**
1453 * Get converted title.
1454 */
1455 public function getTitle() {
1456 return $this->mRuleTitle;
1457 }
1458
1459 /**
1460 * Return how deal with conversion rules.
1461 */
1462 public function getRulesAction() {
1463 return $this->mRulesAction;
1464 }
1465
1466 /**
1467 * Get conversion table. (bidirectional and unidirectional
1468 * conversion table)
1469 */
1470 public function getConvTable() {
1471 return $this->mConvTable;
1472 }
1473
1474 /**
1475 * Get conversion rules string.
1476 */
1477 public function getRules() {
1478 return $this->mRules;
1479 }
1480
1481 /**
1482 * Get conversion flags.
1483 */
1484 public function getFlags() {
1485 return $this->mFlags;
1486 }
1487 }