CodeLoad

CodeLoad is a customisable code page loader. It lets communities set up a system for their users to enable provided code (JavaScript/CSS), in a similar way to the Gadgets extension. On a wiki using the script, user preferences can be configured on the page [ Special:BlankPage?blankspecial=CodeLoadPrefs]. A link to this page is added to the Shortcuts dialog and to the "My tools" menu in the toolbar.
== ==
== Configuring definitions ==
Definitions are loaded from the page MediaWiki:CodeLoad-definitions.js. Some example definitions are available, which may be copy+pasted as a base for a wiki's definition page.
These are configured via the JavaScript variable codeLoad.definitions, which should be an object with a unique ID (this can simply be the name of the script) for each key, and an object (the definition) as its value. Each definition object can contain the following keys:
Key 	Required?	Description
title 	No 	A friendly name for the definition (shown in bold on the preferences page). Wikitext links may be used here.
description 	Yes 	A description of what the definition does (shown after the definition title on the preferences page). Wikitext links may be used here.
group 	No 	Add this definition to a particular group on the preferences page (see below for details).
articles 	Yes 	An array of page names that should be imported when this definition is enabled (see below for details).
preferences 	No 	If a definition has user-configurable settings, these can be set/saved with CodeLoad (see below for details).
requirements	No 	Set pre-requisites before this definition is used/shown (see below for details).
Here is an example definition excerpt for AjaxRC:
=== Groups ===
Definitions can optionally be sorted into groups on the preferences page. These are configured via the JavaScript variable codeLoad.groups, which should be an object with a unique ID for each key, and a string (the friendly name for the group, shown as a heading on the preferences page) as its value. Wikitext links may be used within the friendly group names.
When a definition's group is set to a ID existing in codeLoad.groups, it will be added to that group. Any definition without a set group, or with a group ID not in codeLoad.groups, will be added to the group 'Other'.
=== Articles ===
The articles array should contain page names of one or more CSS (ending with .css) and/or JavaScript (ending with .js) pages. These can be either local pages (stored in the MediaWiki namespace), or pages from Dev Wiki. Imports from outside the MediaWiki namespace or from wikis other than the local wiki and Dev Wiki are not supported. Page names should not contain the MediaWiki namespace prefix. For imports from Dev Wiki, prefix the page name with dev:.
=== Preferences ===
Preferences (if set) should be an object, and can contain the following keys (all optional):
Key 	Description
enabled 	If this is set to true, the definition will be enabled by default. Note that it will also be enabled for logged-out users.
requiresGlobalPrefs	If this is set to true, user preferences for this definition will be each exposed as properties on the global window object. This allows CodeLoad to manage preferences for scripts which weren't specifically written for use with CodeLoad.
globalPrefNamespace	If preferences.requiresGlobalPrefs is set to true and this is set to a string, user preferences for this definition will be added to a single object (namespace), and only this object will be exposed as a property on the global window object, using the name given here. This may be needed for particular scripts.
The preferences object can also contain custom keys for that definition's preferences. A preference ID should be used for each key, and a boolean, number, or string (the default value for the preference) as its value.
Friendly names for preferences can be configured via the JavaScript variable codeLoad.prefDescriptions, which should be an object with a preference ID for each key, and a string (the friendly name for the preference) as its value. Wikitext links may be used within the friendly preference names. These are shared across all definitions, and if a friendly name is available, it will be used on the preferences page in place of the preference ID.
=== Requirements ===
Requirements (if set) should be an object, and can contain the following keys (all optional):
Key 	Description
skins 	character
usergroups	character
=== Intro message ===
A optional message can be configured via the JavaScript variable codeLoad.introMessage, and will be shown below the default intro text. This may be used, for example, to provide more information about the available definitions, or to provide a link to a page with more details. Wikitext links may be used within the message.
== Using CodeLoad-kept preferences ==
Preferences set/saved with CodeLoad can be accessed by calling the codeLoad.getScriptPrefs() function with a definition ID as the first argument. This is the recommended method for configuring local script preferences. Using the AjaxRC definition above as an example, the following code will set the prefs variable with the user preferences for the definition. User preferences can then be accessed via properties of the prefs variable.
=== requiresGlobalPrefs ===
If preferences.requiresGlobalPrefs is set to true for a definition, that definition's preferences will be each exposed as properties on the global window object. This is available to allow scripts from Dev Wiki to be easily configurable using CodeLoad. Using the AjaxRC definition above as an example, the following code accesses user preferences for the definition.
=== globalPrefNamespace ===
If preferences.requiresGlobalPrefs is set to true for a definition and preferences.globalPrefNamespace is set to a string (e.g. AjaxRCConfig), that definition's preferences will be added to a single object (namespace) with the name AjaxRCConfig, and only this object will be exposed as a property on the global window object. This may be needed for particular scripts, depending on how their preferences are configured within the script. Using the AjaxRC definition above as an example, the following code accesses user preferences for the definition.