summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/Translate/utils/ExternalMessageSourceStateComparator.php
diff options
context:
space:
mode:
Diffstat (limited to 'www/wiki/extensions/Translate/utils/ExternalMessageSourceStateComparator.php')
-rw-r--r--www/wiki/extensions/Translate/utils/ExternalMessageSourceStateComparator.php45
1 files changed, 18 insertions, 27 deletions
diff --git a/www/wiki/extensions/Translate/utils/ExternalMessageSourceStateComparator.php b/www/wiki/extensions/Translate/utils/ExternalMessageSourceStateComparator.php
index 56de79de..02407fd8 100644
--- a/www/wiki/extensions/Translate/utils/ExternalMessageSourceStateComparator.php
+++ b/www/wiki/extensions/Translate/utils/ExternalMessageSourceStateComparator.php
@@ -4,14 +4,14 @@
* Finds external changes for file based message groups.
*
* @author Niklas Laxström
- * @license GPL-2.0+
+ * @license GPL-2.0-or-later
* @since 2013.12
*/
class ExternalMessageSourceStateComparator {
/** Process all languages supported by the message group */
const ALL_LANGUAGES = 'all languages';
- protected $changes = array();
+ protected $changes = [];
/**
* Finds changes in external sources compared to wiki state.
@@ -33,9 +33,11 @@ class ExternalMessageSourceStateComparator {
* @return array array[language code][change type] = change.
*/
public function processGroup( FileBasedMessageGroup $group, $languages ) {
- $this->changes = array();
+ $this->changes = [];
+ $processAll = false;
if ( $languages === self::ALL_LANGUAGES ) {
+ $processAll = true;
$languages = $group->getTranslatableLanguages();
// This means all languages
@@ -48,10 +50,13 @@ class ExternalMessageSourceStateComparator {
throw new MWException( 'Invalid input given for $languages' );
}
- // Process the source language before others
+ // Process the source language before others. Source language might not
+ // be included in $group->getTranslatableLanguages(). The expected
+ // behavior is that source language is always processed when given
+ // self::ALL_LANGUAGES.
$sourceLanguage = $group->getSourceLanguage();
$index = array_search( $sourceLanguage, $languages );
- if ( $index !== false ) {
+ if ( $processAll || $index !== false ) {
unset( $languages[$index] );
$this->processLanguage( $group, $sourceLanguage );
}
@@ -104,9 +109,9 @@ class ExternalMessageSourceStateComparator {
) {
/* This throws a warning if message definitions are not yet
* cached and will read the file for definitions. */
- wfSuppressWarnings();
+ Wikimedia\suppressWarnings();
$wiki = $group->initCollection( $code );
- wfRestoreWarnings();
+ Wikimedia\restoreWarnings();
$wiki->filter( 'hastranslation', false );
$wiki->loadTranslations();
$wikiKeys = $wiki->getMessageKeys();
@@ -123,7 +128,6 @@ class ExternalMessageSourceStateComparator {
// Does not exist
if ( $file === false ) {
-
return;
}
@@ -149,6 +153,7 @@ class ExternalMessageSourceStateComparator {
$wikiMessage = $wiki[$key];
$wikiContent = $wikiMessage->translation();
+ // @todo: Fuzzy checking can also be moved to $ffs->isContentEqual();
// If FFS doesn't support it, ignore fuzziness as difference
$wikiContent = str_replace( TRANSLATE_FUZZY, '', $wikiContent );
@@ -157,7 +162,7 @@ class ExternalMessageSourceStateComparator {
$wikiContent = TRANSLATE_FUZZY . $wikiContent;
}
- if ( self::compareContent( $sourceContent, $wikiContent ) ) {
+ if ( $ffs->isContentEqual( $sourceContent, $wikiContent ) ) {
// File and wiki stage agree, nothing to do
continue;
}
@@ -173,8 +178,8 @@ class ExternalMessageSourceStateComparator {
* Hence we check that source === cache && cache !== wiki
* and if so we skip this string. */
if (
- !self::compareContent( $wikiContent, $cacheContent ) &&
- self::compareContent( $sourceContent, $cacheContent )
+ !$ffs->isContentEqual( $wikiContent, $cacheContent ) &&
+ $ffs->isContentEqual( $sourceContent, $cacheContent )
) {
continue;
}
@@ -207,26 +212,12 @@ class ExternalMessageSourceStateComparator {
$this->addChange( 'deletion', $code, $key, null );
}
}
-
}
protected function addChange( $type, $language, $key, $content ) {
- $this->changes[$language][$type][] = array(
+ $this->changes[$language][$type][] = [
'key' => $key,
'content' => $content,
- );
- }
-
- /**
- * Compares two strings.
- * @todo Ignore changes in different way inlined plurals.
- * @todo Handle fuzzy state changes if FFS supports it.
- *
- * @param string $a
- * @param string $b
- * @return bool Whether two strings are equal
- */
- protected static function compareContent( $a, $b ) {
- return $a === $b;
+ ];
}
}