60 if ( !class_exists( Validator::class ) ) {
61 call_user_func( $this->missingDepCallback,
62 'The JsonSchema library cannot be found, please install it through composer.'
68 if ( !class_exists( SpdxLicenses::class ) ) {
69 call_user_func( $this->missingDepCallback,
70 'The spdx-licenses library cannot be found, please install it through composer.'
76 if ( !class_exists( JsonParser::class ) ) {
77 call_user_func( $this->missingDepCallback,
78 'The JSON lint library cannot be found, please install it through composer.'
92 $contents = file_get_contents(
$path );
93 $jsonParser =
new JsonParser();
95 $data = $jsonParser->parse( $contents, JsonParser::DETECT_KEY_CONFLICTS );
96 }
catch ( ParsingException $e ) {
97 if ( $e instanceof DuplicateKeyException ) {
103 if ( !isset( $data->manifest_version ) ) {
105 "$path does not have manifest_version set." );
108 $version = $data->manifest_version;
109 $schemaPath = __DIR__ .
"/../../docs/extension.schema.v$version.json";
115 "$path is using a non-supported schema version"
121 if ( isset( $data->{
'license-name'} ) && is_string( $data->{
'license-name'} ) ) {
122 $licenses =
new SpdxLicenses();
123 $valid = $licenses->validate( $data->{
'license-name'} );
125 $extraErrors[] =
'[license-name] Invalid SPDX license identifier, '
126 .
'see <https://spdx.org/licenses/>';
129 if ( isset( $data->url ) && is_string( $data->url ) ) {
130 $parsed = parse_url( $data->url );
132 if ( !$parsed || !isset( $parsed[
'host'] ) || !isset( $parsed[
'scheme'] ) ) {
133 $extraErrors[] =
'[url] URL cannot be parsed';
135 if ( $parsed[
'host'] ===
'www.mediawiki.org' ) {
137 } elseif ( $parsed[
'host'] ===
'mediawiki.org' ) {
139 $extraErrors[] =
'[url] Should use www.mediawiki.org domain';
142 if ( $mwoUrl && $parsed[
'scheme'] !==
'https' ) {
143 $extraErrors[] =
'[url] Should use HTTPS for www.mediawiki.org URLs';
148 $validator =
new Validator;
149 $validator->check( $data, (
object)[
'$ref' =>
'file://' . $schemaPath ] );
150 if ( $validator->isValid() && !$extraErrors ) {
155 $out =
"$path did not pass validation.\n";
156 foreach ( $validator->getErrors() as $error ) {
157 $out .=
"[{$error['property']}] {$error['message']}\n";
159 if ( $extraErrors ) {
160 $out .= implode(
"\n", $extraErrors ) .
"\n";
162 throw new ExtensionJsonValidationError( $out );