Page MenuHomePhabricator

JavaScript tidbits - things to make custom JS easier
Closed, ResolvedPublic

Description

Here are a few things that would make it much easier to hook in custom JS code,
integrate external tools, etc. Most of it should be quite trivial to add.

Page specific stuff (should be set in a <script> tag in the html header):

  • page name, encoded (with namespace, not encoded, with blanks, as in

the visible page title)

  • page title (the same, without namespace)
  • page namespace (canonical name)
  • numeric page id (for external tools that have access to the database - like

things on the toolserver)

Perhaps a convenience function for encoding would be nice - like javascript's
encode, but with space-to-underscore.

In case of a redirect, the above should reflect the page that is actually shown.
Maybe the page that contains the redirect should be available too, not sure.

User specific stuff (could be set in a <script> tag in the html header, or
referenced there like the user js page; probably the latter, what with caching
and all):

  • user name (with whitespace - should be null or false for anons)
  • user lang (should also work for anons)
  • user skin (maybe - since js code is skin-specific already, this is not

really needed. But it may be nice to have anyway)

Hooks:

  • a onHtmlLoad (or similar) hook, analogous to onLoad, triggered near the end of

html output. There should be an addHtmlOnloadHook analogous to addOnloadHook as
defined in wikibits.js (there's also something in upload.js - not sure why)

Conveniance functions for injecting things would also be nice. Especially:

  • addTab for injecting a tab
  • addTool for injecting into the toolbox
  • maybe addPersonalTool for injecting into the personal toolbar (that has my

talk, preferences, etc)

Generally, it may be a good idea to introduce an MediaWiki:common.js page,
analogous to common.css


Version: 1.7.x
Severity: enhancement

Details

Reference
bz6806

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 21 2014, 9:21 PM
bzimport set Reference to bz6806.
bzimport added a subscriber: Unknown Object (MLST).

lupin.wp wrote:

partial patch

This patch resolves bug 6030 and the page-specific stuff from this bug.

Attached:

page and user variables added as of r15871, utility functions are pending.

I did not use the patch provided, because it added the variables after the
user and site JS had already been executed. It's more useful to have those
values from the very beginning.

As of r15883, onload hooks are called at the end if the html body, in all skins.
Utility functions for adding tabs, etc are pending. Note sure how to do this
consistently for all skins.

jlerner wrote:

Patch to add variables describing the page with the redirect can found at http://bugzilla.wikimedia.org/show_bug.cgi?id=11040.

All of these are done imo.
we got wgUserName etc.
And there's addPortletLink()
As well as a common.js (even a user one with r63300)