MediaWiki  1.29.1
Go to the documentation of this file.
1 <?php
22 use Composer\Spdx\SpdxLicenses;
23 use JsonSchema\Validator;
38  public function __construct( callable $missingDepCallback ) {
39  $this->missingDepCallback = $missingDepCallback;
40  }
45  public function checkDependencies() {
46  if ( !class_exists( Validator::class ) ) {
47  call_user_func( $this->missingDepCallback,
48  'The JsonSchema library cannot be found, please install it through composer.'
49  );
50  return false;
51  } elseif ( !class_exists( SpdxLicenses::class ) ) {
52  call_user_func( $this->missingDepCallback,
53  'The spdx-licenses library cannot be found, please install it through composer.'
54  );
55  return false;
56  }
58  return true;
59  }
66  public function validate( $path ) {
67  $data = json_decode( file_get_contents( $path ) );
68  if ( !is_object( $data ) ) {
69  throw new ExtensionJsonValidationError( "$path is not valid JSON" );
70  }
72  if ( !isset( $data->manifest_version ) ) {
74  "$path does not have manifest_version set." );
75  }
77  $version = $data->manifest_version;
78  $schemaPath = __DIR__ . "/../../docs/extension.schema.v$version.json";
80  // Not too old
83  "$path is using a non-supported schema version"
84  );
85  } elseif ( $version > ExtensionRegistry::MANIFEST_VERSION ) {
87  "$path is using a non-supported schema version"
88  );
89  }
91  $licenseError = false;
92  // Check if it's a string, if not, schema validation will display an error
93  if ( isset( $data->{'license-name'} ) && is_string( $data->{'license-name'} ) ) {
94  $licenses = new SpdxLicenses();
95  $valid = $licenses->validate( $data->{'license-name'} );
96  if ( !$valid ) {
97  $licenseError = '[license-name] Invalid SPDX license identifier, '
98  . 'see <>';
99  }
100  }
102  $validator = new Validator;
103  $validator->check( $data, (object)[ '$ref' => 'file://' . $schemaPath ] );
104  if ( $validator->isValid() && !$licenseError ) {
105  // All good.
106  return true;
107  } else {
108  $out = "$path did pass validation.\n";
109  foreach ( $validator->getErrors() as $error ) {
110  $out .= "[{$error['property']}] {$error['message']}\n";
111  }
112  if ( $licenseError ) {
113  $out .= "$licenseError\n";
114  }
115  throw new ExtensionJsonValidationError( $out );
116  }
117  }
118 }
Version of the highest supported manifest version.
Definition: ExtensionRegistry.php:24
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
callable $missingDepCallback
Definition: ExtensionJsonValidator.php:33
Definition: ExtensionJsonValidator.php:45
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
Version of the oldest supported manifest version.
Definition: ExtensionRegistry.php:29
__construct(callable $missingDepCallback)
Definition: ExtensionJsonValidator.php:38
Definition: ExtensionJsonValidator.php:28
validate( $path)
Definition: ExtensionJsonValidator.php:66
Definition: NoLocalSettings.php:26
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
Definition: ExtensionJsonValidationError.php:21
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output $out
Definition: hooks.txt:783