58 if ( !class_exists( Validator::class ) ) {
59 call_user_func( $this->missingDepCallback,
60 'The JsonSchema library cannot be found, please install it through composer.'
65 if ( !class_exists( SpdxLicenses::class ) ) {
66 call_user_func( $this->missingDepCallback,
67 'The spdx-licenses library cannot be found, please install it through composer.'
72 if ( !class_exists( JsonParser::class ) ) {
73 call_user_func( $this->missingDepCallback,
74 'The JSON lint library cannot be found, please install it through composer.'
87 $contents = file_get_contents(
$path );
88 $jsonParser =
new JsonParser();
90 $data = $jsonParser->parse( $contents, JsonParser::DETECT_KEY_CONFLICTS );
91 }
catch ( ParsingException $e ) {
92 if ( $e instanceof DuplicateKeyException ) {
98 if ( !isset( $data->manifest_version ) ) {
100 "$path does not have manifest_version set." );
103 $version = $data->manifest_version;
104 $schemaPath = __DIR__ .
"/../../docs/extension.schema.v$version.json";
106 if ( $version < ExtensionRegistry::OLDEST_MANIFEST_VERSION ||
107 $version > ExtensionRegistry::MANIFEST_VERSION
110 "$path is using a non-supported schema version"
116 if ( isset( $data->{
'license-name'} ) && is_string( $data->{
'license-name'} ) ) {
117 $licenses =
new SpdxLicenses();
118 $valid = $licenses->validate( $data->{
'license-name'} );
120 $extraErrors[] =
'[license-name] Invalid SPDX license identifier, '
121 .
'see <https://spdx.org/licenses/>';
124 if ( isset( $data->url ) && is_string( $data->url ) ) {
125 $parsed = parse_url( $data->url );
127 if ( !$parsed || !isset( $parsed[
'host'] ) || !isset( $parsed[
'scheme'] ) ) {
128 $extraErrors[] =
'[url] URL cannot be parsed';
130 if ( $parsed[
'host'] ===
'www.mediawiki.org' ) {
132 } elseif ( $parsed[
'host'] ===
'mediawiki.org' ) {
134 $extraErrors[] =
'[url] Should use www.mediawiki.org domain';
137 if ( $mwoUrl && $parsed[
'scheme'] !==
'https' ) {
138 $extraErrors[] =
'[url] Should use HTTPS for www.mediawiki.org URLs';
143 $validator =
new Validator;
144 $validator->check( $data, (
object)[
'$ref' =>
'file://' . $schemaPath ] );
145 if ( $validator->isValid() && !$extraErrors ) {
150 $out =
"$path did not pass validation.\n";
151 foreach ( $validator->getErrors() as $error ) {
152 $out .=
"[{$error['property']}] {$error['message']}\n";
154 if ( $extraErrors ) {
155 $out .= implode(
"\n", $extraErrors ) .
"\n";