Implement extension registration from an extension.json file
[mediawiki.git] / maintenance / validateRegistrationFile.php
blobe7646610f4a40925754d9ae4e9fb9f2bd377dd42
1 <?php
3 require_once __DIR__ . '/Maintenance.php';
5 class ValidateRegistrationFile extends Maintenance {
6 public function __construct() {
7 parent::__construct();
8 $this->addArg( 'path', 'Path to extension.json/skin.json file.', true );
10 public function execute() {
11 if ( !class_exists( 'JsonSchema\Uri\UriRetriever' ) ) {
12 $this->error( 'The JsonSchema library cannot be found, please install it through composer.', 1 );
15 $retriever = new JsonSchema\Uri\UriRetriever();
16 $schema = $retriever->retrieve('file://' . dirname( __DIR__ ) . '/docs/extension.schema.json' );
17 $path = $this->getArg( 0 );
18 $data = json_decode( file_get_contents( $path ) );
19 if ( !is_object( $data ) ) {
20 $this->error( "$path is not a valid JSON file.", 1 );
23 $validator = new JsonSchema\Validator();
24 $validator->check( $data, $schema );
25 if ( $validator->isValid() ) {
26 $this->output( "$path validates against the schema!\n" );
27 } else {
28 foreach ( $validator->getErrors() as $error ) {
29 $this->output( "[{$error['property']}] {$error['message']}\n" );
31 $this->error( "$path does not validate.", 1 );
36 $maintClass = 'ValidateRegistrationFile';
37 require_once RUN_MAINTENANCE_IF_MAIN;