Last modified: 2008-05-19 22:52:31 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T15232, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 13232 - add DOM friendly importScript and importStylesheet functions into wikibits.js
add DOM friendly importScript and importStylesheet functions into wikibits.js
Status: RESOLVED FIXED
Product: MediaWiki
Classification: Unclassified
Interface (Other open bugs)
unspecified
All All
: Normal enhancement with 1 vote (vote)
: ---
Assigned To: Nobody - You can work on this!
: patch, patch-need-review
Depends on: 12773
Blocks: javascript
  Show dependency treegraph
 
Reported: 2008-03-03 07:23 UTC by Splarka
Modified: 2008-05-19 22:52 UTC (History)
5 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments
tab-indented plaintext of proposed functions, per http://test.wikipedia.org/w/index.php?title=MediaWiki_talk:Common.js&oldid=39798 (1.11 KB, text/plain)
2008-03-03 07:23 UTC, Splarka
Details
patch of changes against current trunk (1.76 KB, patch)
2008-03-04 01:14 UTC, Ryan Schmidt
Details
Updated plaintext with new return statements. Taken from http://test.wikipedia.org/w/index.php?title=MediaWiki:Common.js&oldid=40963 (1.14 KB, text/plain)
2008-03-05 14:46 UTC, Derk-Jan Hartman
Details
re-diffed against current trunk with updates (1.83 KB, patch)
2008-03-06 03:51 UTC, Ryan Schmidt
Details
Updated diff. removed extraneous semicolon and ^M chars (1.82 KB, patch)
2008-03-06 20:35 UTC, Derk-Jan Hartman
Details

Description Splarka 2008-03-03 07:23:21 UTC
Created attachment 4689 [details]
tab-indented plaintext of proposed functions, per http://test.wikipedia.org/w/index.php?title=MediaWiki_talk:Common.js&oldid=39798

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:1.8.1.12) Gecko/20080207 Ubuntu/7.10 (gutsy) Firefox/2.0.0.12 (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:1.8.1.11) Gecko/20071128 Iceweasel/2.0.0.11 (Debian-2.0.0.11-1) (Linux)
* Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.8.1.12) Gecko/20080201 Firefox/2.0.0.12 (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:1.8.1.12) Gecko/20080201 Firefox/2.0.0.12
* 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 http://test.wikipedia.org/w/index.php?title=MediaWiki_talk:Common.js&oldid=39798 (which differs from the tested version only in function names and appearance).
Comment 1 Ryan Schmidt 2008-03-04 01:14:48 UTC
Created attachment 4691 [details]
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
Comment 2 Splarka 2008-03-05 03:45:49 UTC
Note: patch 4691 also resolves https://bugzilla.wikimedia.org/show_bug.cgi?id=12773
Comment 3 Derk-Jan Hartman 2008-03-05 14:46:45 UTC
Created attachment 4696 [details]
Updated plaintext with new return statements. Taken from http://test.wikipedia.org/w/index.php?title=MediaWiki:Common.js&oldid=40963

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.
Comment 4 Ryan Schmidt 2008-03-06 03:51:12 UTC
Created attachment 4697 [details]
re-diffed against current trunk with updates
Comment 5 Splarka 2008-03-06 08:47:03 UTC
(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).
Comment 6 Derk-Jan Hartman 2008-03-06 20:35:02 UTC
Created attachment 4701 [details]
Updated diff. removed extraneous semicolon and ^M chars
Comment 7 Andrew Dunbar 2008-03-13 09:55:04 UTC
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.
Comment 8 Derk-Jan Hartman 2008-03-25 13:31:33 UTC
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.
Comment 9 Brion Vibber 2008-05-19 22:52:31 UTC
Looks pretty sweet. :D Applied in r35064

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links