r15831 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r15830‎ | r15831 | r15832 >
Date:14:13, 26 July 2006
Author:tstarling
Status:old
Tags:
Comment:
Experimental FSS support
Modified paths:
  • /trunk/phase3/languages/LanguageConverter.php (modified) (history)

Diff [purge]

Index: trunk/phase3/languages/LanguageConverter.php
@@ -12,7 +12,9 @@
1313 var $mMainLanguageCode;
1414 var $mVariants, $mVariantFallbacks;
1515 var $mTablesLoaded = false;
 16+ var $mUseFss = false;
1617 var $mTables;
 18+ var $mFssObjects;
1719 var $mTitleDisplay='';
1820 var $mDoTitleConvert=true, $mDoContentConvert=true;
1921 var $mCacheKey;
@@ -46,6 +48,9 @@
4749 $this->mMarkup = array_merge($m, $markup);
4850 $f = array('A'=>'A', 'T'=>'T');
4951 $this->mFlags = array_merge($f, $flags);
 52+ if ( function_exists( 'fss_prep_replace' ) ) {
 53+ $this->mUseFss = true;
 54+ }
5055 }
5156
5257 /**
@@ -158,11 +163,11 @@
159164
160165
161166 $m = array_shift($matches);
162 - $ret = strtr($m[0], $this->mTables[$toVariant]);
 167+ $ret = $this->translate($m[0], $toVariant);
163168 $mstart = $m[1]+strlen($m[0]);
164169 foreach($matches as $m) {
165170 $ret .= substr($text, $mstart, $m[1]-$mstart);
166 - $ret .= strtr($m[0], $this->mTables[$toVariant]);
 171+ $ret .= $this->translate($m[0], $toVariant);
167172 $mstart = $m[1] + strlen($m[0]);
168173 }
169174 wfProfileOut( $fname );
@@ -170,6 +175,24 @@
171176 }
172177
173178 /**
 179+ * Translate a string to a variant
 180+ * Doesn't process markup or do any of that other stuff, for that use convert()
 181+ *
 182+ * @param string $text Text to convert
 183+ * @param string $variant Variant language code
 184+ * @return string Translated text
 185+ */
 186+ function translate( $text, $variant ) {
 187+ if( !$this->mTablesLoaded )
 188+ $this->loadTables();
 189+ if ( $this->mUseFss ) {
 190+ return fss_exec_replace( $this->mFssObjects[$variant], $text );
 191+ } else {
 192+ return strtr( $text, $this->mTables[$variant] );
 193+ }
 194+ }
 195+
 196+ /**
174197 * convert text to all supported variants
175198 *
176199 * @param string $text the text to be converted
@@ -184,7 +207,7 @@
185208
186209 $ret = array();
187210 foreach($this->mVariants as $variant) {
188 - $ret[$variant] = strtr($text, $this->mTables[$variant]);
 211+ $ret[$variant] = $this->translate($text, $variant);
189212 }
190213 wfProfileOut( $fname );
191214 return $ret;
@@ -334,6 +357,9 @@
335358
336359 }
337360 }
 361+ if ( $this->mUseFss ) {
 362+ $this->generateFssObjects();
 363+ }
338364 }
339365 }
340366 else {
@@ -498,8 +524,20 @@
499525 $wgMemc->set($this->mCacheKey, $this->mTables, 43200);
500526 $this->unlockCache();
501527 }
 528+ if ( $this->mUseFss ) {
 529+ $this->generateFssObjects();
 530+ }
502531 }
503532
 533+ /**
 534+ * Generate FSS objects. The FSS extension must be available.
 535+ */
 536+ function generateFssObjects() {
 537+ foreach ( $this->mTables as $variant => $table ) {
 538+ $this->mFssObjects[$variant] = fss_prep_replace( $table );
 539+ }
 540+ }
 541+
504542 /**
505543 * Hook for post processig after conversion tables are loaded
506544 *