Implement extension registration from an extension.json file
commitbfe4ddd8108efe00f9395397e92f65f6c66b6a4d
authorKunal Mehta <legoktm@gmail.com>
Wed, 15 Oct 2014 00:31:15 +0000 (14 17:31 -0700)
committerTim Starling <tstarling@wikimedia.org>
Thu, 8 Jan 2015 01:40:01 +0000 (8 01:40 +0000)
tree1f3f38589d8df8e2ec9c1464be42d2d8a533ff3c
parent3226337f17825b1c9e4465cd9635ae83c2ef11c0
Implement extension registration from an extension.json file

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
14 files changed:
autoload.php
composer.json
docs/extension.schema.json [new file with mode: 0644]
includes/DefaultSettings.php
includes/GlobalFunctions.php
includes/Setup.php
includes/WebStart.php
includes/registration/ExtensionProcessor.php [new file with mode: 0644]
includes/registration/ExtensionRegistry.php [new file with mode: 0644]
includes/registration/Processor.php [new file with mode: 0644]
maintenance/convertExtensionToRegistration.php [new file with mode: 0644]
maintenance/doMaintenance.php
maintenance/validateRegistrationFile.php [new file with mode: 0644]
tests/phpunit/includes/registration/ExtensionProcessorTest.php [new file with mode: 0644]