Fandom

Wikia Developers Wiki

CodeLoad

861pages on
this wiki
Add New Page
Talk29 Share

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.

Usage

  1. Add the line below to your wiki's MediaWiki:ImportJS page:
    dev:CodeLoad.js
  2. Code definitions have to be set up by the wiki's administrators. Configuration information is below.

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:

"ajaxrc": {
    "title": "AjaxRC",
    "description": "Advanced auto-refreshing recent changes and watchlist ([[w:c:dev:AjaxRC|more info]])",
    "group": "tools",
    "articles": [
        "dev:AjaxRC/code.js"
    ],
    "preferences": {
        "requiresGlobalPrefs": true,
        "AjaxRCRefreshText": "Auto-refresh",
        "ajaxRefresh": 30000
    }
}

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 wikis other than Dev Wiki, or from outside the local MediaWiki namespace, are not supported. Page names should not contain the MediaWiki namespace prefix, with the exception of CSS pages stored on Dev Wiki. 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 Skins (e.g. oasis, monobook) for which this definition can be used/shown, each separated by the | character
usergroups User groups (e.g. sysop, content-moderator, user) for which this definition can be used/shown, each separated by the | 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.

var prefs = codeLoad.getScriptPrefs('ajaxrc');
 
prefs.AjaxRCRefreshText;  // will return 'Auto-refresh'
prefs.ajaxRefresh;        // will return 30000

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.

window.AjaxRCRefreshText;  // will return 'Auto-refresh'
window.ajaxRefresh;        // will return 30000

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.

window.AjaxRCConfig.AjaxRCRefreshText;  // will return 'Auto-refresh'
window.AjaxRCConfig.ajaxRefresh;        // will return 30000

Start a Discussion Discussions about CodeLoad

  • CodeLoad - code page loader, similar to Gadgets

    9 messages
    • > <span style="font-size:14px;font-weight:normal;line-height:22px;">That API response doesn't look particularly fun...
    • Regarding the API: my concern isn't so mush having to parse the data, but having to parse the data every page load. Storing it on-w...

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.