summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Evans <grknight@gentoo.org>2018-11-20 10:51:06 -0500
committerBrian Evans <grknight@gentoo.org>2018-11-20 10:51:06 -0500
commit1ea74fa59d8d1c6c12d20be6c8e7d5ac7f370fdb (patch)
treead113bd05db878a61b503938c05fe046eca25ee0 /MLEB/LocalisationUpdate
parentLinkAttributes: Update to v0.2 (diff)
downloadextensions-1ea74fa59d8d1c6c12d20be6c8e7d5ac7f370fdb.tar.gz
extensions-1ea74fa59d8d1c6c12d20be6c8e7d5ac7f370fdb.tar.bz2
extensions-1ea74fa59d8d1c6c12d20be6c8e7d5ac7f370fdb.zip
Update to MediaWikiLanguageExtensionBundle-2018.10
Signed-off-by: Brian Evans <grknight@gentoo.org>
Diffstat (limited to 'MLEB/LocalisationUpdate')
-rw-r--r--MLEB/LocalisationUpdate/Autoload.php31
-rw-r--r--MLEB/LocalisationUpdate/LocalisationUpdate.class.php99
-rw-r--r--MLEB/LocalisationUpdate/LocalisationUpdate.i18n.php35
-rw-r--r--MLEB/LocalisationUpdate/LocalisationUpdate.php60
-rw-r--r--MLEB/LocalisationUpdate/QuickArrayReader.php204
-rw-r--r--MLEB/LocalisationUpdate/README2
-rw-r--r--MLEB/LocalisationUpdate/RELEASE-NOTES9
-rw-r--r--MLEB/LocalisationUpdate/Updater.php194
-rw-r--r--MLEB/LocalisationUpdate/fetcher/Fetcher.php26
-rw-r--r--MLEB/LocalisationUpdate/fetcher/FetcherFactory.php24
-rw-r--r--MLEB/LocalisationUpdate/fetcher/FileSystemFetcher.php35
-rw-r--r--MLEB/LocalisationUpdate/fetcher/GitHubFetcher.php38
-rw-r--r--MLEB/LocalisationUpdate/fetcher/HttpFetcher.php40
-rw-r--r--MLEB/LocalisationUpdate/finder/Finder.php107
-rw-r--r--MLEB/LocalisationUpdate/i18n/ca.json5
-rw-r--r--MLEB/LocalisationUpdate/i18n/de.json4
-rw-r--r--MLEB/LocalisationUpdate/i18n/en.json13
-rw-r--r--MLEB/LocalisationUpdate/i18n/es.json5
-rw-r--r--MLEB/LocalisationUpdate/i18n/mk.json1
-rw-r--r--MLEB/LocalisationUpdate/i18n/nb.json4
-rw-r--r--MLEB/LocalisationUpdate/i18n/pt.json2
-rw-r--r--MLEB/LocalisationUpdate/i18n/qqq.json1
-rw-r--r--MLEB/LocalisationUpdate/i18n/sr-ec.json5
-rw-r--r--MLEB/LocalisationUpdate/reader/JSONReader.php30
-rw-r--r--MLEB/LocalisationUpdate/reader/PHPReader.php54
-rw-r--r--MLEB/LocalisationUpdate/reader/Reader.php19
-rw-r--r--MLEB/LocalisationUpdate/reader/ReaderFactory.php36
-rw-r--r--MLEB/LocalisationUpdate/tests/phpunit/UpdaterTest.php47
-rw-r--r--MLEB/LocalisationUpdate/tests/phpunit/finder/FinderTest.php47
-rw-r--r--MLEB/LocalisationUpdate/tests/phpunit/reader/JSONReaderTest.php33
-rw-r--r--MLEB/LocalisationUpdate/tests/phpunit/reader/ReaderFactoryTest.php33
-rw-r--r--MLEB/LocalisationUpdate/update.php42
32 files changed, 149 insertions, 1136 deletions
diff --git a/MLEB/LocalisationUpdate/Autoload.php b/MLEB/LocalisationUpdate/Autoload.php
deleted file mode 100644
index 0b3f14dc..00000000
--- a/MLEB/LocalisationUpdate/Autoload.php
+++ /dev/null
@@ -1,31 +0,0 @@
-<?php
-/**
- * @file
- * @author Niklas Laxström
- * @license GPL-2.0+
- */
-
-global $wgAutoloadClasses;
-$dir = __DIR__;
-
-$wgAutoloadClasses += array(
- 'LocalisationUpdate' => "$dir/LocalisationUpdate.class.php",
- 'LU_Updater' => "$dir/Updater.php",
- 'QuickArrayReader' => "$dir/QuickArrayReader.php",
-
- # fetcher
- 'LU_Fetcher' => "$dir/fetcher/Fetcher.php",
- 'LU_FetcherFactory' => "$dir/fetcher/FetcherFactory.php",
- 'LU_FileSystemFetcher' => "$dir/fetcher/FileSystemFetcher.php",
- 'LU_GitHubFetcher' => "$dir/fetcher/GitHubFetcher.php",
- 'LU_HttpFetcher' => "$dir/fetcher/HttpFetcher.php",
-
- # finder
- 'LU_Finder' => "$dir/finder/Finder.php",
-
- # reader
- 'LU_JSONReader' => "$dir/reader/JSONReader.php",
- 'LU_PHPReader' => "$dir/reader/PHPReader.php",
- 'LU_Reader' => "$dir/reader/Reader.php",
- 'LU_ReaderFactory' => "$dir/reader/ReaderFactory.php",
-);
diff --git a/MLEB/LocalisationUpdate/LocalisationUpdate.class.php b/MLEB/LocalisationUpdate/LocalisationUpdate.class.php
deleted file mode 100644
index d4413ed7..00000000
--- a/MLEB/LocalisationUpdate/LocalisationUpdate.class.php
+++ /dev/null
@@ -1,99 +0,0 @@
-<?php
-
-/**
- * Class for localization update hooks and static methods.
- */
-class LocalisationUpdate {
- /** @todo Remove this once pre-1.24 versions of MW are no longer supported. */
- private static $onRecacheFallbackCalled = false;
-
- /**
- * Hook: LocalisationCacheRecacheFallback
- */
- public static function onRecacheFallback( LocalisationCache $lc, $code, array &$cache ) {
- self::$onRecacheFallbackCalled = true;
-
- $dir = LocalisationUpdate::getDirectory();
- if ( !$dir ) {
- return true;
- }
-
- $fileName = "$dir/" . self::getFilename( $code );
- if ( is_readable( $fileName ) ) {
- $data = FormatJson::decode( file_get_contents( $fileName ), true );
- $cache['messages'] = array_merge( $cache['messages'], $data );
- }
-
- return true;
- }
-
- /**
- * Hook: LocalisationCacheRecache
- */
- public static function onRecache( LocalisationCache $lc, $code, array &$cache ) {
- $dir = LocalisationUpdate::getDirectory();
- if ( !$dir ) {
- return true;
- }
-
- $codeSequence = array_merge( array( $code ), $cache['fallbackSequence'] );
- foreach ( $codeSequence as $csCode ) {
- $fileName = "$dir/" . self::getFilename( $csCode );
- if ( !self::$onRecacheFallbackCalled && is_readable( $fileName ) ) {
- // We're on an old version of MW that doesn't have the hook
- // needed to do things correctly. L10n will be broken here in
- // certain reasonably-common situations (see bug 68781), but
- // there's nothing we can do about it.
- $data = FormatJson::decode( file_get_contents( $fileName ), true );
- $cache['messages'] = array_merge( $cache['messages'], $data );
- }
- $cache['deps'][] = new FileDependency( $fileName );
- }
-
- return true;
- }
-
- /**
- * Returns a directory where updated translations are stored.
- *
- * @return string|false False if not configured.
- * @since 1.1
- */
- public static function getDirectory() {
- global $wgLocalisationUpdateDirectory, $wgCacheDirectory;
-
- // ?: can be used once we drop support for MW 1.19
- return $wgLocalisationUpdateDirectory ?
- $wgLocalisationUpdateDirectory :
- $wgCacheDirectory;
- }
-
- /**
- * Returns a filename where updated translations are stored.
- *
- * @param string $language Language tag
- * @return string
- * @since 1.1
- */
- public static function getFilename( $language ) {
- return "l10nupdate-$language.json";
- }
-
- /**
- * Hook: UnitTestsList
- */
- public static function setupUnitTests( array &$files ) {
- $dir = __DIR__ . '/tests/phpunit';
- $directoryIterator = new RecursiveDirectoryIterator( $dir );
- $fileIterator = new RecursiveIteratorIterator( $directoryIterator );
-
- /// @var SplFileInfo $fileInfo
- foreach ( $fileIterator as $fileInfo ) {
- if ( substr( $fileInfo->getFilename(), -8 ) === 'Test.php' ) {
- $files[] = $fileInfo->getPathname();
- }
- }
-
- return true;
- }
-}
diff --git a/MLEB/LocalisationUpdate/LocalisationUpdate.i18n.php b/MLEB/LocalisationUpdate/LocalisationUpdate.i18n.php
deleted file mode 100644
index f715d123..00000000
--- a/MLEB/LocalisationUpdate/LocalisationUpdate.i18n.php
+++ /dev/null
@@ -1,35 +0,0 @@
-<?php
-/**
- * This is a backwards-compatibility shim, generated by:
- * https://git.wikimedia.org/blob/mediawiki%2Fcore.git/HEAD/maintenance%2FgenerateJsonI18n.php
- *
- * Beginning with MediaWiki 1.23, translation strings are stored in json files,
- * and the EXTENSION.i18n.php file only exists to provide compatibility with
- * older releases of MediaWiki. For more information about this migration, see:
- * https://www.mediawiki.org/wiki/Requests_for_comment/Localisation_format
- *
- * This shim maintains compatibility back to MediaWiki 1.17.
- */
-$messages = array();
-if ( !function_exists( 'wfJsonI18nShim2520f8a069e9942f' ) ) {
- function wfJsonI18nShim2520f8a069e9942f( $cache, $code, &$cachedData ) {
- $codeSequence = array_merge( array( $code ), $cachedData['fallbackSequence'] );
- foreach ( $codeSequence as $csCode ) {
- $fileName = dirname( __FILE__ ) . "/i18n/$csCode.json";
- if ( is_readable( $fileName ) ) {
- $data = FormatJson::decode( file_get_contents( $fileName ), true );
- foreach ( array_keys( $data ) as $key ) {
- if ( $key === '' || $key[0] === '@' ) {
- unset( $data[$key] );
- }
- }
- $cachedData['messages'] = array_merge( $data, $cachedData['messages'] );
- }
-
- $cachedData['deps'][] = new FileDependency( $fileName );
- }
- return true;
- }
-
- $GLOBALS['wgHooks']['LocalisationCacheRecache'][] = 'wfJsonI18nShim2520f8a069e9942f';
-}
diff --git a/MLEB/LocalisationUpdate/LocalisationUpdate.php b/MLEB/LocalisationUpdate/LocalisationUpdate.php
index b3eb3acb..e69de29b 100644
--- a/MLEB/LocalisationUpdate/LocalisationUpdate.php
+++ b/MLEB/LocalisationUpdate/LocalisationUpdate.php
@@ -1,60 +0,0 @@
-<?php
-
-/**
- * Directory to store serialized cache files in. Defaults to $wgCacheDirectory.
- * It's OK to share this directory among wikis as long as the wiki you run
- * update.php on has all extensions the other wikis using the same directory
- * have.
- * NOTE: If this variable and $wgCacheDirectory are both false, this extension
- * WILL NOT WORK.
- */
-$wgLocalisationUpdateDirectory = false;
-
-/**
- * Default repository source to use.
- * @since 2014-03
- */
-$wgLocalisationUpdateRepository = 'github';
-
-/**
- * Available repository sources.
- * @since 2014-03
- */
-$wgLocalisationUpdateRepositories = array();
-$wgLocalisationUpdateRepositories['github'] = array(
- 'mediawiki' =>
- 'https://raw.github.com/wikimedia/mediawiki/master/%PATH%',
- 'extension' =>
- 'https://raw.github.com/wikimedia/mediawiki-extensions-%NAME%/master/%PATH%',
- 'skin' =>
- 'https://raw.github.com/wikimedia/mediawiki-skins-%NAME%/master/%PATH%',
-);
-
-// Example for local filesystem configuration
-#$wgLocalisationUpdateRepositories['local'] = array(
-# 'mediawiki' =>
-# 'file:///resources/projects/mediawiki/master/%PATH%',
-# 'extension' =>
-# 'file:///resources/projects/mediawiki-extensions/extensions/%NAME%/%PATH%',
-# 'skin' =>
-# 'file:///resources/projects/mediawiki-skins/skins/%NAME%/%PATH%',
-#);
-
-$wgExtensionCredits['other'][] = array(
- 'path' => __FILE__,
- 'name' => 'LocalisationUpdate',
- 'author' => array( 'Tom Maaswinkel', 'Niklas Laxström', 'Roan Kattouw' ),
- 'version' => '[https://www.mediawiki.org/wiki/MLEB MLEB 2015.04]',
- 'url' => 'https://www.mediawiki.org/wiki/Extension:LocalisationUpdate',
- 'descriptionmsg' => 'localisationupdate-desc',
-);
-
-$wgHooks['LocalisationCacheRecache'][] = 'LocalisationUpdate::onRecache';
-$wgHooks['LocalisationCacheRecacheFallback'][] = 'LocalisationUpdate::onRecacheFallback';
-$GLOBALS['wgHooks']['UnitTestsList'][] = 'LocalisationUpdate::setupUnitTests';
-
-$dir = __DIR__;
-$wgMessagesDirs['LocalisationUpdate'] = __DIR__ . '/i18n';
-$wgExtensionMessagesFiles['LocalisationUpdate'] = "$dir/LocalisationUpdate.i18n.php";
-
-require "$dir/Autoload.php";
diff --git a/MLEB/LocalisationUpdate/QuickArrayReader.php b/MLEB/LocalisationUpdate/QuickArrayReader.php
deleted file mode 100644
index 691f4a6b..00000000
--- a/MLEB/LocalisationUpdate/QuickArrayReader.php
+++ /dev/null
@@ -1,204 +0,0 @@
-<?php
-
-/**
- * Quickie parser class that can happily read the subset of PHP we need
- * for our localization arrays safely.
- *
- * Still an order of magnitude slower than eval().
- */
-class QuickArrayReader {
- private $vars = array();
-
- /**
- * @param $string string
- */
- function __construct( $string ) {
- $scalarTypes = array(
- T_LNUMBER => true,
- T_DNUMBER => true,
- T_STRING => true,
- T_CONSTANT_ENCAPSED_STRING => true,
- );
- $skipTypes = array(
- T_WHITESPACE => true,
- T_COMMENT => true,
- T_DOC_COMMENT => true,
- );
- $tokens = token_get_all( $string );
- $count = count( $tokens );
- for ( $i = 0; $i < $count; ) {
- while ( isset( $skipTypes[$tokens[$i][0]] ) ) {
- $i++;
- }
- switch ( $tokens[$i][0] ) {
- case T_OPEN_TAG:
- $i++;
- continue;
- case T_VARIABLE:
- // '$messages' -> 'messages'
- $varname = trim( substr( $tokens[$i][1], 1 ) );
- $varindex = null;
-
- while ( isset( $skipTypes[$tokens[++$i][0]] ) );
-
- if ( $tokens[$i] === '[' ) {
- while ( isset( $skipTypes[$tokens[++$i][0]] ) );
-
- if ( isset( $scalarTypes[$tokens[$i][0]] ) ) {
- $varindex = $this->parseScalar( $tokens[$i] );
- } else {
- throw $this->except( $tokens[$i], 'scalar index' );
- }
- while ( isset( $skipTypes[$tokens[++$i][0]] ) );
-
- if ( $tokens[$i] !== ']' ) {
- throw $this->except( $tokens[$i], ']' );
- }
- while ( isset( $skipTypes[$tokens[++$i][0]] ) );
- }
-
- if ( $tokens[$i] !== '=' ) {
- throw $this->except( $tokens[$i], '=' );
- }
- while ( isset( $skipTypes[$tokens[++$i][0]] ) );
-
- if ( isset( $scalarTypes[$tokens[$i][0]] ) ) {
- $buildval = $this->parseScalar( $tokens[$i] );
- } elseif ( $tokens[$i][0] === T_ARRAY ) {
- while ( isset( $skipTypes[$tokens[++$i][0]] ) );
- if ( $tokens[$i] !== '(' ) {
- throw $this->except( $tokens[$i], '(' );
- }
- $buildval = array();
- do {
- while ( isset( $skipTypes[$tokens[++$i][0]] ) );
-
- if ( $tokens[$i] === ')' ) {
- break;
- }
- if ( isset( $scalarTypes[$tokens[$i][0]] ) ) {
- $key = $this->parseScalar( $tokens[$i] );
- }
- while ( isset( $skipTypes[$tokens[++$i][0]] ) );
-
- if ( $tokens[$i][0] !== T_DOUBLE_ARROW ) {
- throw $this->except( $tokens[$i], '=>' );
- }
- while ( isset( $skipTypes[$tokens[++$i][0]] ) );
-
- if ( isset( $scalarTypes[$tokens[$i][0]] ) ) {
- $val = $this->parseScalar( $tokens[$i] );
- }
- wfSuppressWarnings();
- $buildval[$key] = $val;
- wfRestoreWarnings();
- while ( isset( $skipTypes[$tokens[++$i][0]] ) );
-
- if ( $tokens[$i] === ',' ) {
- continue;
- } elseif ( $tokens[$i] === ')' ) {
- break;
- } else {
- throw $this->except( $tokens[$i], ', or )' );
- }
- } while ( true );
- } else {
- throw $this->except( $tokens[$i], 'scalar or array' );
- }
- if ( is_null( $varindex ) ) {
- $this->vars[$varname] = $buildval;
- } else {
- wfSuppressWarnings();
- $this->vars[$varname][$varindex] = $buildval;
- wfRestoreWarnings();
- }
- while ( isset( $skipTypes[$tokens[++$i][0]] ) );
- if ( $tokens[$i] !== ';' ) {
- throw $this->except( $tokens[$i], ';' );
- }
- $i++;
- break;
- default:
- throw $this->except( $tokens[$i], 'open tag, whitespace, or variable.' );
- }
- }
- }
-
- /**
- * @param $got string
- * @param $expected string
- * @return Exception
- */
- private function except( $got, $expected ) {
- if ( is_array( $got ) ) {
- $got = token_name( $got[0] ) . " ('" . $got[1] . "')";
- } else {
- $got = "'" . $got . "'";
- }
-
- return new Exception( "Expected $expected, got $got" );
- }
-
- /**
- * Parse a scalar value in PHP
- *
- * @param $token string
- *
- * @return mixed Parsed value
- */
- function parseScalar( $token ) {
- if ( is_array( $token ) ) {
- $str = $token[1];
- } else {
- $str = $token;
- }
- if ( $str !== '' && $str[0] == '\'' ) {
- // Single-quoted string
- // @fixme trim() call is due to mystery bug where whitespace gets
- // appended to the token; without it we ended up reading in the
- // extra quote on the end!
- return strtr( substr( trim( $str ), 1, -1 ),
- array( '\\\'' => '\'', '\\\\' => '\\' ) );
- }
-
- wfSuppressWarnings();
- if ( $str !== '' && $str[0] == '"' ) {
- // Double-quoted string
- // @fixme trim() call is due to mystery bug where whitespace gets
- // appended to the token; without it we ended up reading in the
- // extra quote on the end!
- wfRestoreWarnings();
- return stripcslashes( substr( trim( $str ), 1, -1 ) );
- }
- wfRestoreWarnings();
-
- if ( substr( $str, 0, 4 ) === 'true' ) {
- return true;
- }
-
- if ( substr( $str, 0, 5 ) === 'false' ) {
- return false;
- }
-
- if ( substr( $str, 0, 4 ) === 'null' ) {
- return null;
- }
-
- // Must be some kind of numeric value, so let PHP's weak typing
- // be useful for a change
- return $str;
- }
-
- /**
- * @param $varname string
- * @return null|string
- */
- function getVar( $varname ) {
- if ( isset( $this->vars[$varname] ) ) {
- return $this->vars[$varname];
- } else {
- return null;
- }
- }
-}
-
diff --git a/MLEB/LocalisationUpdate/README b/MLEB/LocalisationUpdate/README
index 3df784b5..c5e2f72e 100644
--- a/MLEB/LocalisationUpdate/README
+++ b/MLEB/LocalisationUpdate/README
@@ -8,7 +8,7 @@ For more information see:
== Installation ==
1. Add the following to LocalSettings.php of your MediaWiki setup:
- require_once "$IP/extensions/LocalisationUpdate/LocalisationUpdate.php";
+ wfLoadExtension( 'LocalisationUpdate' );
$wgLocalisationUpdateDirectory = "$IP/cache";
2. Create a cache folder in the installation directory, and be sure the server
diff --git a/MLEB/LocalisationUpdate/RELEASE-NOTES b/MLEB/LocalisationUpdate/RELEASE-NOTES
index 0b409a26..e63a2996 100644
--- a/MLEB/LocalisationUpdate/RELEASE-NOTES
+++ b/MLEB/LocalisationUpdate/RELEASE-NOTES
@@ -1,5 +1,6 @@
-== LocalisationUpdate 2015.04 ==
-Released at 2015-04-30.
+== LocalisationUpdate 2018.10 ==
+Released at 2018-10-29.
-=== Highlights ===
-* Localisation updates only.
+=== Noteworthy changes ===
+* Remove PHP entry point. Please update your configuration!
+* Fix handling of exception from GitHubFetcher. If l10n directory is not found, it logs message and continue.
diff --git a/MLEB/LocalisationUpdate/Updater.php b/MLEB/LocalisationUpdate/Updater.php
deleted file mode 100644
index bae492dd..00000000
--- a/MLEB/LocalisationUpdate/Updater.php
+++ /dev/null
@@ -1,194 +0,0 @@
-<?php
-/**
- * @file
- * @author Niklas Laxström
- * @license GPL-2.0+
- */
-
-/**
- * Executes the localisation update.
- */
-class LU_Updater {
- /**
- * Whether the path is a pattern and thus we need to use appropriate
- * code for fetching directories.
- *
- * @param string $path Url
- * @return bool
- */
- public function isDirectory( $path ) {
- $filename = basename( $path );
- return strpos( $filename, '*' ) !== false;
- }
-
- /**
- * Expands repository relative path to full url with the given repository
- * patterns. Extra variables in $info are used as variables and will be
- * replaced the pattern.
- *
- * @param array $info Component information.
- * @param array $repos Repository information.
- * @return string
- */
- public function expandRemotePath( $info, $repos ) {
- $pattern = $repos[$info['repo']];
- unset( $info['repo'], $info['orig'] );
-
- // This assumes all other keys are used as variables
- // in the pattern. For example name -> %NAME%.
- $keys = array();
- foreach ( array_keys( $info ) as $key ) {
- $keys[] = '%' . strtoupper( $key ) . '%';
- }
-
- $values = array_values( $info );
- return str_replace( $keys, $values, $pattern );
- }
-
- /**
- * Parses translations from given list of files.
- *
- * @param LU_ReaderFactory $readerFactory Factory to construct parsers.
- * @param array $files List of files with their contents as array values.
- * @return array List of translations indexed by language code.
- */
- public function readMessages( LU_ReaderFactory $readerFactory, array $files ) {
- $messages = array();
-
- foreach ( $files as $filename => $contents ) {
- $reader = $readerFactory->getReader( $filename );
- try {
- $parsed = $reader->parse( $contents );
- } catch ( Exception $e ) {
- trigger_error( __METHOD__ . ": Unable to parse messages from $filename", E_USER_WARNING );
- continue;
- }
-
- foreach ( $parsed as $code => $langMessages ) {
- if ( !isset( $messages[$code] ) ) {
- $messages[$code] = array();
- }
- $messages[$code] = array_merge( $messages[$code], $langMessages );
- }
-
- $c = array_sum( array_map( 'count', $parsed ) );
- // Useful for debugging, maybe create interface to pass this to the script?
- #echo "$filename with " . get_class( $reader ) . " and $c\n";
- }
-
- return $messages;
- }
-
- /**
- * Find new and changed translations in $remote and returns them.
- *
- * @param array $origin
- * @param array $remote
- * @param array [$blacklist] Array of message keys to ignore, keys as as array keys.
- * @return array
- */
- public function findChangedTranslations( $origin, $remote, $blacklist = array() ) {
- $changed = array();
- foreach ( $remote as $key => $value ) {
- if ( isset( $blacklist[$key] ) ) {
- continue;
- }
-
- if ( !isset( $origin[$key] ) || $value !== $origin[$key] ) {
- $changed[$key] = $value;
- }
- }
- return $changed;
- }
-
- /**
- * Fetches files from given Url pattern.
- *
- * @param LU_FetcherFactory $factory Factory to construct fetchers.
- * @param string $path Url to the file or pattern of files.
- * @return array List of Urls with file contents as path.
- */
- public function fetchFiles( LU_FetcherFactory $factory, $path ) {
- $fetcher = $factory->getFetcher( $path );
-
- if ( $this->isDirectory( $path ) ) {
- $files = $fetcher->fetchDirectory( $path );
- } else {
- $files = array( $path => $fetcher->fetchFile( $path ) );
- }
-
- // Remove files which were not found
- return array_filter( $files );
- }
-
- public function execute(
- LU_Finder $finder,
- LU_ReaderFactory $readerFactory,
- LU_FetcherFactory $fetcherFactory,
- array $repos
- ) {
-
- $components = $finder->getComponents();
-
- $updatedMessages = array();
-
- foreach ( $components as $key => $info ) {
- $originFiles = $this->fetchFiles( $fetcherFactory, $info['orig'] );
- $remoteFiles = $this->fetchFiles( $fetcherFactory, $this->expandRemotePath( $info, $repos ) );
-
- if ( $remoteFiles === array() ) {
- // Small optimization: if nothing to compare with, skip
- continue;
- }
-
- $originMessages = $this->readMessages( $readerFactory, $originFiles );
- $remoteMessages = $this->readMessages( $readerFactory, $remoteFiles );
-
- if ( !isset( $remoteMessages['en'] ) ) {
- // Could not find remote messages
- continue;
- }
-
- // If remote translation in English is not present or differs, we do not want
- // translations for other languages for those messages, as they are either not
- // used in this version of code or can be incompatible.
- $forbiddenKeys = $this->findChangedTranslations(
- $originMessages['en'],
- $remoteMessages['en']
- );
-
- // We never accept updates for English strings
- unset( $originMessages['en'], $remoteMessages['en'] );
-
- // message: string in all languages; translation: string in one language.
- foreach ( $remoteMessages as $language => $remoteTranslations ) {
- // Check for completely new languages
- $originTranslations = array();
- if ( isset( $originMessages[$language] ) ) {
- $originTranslations = $originMessages[$language];
- }
-
- $updatedTranslations = $this->findChangedTranslations(
- $originTranslations,
- $remoteTranslations,
- $forbiddenKeys
- );
-
- // Avoid empty arrays
- if ( $updatedTranslations === array() ) {
- continue;
- }
-
- if ( !isset( $updatedMessages[$language] ) ) {
- $updatedMessages[$language] = array();
- }
-
- // In case of conflicts, which should not exist, this prefers the
- // first translation seen.
- $updatedMessages[$language] += $updatedTranslations;
- }
- }
-
- return $updatedMessages;
- }
-}
diff --git a/MLEB/LocalisationUpdate/fetcher/Fetcher.php b/MLEB/LocalisationUpdate/fetcher/Fetcher.php
deleted file mode 100644
index 9c06c105..00000000
--- a/MLEB/LocalisationUpdate/fetcher/Fetcher.php
+++ /dev/null
@@ -1,26 +0,0 @@
-<?php
-/**
- * @file
- * @author Niklas Laxström
- * @license GPL-2.0+
- */
-
-/**
- * Interface for classes which fetch files over different protocols and ways.
- */
-interface LU_Fetcher {
- /**
- * Fetches a single resource.
- *
- * @return bool|string False on failure.
- */
- public function fetchFile( $url );
-
- /**
- * Fetch a list of resources. This has the benefit of being able to pick up
- * new languages as they appear if languages are stored in separate files.
- *
- * @return array
- */
- public function fetchDirectory( $pattern );
-}
diff --git a/MLEB/LocalisationUpdate/fetcher/FetcherFactory.php b/MLEB/LocalisationUpdate/fetcher/FetcherFactory.php
deleted file mode 100644
index 4e26dc15..00000000
--- a/MLEB/LocalisationUpdate/fetcher/FetcherFactory.php
+++ /dev/null
@@ -1,24 +0,0 @@
-<?php
-/**
- * @file
- * @author Niklas Laxström
- * @license GPL-2.0+
- */
-
-/**
- * Constructs fetchers based on the repository urls.
- */
-class LU_FetcherFactory {
- public function getFetcher( $path ) {
-
- if ( strpos( $path, 'https://raw.github.com/' ) === 0 ) {
- return new LU_GitHubFetcher();
- } elseif ( strpos( $path, 'http://' ) === 0 ) {
- return new LU_HttpFetcher();
- } elseif ( strpos( $path, 'https://' ) === 0 ) {
- return new LU_HttpFetcher();
- } else {
- return new LU_FileSystemFetcher();
- }
- }
-}
diff --git a/MLEB/LocalisationUpdate/fetcher/FileSystemFetcher.php b/MLEB/LocalisationUpdate/fetcher/FileSystemFetcher.php
deleted file mode 100644
index a463d6cd..00000000
--- a/MLEB/LocalisationUpdate/fetcher/FileSystemFetcher.php
+++ /dev/null
@@ -1,35 +0,0 @@
-<?php
-/**
- * @file
- * @author Niklas Laxström
- * @license GPL-2.0+
- */
-
-/**
- * Accesses file system directly.
- */
-class LU_FileSystemFetcher implements LU_Fetcher {
- public function fetchFile( $url ) {
- // Remove the protocol prefix
- $url = preg_replace( '~^file://~', '', $url );
-
- if ( !is_readable( $url ) ) {
- return false;
- }
-
- return file_get_contents( $url );
- }
-
- public function fetchDirectory( $pattern ) {
- // Remove the protocol prefix
- $pattern = preg_replace( '~^file://~', '', $pattern );
-
- $data = array();
- foreach ( glob( $pattern ) as $file ) {
- if ( is_readable( $file ) ) {
- $data["file://$file"] = file_get_contents( $file );
- }
- }
- return $data;
- }
-}
diff --git a/MLEB/LocalisationUpdate/fetcher/GitHubFetcher.php b/MLEB/LocalisationUpdate/fetcher/GitHubFetcher.php
deleted file mode 100644
index 5d25257a..00000000
--- a/MLEB/LocalisationUpdate/fetcher/GitHubFetcher.php
+++ /dev/null
@@ -1,38 +0,0 @@
-<?php
-/**
- * @file
- * @author Niklas Laxström
- * @license GPL-2.0+
- */
-
-/**
- * This class uses GitHub api to obtain a list of files present in a directory
- * to avoid fetching files that don't exist.
- *
- * @todo Could use file hashes to 1) avoid fetching files with same hash as
- * the source. 2) avoid fetching files which haven't changed since last check
- * if we store them.
- */
-class LU_GitHubFetcher extends LU_HttpFetcher {
-
- public function fetchDirectory( $pattern ) {
- $p = '~^https://raw.github\.com/(?P<org>[^/]+)/(?P<repo>[^/]+)/(?P<branch>[^/]+)/(?P<path>.+)/.+$~';
- preg_match( $p, $pattern, $m );
-
- $json = Http::get( "https://api.github.com/repos/{$m['org']}/{$m['repo']}/contents/{$m['path']}" );
- if ( !$json ) {
- throw new Exception( "Unable to get directory listing for {$m['org']}/{$m['repo']}" );
- }
-
- $files = array();
- $json = FormatJson::decode( $json, true );
- foreach ( $json as $fileinfo ) {
- $fileurl = dirname( $pattern ) . '/' . $fileinfo['name'];
- $file = $this->fetchFile( $fileurl );
- if ( $file ) {
- $files[$fileurl] = $file;
- }
- }
- return $files;
- }
-}
diff --git a/MLEB/LocalisationUpdate/fetcher/HttpFetcher.php b/MLEB/LocalisationUpdate/fetcher/HttpFetcher.php
deleted file mode 100644
index 9dfed8db..00000000
--- a/MLEB/LocalisationUpdate/fetcher/HttpFetcher.php
+++ /dev/null
@@ -1,40 +0,0 @@
-<?php
-/**
- * @file
- * @author Niklas Laxström
- * @license GPL-2.0+
- */
-
-/**
- * Fetches files over HTTP(s).
- */
-class LU_HttpFetcher implements LU_Fetcher {
- public function fetchFile( $url ) {
- return Http::get( $url );
- }
-
- /**
- * This is horribly inefficient. Subclasses have more efficient
- * implementation of this.
- */
- public function fetchDirectory( $pattern ) {
- $files = array();
-
- $languages = Language::fetchLanguageNames( null, 'mwfile' );
-
- foreach( array_keys( $languages ) as $code ) {
- // Hack for core
- if ( strpos( $pattern, 'Messages*.php' ) !== false ) {
- $code = ucfirst( strtr( $code, '-', '_' ) );
- }
-
- $url = str_replace( '*', $code, $pattern );
- $file = $this->fetchFile( $url );
- if ( $file ) {
- $files[$url] = $file;
- }
- }
-
- return $files;
- }
-}
diff --git a/MLEB/LocalisationUpdate/finder/Finder.php b/MLEB/LocalisationUpdate/finder/Finder.php
deleted file mode 100644
index dc3a7f69..00000000
--- a/MLEB/LocalisationUpdate/finder/Finder.php
+++ /dev/null
@@ -1,107 +0,0 @@
-<?php
-/**
- * @file
- * @author Niklas Laxström
- * @license GPL-2.0+
- */
-
-/**
- * Interface for classes which provide list of components, which should be
- * included for l10n updates.
- */
-class LU_Finder {
- /**
- * @param array $php See $wgExtensionMessagesFiles
- * @param array $json See $wgMessagesDirs
- * @param string $core Absolute path to MediaWiki core
- */
- public function __construct( $php, $json, $core ) {
- $this->php = $php;
- $this->json = $json;
- $this->core = $core;
- }
-
- /**
- * @return array
- */
- public function getComponents() {
- $components = array();
-
- // For older versions of Mediawiki, pull json updates even though its still using php
- if ( !isset( $this->json['core'] ) ) {
- $components['core'] = array(
- 'repo' => 'mediawiki',
- 'orig' => "file://{$this->core}/languages/messages/Messages*.php",
- 'path' => 'languages/messages/i18n/*.json',
- );
- }
-
- foreach ( $this->json as $key => $value ) {
- // Json should take priority if both exist
- unset( $this->php[$key] );
-
- foreach ( (array)$value as $subkey => $subvalue ) {
- // Mediawiki core files
- $matches = array();
- if ( preg_match( '~/(?P<path>(?:includes|languages|resources)/.*)$~', $subvalue, $matches ) ) {
- $components["$key-$subkey"] = array(
- 'repo' => 'mediawiki',
- 'orig' => "file://$value/*.json",
- 'path' => "{$matches['path']}/*.json",
- );
- continue;
- }
-
- $item = $this->getItem( 'extensions', $subvalue );
- if ( $item !== null ) {
- $item['repo'] = 'extension';
- $components["$key-$subkey"] = $item;
- continue;
- }
-
- $item = $this->getItem( 'skins', $subvalue );
- if ( $item !== null ) {
- $item['repo'] = 'skin';
- $components["$key-$subkey"] = $item;
- continue;
- }
- }
- }
-
- foreach ( $this->php as $key => $value ) {
- $matches = array();
- $ok = preg_match( '~/extensions/(?P<name>[^/]+)/(?P<path>.*\.i18n\.php)$~', $value, $matches );
- if ( !$ok ) {
- continue;
- }
-
- $components[$key] = array(
- 'repo' => 'extension',
- 'name' => $matches['name'],
- 'orig' => "file://$value",
- 'path' => $matches['path'],
- );
- }
-
- return $components;
- }
-
- /**
- * @param string $dir extensions or skins
- * @param string $subvalue
- * @return array|null
- */
- private function getItem( $dir, $subvalue ) {
- // This ignores magic, alias etc. non message files
- $matches = array();
- if ( !preg_match( "~/$dir/(?P<name>[^/]+)/(?P<path>.*)$~", $subvalue, $matches ) ) {
- return null;
- }
-
- return array(
- 'name' => $matches['name'],
- 'orig' => "file://$subvalue/*.json",
- 'path' => "{$matches['path']}/*.json",
- );
- }
-}
diff --git a/MLEB/LocalisationUpdate/i18n/ca.json b/MLEB/LocalisationUpdate/i18n/ca.json
index d37e93a9..4b4ac0af 100644
--- a/MLEB/LocalisationUpdate/i18n/ca.json
+++ b/MLEB/LocalisationUpdate/i18n/ca.json
@@ -1,8 +1,9 @@
{
"@metadata": {
"authors": [
- "Paucabot"
+ "Paucabot",
+ "Fitoschido"
]
},
- "localisationupdate-desc": "Manté els missatges localitzats tan actualitzats com sigui possible"
+ "localisationupdate-desc": "Manté els missatges traduïts tan actualitzats com sigui possible"
}
diff --git a/MLEB/LocalisationUpdate/i18n/de.json b/MLEB/LocalisationUpdate/i18n/de.json
index 3f1d3fbc..98f9dc14 100644
--- a/MLEB/LocalisationUpdate/i18n/de.json
+++ b/MLEB/LocalisationUpdate/i18n/de.json
@@ -2,8 +2,10 @@
"@metadata": {
"authors": [
"Kghbln",
- "Purodha"
+ "Purodha",
+ "Metalhead64"
]
},
+ "localisationupdate-extensionname": "LocalisationUpdate",
"localisationupdate-desc": "Ermöglicht es lokalisierte Texte und Nachrichten so aktuell wie möglich zu halten"
}
diff --git a/MLEB/LocalisationUpdate/i18n/en.json b/MLEB/LocalisationUpdate/i18n/en.json
index 813a9e74..a15cef56 100644
--- a/MLEB/LocalisationUpdate/i18n/en.json
+++ b/MLEB/LocalisationUpdate/i18n/en.json
@@ -1,8 +1,9 @@
{
- "@metadata": {
- "authors": [
- "Tom Maaswinkel"
- ]
- },
- "localisationupdate-desc": "Keeps the localised messages as up to date as possible"
+ "@metadata": {
+ "authors": [
+ "Tom Maaswinkel"
+ ]
+ },
+ "localisationupdate-extensionname": "LocalisationUpdate",
+ "localisationupdate-desc": "Keeps the localised messages as up to date as possible"
} \ No newline at end of file
diff --git a/MLEB/LocalisationUpdate/i18n/es.json b/MLEB/LocalisationUpdate/i18n/es.json
index 2526e852..aea82b47 100644
--- a/MLEB/LocalisationUpdate/i18n/es.json
+++ b/MLEB/LocalisationUpdate/i18n/es.json
@@ -1,8 +1,9 @@
{
"@metadata": {
"authors": [
- "Crazymadlover"
+ "Crazymadlover",
+ "Fitoschido"
]
},
- "localisationupdate-desc": "Mantiene los mensajes localizados tan actualizados como sea posible"
+ "localisationupdate-desc": "Mantiene los mensajes traducidos tan actualizados como sea posible"
}
diff --git a/MLEB/LocalisationUpdate/i18n/mk.json b/MLEB/LocalisationUpdate/i18n/mk.json
index 10eb0966..3ac7e4df 100644
--- a/MLEB/LocalisationUpdate/i18n/mk.json
+++ b/MLEB/LocalisationUpdate/i18n/mk.json
@@ -4,5 +4,6 @@
"Bjankuloski06"
]
},
+ "localisationupdate-extensionname": "Поднова на локализацијата",
"localisationupdate-desc": "Ги одржува локализираните пораки колку што е можно пообновени и повеќе во тек со настаните"
}
diff --git a/MLEB/LocalisationUpdate/i18n/nb.json b/MLEB/LocalisationUpdate/i18n/nb.json
index c7978a78..e9db5be1 100644
--- a/MLEB/LocalisationUpdate/i18n/nb.json
+++ b/MLEB/LocalisationUpdate/i18n/nb.json
@@ -1,8 +1,10 @@
{
"@metadata": {
"authors": [
- "Nghtwlkr"
+ "Nghtwlkr",
+ "Jon Harald Søby"
]
},
+ "localisationupdate-extensionname": "LocalisationUpdate",
"localisationupdate-desc": "Holder de lokaliserte meldingene så oppdaterte som mulig"
}
diff --git a/MLEB/LocalisationUpdate/i18n/pt.json b/MLEB/LocalisationUpdate/i18n/pt.json
index 07fa8c3d..bbda7981 100644
--- a/MLEB/LocalisationUpdate/i18n/pt.json
+++ b/MLEB/LocalisationUpdate/i18n/pt.json
@@ -6,5 +6,5 @@
"Malafaya"
]
},
- "localisationupdate-desc": "Mantém as mensagens localizadas tão atualizadas quanto possível"
+ "localisationupdate-desc": "Mantém as mensagens traduzidas tão atualizadas quanto possível"
}
diff --git a/MLEB/LocalisationUpdate/i18n/qqq.json b/MLEB/LocalisationUpdate/i18n/qqq.json
index c08af070..99da1a04 100644
--- a/MLEB/LocalisationUpdate/i18n/qqq.json
+++ b/MLEB/LocalisationUpdate/i18n/qqq.json
@@ -7,5 +7,6 @@
"Umherirrender"
]
},
+ "localisationupdate-extensionname": "{{name}}",
"localisationupdate-desc": "{{desc|name=Localisation Update|url=https://www.mediawiki.org/wiki/Extension:LocalisationUpdate}}"
}
diff --git a/MLEB/LocalisationUpdate/i18n/sr-ec.json b/MLEB/LocalisationUpdate/i18n/sr-ec.json
index dfd900a4..599334a9 100644
--- a/MLEB/LocalisationUpdate/i18n/sr-ec.json
+++ b/MLEB/LocalisationUpdate/i18n/sr-ec.json
@@ -1,8 +1,9 @@
{
"@metadata": {
"authors": [
- "Михајло Анђелковић"
+ "Михајло Анђелковић",
+ "BadDog"
]
},
- "localisationupdate-desc": "Ажурира локализоване поруке колико је то могуће"
+ "localisationupdate-desc": "Задржава локализоване поруке ажурираним колико год је то могуће"
}
diff --git a/MLEB/LocalisationUpdate/reader/JSONReader.php b/MLEB/LocalisationUpdate/reader/JSONReader.php
deleted file mode 100644
index 636168c8..00000000
--- a/MLEB/LocalisationUpdate/reader/JSONReader.php
+++ /dev/null
@@ -1,30 +0,0 @@
-<?php
-/**
- * @file
- * @author Niklas Laxström
- * @license GPL-2.0+
- */
-
-/**
- * Reads MediaWiki JSON i18n files.
- */
-class LU_JSONReader implements LU_Reader {
- /// @var string Language tag
- protected $code;
-
- public function __construct( $code = null ) {
- $this->code = $code;
- }
-
- public function parse( $contents ) {
- $messages = FormatJson::decode( $contents, true );
- unset( $messages['@metadata'] );
-
- if ( $this->code ) {
- return array( $this->code => $messages );
- }
-
- // Assuming that the array is keyed by language codes
- return $messages;
- }
-}
diff --git a/MLEB/LocalisationUpdate/reader/PHPReader.php b/MLEB/LocalisationUpdate/reader/PHPReader.php
deleted file mode 100644
index 986d7b52..00000000
--- a/MLEB/LocalisationUpdate/reader/PHPReader.php
+++ /dev/null
@@ -1,54 +0,0 @@
-<?php
-/**
- * @file
- * @author Niklas Laxström
- * @license GPL-2.0+
- */
-
-/**
- * Reads MediaWiki PHP i18n files.
- */
-class LU_PHPReader implements LU_Reader {
- /// @var string Language tag
- protected $code;
-
- public function __construct( $code = null ) {
- $this->code = $code;
- }
-
- public function parse( $contents ) {
- if ( strpos( $contents, '$messages' ) === false ) {
- // This happens for some core languages that only have a fallback.
- return array();
- }
-
- $php = $this->cleanupFile( $contents );
- $reader = new QuickArrayReader( "<?php $php" );
- $messages = $reader->getVar( 'messages' );
-
- if ( $this->code ) {
- return array( $this->code => $messages );
- }
-
- // Assuming that the array is keyed by language codes
- return $messages;
- }
-
- /**
- * Removes all unneeded content from a file and returns it.
- *
- * @param string $contents String
- * @return string PHP code without PHP tags
- */
- protected function cleanupFile( $contents ) {
- // We hate the windows vs linux linebreaks.
- $contents = preg_replace( '/\r\n?/', "\n", $contents );
-
- // We only want message arrays.
- $results = array();
- preg_match_all( '/\$messages(?:.*\s)*?\);/', $contents, $results );
-
- // But we want them all in one string.
- return implode( "\n\n", $results[0] );
- }
-}
diff --git a/MLEB/LocalisationUpdate/reader/Reader.php b/MLEB/LocalisationUpdate/reader/Reader.php
deleted file mode 100644
index f55a9372..00000000
--- a/MLEB/LocalisationUpdate/reader/Reader.php
+++ /dev/null
@@ -1,19 +0,0 @@
-<?php
-/**
- * @file
- * @author Niklas Laxström
- * @license GPL-2.0+
- */
-
-/**
- * Interface for file readers.
- */
-interface LU_Reader {
- /**
- * Returns a list of messages indexed by language code. Example
- * array( 'en' => array( 'key' => 'value' ) );
- * @param string $contents File contents as a string.
- * @return array
- */
- public function parse( $contents );
-}
diff --git a/MLEB/LocalisationUpdate/reader/ReaderFactory.php b/MLEB/LocalisationUpdate/reader/ReaderFactory.php
deleted file mode 100644
index 983ec314..00000000
--- a/MLEB/LocalisationUpdate/reader/ReaderFactory.php
+++ /dev/null
@@ -1,36 +0,0 @@
-<?php
-/**
- * @file
- * @author Niklas Laxström
- * @license GPL-2.0+
- */
-
-/**
- * Constructs readers for files based on the names.
- */
-class LU_ReaderFactory {
- /**
- * Constructs a suitable reader for a given path.
- * @param string $filename Usually a relative path to the file name.
- * @return LU_Reader
- * @throw Exception
- */
- public function getReader( $filename ) {
- if ( preg_match( '/i18n\.php$/', $filename ) ) {
- return new LU_PHPReader();
- }
-
- // Ugly hack for core i18n files
- if ( preg_match( '/Messages(.*)\.php$/', $filename ) ) {
- $code = Language::getCodeFromFileName( basename( $filename ), 'Messages' );
- return new LU_PHPReader( $code );
- }
-
- if ( preg_match( '/\.json/', $filename ) ) {
- $code = basename( $filename, '.json' );
- return new LU_JSONReader( $code );
- }
-
- throw new Exception( "Unknown file format: " . $filename );
- }
-}
diff --git a/MLEB/LocalisationUpdate/tests/phpunit/UpdaterTest.php b/MLEB/LocalisationUpdate/tests/phpunit/UpdaterTest.php
index ce742cba..00c45e12 100644
--- a/MLEB/LocalisationUpdate/tests/phpunit/UpdaterTest.php
+++ b/MLEB/LocalisationUpdate/tests/phpunit/UpdaterTest.php
@@ -2,12 +2,21 @@
/**
* @file
* @author Niklas Laxström
- * @license GPL-2.0+
+ * @license GPL-2.0-or-later
*/
-class LU_UpdaterTest extends MediaWikiTestCase {
+namespace LocalisationUpdate;
+
+use PHPUnit4And6Compat;
+
+/**
+ * @covers \LocalisationUpdate\Updater
+ */
+class UpdaterTest extends \PHPUnit\Framework\TestCase {
+ use PHPUnit4And6Compat;
+
public function testIsDirectory() {
- $updater = new LU_Updater();
+ $updater = new Updater();
$this->assertTrue(
$updater->isDirectory( '/IP/extensions/Translate/i18n/*.json' ),
@@ -21,14 +30,14 @@ class LU_UpdaterTest extends MediaWikiTestCase {
}
public function testExpandRemotePath() {
- $updater = new LU_Updater();
- $repos = array( 'main' => 'file:///repos/%NAME%/%SOME-VAR%' );
+ $updater = new Updater();
+ $repos = [ 'main' => 'file:///repos/%NAME%/%SOME-VAR%' ];
- $info = array(
+ $info = [
'repo' => 'main',
'name' => 'product',
'some-var' => 'file',
- );
+ ];
$this->assertEquals(
'file:///repos/product/file',
$updater->expandRemotePath( $info, $repos ),
@@ -37,18 +46,18 @@ class LU_UpdaterTest extends MediaWikiTestCase {
}
public function testReadMessages() {
- $updater = $updater = new LU_Updater();
+ $updater = $updater = new Updater();
- $input = array( 'file' => 'Hello World!' );
- $output = array( 'en' => array( 'key' => $input['file'] ) );
+ $input = [ 'file' => 'Hello World!' ];
+ $output = [ 'en' => [ 'key' => $input['file'] ] ];
- $reader = $this->getMock( 'LU_Reader' );
+ $reader = $this->getMock( 'LocalisationUpdate\Reader' );
$reader
->expects( $this->once() )
->method( 'parse' )
->will( $this->returnValue( $output ) );
- $factory = $this->getMock( 'LU_ReaderFactory' );
+ $factory = $this->getMock( 'LocalisationUpdate\ReaderFactory' );
$factory
->expects( $this->once() )
->method( 'getReader' )
@@ -59,21 +68,21 @@ class LU_UpdaterTest extends MediaWikiTestCase {
}
public function testFindChangedTranslations() {
- $updater = $updater = new LU_Updater();
+ $updater = $updater = new Updater();
- $origin = array(
+ $origin = [
'A' => '1',
'C' => '3',
'D' => '4',
- );
- $remote = array(
+ ];
+ $remote = [
'A' => '1', // No change key
'B' => '2', // New key
'C' => '33', // Changed key
'D' => '44', // Blacklisted key
- );
- $blacklist = array( 'D' => 0 );
- $expected = array( 'B' => '2', 'C' => '33' );
+ ];
+ $blacklist = [ 'D' => 0 ];
+ $expected = [ 'B' => '2', 'C' => '33' ];
$observed = $updater->findChangedTranslations( $origin, $remote, $blacklist );
$this->assertEquals( $expected, $observed, 'Changed and new keys returned' );
}
diff --git a/MLEB/LocalisationUpdate/tests/phpunit/finder/FinderTest.php b/MLEB/LocalisationUpdate/tests/phpunit/finder/FinderTest.php
index b8213bac..1b4db0f4 100644
--- a/MLEB/LocalisationUpdate/tests/phpunit/finder/FinderTest.php
+++ b/MLEB/LocalisationUpdate/tests/phpunit/finder/FinderTest.php
@@ -2,79 +2,84 @@
/**
* @file
* @author Niklas Laxström
- * @license GPL-2.0+
+ * @license GPL-2.0-or-later
*/
-class LU_FinderTest extends MediaWikiTestCase {
+namespace LocalisationUpdate;
+
+/**
+ * @covers \LocalisationUpdate\Finder
+ */
+class FinderTest extends \PHPUnit\Framework\TestCase {
public function testGetComponents() {
- $finder = new LU_Finder(
- array(
+ $finder = new Finder(
+ [
'TranslateSearch' => '/IP/extensions/Translate/TranslateSearch.i18n.php',
'Babel' => '/IP/extensions/Babel/Babel.i18n.php',
- ),
- array(
+ ],
+ [
'Babel' => '/IP/extensions/Babel/i18n',
- 'Door' => array(
+ 'Door' => [
'core' => '/IP/extensions/Door/i18n/core',
'extra' => '/IP/extensions/Door/i18n/extra',
- ),
+ ],
'Vector' => '/IP/skins/Vector/i18n',
- ),
+ ],
'/IP'
);
$observed = $finder->getComponents();
- $expected = array(
+ $expected = [
'repo' => 'mediawiki',
'orig' => "file:///IP/languages/messages/Messages*.php",
'path' => 'languages/messages/i18n/*.json',
- );
+ ];
$this->assertArrayHasKey( 'core', $observed );
$this->assertEquals( $expected, $observed['core'], 'Core php file' );
- $expected = array(
+ $expected = [
'repo' => 'extension',
'name' => 'Translate',
'orig' => 'file:///IP/extensions/Translate/TranslateSearch.i18n.php',
'path' => 'TranslateSearch.i18n.php'
- );
+ ];
$this->assertArrayHasKey( 'TranslateSearch', $observed );
$this->assertEquals( $expected, $observed['TranslateSearch'], 'PHP only extension' );
- $expected = array(
+ $expected = [
'repo' => 'extension',
'name' => 'Babel',
'orig' => 'file:///IP/extensions/Babel/i18n/*.json',
'path' => 'i18n/*.json'
- );
+ ];
$this->assertArrayHasKey( 'Babel-0', $observed );
$this->assertEquals( $expected, $observed['Babel-0'], 'PHP&JSON extension' );
- $expected = array(
+ $expected = [
'repo' => 'extension',
'name' => 'Door',
'orig' => 'file:///IP/extensions/Door/i18n/core/*.json',
'path' => 'i18n/core/*.json'
- );
+ ];
$this->assertArrayHasKey( 'Door-core', $observed );
$this->assertEquals( $expected, $observed['Door-core'], 'Multidir json extension' );
- $expected = array(
+ $expected = [
'repo' => 'extension',
'name' => 'Door',
'orig' => 'file:///IP/extensions/Door/i18n/extra/*.json',
'path' => 'i18n/extra/*.json'
- );
+ ];
$this->assertArrayHasKey( 'Door-extra', $observed );
$this->assertEquals( $expected, $observed['Door-extra'], 'Multidir json extension' );
- $expected = array(
+ $expected = [
'repo' => 'skin',
'name' => 'Vector',
'orig' => 'file:///IP/skins/Vector/i18n/*.json',
'path' => 'i18n/*.json'
- );
+ ];
$this->assertArrayHasKey( 'Vector-0', $observed );
$this->assertEquals( $expected, $observed['Vector-0'], 'Json skin' );
}
diff --git a/MLEB/LocalisationUpdate/tests/phpunit/reader/JSONReaderTest.php b/MLEB/LocalisationUpdate/tests/phpunit/reader/JSONReaderTest.php
index 4bb53af9..11f0a03b 100644
--- a/MLEB/LocalisationUpdate/tests/phpunit/reader/JSONReaderTest.php
+++ b/MLEB/LocalisationUpdate/tests/phpunit/reader/JSONReaderTest.php
@@ -2,36 +2,41 @@
/**
* @file
* @author Niklas Laxström
- * @license GPL-2.0+
+ * @license GPL-2.0-or-later
*/
-class LU_JSONReaderTest extends MediaWikiTestCase {
+namespace LocalisationUpdate;
+
+/**
+ * @covers \LocalisationUpdate\JSONReader
+ */
+class JSONReaderTest extends \PHPUnit\Framework\TestCase {
/**
* @dataProvider parseProvider
*/
public function testParse( $input, $expected, $comment ) {
- $reader = new LU_JSONReader( 'xx' );
+ $reader = new JSONReader( 'xx' );
$observed = $reader->parse( $input );
$this->assertEquals( $expected, $observed['xx'], $comment );
}
public function parseProvider() {
- return array(
- array(
+ return [
+ [
'{}',
- array(),
+ [],
'empty file',
- ),
- array(
+ ],
+ [
'{"key":"value"}',
- array( 'key' => 'value' ),
+ [ 'key' => 'value' ],
'file with one string',
- ),
- array(
+ ],
+ [
'{"@metadata":{"authors":["Nike"]},"key":"value2"}',
- array( 'key' => 'value2' ),
+ [ 'key' => 'value2' ],
'@metadata is ignored',
- )
- );
+ ]
+ ];
}
}
diff --git a/MLEB/LocalisationUpdate/tests/phpunit/reader/ReaderFactoryTest.php b/MLEB/LocalisationUpdate/tests/phpunit/reader/ReaderFactoryTest.php
index ee155b3a..86776395 100644
--- a/MLEB/LocalisationUpdate/tests/phpunit/reader/ReaderFactoryTest.php
+++ b/MLEB/LocalisationUpdate/tests/phpunit/reader/ReaderFactoryTest.php
@@ -2,37 +2,42 @@
/**
* @file
* @author Niklas Laxström
- * @license GPL-2.0+
+ * @license GPL-2.0-or-later
*/
-class LU_ReaderFactoryTest extends MediaWikiTestCase {
+namespace LocalisationUpdate;
+
+/**
+ * @covers \LocalisationUpdate\ReaderFactory
+ */
+class ReaderFactoryTest extends \PHPUnit\Framework\TestCase {
/**
* @dataProvider getReaderProvider
*/
public function testGetReader( $input, $expected, $comment ) {
- $factory = new LU_ReaderFactory();
+ $factory = new ReaderFactory();
$reader = $factory->getReader( $input );
$observed = get_class( $reader );
$this->assertEquals( $expected, $observed, $comment );
}
public function getReaderProvider() {
- return array(
- array(
+ return [
+ [
'languages/messages/MessagesFi.php',
- 'LU_PHPReader',
+ 'LocalisationUpdate\PHPReader',
'core php file',
- ),
- array(
+ ],
+ [
'extensions/Translate/Translate.i18n.php',
- 'LU_PHPReader',
+ 'LocalisationUpdate\PHPReader',
'extension php file',
- ),
- array(
+ ],
+ [
'extension/Translate/i18n/core/de.json',
- 'LU_JSONReader',
+ 'LocalisationUpdate\JSONReader',
'extension json file',
- ),
- );
+ ],
+ ];
}
}
diff --git a/MLEB/LocalisationUpdate/update.php b/MLEB/LocalisationUpdate/update.php
index 1f5eaa77..a8ed7ead 100644
--- a/MLEB/LocalisationUpdate/update.php
+++ b/MLEB/LocalisationUpdate/update.php
@@ -2,12 +2,11 @@
$IP = strval( getenv( 'MW_INSTALL_PATH' ) ) !== ''
? getenv( 'MW_INSTALL_PATH' )
- : realpath( dirname( __FILE__ ) . "/../../" );
-// Can use __DIR__ once we drop support for MW 1.19
+ : realpath( __DIR__ . '/../../' );
require "$IP/maintenance/Maintenance.php";
-class LU extends Maintenance {
+class Update extends Maintenance {
public function __construct() {
parent::__construct();
$this->mDescription = 'Fetches translation updates to MediaWiki core, skins and extensions.';
@@ -17,6 +16,8 @@ class LU extends Maintenance {
false, /*required*/
true /*has arg*/
);
+
+ $this->requireExtension( 'LocalisationUpdate' );
}
public function execute() {
@@ -25,7 +26,8 @@ class LU extends Maintenance {
ini_set( "max_execution_time", 0 );
ini_set( 'memory_limit', -1 );
- global $wgExtensionMessagesFiles, $IP;
+ global $IP;
+ global $wgExtensionMessagesFiles;
global $wgLocalisationUpdateRepositories;
global $wgLocalisationUpdateRepository;
@@ -36,16 +38,11 @@ class LU extends Maintenance {
}
$lc = Language::getLocalisationCache();
- if ( is_callable( array( $lc, 'getMessagesDirs' ) ) ) { // Introduced in 1.25
- $messagesDirs = $lc->getMessagesDirs();
- } else {
- global $wgMessagesDirs;
- $messagesDirs = $wgMessagesDirs;
- }
+ $messagesDirs = $lc->getMessagesDirs();
- $finder = new LU_Finder( $wgExtensionMessagesFiles, $messagesDirs, $IP );
- $readerFactory = new LU_ReaderFactory();
- $fetcherFactory = new LU_FetcherFactory();
+ $finder = new LocalisationUpdate\Finder( $wgExtensionMessagesFiles, $messagesDirs, $IP );
+ $readerFactory = new LocalisationUpdate\ReaderFactory();
+ $fetcherFactory = new LocalisationUpdate\FetcherFactory();
$repoid = $this->getOption( 'repoid', $wgLocalisationUpdateRepository );
if ( !isset( $wgLocalisationUpdateRepositories[$repoid] ) ) {
@@ -55,13 +52,18 @@ class LU extends Maintenance {
}
$repos = $wgLocalisationUpdateRepositories[$repoid];
+ // output and error methods are protected, hence we add logInfo and logError
+ // public methods, that hopefully won't conflict in the future with the base class.
+ $logger = $this;
+
// Do it ;)
- $updater = new LU_Updater();
+ $updater = new LocalisationUpdate\Updater();
$updatedMessages = $updater->execute(
$finder,
$readerFactory,
$fetcherFactory,
- $repos
+ $repos,
+ $logger
);
// Store it ;)
@@ -77,7 +79,15 @@ class LU extends Maintenance {
}
$this->output( "Saved $count new translations\n" );
}
+
+ public function logInfo( $msg ) {
+ $this->output( $msg . "\n" );
+ }
+
+ public function logError( $msg ) {
+ $this->error( $msg );
+ }
}
-$maintClass = 'LU';
+$maintClass = Update::class;
require_once RUN_MAINTENANCE_IF_MAIN;