Last modified: 2011-03-13 18:04: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 T12184, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 10184 - Extension stylesheets should be loaded before any others
Extension stylesheets should be loaded before any others
Status: RESOLVED WONTFIX
Product: MediaWiki
Classification: Unclassified
Parser (Other open bugs)
unspecified
All All
: Lowest trivial with 2 votes (vote)
: ---
Assigned To: Nobody - You can work on this!
: easy
: 12461 (view as bug list)
Depends on:
Blocks: css
  Show dependency treegraph
 
Reported: 2007-06-07 11:51 UTC by Danny B.
Modified: 2011-03-13 18:04 UTC (History)
11 users (show)

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


Attachments
patch for Monobook.php r27436 to put head scripts before site js (1.10 KB, patch)
2007-12-07 16:52 UTC, darklama
Details

Description Danny B. 2007-06-07 11:51:06 UTC
Styles are currently loaded in improper order, where user's style is not loaded as last (concretely eg. GeSHi syntax highlight styles are loaded after).

The proper order should be:

Built-in styles (such as /skins/.../main.css)
MediaWiki:Common.css
MediaWiki:Skin.css
MediaWiki:Extension(s).css (such as syntax highlighting etc.)
User:Common.css (see bug 10183 for details)
User:Skin.css
Comment 1 Daniel Kinzler 2007-06-07 13:56:35 UTC
I think extension stylesheets should also be loaded before site-wide styles like MediaWiki:Common.css and MediaWiki:*Skin*.css, because it would be useful to be able to override them site-wide.
Comment 2 Aryeh Gregor (not reading bugmail, please e-mail directly) 2007-06-07 23:47:52 UTC
Yes, there's no reason whatsoever for anything built in the software to load before customizations.  Specifically, it should follow the order

* CSS and JS in core MediaWiki
* CSS and JS in extensions
* Site-specific CSS and JS
* User-specific CSS and JS

I'd be inclined to just move everything around to fit this.  Since none of the higher rungs on that ladder should even know about the lower ones, for the most part, I find it unlikely that anything bad will happen.  So concretely, for Monobook it would look like

1) Global JS variables (moved from above wikibits)
2) Core files:
 a) main.css
 b) commonPrint.css
 c) handheld.css
 d) IE fixes
 e) wikibits.js
3) Extension files (moved from bottom!)
4) Site files:
 a) CSS files (moved above site JS)
 b) JS files
5) User files:
 a) CSS files
 b) JS files
 c) JS preview

Whereas now it looks like

1) Core files/global JS:
 a) main.css
 b) commonPrint.css
 c) handheld.css
 d) IE fixes
 e) global JS variables
 f) wikibits.js
2) Site files:
 a) JS files
 b) CSS files
3) User files:
 a) CSS files
 b) JS files
 c) JS preview
4) Extension files

So global JS variables moved above the CSS and IE fixes and site JS/CSS order swapped for consistency, neither of which make any difference.  But extension files get moved up, which is the main point.  Any objections?
Comment 3 Danny B. 2007-06-08 00:10:16 UTC
I'd also suggest including of extension CSS files always via

either

<link href="..." />

or

<style>
@import ...
</style>

but never directly like

<style>
selector {
  property: value;
  property: value;
}
...
</style>
Comment 4 Aryeh Gregor (not reading bugmail, please e-mail directly) 2007-06-08 00:21:53 UTC
That's unrelated.  Please create a specific bug for the extension in question if you have an issue with it.
Comment 5 Aryeh Gregor (not reading bugmail, please e-mail directly) 2007-06-29 06:02:19 UTC
Fixed in r23541.
Comment 6 Brion Vibber 2007-06-29 14:14:18 UTC
Reverted as this breaks AJAX watch and god knows what else.
Comment 7 Andrew Whitworth 2007-09-27 16:21:38 UTC
What's the status of this bug? Is there another way to fix this issue without breaking the AJAX watch? instead of moving the extension JS/CSS code up, would it be possible to move the User JS/CSS code *down*? Small difference, i suppose. 

Some of the GeSHi colors conflict with my skin's background color. As a temporary fix, i'm loading an additional stylesheet after the onLoad event to alter the colors. It would seem a waste if many people started doing a hack-job like this just to modify the syntax highlighting.
Comment 8 darklama 2007-12-07 16:52:21 UTC
Created attachment 4416 [details]
patch for Monobook.php r27436 to put head scripts before site js

Looking at r23541, I noticed why it breaks AJAX watch and other things. It was slightly misplaced inside an "if condition" that it shouldn't of been placed inside. Wanting to see this fixed myself, I've made attached a patch against [http://svn.wikimedia.org/viewvc/mediawiki?view=rev&revision=﷒2r27436] do put it outside the if condition.
Comment 9 Andrew Whitworth 2007-12-09 23:43:39 UTC
i've looked over this patch, it appears to be a simple reordering of the previous patch, and it also appears to not break the AJAX watch feature. Of course, this is only on my local test wiki. Can somebody please take a look at this again?
Comment 10 Aryeh Gregor (not reading bugmail, please e-mail directly) 2007-12-11 04:29:50 UTC
(In reply to comment #6)
> Reverted as this breaks AJAX watch and god knows what else.

Possibly because, as darkcode on IRC points out, I moved the head scripts up inside a conditional, which was quite possibly returning false.
Comment 11 Aryeh Gregor (not reading bugmail, please e-mail directly) 2007-12-13 23:36:09 UTC
Fixed in r28455.
Comment 12 Daniel Schwen 2008-01-05 22:45:42 UTC
I'm not convinced that the current JS loading order is good the way it is. It would be helpful, if the Mediawiki:Common.js contents were loaded _before_ the extension JS. Common.js defines common JS functions to be used by other scripts on the site. Specifically when the "Gadgets"-Extension is used the gadget-scripts are currently loaded before common.js and cannot use its functionality. 
Comment 13 Daniel Kinzler 2008-01-06 01:03:44 UTC
With regards to the Gadgets extension, I agree with #12: loading extension JS before commons.js introduces new problems, namely, that gadgets can not use functionality defined globally in common.js. Several scripts where broken by this change. The old order was bad, too, because loading extension's JS last means it can not be overwritten by per-user settings.

What we really need is a way for extensions to control the load order. Perhaps we could introduce numbered slots into the addScript function? The point is that most extensions just have static JS and CSS code, which should be loaded before commons.js etc so it can be overwritten and customized. But extensions like Gadgets load *custom* JS code - and should be loaded after common.js, but before user js. There are probably special cases that would need a still different load order. So a more flexible system is really called for.
Comment 14 Aryeh Gregor (not reading bugmail, please e-mail directly) 2008-01-06 04:08:44 UTC
Yeah, I was assuming extensions were injecting static code, not user-defined site-wide code.  We should have an extra insertion point after site-wide core stuff, for site-wide customizable extension stuff.
Comment 15 Michael Daly 2008-01-06 06:51:37 UTC
> What we really need is a way for extensions to control the load order.

That opens up the possibility that two extensions will generate conflicting sequences.  It would be better to simply force an order and oblige the extensions to fit into their slot(s).  "Common then extensions then user" seems reasonable.  However, it may be worthwhile to have "Common 1 then extensions then common 2 then user" to allow the extensions to have both a before and an after common set of functions - this, of course, increases complexity and requires a new common page; unless there is a clear need, this should not be used.
Comment 16 Aryeh Gregor (not reading bugmail, please e-mail directly) 2008-01-06 18:32:32 UTC
(In reply to comment #15)
> > What we really need is a way for extensions to control the load order.
> 
> That opens up the possibility that two extensions will generate conflicting
> sequences.

The load order for their *own* head items, obviously, not the load order for *all* extensions' head items.
Comment 17 darklama 2008-01-06 19:43:27 UTC
In general I think its a good idea for extensions to not rely on site-wide js code. However
short of allowing extensions decide what order they would like to be loaded in, it might be
a good idea to allow both a before page and an after page, because extensions can benefit
from both. Extensions like Gadgets can benefit from common routines that can be used in
other pages and from common settings that can be overridden site-wide after extension's
default settings are loaded.

One possibility might be to add MediaWiki:Extensions.js or something similar that is loaded
before extensions on pages that load an extension's js. Another possibility might be to
include MediaWiki:Common.js twice, once before and once after, however I am not sure if that
would work at all, or if it would work with all browsers. If it were to work with all browsers
I think that would probably be the best option as browsers could cache the first request
without needing to make a second request and there would be no need to add another MediaWiki
page.
Comment 18 Aryeh Gregor (not reading bugmail, please e-mail directly) 2008-01-06 20:58:10 UTC
This isn't a difficult problem.  Add a HeadScriptsBeforeSiteFiles hook and allow extensions to add stuff there as well as wherever they currently add it.  Someone just has to do it.
Comment 19 darklama 2008-01-06 21:40:38 UTC
(In reply to comment #18)
> This isn't a difficult problem.  Add a HeadScriptsBeforeSiteFiles hook and
> allow extensions to add stuff there as well as wherever they currently add it. 
> Someone just has to do it.

In the current setup, extension files are added before site files, so this
isn't a problem. I suppose a third option I hadn't thought of with the current
setup is that the Gadgets extension could be changed to include a new page such
as MediaWiki:Gadgets-common.js that is always loaded before any gadgets. Which
would allow for gadgets to share some common functions like before, while
allowing extensions to benefit from the site-wide js coming after there default
settings as it is now. So maybe close this bug again and get the Gadgets
extension patched instead?
Comment 20 Aryeh Gregor (not reading bugmail, please e-mail directly) 2008-01-06 21:44:22 UTC
(In reply to comment #19)
> (In reply to comment #18)
> > This isn't a difficult problem.  Add a HeadScriptsBeforeSiteFiles hook and
> > allow extensions to add stuff there as well as wherever they currently add it. 
> > Someone just has to do it.
> 
> In the current setup, extension files are added before site files, so this
> isn't a problem.

It is if the extension wants to access the site files.  That's the point.

> I suppose a third option I hadn't thought of with the current
> setup is that the Gadgets extension could be changed to include a new page such
> as MediaWiki:Gadgets-common.js that is always loaded before any gadgets. Which
> would allow for gadgets to share some common functions like before, while
> allowing extensions to benefit from the site-wide js coming after there default
> settings as it is now. So maybe close this bug again and get the Gadgets
> extension patched instead?

No.  There's no good reason to maintain multiple admin-modifiable CSS or JS files that all get loaded on every page view for everyone.  We only need one of each.  The need for [[MediaWiki:Geshi.css]] is what spawned this whole bug report, actually.
Comment 21 Brion Vibber 2008-01-07 18:40:49 UTC
CSS styles need to be loaded in a predictable order because this controls what overrides what. Eg, a user's custom styles should override the site's custom styles, which override an extension's styles, which override the default skin styles.


For JS, though things should be different. Immediately-executed JS should be mostly limited to function definitions, variable definitions, and some event hooking.

Nothing should really be *running* until all scripts are loaded, so there shouldn't be much issue of functions not yet being defined.
Comment 22 Aryeh Gregor (not reading bugmail, please e-mail directly) 2008-01-07 18:47:34 UTC
In principle . . .
Comment 23 Aryeh Gregor (not reading bugmail, please e-mail directly) 2008-01-07 18:49:33 UTC
. . . hmm, yeah.  Since you point it out, just tell the users to make sure their gadgets are clean.  Is there any reason any given piece of JS has to be loaded in a particular order?  If not, may as well reclose.  Any objections?
Comment 24 darklama 2008-01-07 19:24:38 UTC
(In reply to comment #23)
> . . . hmm, yeah.  Since you point it out, just tell the users to make sure
> their gadgets are clean.  Is there any reason any given piece of JS has to be
> loaded in a particular order?  If not, may as well reclose.  Any objections?

No objections here. I think the loading of additional styles and scripts could
be considered one case in which functions might be called outside a load event.
Another is calling a function to unload events loaded through addOnloadHook.
These cases would be fixed though by adding functions to do these things to
wikibits.js.
Comment 25 AlexSm 2008-01-07 19:33:35 UTC
>Nothing should really be *running* until all scripts are loaded, so 
>there shouldn't be much issue of functions not yet being defined.

Mostly true, except for importScript() function. Right now each gaget has to define it again.
Comment 26 Daniel Schwen 2008-01-07 19:37:12 UTC
Well, as the reopener I do have an objection. The reason I reopened is a Javascript configuration framework which is deployed on commons.wikimedia.org
It allows user scripts and gadgets to define configuration options (assign default values), automatically creates widgets on the preference page to configure values and  stores (and recalls) values to/from cookies completely transparent to user and script programmer. 
Currently new configuration options are declared before the addOnLoadEvent is hooked, this allows the config framework to retrieve stored config values from cookies before the user script accesses them. 
With the current load order there is no way to keep the current clean interface. 
A second JS insertion hook (after common.js) seems to be a very small price to pay for that functionality.
Comment 27 Brion Vibber 2008-01-09 00:32:41 UTC
That sounds like something which should be integrated upstream, not done as a site customization.
Comment 28 Daniel Arnold 2008-01-14 01:36:31 UTC
For the same reasons as Dschwen (Gadgets extension) I really need another load order of Javascripts. Furthermore in MediaWiki:Common.js there are often useful functions that help you making your own Javascript (loaded as Gadget) shorter. So the proposed order of the initial comment is the best one and it is needed *desperately* (and you can acutally do it without brakeing anything - even the contrary some things might even start to work for the first time ;-). So can someone please fix this upstream?
Comment 29 Aryeh Gregor (not reading bugmail, please e-mail directly) 2008-01-14 02:44:22 UTC
Why isn't the tactic suggested by comment 21 sufficient?  If your JavaScript inclusion consists only of function definitions, and the functions are run at page load time, why can't you define your own functions, and use the Common.js functions safe in the knowledge that they'll be loaded before the function is executed?

This might still be useful for CSS at the very least, and I guess for JavaScript as well if people don't adhere to the function-definitions-only system.  It's fairly trivial, someone just needs to bother to write up a patch.
Comment 30 Aryeh Gregor (not reading bugmail, please e-mail directly) 2008-01-18 20:56:54 UTC
*** Bug 12461 has been marked as a duplicate of this bug. ***
Comment 31 Platonides 2008-01-23 18:16:28 UTC
The JavaScript inclusion does other things other than JavaScript inclusion. A good example of it is commons:MediaWiki:Gadget-QuickDelete.js which used a variable defined on Common.js, conditionally including subscripts, using the includePage() defined on Common.js (this should be moved to wikibits.js)
Or as i found today, adding "malicious links" (which eg. would make me delete a page if i followed) before my user script checked for its existance.

Either Common.js is loaded before the extensions js, or extensions can choose where to be added.
Comment 32 Aaron Schulz 2008-09-05 03:15:21 UTC
They should be loaded after the other site css but before custom MediaWiki:/user css. There is an addExtenstionStyle() function for this.

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


Navigation
Links