MediaWiki  master
manageForeignResources.php
Go to the documentation of this file.
1 <?php
22 require_once __DIR__ . '/Maintenance.php';
23 
31  public function __construct() {
32  parent::__construct();
33  $this->addDescription( <<<TEXT
34 Manage foreign resources registered with ResourceLoader.
35 
36 This helps developers with downloading, verifying, and updating local copies of upstream
37 libraries registered as ResourceLoader modules. See resources/lib/foreign-resources.yaml.
38 
39 Use the "update" action to download urls specified in foreign-resources.yaml, and unpack
40 them to the resources directory. This will also verify them against the integrity hashes.
41 
42 Use the "verify" action to verify the files currently in the resources directory match
43 what "update" would replace them with. This is effectively a dry-run and will not change
44 any module resources on disk.
45 
46 Use the "make-sri" action to compute an integrity hash for upstreams that do not publish
47 one themselves. Add or update the urls foreign-resources.yaml as needed, but omit (or
48 leave empty) the "integrity" key. Then, run the "make-sri" action for the module and
49 copy the integrity into the file. Then, you can use "verify" or "update" normally.
50 TEXT
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 
61  public function execute() {
62  global $IP;
63  $frm = new ForeignResourceManager(
64  "{$IP}/resources/lib/foreign-resources.yaml",
65  "{$IP}/resources/lib",
66  function ( $text ) {
67  $this->output( $text );
68  },
69  function ( $text ) {
70  $this->error( $text );
71  },
72  function ( $text ) {
73  if ( $this->hasOption( 'verbose' ) ) {
74  $this->output( $text );
75  }
76  }
77  );
78 
79  $action = $this->getArg( 0 );
80  $module = $this->getArg( 1, 'all' );
81  return $frm->run( $action, $module );
82  }
83 }
84 
85 $maintClass = ManageForeignResources::class;
86 require_once RUN_MAINTENANCE_IF_MAIN;
RUN_MAINTENANCE_IF_MAIN
const RUN_MAINTENANCE_IF_MAIN
Definition: Maintenance.php:38
ManageForeignResources
Manage foreign resources registered with ResourceLoader.
Definition: manageForeignResources.php:30
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition: Maintenance.php:327
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: Maintenance.php:55
Maintenance\addOption
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
Definition: Maintenance.php:245
ForeignResourceManager
Manage foreign resources registered with ResourceLoader.
Definition: ForeignResourceManager.php:30
ManageForeignResources\__construct
__construct()
Default constructor.
Definition: manageForeignResources.php:31
$maintClass
$maintClass
Definition: manageForeignResources.php:85
ResourceLoader
ResourceLoader is a loading system for JavaScript and CSS resources.
Definition: ResourceLoader.php:56
Maintenance\addArg
addArg( $arg, $description, $required=true)
Add some args that are needed.
Definition: Maintenance.php:298
Maintenance\error
error( $err, $die=0)
Throw an error to the user.
Definition: Maintenance.php:462
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:433
ManageForeignResources\execute
execute()
Definition: manageForeignResources.php:61
Maintenance\hasOption
hasOption( $name)
Checks to see if a particular option exists.
Definition: Maintenance.php:266
Maintenance\getArg
getArg( $argId=0, $default=null)
Get an argument.
Definition: Maintenance.php:351
$IP
$IP
Definition: WebStart.php:49