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