Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 24 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
MediaUploaderResourceModule | |
0.00% |
0 / 24 |
|
0.00% |
0 / 3 |
110 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
getMessages | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
20 | |||
getMessagesForLicenseGroups | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
30 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\MediaUploader; |
4 | |
5 | use MediaWiki\Extension\MediaUploader\Config\RawConfig; |
6 | use ResourceLoaderFileModule; |
7 | |
8 | /** |
9 | * Class representing the 'ext.uploadWizard' ResourceLoader module. |
10 | */ |
11 | class MediaUploaderResourceModule extends ResourceLoaderFileModule { |
12 | |
13 | /** @var RawConfig */ |
14 | private $rawConfig; |
15 | |
16 | /** |
17 | * @param array $options Options from resource module definition |
18 | * @param RawConfig $rawConfig |
19 | * |
20 | * @internal use MediaUploaderResourceModuleFactory |
21 | */ |
22 | public function __construct( array $options, RawConfig $rawConfig ) { |
23 | parent::__construct( $options ); |
24 | $this->rawConfig = $rawConfig; |
25 | } |
26 | |
27 | /** |
28 | * Returns messages required by this module. |
29 | * |
30 | * Uses the global MediaUploader config to determine which license messages should |
31 | * be loaded. |
32 | * |
33 | * @return array |
34 | */ |
35 | public function getMessages() { |
36 | $licenseMessages = []; |
37 | |
38 | // Add messages used directly by licenses |
39 | foreach ( $this->rawConfig->getSetting( 'licenses', [] ) as $value ) { |
40 | foreach ( [ 'msg', 'explainMsg' ] as $mKey ) { |
41 | if ( isset( $value[$mKey] ) ) { |
42 | $licenseMessages[] = $value[$mKey]; |
43 | } |
44 | } |
45 | } |
46 | |
47 | $licensing = $this->rawConfig->getSetting( 'licensing', [] ); |
48 | |
49 | return array_unique( array_merge( |
50 | parent::getMessages(), |
51 | $licenseMessages, |
52 | $this->getMessagesForLicenseGroups( $licensing, 'ownWork' ), |
53 | $this->getMessagesForLicenseGroups( $licensing, 'thirdParty' ), |
54 | $this->rawConfig->getSetting( 'additionalMessages', [] ) |
55 | ) ); |
56 | } |
57 | |
58 | /** |
59 | * Returns an array of messages necessary to display all license groups of type $type. |
60 | * |
61 | * @param array $licensingConfig |
62 | * @param string $type Either 'ownWork' or 'thirdParty' |
63 | * |
64 | * @return string[] |
65 | */ |
66 | private function getMessagesForLicenseGroups( |
67 | array $licensingConfig, |
68 | string $type |
69 | ): array { |
70 | if ( !isset( $licensingConfig[$type]['licenseGroups'] ) ) { |
71 | return []; |
72 | } |
73 | |
74 | $messages = []; |
75 | foreach ( $licensingConfig[$type]['licenseGroups'] as $licenseGroup ) { |
76 | if ( isset( $licenseGroup['head'] ) ) { |
77 | $messages[] = $licenseGroup['head']; |
78 | } |
79 | if ( isset( $licenseGroup['subhead'] ) ) { |
80 | $messages[] = $licenseGroup['subhead']; |
81 | } |
82 | } |
83 | |
84 | return $messages; |
85 | } |
86 | } |