aboutsummaryrefslogtreecommitdiffstats
path: root/maintenance/validateRegistrationFile.php
blob: f3e5fbfed500696a5c0df1f0d13de763e286fa68 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php

use MediaWiki\Maintenance\Maintenance;
use MediaWiki\Registration\ExtensionJsonValidationError;
use MediaWiki\Registration\ExtensionJsonValidator;

// @codeCoverageIgnoreStart
require_once __DIR__ . '/Maintenance.php';
// @codeCoverageIgnoreEnd

class ValidateRegistrationFile extends Maintenance {
	public function __construct() {
		parent::__construct();
		$this->addArg(
			'path',
			'Path or glob pattern to extension.json/skin.json file.',
			true
		);
	}

	public function execute() {
		$validator = new ExtensionJsonValidator( function ( $msg ) {
			$this->fatalError( $msg );
		} );
		$validator->checkDependencies();
		$paths = glob( $this->getArg( 0 ) );
		foreach ( $paths as $path ) {
			try {
				$validator->validate( $path );
				$this->output( "$path validates against the schema!\n" );
			} catch ( ExtensionJsonValidationError $e ) {
				$this->fatalError( $e->getMessage() );
			}
		}
	}
}

// @codeCoverageIgnoreStart
$maintClass = ValidateRegistrationFile::class;
require_once RUN_MAINTENANCE_IF_MAIN;
// @codeCoverageIgnoreEnd