Use Doxygen @addtogroup instead of phpdoc @package && @subpackage
[lhc/web/wiklou.git] / languages / LanguageConverter.php
1 <?php
2 /**
3 * @addtogroup Language
4 *
5 * @author Zhengzhu Feng <zhengzhu@gmail.com>
6 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
7 */
8
9 class LanguageConverter {
10 var $mPreferredVariant='';
11 var $mMainLanguageCode;
12 var $mVariants, $mVariantFallbacks;
13 var $mTablesLoaded = false;
14 var $mTables;
15 var $mTitleDisplay='';
16 var $mDoTitleConvert=true, $mDoContentConvert=true;
17 var $mTitleFromFlag = false;
18 var $mCacheKey;
19 var $mLangObj;
20 var $mMarkup;
21 var $mFlags;
22 var $mUcfirst = false;
23 /**
24 * Constructor
25 *
26 * @param string $maincode the main language code of this language
27 * @param array $variants the supported variants of this language
28 * @param array $variantfallback the fallback language of each variant
29 * @param array $markup array defining the markup used for manual conversion
30 * @param array $flags array defining the custom strings that maps to the flags
31 * @access public
32 */
33 function __construct($langobj, $maincode,
34 $variants=array(),
35 $variantfallbacks=array(),
36 $markup=array(),
37 $flags = array()) {
38 $this->mLangObj = $langobj;
39 $this->mMainLanguageCode = $maincode;
40 $this->mVariants = $variants;
41 $this->mVariantFallbacks = $variantfallbacks;
42 $this->mCacheKey = wfMemcKey( 'conversiontables', $maincode );
43 $m = array('begin'=>'-{', 'flagsep'=>'|', 'codesep'=>':',
44 'varsep'=>';', 'end'=>'}-');
45 $this->mMarkup = array_merge($m, $markup);
46 $f = array('A'=>'A', 'T'=>'T', 'R' => 'R');
47 $this->mFlags = array_merge($f, $flags);
48 }
49
50 /**
51 * @access public
52 */
53 function getVariants() {
54 return $this->mVariants;
55 }
56
57 /**
58 * in case some variant is not defined in the markup, we need
59 * to have some fallback. for example, in zh, normally people
60 * will define zh-cn and zh-tw, but less so for zh-sg or zh-hk.
61 * when zh-sg is preferred but not defined, we will pick zh-cn
62 * in this case. right now this is only used by zh.
63 *
64 * @param string $v the language code of the variant
65 * @return string the code of the fallback language or false if there is no fallback
66 * @private
67 */
68 function getVariantFallback($v) {
69 return $this->mVariantFallbacks[$v];
70 }
71
72
73 /**
74 * get preferred language variants.
75 * @param boolean $fromUser Get it from $wgUser's preferences
76 * @return string the preferred language code
77 * @access public
78 */
79 function getPreferredVariant( $fromUser = true ) {
80 global $wgUser, $wgRequest, $wgVariantArticlePath, $wgDefaultLanguageVariant;
81
82 if($this->mPreferredVariant)
83 return $this->mPreferredVariant;
84
85 // see if the preference is set in the request
86 $req = $wgRequest->getText( 'variant' );
87 if( in_array( $req, $this->mVariants ) ) {
88 $this->mPreferredVariant = $req;
89 return $req;
90 }
91
92 // check the syntax /code/ArticleTitle
93 if($wgVariantArticlePath!=false && isset($_SERVER['SCRIPT_NAME'])){
94 // Note: SCRIPT_NAME probably won't hold the correct value if PHP is run as CGI
95 // (it will hold path to php.cgi binary), and might not exist on some very old PHP installations
96 $scriptBase = basename( $_SERVER['SCRIPT_NAME'] );
97 if(in_array($scriptBase,$this->mVariants)){
98 $this->mPreferredVariant = $scriptBase;
99 return $this->mPreferredVariant;
100 }
101 }
102
103 // get language variant preference from logged in users
104 // Don't call this on stub objects because that causes infinite
105 // recursion during initialisation
106 if( $fromUser && $wgUser->isLoggedIn() ) {
107 $this->mPreferredVariant = $wgUser->getOption('variant');
108 return $this->mPreferredVariant;
109 }
110
111 // see if default variant is globaly set
112 if($wgDefaultLanguageVariant != false && in_array( $wgDefaultLanguageVariant, $this->mVariants )){
113 $this->mPreferredVariant = $wgDefaultLanguageVariant;
114 return $this->mPreferredVariant;
115 }
116
117 # FIXME rewrite code for parsing http header. The current code
118 # is written specific for detecting zh- variants
119 if( !$this->mPreferredVariant ) {
120 // see if some supported language variant is set in the
121 // http header, but we don't set the mPreferredVariant
122 // variable in case this is called before the user's
123 // preference is loaded
124 $pv=$this->mMainLanguageCode;
125 if(array_key_exists('HTTP_ACCEPT_LANGUAGE', $_SERVER)) {
126 $header = str_replace( '_', '-', strtolower($_SERVER["HTTP_ACCEPT_LANGUAGE"]));
127 $zh = strstr($header, $pv.'-');
128 if($zh) {
129 $pv = substr($zh,0,5);
130 }
131 }
132 // don't try to return bad variant
133 if(in_array( $pv, $this->mVariants ))
134 return $pv;
135 }
136
137 return $this->mMainLanguageCode;
138
139 }
140
141 /**
142 * dictionary-based conversion
143 *
144 * @param string $text the text to be converted
145 * @param string $toVariant the target language code
146 * @return string the converted text
147 * @private
148 */
149 function autoConvert($text, $toVariant=false) {
150 $fname="LanguageConverter::autoConvert";
151
152 wfProfileIn( $fname );
153
154 if(!$this->mTablesLoaded)
155 $this->loadTables();
156
157 if(!$toVariant)
158 $toVariant = $this->getPreferredVariant();
159 if(!in_array($toVariant, $this->mVariants))
160 return $text;
161
162 /* we convert everything except:
163 1. html markups (anything between < and >)
164 2. html entities
165 3. place holders created by the parser
166 */
167 global $wgParser;
168 if (isset($wgParser))
169 $marker = '|' . $wgParser->UniqPrefix() . '[\-a-zA-Z0-9]+';
170 else
171 $marker = "";
172
173 // this one is needed when the text is inside an html markup
174 $htmlfix = '|<[^>]+$|^[^<>]*>';
175
176 // disable convert to variants between <code></code> tags
177 $codefix = '<code>.+?<\/code>|';
178 // disable convertsion of <script type="text/javascript"> ... </script>
179 $scriptfix = '<script.*?>.*?<\/script>|';
180
181 $reg = '/'.$codefix . $scriptfix . '<[^>]+>|&[a-zA-Z#][a-z0-9]+;' . $marker . $htmlfix . '/s';
182
183 $matches = preg_split($reg, $text, -1, PREG_SPLIT_OFFSET_CAPTURE);
184
185 $m = array_shift($matches);
186
187 $ret = $this->translate($m[0], $toVariant);
188 $mstart = $m[1]+strlen($m[0]);
189 foreach($matches as $m) {
190 $ret .= substr($text, $mstart, $m[1]-$mstart);
191 $ret .= $this->translate($m[0], $toVariant);
192 $mstart = $m[1] + strlen($m[0]);
193 }
194 wfProfileOut( $fname );
195 return $ret;
196 }
197
198 /**
199 * Translate a string to a variant
200 * Doesn't process markup or do any of that other stuff, for that use convert()
201 *
202 * @param string $text Text to convert
203 * @param string $variant Variant language code
204 * @return string Translated text
205 */
206 function translate( $text, $variant ) {
207 wfProfileIn( __METHOD__ );
208 if( !$this->mTablesLoaded )
209 $this->loadTables();
210 $text = $this->mTables[$variant]->replace( $text );
211 wfProfileOut( __METHOD__ );
212 return $text;
213 }
214
215 /**
216 * convert text to all supported variants
217 *
218 * @param string $text the text to be converted
219 * @return array of string
220 * @public
221 */
222 function autoConvertToAllVariants($text) {
223 $fname="LanguageConverter::autoConvertToAllVariants";
224 wfProfileIn( $fname );
225 if( !$this->mTablesLoaded )
226 $this->loadTables();
227
228 $ret = array();
229 foreach($this->mVariants as $variant) {
230 $ret[$variant] = $this->translate($text, $variant);
231 }
232
233 wfProfileOut( $fname );
234 return $ret;
235 }
236
237 /**
238 * convert link text to all supported variants
239 *
240 * @param string $text the text to be converted
241 * @return array of string
242 * @public
243 */
244 function convertLinkToAllVariants($text) {
245 if( !$this->mTablesLoaded )
246 $this->loadTables();
247
248 $ret = array();
249 $tarray = explode($this->mMarkup['begin'], $text);
250 $tfirst = array_shift($tarray);
251
252 foreach($this->mVariants as $variant)
253 $ret[$variant] = $this->translate($tfirst,$variant);
254
255 foreach($tarray as $txt) {
256 $marked = explode($this->mMarkup['end'], $txt, 2);
257
258 foreach($this->mVariants as $variant){
259 $ret[$variant] .= $this->mMarkup['begin'].$marked[0].$this->mMarkup['end'];
260 if(array_key_exists(1, $marked))
261 $ret[$variant] .= $this->translate($marked[1],$variant);
262 }
263
264 }
265
266 return $ret;
267 }
268
269
270 /**
271 * Convert text using a parser object for context
272 */
273 function parserConvert( $text, &$parser ) {
274 global $wgDisableLangConversion;
275 /* don't do anything if this is the conversion table */
276 if ( $parser->getTitle()->getNamespace() == NS_MEDIAWIKI &&
277 strpos($parser->mTitle->getText(), "Conversiontable") !== false )
278 {
279 return $text;
280 }
281
282 if($wgDisableLangConversion)
283 return $text;
284
285 $text = $this->convert( $text );
286 $parser->mOutput->setTitleText( $this->mTitleDisplay );
287 return $text;
288 }
289
290 /**
291 * Parse flags with syntax -{FLAG| ... }-
292 *
293 */
294 function parseFlags($marked){
295 $flags = array();
296
297 // process flag only if the flag is valid
298 if(strlen($marked) < 2 || !(in_array($marked[0],$this->mFlags) && $marked[1]=='|' ) )
299 return array($marked,array());
300
301 $tt = explode($this->mMarkup['flagsep'], $marked, 2);
302
303 if(sizeof($tt) == 2) {
304 $f = explode($this->mMarkup['varsep'], $tt[0]);
305 foreach($f as $ff) {
306 $ff = trim($ff);
307 if(array_key_exists($ff, $this->mFlags) &&
308 !array_key_exists($this->mFlags[$ff], $flags))
309 $flags[] = $this->mFlags[$ff];
310 }
311 $rules = $tt[1];
312 }
313 else
314 $rules = $marked;
315
316 if( !in_array('R',$flags) ){
317 //FIXME: may cause trouble here...
318 //strip &nbsp; since it interferes with the parsing, plus,
319 //all spaces should be stripped in this tag anyway.
320 $rules = str_replace('&nbsp;', '', $rules);
321 }
322
323 return array($rules,$flags);
324 }
325
326 /**
327 * convert text to different variants of a language. the automatic
328 * conversion is done in autoConvert(). here we parse the text
329 * marked with -{}-, which specifies special conversions of the
330 * text that can not be accomplished in autoConvert()
331 *
332 * syntax of the markup:
333 * -{code1:text1;code2:text2;...}- or
334 * -{text}- in which case no conversion should take place for text
335 *
336 * @param string $text text to be converted
337 * @param bool $isTitle whether this conversion is for the article title
338 * @return string converted text
339 * @access public
340 */
341 function convert( $text , $isTitle=false) {
342 $mw =& MagicWord::get( 'notitleconvert' );
343 if( $mw->matchAndRemove( $text ) )
344 $this->mDoTitleConvert = false;
345
346 $mw =& MagicWord::get( 'nocontentconvert' );
347 if( $mw->matchAndRemove( $text ) ) {
348 $this->mDoContentConvert = false;
349 }
350
351 // no conversion if redirecting
352 $mw =& MagicWord::get( 'redirect' );
353 if( $mw->matchStart( $text ))
354 return $text;
355
356 if( $isTitle ) {
357
358 // use the title from the T flag if any
359 if($this->mTitleFromFlag){
360 $this->mTitleFromFlag = false;
361 return $this->mTitleDisplay;
362 }
363
364 // check for __NOTC__ tag
365 if( !$this->mDoTitleConvert ) {
366 $this->mTitleDisplay = $text;
367 return $text;
368 }
369
370 global $wgRequest;
371 $isredir = $wgRequest->getText( 'redirect', 'yes' );
372 $action = $wgRequest->getText( 'action' );
373 if ( $isredir == 'no' || $action == 'edit' ) {
374 return $text;
375 }
376 else {
377 $this->mTitleDisplay = $this->convert($text);
378 return $this->mTitleDisplay;
379 }
380 }
381
382 $plang = $this->getPreferredVariant();
383 if( isset( $this->mVariantFallbacks[$plang] ) ) {
384 $fallback = $this->mVariantFallbacks[$plang];
385 } else {
386 $fallback = $this->mMainLanguageCode;
387 }
388
389 $tarray = explode($this->mMarkup['begin'], $text);
390 $tfirst = array_shift($tarray);
391 if($this->mDoContentConvert)
392 $text = $this->autoConvert($tfirst);
393 else
394 $text = $tfirst;
395 foreach($tarray as $txt) {
396 $marked = explode($this->mMarkup['end'], $txt, 2);
397
398 // strip the flags from syntax like -{T| ... }-
399 list($rules,$flags) = $this->parseFlags($marked[0]);
400
401 // proces R flag: output raw content of -{ ... }-
402 if( in_array('R',$flags) ){
403 $disp = $rules;
404 } else if( $this->mDoContentConvert){
405 // parse the contents -{ ... }-
406 $carray = $this->parseManualRule($rules, $flags);
407
408 $disp = '';
409 if(array_key_exists($plang, $carray)) {
410 $disp = $carray[$plang];
411 } else if(array_key_exists($fallback, $carray)) {
412 $disp = $carray[$fallback];
413 }
414 } else{
415 // if we don't do content convert, still strip the -{}- tags
416 $disp = $rules;
417 $flags = array();
418 }
419
420 if($disp) {
421 // use syntax -{T|zh:TitleZh;zh-tw:TitleTw}- for custom conversion in title
422 if(in_array('T', $flags)){
423 $this->mTitleFromFlag = true;
424 $this->mTitleDisplay = $disp;
425 }
426 else
427 $text .= $disp;
428
429 // use syntax -{A|zh:WordZh;zh-tw:WordTw}- to introduce a custom mapping between
430 // words WordZh and WordTw in the whole text
431 if(in_array('A', $flags)) {
432
433 /* fill in the missing variants, if any,
434 with fallbacks */
435 foreach($this->mVariants as $v) {
436 if(!array_key_exists($v, $carray)) {
437 $vf = $this->getVariantFallback($v);
438 if(array_key_exists($vf, $carray))
439 $carray[$v] = $carray[$vf];
440 }
441 }
442
443 foreach($this->mVariants as $vfrom) {
444 if(!array_key_exists($vfrom, $carray))
445 continue;
446 foreach($this->mVariants as $vto) {
447 if($vfrom == $vto)
448 continue;
449 if(!array_key_exists($vto, $carray))
450 continue;
451 $this->mTables[$vto]->setPair($carray[$vfrom], $carray[$vto]);
452 }
453 }
454 }
455 }
456 else {
457 $text .= $marked[0];
458 }
459 if(array_key_exists(1, $marked)){
460 if( $this->mDoContentConvert )
461 $text .= $this->autoConvert($marked[1]);
462 else
463 $text .= $marked[1];
464 }
465 }
466
467 return $text;
468 }
469
470 /**
471 * parse the manually marked conversion rule
472 * @param string $rule the text of the rule
473 * @return array of the translation in each variant
474 * @private
475 */
476 function parseManualRule($rules, $flags=array()) {
477
478 $choice = explode($this->mMarkup['varsep'], $rules);
479 $carray = array();
480 if(sizeof($choice) == 1) {
481 /* a single choice */
482 foreach($this->mVariants as $v)
483 $carray[$v] = $choice[0];
484 }
485 else {
486 foreach($choice as $c) {
487 $v = explode($this->mMarkup['codesep'], $c);
488 if(sizeof($v) != 2) // syntax error, skip
489 continue;
490 $carray[trim($v[0])] = trim($v[1]);
491 }
492 }
493 return $carray;
494 }
495
496 /**
497 * if a language supports multiple variants, it is
498 * possible that non-existing link in one variant
499 * actually exists in another variant. this function
500 * tries to find it. See e.g. LanguageZh.php
501 *
502 * @param string $link the name of the link
503 * @param mixed $nt the title object of the link
504 * @return null the input parameters may be modified upon return
505 * @access public
506 */
507 function findVariantLink( &$link, &$nt ) {
508 global $wgDisableLangConversion;
509 $linkBatch = new LinkBatch();
510
511 $ns=NS_MAIN;
512
513 if(is_object($nt))
514 $ns = $nt->getNamespace();
515
516 $variants = $this->autoConvertToAllVariants($link);
517 if($variants == false) //give up
518 return;
519
520 $titles = array();
521
522 foreach( $variants as $v ) {
523 if($v != $link){
524 $varnt = Title::newFromText( $v, $ns );
525 if(!is_null($varnt)){
526 $linkBatch->addObj($varnt);
527 $titles[]=$varnt;
528 }
529 }
530 }
531
532 // fetch all variants in single query
533 $linkBatch->execute();
534
535 foreach( $titles as $varnt ) {
536 if( $varnt->getArticleID() > 0 ) {
537 $nt = $varnt;
538 if( !$wgDisableLangConversion )
539 $link = $v;
540 break;
541 }
542 }
543 }
544
545 /**
546 * returns language specific hash options
547 *
548 * @access public
549 */
550 function getExtraHashOptions() {
551 $variant = $this->getPreferredVariant();
552 return '!' . $variant ;
553 }
554
555 /**
556 * get title text as defined in the body of the article text
557 *
558 * @access public
559 */
560 function getParsedTitle() {
561 return $this->mTitleDisplay;
562 }
563
564 /**
565 * a write lock to the cache
566 *
567 * @private
568 */
569 function lockCache() {
570 global $wgMemc;
571 $success = false;
572 for($i=0; $i<30; $i++) {
573 if($success = $wgMemc->add($this->mCacheKey . "lock", 1, 10))
574 break;
575 sleep(1);
576 }
577 return $success;
578 }
579
580 /**
581 * unlock cache
582 *
583 * @private
584 */
585 function unlockCache() {
586 global $wgMemc;
587 $wgMemc->delete($this->mCacheKey . "lock");
588 }
589
590
591 /**
592 * Load default conversion tables
593 * This method must be implemented in derived class
594 *
595 * @private
596 */
597 function loadDefaultTables() {
598 $name = get_class($this);
599 wfDie("Must implement loadDefaultTables() method in class $name");
600 }
601
602 /**
603 * load conversion tables either from the cache or the disk
604 * @private
605 */
606 function loadTables($fromcache=true) {
607 global $wgMemc;
608 if( $this->mTablesLoaded )
609 return;
610 wfProfileIn( __METHOD__ );
611 $this->mTablesLoaded = true;
612 $this->mTables = false;
613 if($fromcache) {
614 wfProfileIn( __METHOD__.'-cache' );
615 $this->mTables = $wgMemc->get( $this->mCacheKey );
616 wfProfileOut( __METHOD__.'-cache' );
617 }
618 if ( !$this->mTables || !isset( $this->mTables['VERSION 2'] ) ) {
619 wfProfileIn( __METHOD__.'-recache' );
620 // not in cache, or we need a fresh reload.
621 // we will first load the default tables
622 // then update them using things in MediaWiki:Zhconversiontable/*
623 $this->loadDefaultTables();
624 foreach($this->mVariants as $var) {
625 $cached = $this->parseCachedTable($var);
626 $this->mTables[$var]->mergeArray($cached);
627 }
628
629 $this->postLoadTables();
630 $this->mTables['VERSION 2'] = true;
631
632 if($this->lockCache()) {
633 $wgMemc->set($this->mCacheKey, $this->mTables, 43200);
634 $this->unlockCache();
635 }
636 wfProfileOut( __METHOD__.'-recache' );
637 }
638 wfProfileOut( __METHOD__ );
639 }
640
641 /**
642 * Hook for post processig after conversion tables are loaded
643 *
644 */
645 function postLoadTables() {}
646
647 /**
648 * Reload the conversion tables
649 *
650 * @private
651 */
652 function reloadTables() {
653 if($this->mTables)
654 unset($this->mTables);
655 $this->mTablesLoaded = false;
656 $this->loadTables(false);
657 }
658
659
660 /**
661 * parse the conversion table stored in the cache
662 *
663 * the tables should be in blocks of the following form:
664
665 * -{
666 * word => word ;
667 * word => word ;
668 * ...
669 * }-
670 *
671 * to make the tables more manageable, subpages are allowed
672 * and will be parsed recursively if $recursive=true
673 *
674 * @private
675 */
676 function parseCachedTable($code, $subpage='', $recursive=true) {
677 global $wgMessageCache;
678 static $parsed = array();
679
680 if(!is_object($wgMessageCache))
681 return array();
682
683 $key = 'Conversiontable/'.$code;
684 if($subpage)
685 $key .= '/' . $subpage;
686
687 if(array_key_exists($key, $parsed))
688 return array();
689
690
691 $txt = $wgMessageCache->get( $key, true, true, true );
692
693 // get all subpage links of the form
694 // [[MediaWiki:conversiontable/zh-xx/...|...]]
695 $linkhead = $this->mLangObj->getNsText(NS_MEDIAWIKI) . ':Conversiontable';
696 $subs = explode('[[', $txt);
697 $sublinks = array();
698 foreach( $subs as $sub ) {
699 $link = explode(']]', $sub, 2);
700 if(count($link) != 2)
701 continue;
702 $b = explode('|', $link[0]);
703 $b = explode('/', trim($b[0]), 3);
704 if(count($b)==3)
705 $sublink = $b[2];
706 else
707 $sublink = '';
708
709 if($b[0] == $linkhead && $b[1] == $code) {
710 $sublinks[] = $sublink;
711 }
712 }
713
714
715 // parse the mappings in this page
716 $blocks = explode($this->mMarkup['begin'], $txt);
717 array_shift($blocks);
718 $ret = array();
719 foreach($blocks as $block) {
720 $mappings = explode($this->mMarkup['end'], $block, 2);
721 $stripped = str_replace(array("'", '"', '*','#'), '', $mappings[0]);
722 $table = explode( ';', $stripped );
723 foreach( $table as $t ) {
724 $m = explode( '=>', $t );
725 if( count( $m ) != 2)
726 continue;
727 // trim any trailling comments starting with '//'
728 $tt = explode('//', $m[1], 2);
729 $ret[trim($m[0])] = trim($tt[0]);
730 }
731 }
732 $parsed[$key] = true;
733
734
735 // recursively parse the subpages
736 if($recursive) {
737 foreach($sublinks as $link) {
738 $s = $this->parseCachedTable($code, $link, $recursive);
739 $ret = array_merge($ret, $s);
740 }
741 }
742
743 if ($this->mUcfirst) {
744 foreach ($ret as $k => $v) {
745 $ret[Language::ucfirst($k)] = Language::ucfirst($v);
746 }
747 }
748 return $ret;
749 }
750
751 /**
752 * Enclose a string with the "no conversion" tag. This is used by
753 * various functions in the Parser
754 *
755 * @param string $text text to be tagged for no conversion
756 * @return string the tagged text
757 */
758 function markNoConversion($text, $noParse=false) {
759 # don't mark if already marked
760 if(strpos($text, $this->mMarkup['begin']) ||
761 strpos($text, $this->mMarkup['end']))
762 return $text;
763
764 $ret = $this->mMarkup['begin'] . $text . $this->mMarkup['end'];
765 return $ret;
766 }
767
768 /**
769 * convert the sorting key for category links. this should make different
770 * keys that are variants of each other map to the same key
771 */
772 function convertCategoryKey( $key ) {
773 return $key;
774 }
775 /**
776 * hook to refresh the cache of conversion tables when
777 * MediaWiki:conversiontable* is updated
778 * @private
779 */
780 function OnArticleSaveComplete($article, $user, $text, $summary, $isminor, $iswatch, $section) {
781 $titleobj = $article->getTitle();
782 if($titleobj->getNamespace() == NS_MEDIAWIKI) {
783 /*
784 global $wgContLang; // should be an LanguageZh.
785 if(get_class($wgContLang) != 'languagezh')
786 return true;
787 */
788 $title = $titleobj->getDBkey();
789 $t = explode('/', $title, 3);
790 $c = count($t);
791 if( $c > 1 && $t[0] == 'Conversiontable' ) {
792 if(in_array($t[1], $this->mVariants)) {
793 $this->reloadTables();
794 }
795 }
796 }
797 return true;
798 }
799
800 /**
801 * Armour rendered math against conversion
802 * Wrap math into rawoutput -{R| math }- syntax
803 */
804 function armourMath($text){
805 $ret = $this->mMarkup['begin'] . 'R|' . $text . $this->mMarkup['end'];
806 return $ret;
807 }
808
809
810 }
811
812 ?>