MediaWiki  1.29.2
Finder.php
Go to the documentation of this file.
1 <?php
8 namespace LocalisationUpdate;
9 
14 class Finder {
20  public function __construct( $php, $json, $core ) {
21  $this->php = $php;
22  $this->json = $json;
23  $this->core = $core;
24  }
25 
29  public function getComponents() {
30  $components = [];
31 
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',
38  ];
39  }
40 
41  foreach ( $this->json as $key => $value ) {
42  // Json should take priority if both exist
43  unset( $this->php[$key] );
44 
45  foreach ( (array)$value as $subkey => $subvalue ) {
46  // Mediawiki core files
47  $matches = [];
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",
53  ];
54  continue;
55  }
56 
57  $item = $this->getItem( 'extensions', $subvalue );
58  if ( $item !== null ) {
59  $item['repo'] = 'extension';
60  $components["$key-$subkey"] = $item;
61  continue;
62  }
63 
64  $item = $this->getItem( 'skins', $subvalue );
65  if ( $item !== null ) {
66  $item['repo'] = 'skin';
67  $components["$key-$subkey"] = $item;
68  continue;
69  }
70  }
71  }
72 
73  foreach ( $this->php as $key => $value ) {
74  $matches = [];
75  $ok = preg_match( '~/extensions/(?P<name>[^/]+)/(?P<path>.*\.i18n\.php)$~', $value, $matches );
76  if ( !$ok ) {
77  continue;
78  }
79 
80  $components[$key] = [
81  'repo' => 'extension',
82  'name' => $matches['name'],
83  'orig' => "file://$value",
84  'path' => $matches['path'],
85  ];
86  }
87 
88  return $components;
89  }
90 
96  private function getItem( $dir, $subvalue ) {
97  // This ignores magic, alias etc. non message files
98  $matches = [];
99  if ( !preg_match( "~/$dir/(?P<name>[^/]+)/(?P<path>.*)$~", $subvalue, $matches ) ) {
100  return null;
101  }
102 
103  return [
104  'name' => $matches['name'],
105  'orig' => "file://$subvalue/*.json",
106  'path' => "{$matches['path']}/*.json",
107  ];
108  }
109 }
LocalisationUpdate\Finder\getComponents
getComponents()
Definition: Finder.php:29
LocalisationUpdate\Finder\getItem
getItem( $dir, $subvalue)
Definition: Finder.php:96
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
$matches
$matches
Definition: NoLocalSettings.php:24
json
The package json
Definition: README.txt:1
$dir
$dir
Definition: Autoload.php:8
LocalisationUpdate
Definition: Fetcher.php:8
$value
$value
Definition: styleTest.css.php:45
core
error also a ContextSource you ll probably need to make sure the header is varied on and they can depend only on the ResourceLoaderContext such as when responding to a resource loader request or generating HTML output included in core
Definition: hooks.txt:2612
LocalisationUpdate\Finder\__construct
__construct( $php, $json, $core)
Definition: Finder.php:20
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
LocalisationUpdate\Finder
Interface for classes which provide list of components, which should be included for l10n updates.
Definition: Finder.php:14
array
the array() calling protocol came about after MediaWiki 1.4rc1.