Commit graph

41 commits

Author SHA1 Message Date
Reedy
aed1e72c96 registration: Move SearchMappings to CORE_ATTRIBS from NOT_ATTRIBS
Also remove SearchMappings from extension.v1.json

Bug: T250977
Change-Id: I010ac37a869ad12c4dcbe65805a19ee0662a34e3
Follows-Up: Ib9634128f07d428276e80a6f2f492b850eef17e8
2020-05-01 18:23:12 +00:00
Reedy
eeb8cb1342 search: Add 'SearchMappings' attribute to map canonical name to PHP class
This allows indirection between the values in $wgSearchType and
$wgSearchTypeAlternatives where the underlying class name
doesn't match the actual class name that subclasses
SearchEngine.

Bug: T250977
Change-Id: Ib9634128f07d428276e80a6f2f492b850eef17e8
2020-04-30 04:29:17 +00:00
Reedy
b0ef0b3717 Clarifiy that (extension|skin).json requires properties can be for skins too
Change-Id: I61f92dee4092ea2644f1d93eeaf7b03a6ef2308d
2020-04-22 15:50:30 +01:00
Timo Tijhof
e456b68651 resourceloader: Allow 'localBasePath' for ImageModule to extension.json
This wasn't yet part of the schema, hereby added.
Being used for TemplateData in Ic8975d7ba349.

Change-Id: If661c68bea069e99cfff35711efdde7805a12851
2020-03-15 14:54:56 +00:00
mainframe98
ac48c84224 Allow specifying autoloaded classes for tests
This introduces two new keys to the extension schema, analogous to
the existing autoloader keys: TestAutoloadNamespaces and
TestAutoloadClasses.

The classes and namespaces defined by these keys are only loaded by
the registry when ExtensionRegistry::setLoadTestClassesAndNamespaces
is called. The phpunit wrapper does this in PHPUnitMaintClass::setup.
The unit test bootstrap file calls
ExtensionRegistry::exportTestAutoloadClassesAndNamespaces instead,
similar to how it loads the regular classes and namespaces.

Bug: T196090
Change-Id: I88cf69663362fd599c20649b1df641907a02678d
2019-12-10 21:39:30 +00:00
Bartosz Dziewoński
d50c7f5b56 extension.schema.v2: Fix schemas for 'packageFiles'
The PHP code handling 'packageFiles' looks like it only expects
numeric arrays, and not associative arrays. Therefore in JSON the
value for the 'packageFiles' key should be arrays and not objects.
(And a special case of a string, handled the same as single-element
array, is also accepted.)

Individual items in the array can be not only strings, but also
objects, describing data which is pulled from other sources than a
file.

* ResourceLoaderFileModule: Remove unused variable and tweak docs.

Change-Id: I6c3d186de1877f73d4a4e3fec7d6d632a5d5fa83
2019-10-24 22:30:10 +02:00
Timo Tijhof
34bff221ba mediawiki.messagePoster: Introduce 'MessagePosterModule' extension attribute
This allows extensions to add additional files or dependencies to
the 'mediawiki.messagePoster' module bundle.

Bug: T235315
Change-Id: I17c34cbb26e786328d3d99beb0c0fa65e15ea084
2019-10-17 18:00:10 +00:00
mainframe98
b7b490e46d Support the creation of special pages with services injected
Now that the ObjectFactory library supports object creation with
services (T222409), the special page factory can use the object
factory to create special pages based off a spec, allowing the
creation of special pages that need services injected.

The object factory now also handles constructing from class name
and from callable.

This also deprecates providing the special page list with an
instance of SpecialPage, which hasn't been necessary since
r15031.

Bug: T222388
Change-Id: Iabb78ce5c98cfb3b586644be35d984871cb750cb
2019-09-08 12:57:54 +02:00
Bartosz Dziewoński
77f4bab8b7 Allow skins/extensions to define custom OOUI themes
This change follows I39cc2a735d9625c87bf4ede6f5fb0ec441d47dcc.

docs/extension.schema.v1.json
docs/extension.schema.v2.json
includes/registration/ExtensionProcessor.php
* The new extension attribute 'OOUIThemePaths' can be used to define
  custom OOUI themes. See I9187a63e509b601b8558ea82850fa828e5c8cc0a
  for an example usage.

includes/resourceloader/ResourceLoaderOOUIModule.php
* Add support for 'OOUIThemePaths'.
* Defining 'images' is now optional. I figure custom themes are
  unlikely to have or need them.
* Use ResourceLoaderFilePath objects to allow skin-/extension-defined
  OOUI module files to use skin/extension's base paths.
  This was previously used to support $wgResourceModuleSkinStyles,
  but only for 'skinStyles' - now ResourceLoaderFileModule needs
  to also handle it for 'skinScripts', and ResourceLoaderImageModule
  for 'images').

includes/resourceloader/ResourceLoaderFilePath.php
* Add getters for local/remote base paths, for when we need to
  construct a new ResourceLoaderFilePath based on existing one.

includes/resourceloader/ResourceLoaderFileModule.php
includes/resourceloader/ResourceLoaderImageModule.php
includes/resourceloader/ResourceLoaderOOUIImageModule.php
* Add or improve handling of ResourceLoaderFilePaths:
  * Replace `(array)` casts with explicit array wrapping, to avoid
    casting objects into associative arrays.
  * Use getLocalPath() instead of string concatenation.

tests/phpunit/includes/resourceloader/ResourceLoaderFileModuleTest.php
tests/phpunit/includes/resourceloader/ResourceLoaderImageModuleTest.php
* Some basic checks for the above.

Bug: T100896
Change-Id: I74362f0fc215b26f1f104ce7bdbbac1e106736ad
2019-07-10 22:08:14 +02:00
Kunal Mehta
286a2a1852 registration: Deprecate ParserTestFiles in extension.json
Warnings will be emitted whenever validation is checked or unit tests are
run.

Bug: T192154
Change-Id: Ib968f696890667841d850ef5562e05989cb4f431
2019-06-02 21:53:31 -04:00
Kunal Mehta
1aa819513b registration: Add development requirements to extension.json
Extensions can specify development dependencies in extension.json under
the "dev-requires" key. It's identical to the "requires" field.

Any requirement that is needed to pass tests, including but not limited
to, PHPUnit, QUnit, structure, phan, should be documented in this new
field. The main intention is that CI will ensure that all of these
dependencies are satisfied before running tests.

At standard runtime, the development requirements will be ignored by
MediaWiki, since it only checks for real requirements. Scripts can
manually check development requirements by calling
ExtensionRegistry::setCheckDevRequires( true ) before trying to load
things.

If both "requires" and "dev-requires" are present, MediaWiki will merge
the two together, so the environment will need to satisfy both before
proceeding.

Bug: T193824
Change-Id: I9b2936666ee3c96f5c976c7a17f11c437c2c7f48
2019-05-22 01:59:33 -07:00
Kunal Mehta
cfd5d33da2 registration: Fix validation of ext-foo values
Our json-schema library doesn't yet support "const" (at least not in a
released version), so use "enum" with one element, since it's functionally
equivalent per <https://json-schema.org/understanding-json-schema/reference/generic.html#constant-values>.

Change-Id: Ib9ebb5c6b9d07903fa47603fbe54a148e9c00352
2019-05-22 01:57:32 -07:00
MGChecker
5e2c7466ad registration: Allow to require environment abilities
This patch adds the possibility for extensions and skins to require
certain environment abiltites that are not necessarily PHP extensions.

For now, the only ability introduced is the ability to shell out, but
the processing and testing is written in a more general way to allow
users to add more abilties later on by just changing getAbilities().

In theory, this allows using VersionChecker to check for random
abilities if they are specified in the constructor, as it is comletely
environment agnostic and not really bound to just be used for checking
extension compatibility.

Furthermore, it is possible to specify custom error messages for each of
these abilities in the constructor. Other parts of MediaWiki may use
these features to check for requirements while working with totally
different abilities.

Bug: T212472
Change-Id: Iff8512530b08ef509e7ac0b6ed8fe9578ef3e2a1
2019-04-13 08:14:44 -07:00
Kunal Mehta
0a8a4fe75e registration: Fix 'ResourceLoaderWikiModule' schema validation
There is a full schema for ResourceModules when the
class: ResourceLoaderWikiModule is used. Except it doesn't actually work,
since it it fails validating against that schema, it will continue to check
the other anyOf schemas, find the arbitrary class one, and pass that one.

Blacklisting ResourceLoaderWikiModule from the arbitrary class schema means
that it has to pass the specified schema for it, or fail validation.

I verified that all extensions and skins in Gerrit pass validation with this
patch.

Change-Id: Icb862088c0ca1f89ed5a57a4286dd9049d213021
2019-02-22 17:17:05 -08:00
Kunal Mehta
291fcff08e registration: Fix 'arbitrary ResourceLoaderModule definition' schema regex
We want this regex to match on everything that is not the literal string
'ResourceFileModule' or 'ResourceImageModule' (actually
'ResourceLoaderWikiModule' should be in this too, but I'll fix that in a
follow-up). But the current regex would not match if one of those was in a
substring.

The new regex should match everything that is *not* those two strings.

Bug: T216861
Change-Id: I7d888adfdc67b2075028e49432710308aa0125af
2019-02-22 17:03:01 -08:00
Gilles Dubuc
bd2a9bfd97 registration: Define packageFiles for v1 extension schema
Follows 56fa42d433.

Bug: T215756
Change-Id: Icbf433b6b147f53cf99533a7272fc83392a8999d
2019-02-11 20:45:20 +00:00
Timo Tijhof
d1666a89ff resourceloader: Support TestModules registration via extension.json
Bug: T126091
Change-Id: I27ecebe27d7aaebe6d1317bc5eaea9cca368b45d
2019-02-05 15:27:37 -08:00
Bartosz Dziewoński
e3a736b42d registration: Fix typo in schemas
Change-Id: I8d39290904593c1ef962be2995a536028d0635bc
2019-01-22 02:30:48 +00:00
Gergő Tisza
265cb893cb Add $wgReauthenticateTime to extension.json
Change-Id: I9722c065d522e18b6bf488c721f48ee7b7b9e494
2018-11-15 15:41:50 -08:00
MGChecker
c7e45b6211 registration: Let extensions add PHP extension requirements
This change adds the possibility to specify ext-* keys under the 'platform'
key introduced in I6744cc0be2 to require given PHP extensions. Note that
it's impossible to add constraints different from '*', as there is no universal
way to retrieve PHP extension versions.

Bug: T197535
Change-Id: I510de1e6d80f5c1d92dc1d1665aaa6c25bf28bf7
2018-09-30 19:55:57 +02:00
MGChecker
8af76decf8 registration: Let extensions add PHP version requirements
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
2018-09-22 03:43:28 +02:00
Gergő Tisza
2ed7bdc46d
Require editsitecss/editsitejs for editing raw messages
Bug: T45646
Change-Id: Ib16db04e499ad28216ee08b8cccccf3f141e2bad
2018-08-26 23:56:06 +02:00
Timo Tijhof
ca510f742f resourceloader: Remove $wgResourceLoaderLESSVars support
The use of global variables was deprecated in favour of
ResourceLoaderModule::getLessVars() on a per-module basis.

Also moved testLessFileCompilation case to the appropiate file as it
covers ResourceLoaderFileModule.php, not ResourceLoader.php.

Bug: T140804
Depends-On: Ib1b2808df2384473bfac47f53a5d25d7c9bbca2b
Depends-On: I96047f69d01c4736306df2719267e6347daf556f
Change-Id: If708087c85c80355c7e78f1768529b5f2e16ed07
2018-08-14 18:57:45 +00:00
jdlrobson
89b2e1eb2c registration: Document ResourceLoaderImageModule's useDataURI option
Without these rules, validation will fail in any skin or
extension that tries to use it.

Follows-up 36252b7.

Bug: T198930
Change-Id: Iee77655d4868a7d921be8cc23776a7859d9acf0c
2018-07-10 00:23:33 +00:00
jdlrobson
8faba225fe ResourceLoaderImage module definitions can define a defaultColor
Bug: T197909
Change-Id: I0745e112d11026ed59d8daca990b313305cd094a
2018-06-27 20:36:47 +00:00
Kunal Mehta
bf9bc2ae49 registration: Validate AutoloadNamespaces keys have trailing \
The PSR-4 autoloader requires "AutoloadNamespaces" keys to have a
trailing \ (\\ in JSON), so add a validation check for that.

Unfortunately the validation error isn't great, since it checks to see
if the property matches patternProperties, and when it doesn't, it
claims the property isn't defined since additionalProperties is false.
But it's still better than not failing when they are missing.

Bug: T189136
Change-Id: If01bd06cdd767fb704a8ff85cdf1c143e53fa4ca
2018-05-20 12:13:05 -07:00
James D. Forrester
2cbd34dc55 Follow-up 8a7fb8577: For deprecated RL modules, allow strings
So that more than just PHP code and MediaWiki core can use it, but
also JSON-based static extension registrations. :-)

Change-Id: If22fccbb43c5b05db2a666d61ae8864ee9815e7d
2018-01-08 16:05:05 -08:00
Kunal Mehta
036f5b47ef Enable using PSR-4 autoloader for MediaWiki core and extensions
This adds support for a PSR-4 (<http://www.php-fig.org/psr/psr-4/>)
autoloader, so instead of needing to manually list each class, just the
namespace prefix is needed.

Extensions can set a "AutoloadNamespaces" property in extension.json to
register PSR-4 compatible namespaces to be autoloaded.

The implementation is based off of the example implementation
(<http://www.php-fig.org/psr/psr-4/examples/>) with some modifications
for performance, notably cutting down on function calls, and only trying
to look up classes that are namespaced.

The generateLocalAutoload.php script will ignore any directory that is
registered as a PSR-4 namespace.

Bug: T99865
Bug: T173799
Change-Id: Id095dde37cbb40aa424fb628bd3c94e684ca2f65
2017-12-12 00:20:11 +00:00
Kunal Mehta
679589828c registration: Allow protocol-relative links in "url" field
Bug: T93010
Change-Id: I626fb5528b41910d859d8596a8ad350f94c1082e
2017-07-17 10:13:49 -07:00
Lucas Werkmeister
a57252a1f5 Allow callback functions for creating jobs
$wgJobClasses can now specify a factory function for creating a job,
instead of a class to be instantiated directly. This makes it possible
to inject services in a job constructor, and register a factory function
that calls the constructor with default services.

This follows Ieb85493a7765 and Ia2107dc5af78, which introduced factory
functions for API modules and special pages.

Change-Id: I0461e59da2a8fa6681e3b1fcdfc38bfed7f3ac32
2017-05-09 19:26:13 +02:00
Umherirrender
0872063d71 registration: Allow properties in "requires" from v2
v2 of the schema allows extensions and skins to be definied under
"requires". This is also used by some extensions in extension.json for
v1.
It works, so allow the same properties in v1 as in v2.

Change-Id: I9b5f1986cadbd714d6f3460ac3e1db3bf7aae65d
2017-01-30 18:51:16 +01:00
Reedy
2f5ee95188 registration: FileExtensions should be an array, not an object
Change-Id: Iff44a4c241ab953906a7b0611f09e66856b1f7dc
2016-11-21 05:54:48 +00:00
Reedy
ad86dda42f registration: Set "FileExtensions" to $GLOBALS
Change-Id: Ie52004d25ebc06c81cd7d8d7de60479ff365ccea
2016-11-17 23:24:42 +00:00
Reedy
34e549ff61 registration: Support setting $wgPasswordPolicy in extension.json
Bug: T149597
Change-Id: I56c0b8932fcd42ec9b748529daa32a998fb19bf8
2016-11-17 22:46:32 +00:00
Yuri Astrakhan
ab224f8211 Added array_replace_recursive merge strategy
For extension registry, add array_replace_recursive merge strategy,
as some extensions/configuration may prefer that to array_merge_recursive.

In some cases, configuration is merged from multiple extensions,
such as JsonConfig's $wgJsonConfigs configuration: ZeroBanner defines

	"JsonZeroConfig": {
		"namespace": 480,
		"nsName": "Zero",
		"isLocal": false,
		"cacheKey": "1"
	}

and mobile.php overrides it with
	$wgJsonConfigs['JsonZeroConfig']['isLocal'] = false;
	$wgJsonConfigs['JsonZeroConfig']['remote'] = [
		'url' => 'https://zero.wikimedia.org/w/api.php',
		'username' => $wmgZeroPortalApiUserName,
		'password' => $wmgZeroPortalApiPassword,
	];

Having identical value 'isLocal' would be converted into an array
if array_merge_recursive is used, but the replace strategy fixes it.

Change-Id: Ica6ddd0ae76f23e60de9b6235c6e2a3f2754a95d
2016-10-24 19:20:04 +00:00
Brion Vibber
ff490cc42a Add 'noflip' option on RL modules to disable CSSJanus
Should be useful for cases where we pull in an external library
that already manages RTL flipping in its styles, and CSSJanus
does the wrong thing without extra markup.

Example:

  'ext.tmh.video-js' => $baseExtensionResource + [
      'scripts' => 'resources/videojs/video.js',
      'styles' => 'resources/videojs/video-js.css',
      'noflip' => true,
      ...
  ],

Bug: T148572
Bug: T148565
Change-Id: Icbad20d8a6e9a0d354ad159f5816f4fb67cc2775
2016-10-18 13:36:27 -07:00
Kunal Mehta
f6644c07cb registration: Improve license-name validation
Our hardcoded enum list in the extension.json schema for license-name
values was incomplete and did not cover the full SPDX license identifier
specification, which includes things like "AND" for specifying multiple
licenses.

Composer already has solid code in a library to do this validation, so
let's use it! This updates both the validateRegistrationFile.php and
ExtensionJsonValidationTest.php to use the composer/spdx-licenses
library (a new development dependency) to ensure the license-name field
is a valid SPDX identifier.

Also fix a silly typo in the validateRegistrationFile script which
prevented it from running, and use ::class so it will be easier to
detect typos like that in the future.

Bug: T146862
Change-Id: Ibb8973ed7950ae81c90558f9630f73746b2aff2c
2016-09-28 20:50:48 +00:00
Kunal Mehta
64692bfd36 registration: Support 'ServiceWiringFiles' in extension.json
Change-Id: Ib413a14cb8e21207264fa1c45d84550b3eab7a4e
2016-08-25 23:08:28 -07:00
jdlrobson
8af960e484 resourceloader: Implement 'deprecated' option for FileModule
ResourceLoader modules can now carry a 'deprecated' option which can
be a boolean or an object with message key. This message or a default
deprecation message will be show whenever that module is used in production.

Note: This will not work in debug mode for ResourceLoaderFile modules
and this is deemed acceptable for the time being. We can revisit later.

Bug: T137772
Change-Id: Ib9ebd2d39a59fd41d8537e06884699f77b03580c
2016-08-04 18:01:53 +00:00
Kunal Mehta
93aed1e7eb registration: Support conditionally registered namespaces
Some extensions (e.g. EventLogging) conditionally register a namespace
depending upon the wiki's configuration using the CanonicalNamespaces
hook. Since the "namespaces" key automatically registers the namespace,
we need an option to not register it and let the extension take care of
that manually using the hook.

All of the other namespace related settings are safe to unconditionally
set since they won't do anything if the namespace doesn't actually
exist.

Bug: T141604
Change-Id: Ie8c217fdc8bd783b30f98210309ea56fef39c0da
2016-07-29 01:09:24 -07:00
Kunal Mehta
83ec5909d4 registration: Convert "config" into an object with metadata
To add extra metadata for "config" options without constantly adding
hacky underscore prefixed keys, convert "config" items into an object,
where the value is under a "value" key.

"_merge_strategy" is now just "merge_strategy", but still has the
underscore prefix for the cache structure, to avoid changing it.

Since this is a fully breaking change, it only applies to files with
manifest_version: 2 set. A conversion script has been added to assist
with automated conversion.

Bug: T133626
Change-Id: Id1071fc0647892438e5cd0e3ee621fbdaaa64014
2016-07-13 14:58:00 -07:00