Introduces wfLoadExtension()/wfLoadSkin() which should be used in LocalSettings.php rather than require-ing a PHP entry point. Extensions and skins would add "extension.json" or "skin.json" files in their root, which contains all the information typically present in PHP entry point files (classes to autoload, special pages, API modules, etc.) A full schema can be found at docs/extension.schema.json, and a script to validate these to the schema is provided. An additional script is provided to convert typical PHP entry point files into their JSON equivalents. The basic flow of loading an extension goes like: * Get the ExtensionRegistry singleton instance * ExtensionRegistry takes a filename, reads the file or tries to get the parsed JSON from APC if possible. * The JSON is run through a Processor instance, which registers things with the appropriate global settings. * The output of the processor is cached in APC if possible. * The extension/skin is marked as loaded in the ExtensionRegistry and a callback function is executed if one was specified. For ideal performance, a batch loading method is also provided: * The absolute path name to the JSON file is queued in the ExtensionRegistry instance. * When loadFromQueue() is called, it constructs a hash unique to the members of the current queue, and sees if the queue has been cached in APC. If not, it processes each file individually, and combines the result of each Processor into one giant array, which is cached in APC. * The giant array then sets various global settings, defines constants, and calls callbacks. To invalidate the cached processed info, by default the mtime of each JSON file is checked. However that can be slow if you have a large number of extensions, so you can set $wgExtensionInfoMTime to the mtime of one file, and `touch` it whenever you update your extensions. Change-Id: I7074b65d07c5c7d4e3f1fb0755d74a0b07ed4596
37 lines
1.2 KiB
PHP
37 lines
1.2 KiB
PHP
<?php
|
|
|
|
require_once __DIR__ . '/Maintenance.php';
|
|
|
|
class ValidateRegistrationFile extends Maintenance {
|
|
public function __construct() {
|
|
parent::__construct();
|
|
$this->addArg( 'path', 'Path to extension.json/skin.json file.', true );
|
|
}
|
|
public function execute() {
|
|
if ( !class_exists( 'JsonSchema\Uri\UriRetriever' ) ) {
|
|
$this->error( 'The JsonSchema library cannot be found, please install it through composer.', 1 );
|
|
}
|
|
|
|
$retriever = new JsonSchema\Uri\UriRetriever();
|
|
$schema = $retriever->retrieve('file://' . dirname( __DIR__ ) . '/docs/extension.schema.json' );
|
|
$path = $this->getArg( 0 );
|
|
$data = json_decode( file_get_contents( $path ) );
|
|
if ( !is_object( $data ) ) {
|
|
$this->error( "$path is not a valid JSON file.", 1 );
|
|
}
|
|
|
|
$validator = new JsonSchema\Validator();
|
|
$validator->check( $data, $schema );
|
|
if ( $validator->isValid() ) {
|
|
$this->output( "$path validates against the schema!\n" );
|
|
} else {
|
|
foreach ( $validator->getErrors() as $error ) {
|
|
$this->output( "[{$error['property']}] {$error['message']}\n" );
|
|
}
|
|
$this->error( "$path does not validate.", 1 );
|
|
}
|
|
}
|
|
}
|
|
|
|
$maintClass = 'ValidateRegistrationFile';
|
|
require_once RUN_MAINTENANCE_IF_MAIN;
|