4 * @author Niklas Laxström
8 namespace LocalisationUpdate;
11 * Interface for classes which provide list of components, which should be
12 * included for l10n updates.
16 * @param array $php See $wgExtensionMessagesFiles
17 * @param array $json See $wgMessagesDirs
18 * @param string $core Absolute path to MediaWiki core
20 public function __construct( $php, $json, $core ) {
29 public function getComponents() {
32 // For older versions of Mediawiki, pull json updates even though its still using php
33 if ( !isset( $this->json['core'] ) ) {
34 $components['core'] = [
35 'repo' => 'mediawiki',
36 'orig' => "file://{$this->core}/languages/messages/Messages*.php",
37 'path' => 'languages/messages/i18n/*.json',
41 foreach ( $this->json as $key => $value ) {
42 // Json should take priority if both exist
43 unset( $this->php[$key] );
45 foreach ( (array)$value as $subkey => $subvalue ) {
46 // Mediawiki core files
48 if ( preg_match( '~/(?P<path>(?:includes|languages|resources)/.*)$~', $subvalue, $matches ) ) {
49 $components["$key-$subkey"] = [
50 'repo' => 'mediawiki',
51 'orig' => "file://$value/*.json",
52 'path' => "{$matches['path']}/*.json",
57 $item = $this->getItem( 'extensions', $subvalue );
58 if ( $item !== null ) {
59 $item['repo'] = 'extension';
60 $components["$key-$subkey"] = $item;
64 $item = $this->getItem( 'skins', $subvalue );
65 if ( $item !== null ) {
66 $item['repo'] = 'skin';
67 $components["$key-$subkey"] = $item;
73 foreach ( $this->php as $key => $value ) {
75 $ok = preg_match( '~/extensions/(?P<name>[^/]+)/(?P<path>.*\.i18n\.php)$~', $value, $matches );
81 'repo' => 'extension',
82 'name' => $matches['name'],
83 'orig' => "file://$value",
84 'path' => $matches['path'],
92 * @param string $dir extensions or skins
93 * @param string $subvalue
96 private function getItem( $dir, $subvalue ) {
97 // This ignores magic, alias etc. non message files
99 if ( !preg_match( "~/$dir/(?P<name>[^/]+)/(?P<path>.*)$~", $subvalue, $matches ) ) {
104 'name' => $matches['name'],
105 'orig' => "file://$subvalue/*.json",
106 'path' => "{$matches['path']}/*.json",