MediaWiki REL1_37
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 upstream
37libraries registered as ResourceLoader modules. See resources/lib/foreign-resources.yaml.
38
39Use the "update" action to download urls specified in foreign-resources.yaml, and unpack
40them to the resources directory. This will also verify them against the integrity hashes.
41
42Use the "verify" action to verify the files currently in the resources directory match
43what "update" would replace them with. This is effectively a dry-run and will not change
44any module resources on disk.
45
46Use the "make-sri" action to compute an integrity hash for upstreams that do not publish
47one themselves. Add or update the urls foreign-resources.yaml as needed, but omit (or
48leave empty) the "integrity" key. Then, run the "make-sri" action for the module and
49copy the integrity into the file. Then, you can use "verify" or "update" normally.
50TEXT
51 );
52 $this->addArg( 'action', 'One of "update", "verify" or "make-sri"', true );
53 $this->addArg( 'module', 'Name of a single module (Default: all)', false );
54 $this->addOption( 'verbose', 'Be verbose', false, false, 'v' );
55 }
56
60 public function execute() {
61 global $IP;
62 $frm = new ForeignResourceManager(
63 "{$IP}/resources/lib/foreign-resources.yaml",
64 "{$IP}/resources/lib",
65 function ( $text ) {
66 $this->output( $text );
67 },
68 function ( $text ) {
69 $this->error( $text );
70 },
71 function ( $text ) {
72 if ( $this->hasOption( 'verbose' ) ) {
73 $this->output( $text );
74 }
75 }
76 );
77
78 $action = $this->getArg( 0 );
79 $module = $this->getArg( 1, 'all' );
80
81 try {
82 return $frm->run( $action, $module );
83 } catch ( Exception $e ) {
84 $this->fatalError( "Error: {$e->getMessage()}" );
85 }
86 }
87}
88
89$maintClass = ManageForeignResources::class;
90require_once RUN_MAINTENANCE_IF_MAIN;
$IP
Definition WebStart.php:49
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.
ResourceLoader is a loading system for JavaScript and CSS resources.