While MediaWiki Core already sets requirements for PHP versions, it should be
possible for extensions to tighten these requirements. This mirrors the PHP
parameter of extension infoboxes as well.
This change introduces a new 'platform' key (in addition to 'MediaWiki', 'skins'
and 'extensions', where non-MediaWiki software requirements will be listed
in the future, starting with a PHP version constraint. Further keys are
supposed to be added to allow setting constraints against php extensions
and other abilities of the platform.
Bug: T197535
Change-Id: I6744cc0be2363b603331af9dc860eb8603a1a89a
The code for ParserTestFiles and ServiceWiringFiles was identical, so
unify it into one function. For most extensions, this should save two
unnecessary function calls as a bonus.
Change-Id: If5ed189f97b7d3b9cd7b550f3ad2e90abe30005d
These tests apply to things that are not relevant to PHP code coverage,
such as testing presence of messages, JSON files, or the PHPUnit tests
themselves.
Using @coversNothing indicates that there is no code here to be covered,
and prevents warnings when using --strict-coverage mode (T152923).
Change-Id: Id89ee2c15a3ce3f10e34b13fb677cd1af75af9e6
ExtensionProcessor would previously just blindly overwrite duplicate
config settings, which ends up depending upon load order.
It's relatively hard to debug since it is silently overwritten. This now
throws exceptions in case of duplicate config settings.
This will also have some side-effects of catching people putting things
like "ResourceModules" in their "config" section when it should be a
top-level item.
Bug: T152929
Depends-On: I4c5eaf87657f5dc07787480a2f1a56a1db8c714f
Change-Id: Ieeb26011e42c741041d2c3252238ca0823b99eb4
ExtensionProcessor would previously just blindly overwrite duplicate
config settings, which ends up depending upon load order.
It's relatively hard to debug since it is silently overwritten. This now
throws exceptions in case of duplicate config settings.
This will also have some side-effects of catching people putting things
like "ResourceModules" in their "config" section when it should be a
top-level item.
Bug: T152929
Change-Id: Iaef32efab397e82ff70ddca8ac79c545c5b7d2bb
This moves attributes out of the top level, and namespaces them under
each extension. If the extension that it belongs to is not installed,
the attribute is not exported and dropped.
The full name of the attribute is the name of the extension plus the
name of the attribute key. This enforces the recommendation that the
attribute name start with the extension's name.
Add test coverage for attributes under manifest_version 1 and 2.
Bug: T133627
Depends-On: I5a148763f68989c8da313a4fb1d0213658ee4495
Depends-On: I5a148763f68989c8da313a4fb1d0213658ee4459
Change-Id: I8613a027c56e2c9d2c6a83ca14749eb1c8fc23be
This allows extension namespaces to be assigned a custom ID, e.g. in case
the namespace pre-defined by the extension is already taken on the local
wiki.
This is done by defining the respective namespace constant in
LocalSettings.php.
Bug: T160462
Change-Id: If648d6e218847e6632d643ea724cd3da3945db70
Replaces \TestingAccessWrapper (defined in core) with
\Wikimedia\TestingAccessWrapper (defined in the composer package
wikimedia/testing-access-wrapper).
See https://gerrit.wikimedia.org/r/#/q/topic:librarize-testing-access-wrapper
for downstream patches.
The core version of the class is kept around for a while to avoid
circular dependency problems.
Bug: T163434
Change-Id: I52cc257e593da3d6c3b01a909e554a950225aec8
Instead of having the current version of the schema live at
extension.schema.json, always include a version number in it. This
simplifies both the code, and makes merging, cherry-picks, rebasing,
etc. easier when the current schema version changes.
Change-Id: I1b5ef4ced1eb34b8bdda7ba9b3f086b1997b704c
Add support for configuration settings that are relative paths to the
extension directory. The most common use-case for this is where the
extension ships a generic default file, but sysadmins or packagers may
want to override it. Setting `"path": true` on the config definition
will make the value be interpreted as a relative path.
And add tests!
Bug: T100956
Change-Id: Ia87ced25b35be7a314ee2937e0ccc63f9acc5bb5
Verify that all the global settings listed in
ExtensionProcessor::$globalSettings are documented in the extension.json
schema.
Change-Id: If0ed09ed19b92934e869bbd40d8716a83e4b0a30
Instead of forcing an object even for single-hook-listeners, allow
string values, too (one hook listener for one hook, only). Also:
use it as default for the conversion script, if only one listener
is added to a hook (which is usually the case). This leads into a
much cleaner output of the Hooks section of extension.json.
Bug: T133628
Change-Id: Ie9e54f0931c41706eb8d82d00256698992ec41cc
PHP_CodeCoverage_Exception:
> Trying to @cover not existing method "SwiftFileBackend::sanitzeHdrs".
> Trying to @cover not existing method "LineFormatter::normalizeException".
> Trying to @cover not existing method "MonologSpi::mergeConfig".
> Trying to @cover not existing method "ProcessCacheLRU::het".
> Trying to @cover not existing method "BitmapHandler::swapICCProfile".
> Trying to @cover not existing class or interface "checkParseSafety".
> Trying to @cover not existing method "Article::__call". (was removed).
> Trying to @cover not existing method "ExtensionProcessor::extracttExtensionMessagesFiles".
> Trying to @cover not existing method "FileContentsHasher::getFileContentHash".
Makes code coverage run fail at the moment. These used to be warnings
in PHPUnit 3.x, but are now hard exceptions in PHPUnit 4.x when requesting
a coverage report.
Change-Id: If7f45ca57fd7d480d35b1414a889398837c0c472
Noticed it in APC usage for ResourceLoader that various keys from
FileContentsHasher contain double slashes. All from extensions that
use the `"localBasePath": ""` trick in extension.json (e.g. Citoid).
Change-Id: I5bac1e2e05e063aa7ff251ce7ffaa965a3451db9
Normally the registry load queue should filter out duplicates, but if
people do weird things with symlinks, throw a useful error message if
the double-loading makes it all the way to the processor.
Bug: T121493
Change-Id: I47f5cd754e5f3c91e6b83a6d0ab542404347a421
Allow extensions which are using "$eg" or any other prefix to migrate.
Extensions can override the default of "wg" by setting a magic "_prefix"
key in the "config" object.
Note that the migration helper script will not be able to automatically
migrate custom-prefixed configuration settings.
Bug: T97186
Change-Id: I79203cd5e3a2405b92ad01da869de3bd3d359d19
Instead of hardcoding specific global settings in ExtensionRegistry,
create specific "merge strategies" that are used to merge globals.
Merge strategies are set for core properties in the ExtensionProcessor,
and extensions can set them for their own configuration settings using
the magic "_merge_strategy" key.
The following merge strategies are included:
* array_merge_recursive - call `array_merge_recursive` on the two arrays
* array_plus - use the "+" operator to combine arrays, preserving
integer keys
* array_plus_2d - A version of array_plus that works on 2d arrays, used
for merging arrays like $wgGroupPermissions
* array_merge - call `array_merge` (default)
This changes the merging of various namespaces related settings to use
array_plus so they actually work.
Bug: T107646
Change-Id: I64cb0553864e3b78b0f203333f58bb73b86a6434
Codesniffer says that the `var` keyword must not be used to declare a
property and that visibility must be declared on class properties.
Change-Id: I28240aa0f394588b1df315621dbcd260c51430c1
Versioning the extension.json schema will allow us to make breaking changes
to the schema in a non-breaking manner.
Extensiosn and skins will set a 'manifest_version' value, stating which
version of the schema the file is written for. Processor::extractInfo() will
be passed the version number, and can switch behavior depending upon it.
For backwards-compatability, a version number of 1 is assumed if none is set.
The validateRegistrationFile.php script will emit a warning if this is the
case.
Bug: T99344
Change-Id: I2086a1465ceaeedd1ccc6804fda2c304ad16ffa0
Rather than continuously creating an array of keys that were used, just
hardcode a list of keys that aren't attributes. This also handles keys
like "AutoloadClasses" that is handled by the registry.
Bug: T98977
Change-Id: I35088a76ff4c58db71e8c9bc139fa0ccca738e3b
Structurally, it's set up exactly the same as ResourceModules, so we can
re-use the same code.
Bug: T91566
Change-Id: I7cd1330edc3e97b4658c81aac67071a90ac61fb6
Previously any module definition that specified a "class" was skipped. This
is problematic for custom modules that extend ResourceLoaderFileModule and
should be using the default paths.
Since we can't determine at initialization time whether a module class is a
ResourceLoaderFileModule or not, just add the default paths to all modules,
and leave it up to the individual classes to use the extra arguments or not.
Change-Id: Iee5d178343326030968755983f62629b81ef3c88
This allows for extensions to specify common arguments to ResourceLoader
module definitions by only specifying them once.
The only supported values are "localBasePath" (which is relative to the
current directory), "remoteSkinPath", and "remoteExtPath". If a module
is using a custom class or is already specifying paths, the default paths
will not be added.
Tests are included to cover existing functionality and newly added
functionality. The convertExtensionToRegistration.php script was also
extended to try and guess what the default paths should be.
Bug: T88786
Change-Id: I802461796e8d8584dacf3b0c811b5ba97a4a8f7f
In f2daeaa749, the handling of MessageDirs was fixed to properly
handle arrays, except that broke ExtensionMessagesFiles which doesn't
support arrays. Since both settings are pretty much different, I split
them into separate functions.
Bug: T88858
Change-Id: I48765af2489d2ef1e30adb1d7c5a5a8f23bf522d
Previously the code was designed to handle:
"MessagesDirs": {
"FooBar": "i18n"
}
However, it can also be an array, and some extensions (VisualEditor)
use it like:
"MessagesDirs": {
"FooBar": [
"i18n",
"also-i18n"
]
}
This properly handles both strings and arrays and adds tests to verify
the behavior.
Change-Id: Iff1523b86f754cac1f5b8d822d4324c5fbfc1a50
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