Index: trunk/phase3/languages/LanguageConverter.php |
— | — | @@ -318,14 +318,10 @@ |
319 | 319 | * @return String: the converted text |
320 | 320 | */ |
321 | 321 | public function autoConvert( $text, $toVariant = false ) { |
322 | | - $fname = 'LanguageConverter::autoConvert'; |
| 322 | + wfProfileIn( __METHOD__ ); |
323 | 323 | |
324 | | - wfProfileIn( $fname ); |
| 324 | + $this->loadTables(); |
325 | 325 | |
326 | | - if ( !$this->mTablesLoaded ) { |
327 | | - $this->loadTables(); |
328 | | - } |
329 | | - |
330 | 326 | if ( !$toVariant ) { |
331 | 327 | $toVariant = $this->getPreferredVariant(); |
332 | 328 | if ( !$toVariant ) { |
— | — | @@ -390,7 +386,7 @@ |
391 | 387 | $ret .= array_shift( $notrtext ); |
392 | 388 | $ret .= $t; |
393 | 389 | } |
394 | | - wfProfileOut( $fname ); |
| 390 | + wfProfileOut( __METHOD__ ); |
395 | 391 | return $ret; |
396 | 392 | } |
397 | 393 | |
— | — | @@ -408,9 +404,7 @@ |
409 | 405 | // If $text is empty or only includes spaces, do nothing |
410 | 406 | // Otherwise translate it |
411 | 407 | if ( trim( $text ) ) { |
412 | | - if ( !$this->mTablesLoaded ) { |
413 | | - $this->loadTables(); |
414 | | - } |
| 408 | + $this->loadTables(); |
415 | 409 | $text = $this->mTables[$variant]->replace( $text ); |
416 | 410 | } |
417 | 411 | wfProfileOut( __METHOD__ ); |
— | — | @@ -424,57 +418,31 @@ |
425 | 419 | * @return Array: variant => converted text |
426 | 420 | */ |
427 | 421 | public function autoConvertToAllVariants( $text ) { |
428 | | - $fname = 'LanguageConverter::autoConvertToAllVariants'; |
429 | | - wfProfileIn( $fname ); |
430 | | - if ( !$this->mTablesLoaded ) { |
431 | | - $this->loadTables(); |
432 | | - } |
| 422 | + wfProfileIn( __METHOD__ ); |
| 423 | + $this->loadTables(); |
433 | 424 | |
434 | 425 | $ret = array(); |
435 | 426 | foreach ( $this->mVariants as $variant ) { |
436 | 427 | $ret[$variant] = $this->translate( $text, $variant ); |
437 | 428 | } |
438 | 429 | |
439 | | - wfProfileOut( $fname ); |
| 430 | + wfProfileOut( __METHOD__ ); |
440 | 431 | return $ret; |
441 | 432 | } |
442 | 433 | |
443 | 434 | /** |
444 | | - * Convert link text to all supported variants. |
| 435 | + * Convert link text to all valid variants. |
| 436 | + * In the first, this function only convert text outside the |
| 437 | + * "-{" "}-" markups. Since the "{" and "}" are not allowed in |
| 438 | + * titles, the text will get all converted always. |
| 439 | + * So I removed this feature and deprecated the function. |
445 | 440 | * |
446 | 441 | * @param $text String: the text to be converted |
447 | 442 | * @return Array: variant => converted text |
| 443 | + * @deprecated Use autoConvertToAllVariants() instead |
448 | 444 | */ |
449 | 445 | public function convertLinkToAllVariants( $text ) { |
450 | | - if ( !$this->mTablesLoaded ) { |
451 | | - $this->loadTables(); |
452 | | - } |
453 | | - |
454 | | - $ret = array(); |
455 | | - $tarray = StringUtils::explode( '-{', $text ); |
456 | | - $first = true; |
457 | | - |
458 | | - foreach ( $tarray as $txt ) { |
459 | | - if ( $first ) { |
460 | | - $first = false; |
461 | | - foreach ( $this->mVariants as $variant ) { |
462 | | - $ret[$variant] = $this->translate( $txt, $variant ); |
463 | | - } |
464 | | - continue; |
465 | | - } |
466 | | - |
467 | | - $marked = explode( '}-', $txt, 2 ); |
468 | | - |
469 | | - foreach ( $this->mVariants as $variant ) { |
470 | | - $ret[$variant] .= '-{' . $marked[0] . '}-'; |
471 | | - if ( array_key_exists( 1, $marked ) ) { |
472 | | - $ret[$variant] .= $this->translate( $marked[1], $variant ); |
473 | | - } |
474 | | - } |
475 | | - |
476 | | - } |
477 | | - |
478 | | - return $ret; |
| 446 | + return $this->autoConvertToAllVariants( $text ); |
479 | 447 | } |
480 | 448 | |
481 | 449 | /** |
— | — | @@ -756,10 +724,10 @@ |
757 | 725 | * @private |
758 | 726 | */ |
759 | 727 | function loadTables( $fromcache = true ) { |
760 | | - global $wgMemc; |
761 | 728 | if ( $this->mTablesLoaded ) { |
762 | 729 | return; |
763 | 730 | } |
| 731 | + global $wgMemc; |
764 | 732 | wfProfileIn( __METHOD__ ); |
765 | 733 | $this->mTablesLoaded = true; |
766 | 734 | $this->mTables = false; |