57 if ( !class_exists( Validator::class ) ) {
58 ( $this->missingDepCallback )(
59 'The JsonSchema library cannot be found, please install it through composer.'
65 if ( !class_exists( SpdxLicenses::class ) ) {
66 ( $this->missingDepCallback )(
67 'The spdx-licenses library cannot be found, please install it through composer.'
73 if ( !class_exists( JsonParser::class ) ) {
74 ( $this->missingDepCallback )(
75 'The JSON lint library cannot be found, please install it through composer.'
89 $contents = file_get_contents(
$path );
90 $jsonParser =
new JsonParser();
92 $data = $jsonParser->parse( $contents, JsonParser::DETECT_KEY_CONFLICTS );
93 }
catch ( ParsingException $e ) {
94 if ( $e instanceof DuplicateKeyException ) {
100 if ( !isset( $data->manifest_version ) ) {
102 "$path does not have manifest_version set." );
105 $version = $data->manifest_version;
106 $schemaPath = __DIR__ .
"/../../docs/extension.schema.v$version.json";
112 "$path is using a non-supported schema version"
118 if ( isset( $data->{
'license-name'} ) && is_string( $data->{
'license-name'} ) ) {
119 $licenses =
new SpdxLicenses();
120 $valid = $licenses->validate( $data->{
'license-name'} );
122 $extraErrors[] =
'[license-name] Invalid SPDX license identifier, '
123 .
'see <https://spdx.org/licenses/>';
126 if ( isset( $data->url ) && is_string( $data->url ) ) {
127 $parsed = parse_url( $data->url );
129 if ( !$parsed || !isset( $parsed[
'host'] ) || !isset( $parsed[
'scheme'] ) ) {
130 $extraErrors[] =
'[url] URL cannot be parsed';
132 if ( $parsed[
'host'] ===
'www.mediawiki.org' ) {
134 } elseif ( $parsed[
'host'] ===
'mediawiki.org' ) {
136 $extraErrors[] =
'[url] Should use www.mediawiki.org domain';
139 if ( $mwoUrl && $parsed[
'scheme'] !==
'https' ) {
140 $extraErrors[] =
'[url] Should use HTTPS for www.mediawiki.org URLs';
145 $validator =
new Validator;
146 $validator->check( $data, (
object)[
'$ref' =>
'file://' . $schemaPath ] );
147 if ( $validator->isValid() && !$extraErrors ) {
152 $out =
"$path did not pass validation.\n";
153 foreach ( $validator->getErrors() as $error ) {
154 $out .=
"[{$error['property']}] {$error['message']}\n";
156 if ( $extraErrors ) {
157 $out .= implode(
"\n", $extraErrors ) .
"\n";
159 throw new ExtensionJsonValidationError( $out );