Last modified: 2012-03-10 22:06:20 UTC

Wikimedia Bugzilla is closed!

Wikimedia has migrated from Bugzilla to Phabricator. Bug reports should be created and updated in Wikimedia Phabricator instead. Please create an account in Phabricator and add your Bugzilla email address to it.
Wikimedia Bugzilla is read-only. If you try to edit or create any bug report in Bugzilla you will be shown an intentional error message.
In order to access the Phabricator task corresponding to a Bugzilla report, just remove "static-" from its URL.
You could still run searches in Bugzilla or access your list of votes but bug reports will obviously not be up-to-date in Bugzilla.
Bug 25845 - Support loading wiki pages through mediaWiki.loader.load()
Support loading wiki pages through mediaWiki.loader.load()
Status: RESOLVED WONTFIX
Product: MediaWiki
Classification: Unclassified
ResourceLoader (Other open bugs)
1.17.x
All All
: Normal enhancement with 2 votes (vote)
: ---
Assigned To: Nobody - You can work on this!
: javascript, patch, patch-need-review
: 27475 (view as bug list)
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2010-11-09 09:39 UTC by Michael M.
Modified: 2012-03-10 22:06 UTC (History)
10 users (show)

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


Attachments
Proposed patch (1.76 KB, patch)
2010-12-08 08:29 UTC, Michael M.
Details

Description Michael M. 2010-11-09 09:39:36 UTC
According to http://www.mediawiki.org/wiki/ResourceLoader/JavaScript_Deprecations#wikibits.js importScript should be replaced by mediaWiki.loader.load in the future, but at the moment it's not a good substitute. If you want a script to be loaded both via http or https depending you have to replace
  importScript('User:Foo/bar.js');
by
  mediaWiki.loader.load(mediaWiki.config.get('wgServer') + mediaWiki.config.get('wgScript') + '?title=User:Foo/bar.js&action=raw&ctype=text/javascript');

Another user suggested the syntax
  mediaWiki.loader.load('[[User:Foo/bar.js]]');

This has two advantages: It doesn't conflict with names of modules and it generates an entry in "What links here".
Comment 1 Michael M. 2010-12-08 08:29:20 UTC
Created attachment 7897 [details]
Proposed patch

I added a patch by [[User:PerfektesChaos]].
Comment 2 Helder 2011-02-17 09:39:38 UTC
*** Bug 27475 has been marked as a duplicate of this bug. ***
Comment 3 Helder 2011-02-17 09:42:15 UTC
(In reply to comment #0)
> Another user suggested the syntax
>   mediaWiki.loader.load('[[User:Foo/bar.js]]');
> 
> This has two advantages: It doesn't conflict with names of modules and it
> generates an entry in "What links here".

I would support this syntax, because of the second advantage.
Comment 4 Woojin Kim 2011-02-17 14:55:22 UTC
(In reply to comment #0)
> According to
> http://www.mediawiki.org/wiki/ResourceLoader/JavaScript_Deprecations#wikibits.js
> importScript should be replaced by mediaWiki.loader.load in the future, but at
> the moment it's not a good substitute. If you want a script to be loaded both
> via http or https depending you have to replace
>   importScript('User:Foo/bar.js');
> by
>   mediaWiki.loader.load(mediaWiki.config.get('wgServer') +
> mediaWiki.config.get('wgScript') +
> '?title=User:Foo/bar.js&action=raw&ctype=text/javascript');
> 
> Another user suggested the syntax
>   mediaWiki.loader.load('[[User:Foo/bar.js]]');
> 
> This has two advantages: It doesn't conflict with names of modules and it
> generates an entry in "What links here".

No brackets please. If there is any bracket, we may be in need of lines of script for eliminating brackets. I think distinguishment with former importScriptURI can be done by protocol. Best regards.
Comment 5 Michael Dale 2011-02-17 15:18:14 UTC
[[PageToImport]] could work or they could be namespaced somehow. The important part is they have a way to transition into normal named modules. The patch is a good start. 

A followup patch should have the page assets loaded through the resource loader, so you can load multiple pages in a single request, they get minified when not in debug mode, and [[myPage.css]] has auto LTR css transforms / optimizations etc. 

Also would be nice to support a simple interface or SpecialPage for defining what page resources ( and associated messages / dependencies for thous resources ) are globally used on a given wiki, this way their versions numbers can be included in the start-up module definitions. This would probably fit best within the "gadgets" extension and expand the gadgets concept to include "on-by-default" gadgets.
Comment 6 Helder 2011-02-17 15:34:30 UTC
(In reply to comment #5)
[snip]
> This would probably fit
> best within the "gadgets" extension and expand the gadgets concept to include
> "on-by-default" gadgets.
About this, see Bug 13742.
Comment 7 aokomoriuta 2011-02-17 18:10:53 UTC
How about using different method name from "load"?
For example:
* mw.loader.loadScript(page), same as importScript(page) does 
* mw.loader.loadStyleSheet(page) same as importStyleSheet(page) does
Comment 8 Michael Dale 2011-02-17 18:19:29 UTC
The problem with a different method is that you move the page loads out of the resource loader loading system. This may be fine for individual page loads and prototyping... For obvious reasons we should have user-space javascript loading through the resource loader.
Comment 9 aokomoriuta 2011-02-17 18:34:36 UTC
(In reply to comment #8)
> The problem with a different method is that you move the page loads out of the
> resource loader loading system. This may be fine for individual page loads and
> prototyping... For obvious reasons we should have user-space javascript loading
> through the resource loader.

Forgive me, let me make comment #7 clear.

mw.loader.loadScript converts given pagename to URL and uses mw.loader.load internally.
It's just to make a helper method, not to rename.

Or must we use mw.loader.load directly otherwise the page loads get moved?
Comment 10 Roan Kattouw 2011-02-18 17:30:09 UTC
*** Bug 27535 has been marked as a duplicate of this bug. ***
Comment 11 Roan Kattouw 2011-02-19 13:27:32 UTC
(In reply to comment #10)
> *** Bug 27535 has been marked as a duplicate of this bug. ***
And unduped. bug 27535 requests a broader feature where wiki pages are and/or user scripts are treated as fully-fledged modules.
Comment 12 Krinkle 2011-02-19 15:32:33 UTC
mw.loader.load either loads modules (combined/minified/localized) or external links (seperate, unmodified).

I think adding support to load wiki-pages as external links is a bad idea and ineffecient as well (since they'd be all seperate and unminified). Instead they should be loaded as modules:

ie. mw.loader.load( ['gadget.Foobar', 'user.Foo.bar'] );

Support to allow normal wiki pages (other then MediaWiki:Common.js and User:name/vector.js etc.) to be part of a module is bug 27535.

Support to register them from JavaScript as well is bug 27561.

Proposing to close this bug as WONTFIX.
Comment 13 Ryan Kaldari 2011-04-13 01:58:50 UTC
Reply to Comment #12:
Requiring the user to register user scripts as modules seems a bit onerous to me. I think we should keep this simple for end users. Otherwise, they are going to keep using importScript for the rest of time.

Couldn't we just detect for a parameter of type /(.*)\:(.*)\.(js|css)/i
and either convert it into an external link or construct a module on behalf of the user?

Then people could easily migrate...
importScript('User:Foo/bar.js');
...to...
mediaWiki.loader.load('User:Foo/bar.js');
Comment 14 Krinkle 2011-04-13 15:09:24 UTC
(In reply to comment #13)
> Reply to Comment #12:
> Requiring the user to register user scripts as modules seems a bit onerous to
> me. I think we should keep this simple for end users. Otherwise, they are going
> to keep using importScript for the rest of time.
> 
> Couldn't we just detect for a parameter of type /(.*)\:(.*)\.(js|css)/i
> and either convert it into an external link or construct a module on behalf of
> the user?
> 
> Then people could easily migrate...
> importScript('User:Foo/bar.js');
> ...to...
> mediaWiki.loader.load('User:Foo/bar.js');

I couldn't agree more that such a short cut would be ideal, and in fact I believe it should be implemented. However in should not do what mw.legacy.importScript did (loading index.php&title=..&action=raw). Instead it would register/load the module on-demand.

ie. load.php?wikiscripts=User:Foo/bar.js&wikistyles=User:Foo/bar.css|MediaWiki:VectorAltenative.css (or just &wikipages=).

It doesn't even depend on bug bug 27561 being fixed. See also comments on bug 27535.
Comment 15 Bugmeister Bot 2011-08-19 19:12:55 UTC
Unassigning default assignments. http://article.gmane.org/gmane.science.linguistics.wikipedia.technical/54734
Comment 16 Sumana Harihareswara 2011-11-10 02:07:21 UTC
Michael M., thanks for submitting the patch.  Adding the need-review keyword since it seems to me the patch hasn't quite been reviewed -- if you feel you and the author have gotten sufficient feedback, feel free to replace "need-review" with "reviewed".  Thanks.
Comment 17 Helder 2012-01-24 19:34:56 UTC
There should be some way to import a minified version of [[MediaWiki:SomePage.js]] or [[User:AnotherPage.js]], and importScript currently doesn't do that. I don't know which bug needs to be fixed in order to have this functionality (bug 27561? bug 27535?).

I believe such a feature is necessary if we want to avoid loading the full code of a script in the case of certain conditions are met. For example, if we create a long script which we want to be loaded only on [[ThisPage]], it seems desirable to be able to create a loader script with something like this:
----
if ( mw.config.get( 'wgPageName') === 'ThisPage' ) {
    importMinifiedScript( 'FromAnotherPage.js' );
}
----

Then, the JavaScript 'FromAnotherPage.js' wouldn't be loaded unless it is needed.

See also [[mw:Thread:Talk:ResourceLoader/Migration guide (users)/Minifying central gadgets]].
Comment 18 Helder 2012-02-24 11:19:05 UTC
See also:
* Bug 27281 - Add support in the front-end for loading wiki pages as resources
Comment 19 Krinkle 2012-03-10 22:03:03 UTC
mw.loader.load has 2 purposes:
* On-demand loading of a module registered in ResourceLoader
* On-demand loading of a raw url

I think this is a solid system. And loading wiki pages is not a useful feature. Instead we should focus on implementing the ability for users to create their own complete ResourceLoader modules within their own space. Allowing raw loading of wiki pages (although minified) is barely any improvement over the current system and doesn't address any of the following issues, which have on the contrary been solved in ResourceLoader
* Proper caching
* Not loading the same content twice (using dependency lists of modules by a name instead of direct loading of a script page)
* Concatenation
* Translation
* RTL-support
* more..

The original request "Include the functionality of importScript into mediaWiki.loader.load" is in my opinion a WONTFIX. Until a proper solution exists, please use importScript() (or if you need a callback, use jQuery.getScript(url, callback).

The underlying need however is not a wontfix, but a valid need. Instead of addressing that by adding support for direct loading of a wiki page to mw.loader.load is bug 34958 (creation of ResourceLoader modules on a user level)

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


Navigation
Links