MediaWiki REL1_31
Finder.php
Go to the documentation of this file.
1<?php
8namespace LocalisationUpdate;
9
14class 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}
The package json
Definition README.txt:1
Interface for classes which provide list of components, which should be included for l10n updates.
Definition Finder.php:14
__construct( $php, $json, $core)
Definition Finder.php:35
getItem( $dir, $subvalue)
Definition Finder.php:111
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction 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:2819