MediaWiki REL1_39
manageForeignResources.php
Go to the documentation of this file.
1<?php
22require_once __DIR__ . '/Maintenance.php';
23
31 public function __construct() {
32 parent::__construct();
33 $this->addDescription( <<<TEXT
34Manage foreign resources registered with ResourceLoader.
35
36This helps developers with downloading, verifying, and updating local copies of
37upstream libraries registered as ResourceLoader modules. See
38resources/lib/foreign-resources.yaml.
39
40Use the "update" action to download urls specified in foreign-resources.yaml,
41and unpack them to the resources directory. This will also verify them against
42the integrity hashes.
43
44Use the "verify" action to verify the files currently in the resources directory
45match what "update" would replace them with. This is effectively a dry-run and
46will not change any module resources on disk.
47
48Use the "make-sri" action to compute an integrity hash for upstreams that do not
49publish one themselves. Add or update the urls foreign-resources.yaml as needed,
50but omit (or leave empty) the "integrity" key. Then, run the "make-sri" action
51for the module and copy the integrity into the file. Then, you can use "verify"
52or "update" normally.
53TEXT
54 );
55 $this->addArg( 'action', 'One of "update", "verify" or "make-sri"', true );
56 $this->addArg( 'module', 'Name of a single module (Default: all)', false );
57 $this->addOption( 'verbose', 'Be verbose', false, false, 'v' );
58 }
59
63 public function execute() {
64 global $IP;
65 $frm = new ForeignResourceManager(
66 "{$IP}/resources/lib/foreign-resources.yaml",
67 "{$IP}/resources/lib",
68 function ( $text ) {
69 $this->output( $text );
70 },
71 function ( $text ) {
72 $this->error( $text );
73 },
74 function ( $text ) {
75 if ( $this->hasOption( 'verbose' ) ) {
76 $this->output( $text );
77 }
78 }
79 );
80
81 $action = $this->getArg( 0 );
82 $module = $this->getArg( 1, 'all' );
83
84 try {
85 return $frm->run( $action, $module );
86 } catch ( Exception $e ) {
87 $this->fatalError( "Error: {$e->getMessage()}" );
88 }
89 }
90}
91
92$maintClass = ManageForeignResources::class;
93require_once RUN_MAINTENANCE_IF_MAIN;
if(!defined( 'MEDIAWIKI')) if(ini_get('mbstring.func_overload')) if(!defined( 'MW_ENTRY_POINT')) global $IP
Environment checks.
Definition Setup.php:91
Manage foreign resources registered with ResourceLoader.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
error( $err, $die=0)
Throw an error to the user.
addArg( $arg, $description, $required=true)
Add some args that are needed.
output( $out, $channel=null)
Throw some output to the user.
hasOption( $name)
Checks to see if a particular option was set.
getArg( $argId=0, $default=null)
Get an argument.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
Manage foreign resources registered with ResourceLoader.
__construct()
Default constructor.