Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 37 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
ManageForeignResources | |
0.00% |
0 / 37 |
|
0.00% |
0 / 2 |
30 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 26 |
|
0.00% |
0 / 1 |
20 |
1 | <?php |
2 | /** |
3 | * This program is free software; you can redistribute it and/or modify |
4 | * it under the terms of the GNU General Public License as published by |
5 | * the Free Software Foundation; either version 2 of the License, or |
6 | * (at your option) any later version. |
7 | * |
8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. |
12 | * |
13 | * You should have received a copy of the GNU General Public License along |
14 | * with this program; if not, write to the Free Software Foundation, Inc., |
15 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
16 | * http://www.gnu.org/copyleft/gpl.html |
17 | * |
18 | * @file |
19 | */ |
20 | |
21 | use MediaWiki\Maintenance\Maintenance; |
22 | use MediaWiki\Registration\ExtensionRegistry; |
23 | use MediaWiki\ResourceLoader\ForeignResourceManager; |
24 | |
25 | // @codeCoverageIgnoreStart |
26 | require_once __DIR__ . '/Maintenance.php'; |
27 | // @codeCoverageIgnoreEnd |
28 | |
29 | /** |
30 | * Manage foreign resources registered with ResourceLoader. |
31 | * |
32 | * This uses the MediaWiki\ResourceLoader\ForeignResourceManager class internally. |
33 | * See also ForeignResourceStructureTest, which runs the "verify" action in CI. |
34 | * |
35 | * @ingroup Maintenance |
36 | * @ingroup ResourceLoader |
37 | * @since 1.32 |
38 | * @see https://www.mediawiki.org/wiki/Manual:ManageForeignResources.php |
39 | */ |
40 | class ManageForeignResources extends Maintenance { |
41 | public function __construct() { |
42 | parent::__construct(); |
43 | $this->addDescription( <<<TEXT |
44 | Manage foreign resources registered with ResourceLoader. |
45 | |
46 | This helps developers with downloading, verifying, and updating local copies of |
47 | upstream libraries registered as ResourceLoader modules. See |
48 | https://www.mediawiki.org/wiki/Foreign_resources |
49 | |
50 | Use the "update" action to download urls specified in foreign-resources.yaml, |
51 | and unpack them to the resources directory. This will also verify them against |
52 | the integrity hashes. |
53 | |
54 | Use the "verify" action to verify the files currently in the resources directory |
55 | match what "update" would replace them with. This is effectively a dry-run and |
56 | will not change any module resources on disk. |
57 | |
58 | Use the "make-sri" action to compute an integrity hash for upstreams that do not |
59 | publish one themselves. Add or update the urls foreign-resources.yaml as needed, |
60 | but omit (or leave empty) the "integrity" key. Then, run the "make-sri" action |
61 | for the module and copy the integrity into the file. Then, you can use "verify" |
62 | or "update" normally. |
63 | |
64 | The "make-cdx" option generates a CycloneDX SBOM file. |
65 | TEXT |
66 | ); |
67 | $this->addArg( 'action', 'One of "update", "verify", "make-sri" or "make-cdx"', true ); |
68 | $this->addArg( 'module', 'Name of a single module (Default: all)', false ); |
69 | $this->addOption( 'extension', 'Manage foreign resources for the given extension, instead of core', |
70 | false, true ); |
71 | $this->addOption( 'skin', 'Manage foreign resources for the given skin, instead of core', |
72 | false, true ); |
73 | $this->addOption( 'verbose', 'Be verbose', false, false, 'v' ); |
74 | } |
75 | |
76 | /** |
77 | * @return bool |
78 | */ |
79 | public function execute() { |
80 | global $IP; |
81 | |
82 | $component = $this->getOption( 'extension' ) ?? $this->getOption( 'skin' ) ?? '#core'; |
83 | $foreignResourcesDirs = ExtensionRegistry::getInstance()->getAttribute( 'ForeignResourcesDir' ) |
84 | + [ '#core' => "{$IP}/resources/lib" ]; |
85 | if ( !array_key_exists( $component, $foreignResourcesDirs ) ) { |
86 | $this->fatalError( "Unknown component: $component\n" ); |
87 | } |
88 | $foreignResourcesFile = "{$foreignResourcesDirs[$component]}/foreign-resources.yaml"; |
89 | |
90 | $frm = new ForeignResourceManager( |
91 | $foreignResourcesFile, |
92 | dirname( $foreignResourcesFile ), |
93 | function ( $text ) { |
94 | $this->output( $text ); |
95 | }, |
96 | function ( $text ) { |
97 | $this->error( $text ); |
98 | }, |
99 | function ( $text ) { |
100 | if ( $this->hasOption( 'verbose' ) ) { |
101 | $this->output( $text ); |
102 | } |
103 | } |
104 | ); |
105 | |
106 | $action = $this->getArg( 0 ); |
107 | $module = $this->getArg( 1, 'all' ); |
108 | |
109 | try { |
110 | return $frm->run( $action, $module ); |
111 | } catch ( Exception $e ) { |
112 | $this->fatalError( "Error: {$e->getMessage()}" ); |
113 | } |
114 | } |
115 | } |
116 | |
117 | // @codeCoverageIgnoreStart |
118 | $maintClass = ManageForeignResources::class; |
119 | require_once RUN_MAINTENANCE_IF_MAIN; |
120 | // @codeCoverageIgnoreEnd |