diff options
Diffstat (limited to 'extensions/LocalisationUpdate')
10 files changed, 169 insertions, 27 deletions
diff --git a/extensions/LocalisationUpdate/LocalisationUpdate.class.php b/extensions/LocalisationUpdate/LocalisationUpdate.class.php index 349c35f0..d4413ed7 100644 --- a/extensions/LocalisationUpdate/LocalisationUpdate.class.php +++ b/extensions/LocalisationUpdate/LocalisationUpdate.class.php @@ -78,4 +78,22 @@ class LocalisationUpdate { 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/extensions/LocalisationUpdate/LocalisationUpdate.php b/extensions/LocalisationUpdate/LocalisationUpdate.php index 53aa5adc..6548a3c6 100644 --- a/extensions/LocalisationUpdate/LocalisationUpdate.php +++ b/extensions/LocalisationUpdate/LocalisationUpdate.php @@ -1,5 +1,19 @@ <?php +if ( function_exists( 'wfLoadExtension' ) ) { + wfLoadExtension( 'LocalisationUpdate' ); + // Keep i18n globals so mergeMessageFileList.php doesn't break + $wgMessagesDirs['LocalisationUpdate'] = __DIR__ . '/i18n'; + /* wfWarn( + 'Deprecated PHP entry point used for LocalisationUpdate extension. Please use wfLoadExtension instead, ' . + 'see https://www.mediawiki.org/wiki/Extension_registration for more details.' + ); */ + return true; +} +/** + * Setup for pre-1.25 wikis. Make sure this is kept in sync with extension.json + */ + /** * 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 @@ -23,9 +37,11 @@ $wgLocalisationUpdateRepository = 'github'; $wgLocalisationUpdateRepositories = array(); $wgLocalisationUpdateRepositories['github'] = array( 'mediawiki' => - 'https://raw.github.com/wikimedia/mediawiki-core/master/%PATH%', + '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 @@ -34,6 +50,8 @@ $wgLocalisationUpdateRepositories['github'] = array( # '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( @@ -47,6 +65,7 @@ $wgExtensionCredits['other'][] = array( $wgHooks['LocalisationCacheRecache'][] = 'LocalisationUpdate::onRecache'; $wgHooks['LocalisationCacheRecacheFallback'][] = 'LocalisationUpdate::onRecacheFallback'; +$GLOBALS['wgHooks']['UnitTestsList'][] = 'LocalisationUpdate::setupUnitTests'; $dir = __DIR__; $wgMessagesDirs['LocalisationUpdate'] = __DIR__ . '/i18n'; diff --git a/extensions/LocalisationUpdate/extension.json b/extensions/LocalisationUpdate/extension.json new file mode 100644 index 00000000..43262f09 --- /dev/null +++ b/extensions/LocalisationUpdate/extension.json @@ -0,0 +1,55 @@ +{ + "@note": "This file must be kept in sync with LocalisationUpdate.php", + "name": "LocalisationUpdate", + "version": "1.3.0", + "author": [ + "Tom Maaswinkel", + "Niklas Laxström", + "Roan Kattouw" + ], + "url": "https://www.mediawiki.org/wiki/Extension:LocalisationUpdate", + "descriptionmsg": "localisationupdate-desc", + "type": "other", + "MessagesDirs": { + "LocalisationUpdate": [ + "i18n" + ] + }, + "AutoloadClasses": { + "LocalisationUpdate": "LocalisationUpdate.class.php", + "LU_Updater": "Updater.php", + "QuickArrayReader": "QuickArrayReader.php", + "LU_Fetcher": "fetcher/Fetcher.php", + "LU_FetcherFactory": "fetcher/FetcherFactory.php", + "LU_FileSystemFetcher": "fetcher/FileSystemFetcher.php", + "LU_GitHubFetcher": "fetcher/GitHubFetcher.php", + "LU_HttpFetcher": "fetcher/HttpFetcher.php", + "LU_Finder": "finder/Finder.php", + "LU_JSONReader": "reader/JSONReader.php", + "LU_PHPReader": "reader/PHPReader.php", + "LU_Reader": "reader/Reader.php", + "LU_ReaderFactory": "reader/ReaderFactory.php" + }, + "Hooks": { + "LocalisationCacheRecache": [ + "LocalisationUpdate::onRecache" + ], + "LocalisationCacheRecacheFallback": [ + "LocalisationUpdate::onRecacheFallback" + ], + "UnitTestsList": [ + "LocalisationUpdate::setupUnitTests" + ] + }, + "config": { + "LocalisationUpdateDirectory": false, + "LocalisationUpdateRepository": "github", + "LocalisationUpdateRepositories": { + "github": { + "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%" + } + } + } +} diff --git a/extensions/LocalisationUpdate/fetcher/GitHubFetcher.php b/extensions/LocalisationUpdate/fetcher/GitHubFetcher.php index 00c9b6ca..5d25257a 100644 --- a/extensions/LocalisationUpdate/fetcher/GitHubFetcher.php +++ b/extensions/LocalisationUpdate/fetcher/GitHubFetcher.php @@ -21,7 +21,7 @@ class LU_GitHubFetcher extends LU_HttpFetcher { $json = Http::get( "https://api.github.com/repos/{$m['org']}/{$m['repo']}/contents/{$m['path']}" ); if ( !$json ) { - throw new MWException( "Unable to get directory listing for {$m['org']}/{$m['repo']}" ); + throw new Exception( "Unable to get directory listing for {$m['org']}/{$m['repo']}" ); } $files = array(); diff --git a/extensions/LocalisationUpdate/finder/Finder.php b/extensions/LocalisationUpdate/finder/Finder.php index 5c598730..dc3a7f69 100644 --- a/extensions/LocalisationUpdate/finder/Finder.php +++ b/extensions/LocalisationUpdate/finder/Finder.php @@ -41,24 +41,34 @@ class LU_Finder { unset( $this->php[$key] ); foreach ( (array)$value as $subkey => $subvalue ) { - // This ignores magic, alias etc. non message files + // Mediawiki core files $matches = array(); - $ok = preg_match( '~/extensions/(?P<name>[^/]+)/(?P<path>.*)$~', $subvalue, $matches ); - if ( !$ok ) { + 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; } - $components["$key-$subkey"] = array( - 'repo' => 'extension', - 'name' => $matches['name'], - 'orig' => "file://$subvalue/*.json", - 'path' => "{$matches['path']}/*.json", - ); + $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 ) { - // This currently skips core i18n files like resources/oojs-ui/i18n $matches = array(); $ok = preg_match( '~/extensions/(?P<name>[^/]+)/(?P<path>.*\.i18n\.php)$~', $value, $matches ); if ( !$ok ) { @@ -75,4 +85,23 @@ class LU_Finder { 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/extensions/LocalisationUpdate/i18n/qqq.json b/extensions/LocalisationUpdate/i18n/qqq.json index c6978bbb..c08af070 100644 --- a/extensions/LocalisationUpdate/i18n/qqq.json +++ b/extensions/LocalisationUpdate/i18n/qqq.json @@ -3,8 +3,9 @@ "authors": [ "Fryed-peach", "Purodha", - "Shirayuki" + "Shirayuki", + "Umherirrender" ] }, - "localisationupdate-desc": "{{desc|name=Localisation Update|url=http://www.mediawiki.org/wiki/Extension:LocalisationUpdate}}" + "localisationupdate-desc": "{{desc|name=Localisation Update|url=https://www.mediawiki.org/wiki/Extension:LocalisationUpdate}}" } diff --git a/extensions/LocalisationUpdate/i18n/zh-hant.json b/extensions/LocalisationUpdate/i18n/zh-hant.json index 97e51cfe..511b9790 100644 --- a/extensions/LocalisationUpdate/i18n/zh-hant.json +++ b/extensions/LocalisationUpdate/i18n/zh-hant.json @@ -2,8 +2,9 @@ "@metadata": { "authors": [ "Mark85296341", - "Tom Maaswinkel" + "Tom Maaswinkel", + "LNDDYL" ] }, - "localisationupdate-desc": "將本地化的資訊盡可能保持最新" + "localisationupdate-desc": "將在地化的資訊盡可能保持最新" } diff --git a/extensions/LocalisationUpdate/reader/ReaderFactory.php b/extensions/LocalisationUpdate/reader/ReaderFactory.php index 530ab3f9..983ec314 100644 --- a/extensions/LocalisationUpdate/reader/ReaderFactory.php +++ b/extensions/LocalisationUpdate/reader/ReaderFactory.php @@ -13,7 +13,7 @@ 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 MWException + * @throw Exception */ public function getReader( $filename ) { if ( preg_match( '/i18n\.php$/', $filename ) ) { @@ -31,6 +31,6 @@ class LU_ReaderFactory { return new LU_JSONReader( $code ); } - throw new MWException( "Unknown file format: " . $filename ); + throw new Exception( "Unknown file format: " . $filename ); } } diff --git a/extensions/LocalisationUpdate/tests/phpunit/finder/FinderTest.php b/extensions/LocalisationUpdate/tests/phpunit/finder/FinderTest.php index 8cc0f7d7..b8213bac 100644 --- a/extensions/LocalisationUpdate/tests/phpunit/finder/FinderTest.php +++ b/extensions/LocalisationUpdate/tests/phpunit/finder/FinderTest.php @@ -18,6 +18,7 @@ class LU_FinderTest extends MediaWikiTestCase { 'core' => '/IP/extensions/Door/i18n/core', 'extra' => '/IP/extensions/Door/i18n/extra', ), + 'Vector' => '/IP/skins/Vector/i18n', ), '/IP' ); @@ -26,10 +27,11 @@ class LU_FinderTest extends MediaWikiTestCase { $expected = array( 'repo' => 'mediawiki', 'orig' => "file:///IP/languages/messages/Messages*.php", - 'path' => 'languages/messages/Messages*.php', + 'path' => 'languages/messages/i18n/*.json', ); + $this->assertArrayHasKey( 'core', $observed ); - $this->assertSame( $expected, $observed['core'], 'Core php file' ); + $this->assertEquals( $expected, $observed['core'], 'Core php file' ); $expected = array( 'repo' => 'extension', @@ -38,7 +40,7 @@ class LU_FinderTest extends MediaWikiTestCase { 'path' => 'TranslateSearch.i18n.php' ); $this->assertArrayHasKey( 'TranslateSearch', $observed ); - $this->assertSame( $expected, $observed['TranslateSearch'], 'PHP only extension' ); + $this->assertEquals( $expected, $observed['TranslateSearch'], 'PHP only extension' ); $expected = array( 'repo' => 'extension', @@ -47,7 +49,7 @@ class LU_FinderTest extends MediaWikiTestCase { 'path' => 'i18n/*.json' ); $this->assertArrayHasKey( 'Babel-0', $observed ); - $this->assertSame( $expected, $observed['Babel-0'], 'PHP&JSON extension' ); + $this->assertEquals( $expected, $observed['Babel-0'], 'PHP&JSON extension' ); $expected = array( 'repo' => 'extension', @@ -56,7 +58,7 @@ class LU_FinderTest extends MediaWikiTestCase { 'path' => 'i18n/core/*.json' ); $this->assertArrayHasKey( 'Door-core', $observed ); - $this->assertSame( $expected, $observed['Door-core'], 'Multidir json extension' ); + $this->assertEquals( $expected, $observed['Door-core'], 'Multidir json extension' ); $expected = array( 'repo' => 'extension', @@ -65,6 +67,15 @@ class LU_FinderTest extends MediaWikiTestCase { 'path' => 'i18n/extra/*.json' ); $this->assertArrayHasKey( 'Door-extra', $observed ); - $this->assertSame( $expected, $observed['Door-extra'], 'Multidir json extension' ); + $this->assertEquals( $expected, $observed['Door-extra'], 'Multidir json extension' ); + + $expected = array( + '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/extensions/LocalisationUpdate/update.php b/extensions/LocalisationUpdate/update.php index 1f66e736..1f5eaa77 100644 --- a/extensions/LocalisationUpdate/update.php +++ b/extensions/LocalisationUpdate/update.php @@ -10,7 +10,7 @@ require "$IP/maintenance/Maintenance.php"; class LU extends Maintenance { public function __construct() { parent::__construct(); - $this->mDescription = 'Fetches translation updates to MediaWiki and extensions.'; + $this->mDescription = 'Fetches translation updates to MediaWiki core, skins and extensions.'; $this->addOption( 'repoid', 'Fetch translations from repositories identified by this', @@ -25,7 +25,7 @@ class LU extends Maintenance { ini_set( "max_execution_time", 0 ); ini_set( 'memory_limit', -1 ); - global $wgExtensionMessagesFiles, $wgMessagesDirs, $IP; + global $wgExtensionMessagesFiles, $IP; global $wgLocalisationUpdateRepositories; global $wgLocalisationUpdateRepository; @@ -35,7 +35,15 @@ class LU extends Maintenance { return; } - $finder = new LU_Finder( $wgExtensionMessagesFiles, $wgMessagesDirs, $IP ); + $lc = Language::getLocalisationCache(); + if ( is_callable( array( $lc, 'getMessagesDirs' ) ) ) { // Introduced in 1.25 + $messagesDirs = $lc->getMessagesDirs(); + } else { + global $wgMessagesDirs; + $messagesDirs = $wgMessagesDirs; + } + + $finder = new LU_Finder( $wgExtensionMessagesFiles, $messagesDirs, $IP ); $readerFactory = new LU_ReaderFactory(); $fetcherFactory = new LU_FetcherFactory(); |