Merge "Don't check namespace in SpecialWantedtemplates"
[lhc/web/wiklou.git] / maintenance / validateRegistrationFile.php
1 <?php
2
3 require_once __DIR__ . '/Maintenance.php';
4
5 class ValidateRegistrationFile extends Maintenance {
6 public function __construct() {
7 parent::__construct();
8 $this->addArg( 'path', 'Path to extension.json/skin.json file.', true );
9 }
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 );
13 }
14
15 $path = $this->getArg( 0 );
16 $data = json_decode( file_get_contents( $path ) );
17 if ( !is_object( $data ) ) {
18 $this->error( "$path is not a valid JSON file.", 1 );
19 }
20 if ( !isset( $data->manifest_version ) ) {
21 $this->output( "Warning: No manifest_version set, assuming 1.\n" );
22 // For backwards-compatability assume 1
23 $data->manifest_version = 1;
24 }
25 $version = $data->manifest_version;
26 if ( $version !== ExtensionRegistry::MANIFEST_VERSION ) {
27 $schemaPath = dirname( __DIR__ ) . "/docs/extension.schema.v$version.json";
28 } else {
29 $schemaPath = dirname( __DIR__ ) . '/docs/extension.schema.json';
30 }
31
32 if ( $version < ExtensionRegistry::OLDEST_MANIFEST_VERSION
33 || $version > ExtensionRegistry::MANIFEST_VERSION
34 ) {
35 $this->error( "Error: $path is using a non-supported schema version, it should use "
36 . ExtensionRegistry::MANIFEST_VERSION, 1 );
37 } elseif ( $version < ExtensionRegistry::MANIFEST_VERSION ) {
38 $this->output( "Warning: $path is using a deprecated schema, and should be updated to "
39 . ExtensionRegistry::MANIFEST_VERSION . "\n" );
40 }
41 $retriever = new JsonSchema\Uri\UriRetriever();
42 $schema = $retriever->retrieve( 'file://' . $schemaPath );
43
44 $validator = new JsonSchema\Validator();
45 $validator->check( $data, $schema );
46 if ( $validator->isValid() ) {
47 $this->output( "$path validates against the version $version schema!\n" );
48 } else {
49 foreach ( $validator->getErrors() as $error ) {
50 $this->output( "[{$error['property']}] {$error['message']}\n" );
51 }
52 $this->error( "$path does not validate.", 1 );
53 }
54 }
55 }
56
57 $maintClass = 'ValidateRegistrationFile';
58 require_once RUN_MAINTENANCE_IF_MAIN;