Don't use deprecated User::checkPassword() in TestUser
[mediawiki.git] / maintenance / validateRegistrationFile.php
blob9cf7b2bdc84fcc428d75732216d88c86f9be56b6
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 $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 );
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;
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';
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" );
41 $retriever = new JsonSchema\Uri\UriRetriever();
42 $schema = $retriever->retrieve( 'file://' . $schemaPath );
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" );
52 $this->error( "$path does not validate.", 1 );
57 $maintClass = 'ValidateRegistrationFile';
58 require_once RUN_MAINTENANCE_IF_MAIN;