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