r68605 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r68604‎ | r68605 | r68606 >
Date:12:50, 26 June 2010
Author:nikerabbit
Status:ok
Tags:
Comment:
Fixed translation completion percentage calculation bug.

This was triggered when new the "do not mark translations outdated"
switch was used. The calculation would however see that translation
was made against an older version and added 20% penalty for it.

The fix is to consider the number of changes since the version the
translation was made against only if the message is currently marked
outdated.
Modified paths:
  • /trunk/extensions/Translate/tag/SpecialPageTranslation.php (modified) (history)
  • /trunk/extensions/Translate/tag/TranslatablePage.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/tag/TranslatablePage.php
@@ -478,10 +478,9 @@
479479 $memcKey = wfMemcKey( 'pt', 'status', $this->getTitle()->getPrefixedText() );
480480 $cache = $wgMemc->get( $memcKey );
481481
482 - if ( !$force && $wgRequest->getText( 'action' ) !== 'purge' ) {
483 - if ( is_array( $cache ) ) {
484 - return $cache;
485 - }
 482+ $force = $force || $wgRequest->getText( 'action' ) === 'purge';
 483+ if ( !$force && is_array( $cache ) ) {
 484+ return $cache;
486485 }
487486
488487 $titles = $this->getTranslationPages();
@@ -532,21 +531,24 @@
533532 // Fuzzy halves score
534533 if ( $message->hasTag( 'fuzzy' ) ) {
535534 $score *= 0.5;
536 - }
537535
538 - // Reduce 20% for every newer revision than what is translated against
539 - $rev = $this->getTransrev( $key . '/' . $collection->code );
540 - foreach ( $markedRevs as $r ) {
541 - if ( $rev === $r->rt_revision ) break;
542 - $changed = explode( '|', unserialize( $r->rt_value ) );
 536+ /* Reduce 20% for every newer revision than what is translated against.
 537+ * This is inside fuzzy clause, because there might be silent changes
 538+ * which we don't want to decrease the translation percentage.
 539+ */
 540+ $rev = $this->getTransrev( $key . '/' . $collection->code );
 541+ foreach ( $markedRevs as $r ) {
 542+ if ( $rev === $r->rt_revision ) break;
 543+ $changed = explode( '|', unserialize( $r->rt_value ) );
543544
544 - // Get a suitable section key
545 - $parts = explode( '/', $key );
546 - $ikey = $parts[count( $parts ) - 1];
 545+ // Get a suitable section key
 546+ $parts = explode( '/', $key );
 547+ $ikey = $parts[count( $parts ) - 1];
547548
548 - // If the section was changed, reduce the score
549 - if ( in_array( $ikey, $changed, true ) ) {
550 - $score *= 0.8;
 549+ // If the section was changed, reduce the score
 550+ if ( in_array( $ikey, $changed, true ) ) {
 551+ $score *= 0.8;
 552+ }
551553 }
552554 }
553555 $total += $score;
Index: trunk/extensions/Translate/tag/SpecialPageTranslation.php
@@ -487,7 +487,8 @@
488488 $dbw->delete( 'translate_sections', array( 'trs_page' => $page->getTitle()->getArticleId() ), __METHOD__ );
489489 $ok = $dbw->insert( 'translate_sections', $inserts, __METHOD__ );
490490
491 - // Stores the names of changed sections in the database. Not currently used for anything.
 491+ /* Stores the names of changed sections in the database.
 492+ * Used for calculating completion percentages for outdated messages */
492493 $page->addMarkedTag( $newrevision, $changed );
493494 $this->addFuzzyTags( $page, $changed );
494495

Status & tagging log