add DOM friendly importScript and importStylesheet functions into wikibits.js
Closed, ResolvedPublic


Author: herd

tab-indented plaintext of proposed functions, per

Per discussions on mediawiki javascript bloat, and dom-safe script/style functions in common use on the major wikis, users in #mediawiki-scripts have written some browser-safe import*() functions for CSS and JS, which could be added to wikibits.js, and replace many instances of document.write()(which can be buggy in safari and other browsers) as well as give script writers more options to optionally include libraries.

This proposed version (5 functions with little redundancy, importScript(), importScriptURI(), importStylesheet(), importStylesheetURI(), and appendCSS() -- see attachment, sorry it isn't a patch) maintain full backward compatabilty with existing copies of importScript() and importStylesheet() (as used on the English Wikipedia), and fix a few bugs in IE and Safari as well. They have been tested on the following browsers:

  • Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.5a) Gecko/20030728 Mozilla Firebird/0.6.1 (Windows 98)
  • Mozilla/5.0 (X11; U; Linux i686; en-US; rv: Gecko/20080207 Ubuntu/7.10 (gutsy) Firefox/ (Linux)
  • Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9b3pre) Gecko/2008020507 Firefox/3.0b3pre (Linux)
  • Mozilla/5.0 (X11; U; Linux i686; en-US; rv: Gecko/20071128 Iceweasel/ (Debian- (Linux)
  • Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv: Gecko/20080201 Firefox/ (Windows XP)
  • Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; InfoPath.2) (Windows XP)
  • Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Maxthon; .NET CLR 1.0.3705; .NET CLR 1.1.4322; rm ; .NET CLR 2.0.50727) (Win XP)
  • Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-us) AppleWebKit/523.15.1 (KHTML, like Gecko) Version/3.0.4 Safari/523.15
  • Opera/9.10 (Macintosh; Intel Mac OS X; U; en)
  • Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv: Gecko/20080201 Firefox/
  • Opera/8.5 (Macintosh; Intel Mac OS X; U; en)

The functions should be added near the top, but probably below function addOnloadHook() and function hookEvent().

The current attachment version is from (which differs from the tested version only in function names and appearance).

Version: unspecified
Severity: enhancement

Attached: wikibits_import_functions.txt

bzimport added a project: MediaWiki-Interface.Via ConduitNov 21 2014, 10:06 PM
bzimport added a subscriber: wikibugs-l.
bzimport set Reference to bz13232.
bzimport created this task.Via LegacyMar 3 2008, 7:23 AM
bzimport added a comment.Via ConduitMar 4 2008, 1:14 AM

skizzerz wrote:

patch of changes against current trunk

added patch of the diff between current trunk and Splarka's modifications as per Splarka's request on IRC

attachment diff.patch ignored as obsolete

bzimport added a comment.Via ConduitMar 5 2008, 3:45 AM

herd wrote:

Note: patch 4691 also resolves

TheDJ added a comment.Via ConduitMar 5 2008, 2:46 PM

Created attachment 4696
Updated plaintext with new return statements. Taken from

This new plaintext version of the proposed functions adds a few return statements.

These can be useful in order to do things like:
var s=importScript('User:AzaToth/morebits.js');
s.onload = function loadRestOfTwinkle(){

And other changes or checks of the added DOM element.

Attached: import-raw.txt

bzimport added a comment.Via ConduitMar 6 2008, 3:51 AM

skizzerz wrote:

re-diffed against current trunk with updates

attachment diff2.patch ignored as obsolete

bzimport added a comment.Via ConduitMar 6 2008, 8:47 AM

herd wrote:

(In reply to comment #4)

Created an attachment (id=4697) [details]
re-diffed against current trunk with updates

Oops, 4697 has an extranuous semicolon in it, I probably sent the wrong file to Ryan.
+ onloadFuncts[onloadFuncts.length]; = hookFunct;
should be
+ onloadFuncts[onloadFuncts.length] = hookFunct;

Also, only the original patch was tested against all the listed browsers, the feature creeping may get to the point of invalidating those tests somewhat.

Also, please send all future suggested changes as unified patches (or we'll make a mess, and #mediawiki-scripts will be laughed at).

TheDJ added a comment.Via ConduitMar 6 2008, 8:35 PM

Created attachment 4701
Updated diff. removed extraneous semicolon and ^M chars

Attached: import_diff.patch

bzimport added a comment.Via ConduitMar 13 2008, 9:55 AM

hippytrail wrote:

If a script requires JavaScript 1.7 or 1.8 this needs to be declared in the <script> tag.

To make this possible importScript needs an optional JavaScript version parameter.

TheDJ added a comment.Via ConduitMar 25 2008, 1:31 PM

We discussed this a bit in #mediawiki-scripts

We currently do not see the need to add this. 1.7 and 1.8 features are hardly used. If someone does need it, we can add it easily enough at a later time.

brion added a comment.Via ConduitMay 19 2008, 10:52 PM

Looks pretty sweet. :D Applied in r35064

matmarex added a project: JavaScript.Via WebDec 21 2014, 7:07 PM

Add Comment

Column Prototype
This is a very early prototype of a persistent column. It is not expected to work yet, and leaving it open will activate other new features which will break things. Press "\" (backslash) on your keyboard to close it now.