r69134 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r69133‎ | r69134 | r69135 >
Date:08:59, 7 July 2010
Author:philip
Status:ok (Comments)
Tags:
Comment:
* Deprecated convertLinkToAllVariants() since the "{" and "}" are not allowed in titles, the text will get all converted always like autoConvertToAllVariants().
* Removed some redundant code.
Modified paths:
  • /trunk/phase3/languages/LanguageConverter.php (modified) (history)

Diff [purge]

Index: trunk/phase3/languages/LanguageConverter.php
@@ -318,14 +318,10 @@
319319 * @return String: the converted text
320320 */
321321 public function autoConvert( $text, $toVariant = false ) {
322 - $fname = 'LanguageConverter::autoConvert';
 322+ wfProfileIn( __METHOD__ );
323323
324 - wfProfileIn( $fname );
 324+ $this->loadTables();
325325
326 - if ( !$this->mTablesLoaded ) {
327 - $this->loadTables();
328 - }
329 -
330326 if ( !$toVariant ) {
331327 $toVariant = $this->getPreferredVariant();
332328 if ( !$toVariant ) {
@@ -390,7 +386,7 @@
391387 $ret .= array_shift( $notrtext );
392388 $ret .= $t;
393389 }
394 - wfProfileOut( $fname );
 390+ wfProfileOut( __METHOD__ );
395391 return $ret;
396392 }
397393
@@ -408,9 +404,7 @@
409405 // If $text is empty or only includes spaces, do nothing
410406 // Otherwise translate it
411407 if ( trim( $text ) ) {
412 - if ( !$this->mTablesLoaded ) {
413 - $this->loadTables();
414 - }
 408+ $this->loadTables();
415409 $text = $this->mTables[$variant]->replace( $text );
416410 }
417411 wfProfileOut( __METHOD__ );
@@ -424,57 +418,31 @@
425419 * @return Array: variant => converted text
426420 */
427421 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();
433424
434425 $ret = array();
435426 foreach ( $this->mVariants as $variant ) {
436427 $ret[$variant] = $this->translate( $text, $variant );
437428 }
438429
439 - wfProfileOut( $fname );
 430+ wfProfileOut( __METHOD__ );
440431 return $ret;
441432 }
442433
443434 /**
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.
445440 *
446441 * @param $text String: the text to be converted
447442 * @return Array: variant => converted text
 443+ * @deprecated Use autoConvertToAllVariants() instead
448444 */
449445 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 );
479447 }
480448
481449 /**
@@ -756,10 +724,10 @@
757725 * @private
758726 */
759727 function loadTables( $fromcache = true ) {
760 - global $wgMemc;
761728 if ( $this->mTablesLoaded ) {
762729 return;
763730 }
 731+ global $wgMemc;
764732 wfProfileIn( __METHOD__ );
765733 $this->mTablesLoaded = true;
766734 $this->mTables = false;

Follow-up revisions

RevisionCommit summaryAuthorDate
r71459follow up r69134. Change all of convertLinkToAllVariants()'s callers to call ...philip02:07, 23 August 2010

Comments

#Comment by Platonides (talk | contribs)   20:24, 21 August 2010

convertLinkToAllVariants() is called from Language::convertLinkToAllVariants(), so either all its calls (Parser.php, LinkHolderArray.php, SearchEngine.php) are changed to autoConvertToAllVariants() deprecating all convertLinkToAllVariants() or we keep the interface and not deprecate any of them.

#Comment by PhiLiP (talk | contribs)   02:08, 23 August 2010

Status & tagging log