Nikerabbit has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/52225


Change subject: (bug 42635) Some GettextFFS messages were not unfuzzied on 
import
......................................................................

(bug 42635) Some GettextFFS messages were not unfuzzied on import

Namely those, where only change was removal of fuzzy flag.

Bug: 42635
Change-Id: Ic07c5e8056d10a6cd23201d6ddc2bbb580b0d97d
---
M ffs/FFS.php
M ffs/GettextFFS.php
M ffs/IniFFS.php
M ffs/JavaFFS.php
M ffs/MediaWikiExtensionFFS.php
M scripts/processMessageChanges.php
6 files changed, 66 insertions(+), 16 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Translate 
refs/changes/25/52225/1

diff --git a/ffs/FFS.php b/ffs/FFS.php
index d2a1dff..c8314f5 100644
--- a/ffs/FFS.php
+++ b/ffs/FFS.php
@@ -64,6 +64,16 @@
         * @return \string
         */
        public function writeIntoVariable( MessageCollection $collection );
+
+       /**
+        * Query the capabilities of this FFS. Allowed values are:
+        *  - yes
+        *  - write (ignored on read)
+        *  - no (stripped on write)
+        * @return string
+        * @since 2013-03-05
+        */
+       public function supportsFuzzy();
 }
 
 /**
@@ -392,4 +402,8 @@
 
                return $data;
        }
+
+       public function supportsFuzzy() {
+               return 'no';
+       }
 }
diff --git a/ffs/GettextFFS.php b/ffs/GettextFFS.php
index f865fc1..83dcdcd 100644
--- a/ffs/GettextFFS.php
+++ b/ffs/GettextFFS.php
@@ -630,4 +630,9 @@
 
                return $splitPlurals;
        }
+
+       public function supportsFuzzy() {
+               return 'yes';
+       }
+
 }
diff --git a/ffs/IniFFS.php b/ffs/IniFFS.php
index b8f5e45..56438d1 100644
--- a/ffs/IniFFS.php
+++ b/ffs/IniFFS.php
@@ -102,4 +102,8 @@
                $header .= '[' . $collection->getLanguage() . "]\n";
                return $header . $output;
        }
+
+       public function supportsFuzzy() {
+               return 'write';
+       }
 }
diff --git a/ffs/JavaFFS.php b/ffs/JavaFFS.php
index f3e6dda..f291a28 100644
--- a/ffs/JavaFFS.php
+++ b/ffs/JavaFFS.php
@@ -239,4 +239,8 @@
 
                return $output;
        }
+
+       public function supportsFuzzy() {
+               return 'write';
+       }
 }
diff --git a/ffs/MediaWikiExtensionFFS.php b/ffs/MediaWikiExtensionFFS.php
index 3517026..b5ccb62 100644
--- a/ffs/MediaWikiExtensionFFS.php
+++ b/ffs/MediaWikiExtensionFFS.php
@@ -263,4 +263,8 @@
                return $quote . $value . $quote;
        }
 
+       public function supportsFuzzy() {
+               return 'write';
+       }
+
 }
diff --git a/scripts/processMessageChanges.php 
b/scripts/processMessageChanges.php
index bd857a1..2a68186 100644
--- a/scripts/processMessageChanges.php
+++ b/scripts/processMessageChanges.php
@@ -158,7 +158,7 @@
                        $path = $group->getSourceFilePath( $code );
                        $this->error( "Source message file for 
{$group->getId()} does not exist. Looking for $path", 1 );
                }
-               $file = $group->getFFS()->read( $code );
+               $file = $ffs->read( $code );
                if ( !isset( $file['MESSAGES'] ) ) {
                        error_log( "{$group->getId()} has an FFS - the FFS 
didn't return cake for $code" );
                }
@@ -166,22 +166,43 @@
 
                $common = array_intersect( $fileKeys, $wikiKeys );
 
+               $supportsFuzzy = $ffs->supportsFuzzy();
+
                foreach ( $common as $key ) {
                        $sourceContent = $file['MESSAGES'][$key];
                        $wikiContent = $wiki[$key]->translation();
 
-                       if ( !self::compareContent( $sourceContent, 
$wikiContent ) ) {
-                               if ( $reason !== MessageGroupCache::NO_CACHE ) {
-                                       $cacheContent = $cache->get( $key );
-                                       if ( self::compareContent( 
$sourceContent, $cacheContent ) ) {
-                                               /* This message has only 
changed in the wiki, which means
-                                                * we can ignore the difference 
and have it exported on
-                                                * next export. */
-                                               continue;
-                                       }
-                               }
-                               $this->addChange( 'change', $group, $code, 
$key, $sourceContent );
+                       // If FFS doesn't support it, ignore fuzziness as 
difference
+                       $wikiContent = str_replace( TRANSLATE_FUZZY, '', 
$wikiContent );
+                       // But if it does, ensure we have exactly one fuzzy 
marker prefixed
+                       if ( $supportsFuzzy === 'yes' && $wiki[$key]->hasTag( 
'fuzzy' ) ) {
+                               $wikiContent = TRANSLATE_FUZZY . $wikiContent;
                        }
+
+                       if ( self::compareContent( $sourceContent, $wikiContent 
) ) {
+                               // File and wiki stage agree, nothing to do
+                               continue;
+                       }
+
+                       // Check against interim cache to see whether we have 
changes
+                       // in the wiki, in the file or both.
+
+                       if ( $reason !== MessageGroupCache::NO_CACHE ) {
+                               $cacheContent = $cache->get( $key );
+
+                               /* We want to ignore the common situation that 
the string
+                                * in the wiki has been changed since the last 
export.
+                                * Hence we check that source === cache && 
cache !== wiki
+                                * and if so we skip this string. */
+                               if (
+                                       !self::compareContent( $wikiContent, 
$cacheContent ) &&
+                                       self::compareContent( $sourceContent, 
$cacheContent )
+                               ) {
+                                       continue;
+                               }
+                       }
+
+                       $this->addChange( 'change', $group, $code, $key, 
$sourceContent );
                }
 
                $added = array_diff( $fileKeys, $wikiKeys );
@@ -221,15 +242,13 @@
        }
 
        /**
-        * Compares two strings ignoring fuzzy markers.
+        * Compares two strings.
         * @since 2012-05-08
         * @param string $a
         * @param string $b
-        * @return bool
+        * @return bool Whether two strings are equal
         */
        protected static function compareContent( $a, $b ) {
-               $a = str_replace( TRANSLATE_FUZZY, '', $a );
-               $b = str_replace( TRANSLATE_FUZZY, '', $b );
                return $a === $b;
        }
 

-- 
To view, visit https://gerrit.wikimedia.org/r/52225
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic07c5e8056d10a6cd23201d6ddc2bbb580b0d97d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Translate
Gerrit-Branch: master
Gerrit-Owner: Nikerabbit <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to