43 if ( !class_exists( Validator::class ) ) {
44 ( $this->missingDepCallback )(
45 'The JsonSchema library cannot be found, please install it through composer.'
51 if ( !class_exists( SpdxLicenses::class ) ) {
52 ( $this->missingDepCallback )(
53 'The spdx-licenses library cannot be found, please install it through composer.'
59 if ( !class_exists( JsonParser::class ) ) {
60 ( $this->missingDepCallback )(
61 'The JSON lint library cannot be found, please install it through composer.'
75 $contents = file_get_contents(
$path );
76 $jsonParser =
new JsonParser();
78 $data = $jsonParser->parse( $contents, JsonParser::DETECT_KEY_CONFLICTS );
79 }
catch ( ParsingException $e ) {
80 if ( $e instanceof DuplicateKeyException ) {
86 if ( !isset( $data->manifest_version ) ) {
88 "$path does not have manifest_version set." );
91 $version = $data->manifest_version;
92 $schemaPath = __DIR__ .
"/../../docs/extension.schema.v$version.json";
98 "$path is using a non-supported schema version"
104 if ( isset( $data->{
'license-name'} ) && is_string( $data->{
'license-name'} ) ) {
105 $licenses =
new SpdxLicenses();
106 $valid = $licenses->validate( $data->{
'license-name'} );
108 $extraErrors[] =
'[license-name] Invalid SPDX license identifier, '
109 .
'see <https://spdx.org/licenses/>';
112 if ( isset( $data->url ) && is_string( $data->url ) ) {
113 $parsed = parse_url( $data->url );
115 if ( !$parsed || !isset( $parsed[
'host'] ) || !isset( $parsed[
'scheme'] ) ) {
116 $extraErrors[] =
'[url] URL cannot be parsed';
118 if ( $parsed[
'host'] ===
'www.mediawiki.org' ) {
120 } elseif ( $parsed[
'host'] ===
'mediawiki.org' ) {
122 $extraErrors[] =
'[url] Should use www.mediawiki.org domain';
125 if ( $mwoUrl && $parsed[
'scheme'] !==
'https' ) {
126 $extraErrors[] =
'[url] Should use HTTPS for www.mediawiki.org URLs';
131 $validator =
new Validator;
132 $validator->check( $data, (
object)[
'$ref' =>
'file://' . $schemaPath ] );
133 if ( $validator->isValid() && !$extraErrors ) {
138 $out =
"$path did not pass validation.\n";
139 foreach ( $validator->getErrors() as $error ) {
140 $out .=
"[{$error['property']}] {$error['message']}\n";
142 if ( $extraErrors ) {
143 $out .= implode(
"\n", $extraErrors ) .
"\n";
145 throw new ExtensionJsonValidationError( $out );