From: Kunal Mehta Date: Sun, 2 Aug 2015 23:42:46 +0000 (-0700) Subject: registration: Support custom classes in "ResourceModules" schema X-Git-Tag: 1.31.0-rc.0~9222 X-Git-Url: https://git.cyclocoop.org/%27%20.%20%24this-%3EgetSkin%28%29-%3EescapeSearchLink%28%29%20.%20%27?a=commitdiff_plain;h=7014e432cffcee992bbf8291b2003440b66b4e7d;p=lhc%2Fweb%2Fwiklou.git registration: Support custom classes in "ResourceModules" schema Instead of expecting everything to be a ResourceLoaderFileModule, use the "anyOf" property to validate against multiple schemas. The following schemas are now allowed: * The ResourceLoaderFileModule schema, now with the "targets" property * A schema for ResourceLoaderImageModule * A generic schema that requires the "class" property is set, but not to "ResourceLoaderFileModule" or "ResourceLoaderImageModule". The last schema will allow for any custom ResourceLoaderModule class to be set in extension.json with arbitrary parameters. One downside of this is that the error messages shown when a file does not validate get a little more confusing, as it shows the error messages for each schema it does not match. Bug: T105236 Change-Id: I5e4bfa69c733187c7b27294c159cac05b3b92e81 --- diff --git a/docs/extension.schema.json b/docs/extension.schema.json index 218a19c3b9..dde4fa189e 100644 --- a/docs/extension.schema.json +++ b/docs/extension.schema.json @@ -302,128 +302,185 @@ "ResourceModules": { "type": "object", "description": "ResourceLoader modules to register", - "additionalProperties": false, "patternProperties": { "^[a-zA-Z0-9-\\.]+$": { "type": "object", - "description": "A single ResourceLoader module descriptor", - "properties": { - "localBasePath": { - "type": "string", - "description": "Base path to prepend to all local paths in $options. Defaults to $IP" - }, - "remoteBasePath": { - "type": "string", - "description": "Base path to prepend to all remote paths in $options. Defaults to $wgScriptPath" - }, - "remoteExtPath": { - "type": "string", - "description": "Equivalent of remoteBasePath, but relative to $wgExtensionAssetsPath" - }, - "scripts": { - "type": ["string", "array"], - "description": "Scripts to always include (array of file paths)", - "items": { - "type": "string" - } - }, - "languageScripts": { - "type": "object", - "description": "Scripts to include in specific language contexts (mapping of language code to file path(s))", - "patternProperties": { - "^[a-zA-Z0-9-]{2,}$": { - "type": [ - "string", - "array" - ], + "anyOf": [ + { + "description": "A ResourceLoaderFileModule definition", + "additionalProperties": false, + "properties": { + "localBasePath": { + "type": "string", + "description": "Base path to prepend to all local paths in $options. Defaults to $IP" + }, + "remoteBasePath": { + "type": "string", + "description": "Base path to prepend to all remote paths in $options. Defaults to $wgScriptPath" + }, + "remoteExtPath": { + "type": "string", + "description": "Equivalent of remoteBasePath, but relative to $wgExtensionAssetsPath" + }, + "scripts": { + "type": ["string", "array"], + "description": "Scripts to always include (array of file paths)", "items": { "type": "string" } - } - } - }, - "skinScripts": { - "type": "object", - "description": "Scripts to include in specific skin contexts (mapping of skin name to script(s)", - "patternProperties": { - ".+": { - "type": [ - "string", - "array" - ], + }, + "languageScripts": { + "type": "object", + "description": "Scripts to include in specific language contexts (mapping of language code to file path(s))", + "patternProperties": { + "^[a-zA-Z0-9-]{2,}$": { + "type": [ + "string", + "array" + ], + "items": { + "type": "string" + } + } + } + }, + "skinScripts": { + "type": "object", + "description": "Scripts to include in specific skin contexts (mapping of skin name to script(s)", + "patternProperties": { + ".+": { + "type": [ + "string", + "array" + ], + "items": { + "type": "string" + } + } + } + }, + "debugScripts": { + "type": ["string", "array"], + "description": "Scripts to include in debug contexts", "items": { "type": "string" } - } - } - }, - "debugScripts": { - "type": ["string", "array"], - "description": "Scripts to include in debug contexts", - "items": { - "type": "string" - } - }, - "loaderScripts": { - "type": ["string", "array"], - "description": "Scripts to include in the startup module", - "items": { - "type": "string" - } - }, - "dependencies": { - "type": ["string", "array"], - "description": "Modules which must be loaded before this module", - "items": { - "type": "string" - } - }, - "styles": { - "type": ["string", "array", "object"], - "description": "Styles to always load", - "items": { - "type": "string" - } - }, - "skinStyles": { - "type": "object", - "description": "Styles to include in specific skin contexts (mapping of skin name to style(s))", - "patternProperties": { - ".+": { - "type": [ - "string", - "array" - ], + }, + "loaderScripts": { + "type": ["string", "array"], + "description": "Scripts to include in the startup module", + "items": { + "type": "string" + } + }, + "dependencies": { + "type": ["string", "array"], + "description": "Modules which must be loaded before this module", + "items": { + "type": "string" + } + }, + "styles": { + "type": ["string", "array", "object"], + "description": "Styles to always load", + "items": { + "type": "string" + } + }, + "skinStyles": { + "type": "object", + "description": "Styles to include in specific skin contexts (mapping of skin name to style(s))", + "patternProperties": { + ".+": { + "type": [ + "string", + "array" + ], + "items": { + "type": "string" + } + } + } + }, + "messages": { + "type": ["string", "array"], + "description": "Messages to always load", + "items": { + "type": "string" + } + }, + "group": { + "type": "string", + "description": "Group which this module should be loaded together with" + }, + "position": { + "type": "string", + "description": "Position on the page to load this module at", + "enum": [ + "bottom", + "top" + ] + }, + "templates": { + "type": "object", + "description": "Templates to be loaded for client-side usage" + }, + "targets": { + "type": ["string", "array"], + "description": "ResourceLoader target the module can run on", "items": { "type": "string" } } } }, - "messages": { - "type": ["string", "array"], - "description": "Messages to always load", - "items": { - "type": "string" + { + "description": "A ResourceLoaderImageModule definition", + "additionalProperties": false, + "properties": { + "class": { + "enum": ["ResourceLoaderImageModule"] + }, + "data": { + "type": "string" + }, + "prefix": { + "type": "string" + }, + "selector": { + "type": "string" + }, + "selectorWithoutVariant": { + "type": "string" + }, + "selectorWithVariant": { + "type": "string" + }, + "variants": { + "type": "object" + }, + "images": { + "type": "object" + }, + "position": { + "enum": [ + "top", + "bottom" + ] + } } }, - "group": { - "type": "string", - "description": "Group which this module should be loaded together with" - }, - "position": { - "type": "string", - "description": "Position on the page to load this module at", - "enum": [ - "bottom", - "top" - ] - }, - "templates": { - "type": "object", - "description": "Templates to be loaded for client-side usage" + { + "description": "An arbitrary ResourceLoaderModule definition", + "properties": { + "class": { + "type": "string", + "pattern": "^((?!ResourceLoader(File|Image)Module).)*$" + } + }, + "required": ["class"] } - } + ] } } },