MediaWiki  1.33.0
Finder.php
Go to the documentation of this file.
1 <?php
8 namespace LocalisationUpdate;
9 
14 class Finder {
15 
19  private $php;
20 
24  private $json;
25 
29  private $core;
35  public function __construct( $php, $json, $core ) {
36  $this->php = $php;
37  $this->json = $json;
38  $this->core = $core;
39  }
40 
44  public function getComponents() {
45  $components = [];
46 
47  // For older versions of Mediawiki, pull json updates even though its still using php
48  if ( !isset( $this->json['core'] ) ) {
49  $components['core'] = [
50  'repo' => 'mediawiki',
51  'orig' => "file://{$this->core}/languages/messages/Messages*.php",
52  'path' => 'languages/messages/i18n/*.json',
53  ];
54  }
55 
56  foreach ( $this->json as $key => $value ) {
57  // Json should take priority if both exist
58  unset( $this->php[$key] );
59 
60  foreach ( (array)$value as $subkey => $subvalue ) {
61  // Mediawiki core files
62  $matches = [];
63  if ( preg_match( '~/(?P<path>(?:includes|languages|resources)/.*)$~', $subvalue, $matches ) ) {
64  $components["$key-$subkey"] = [
65  'repo' => 'mediawiki',
66  'orig' => "file://$value/*.json",
67  'path' => "{$matches['path']}/*.json",
68  ];
69  continue;
70  }
71 
72  $item = $this->getItem( 'extensions', $subvalue );
73  if ( $item !== null ) {
74  $item['repo'] = 'extension';
75  $components["$key-$subkey"] = $item;
76  continue;
77  }
78 
79  $item = $this->getItem( 'skins', $subvalue );
80  if ( $item !== null ) {
81  $item['repo'] = 'skin';
82  $components["$key-$subkey"] = $item;
83  continue;
84  }
85  }
86  }
87 
88  foreach ( $this->php as $key => $value ) {
89  $matches = [];
90  $ok = preg_match( '~/extensions/(?P<name>[^/]+)/(?P<path>.*\.i18n\.php)$~', $value, $matches );
91  if ( !$ok ) {
92  continue;
93  }
94 
95  $components[$key] = [
96  'repo' => 'extension',
97  'name' => $matches['name'],
98  'orig' => "file://$value",
99  'path' => $matches['path'],
100  ];
101  }
102 
103  return $components;
104  }
105 
111  private function getItem( $dir, $subvalue ) {
112  // This ignores magic, alias etc. non message files
113  $matches = [];
114  if ( !preg_match( "~/$dir/(?P<name>[^/]+)/(?P<path>.*)$~", $subvalue, $matches ) ) {
115  return null;
116  }
117 
118  return [
119  'name' => $matches['name'],
120  'orig' => "file://$subvalue/*.json",
121  'path' => "{$matches['path']}/*.json",
122  ];
123  }
124 }
LocalisationUpdate\Finder\getComponents
getComponents()
Definition: Finder.php:44
LocalisationUpdate\Finder\getItem
getItem( $dir, $subvalue)
Definition: Finder.php:111
LocalisationUpdate\Finder\$php
array $php
Definition: Finder.php:19
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
LocalisationUpdate\Finder\$core
string $core
Definition: Finder.php:29
array
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
json
The package json
Definition: README.txt:1
LocalisationUpdate
Definition: Fetcher.php:8
$value
$value
Definition: styleTest.css.php:49
LocalisationUpdate\Finder\__construct
__construct( $php, $json, $core)
Definition: Finder.php:35
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
LocalisationUpdate\Finder\$json
array $json
Definition: Finder.php:24