Last modified: 2011-06-26 13:39:09 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 T31584, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 29584 - Extend mw.loader.load to accept wiki pagenames
Extend mw.loader.load to accept wiki pagenames
Status: RESOLVED WONTFIX
Product: MediaWiki
Classification: Unclassified
JavaScript (Other open bugs)
1.20.x
All All
: Normal enhancement (vote)
: ---
Assigned To: Nobody - You can work on this!
: patch, patch-need-review
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2011-06-25 15:56 UTC by Erwin Dokter
Modified: 2011-06-26 13:39 UTC (History)
3 users (show)

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


Attachments
Patch for mediawiki.js (1.60 KB, patch)
2011-06-25 15:57 UTC, Erwin Dokter
Details
Patch for mediawiki.js (1.62 KB, application/octet-stream)
2011-06-26 01:24 UTC, Erwin Dokter
Details
Patch for mediawiki.js (1.62 KB, patch)
2011-06-26 01:26 UTC, Erwin Dokter
Details

Description Erwin Dokter 2011-06-25 15:56:53 UTC
I extended the mw.loader.load function to automatically detect internal links, for example "User:Edokter/MenuToTabs.js", as a substitute for importScript and importStylesheet. It does so by examining the extension first to see if it is an URL or a module. It then checks for "http://" or "https://" and builds a full link if is internal.

A possible improvement would be to use load.php directly instead of linking to index.php for internal links.

This patch works under the assumption that a module name never ends with ".css" or ".js". If that is not the case, then discard this patch. Another function would then have to be added.
Comment 1 Erwin Dokter 2011-06-25 15:57:45 UTC
Created attachment 8705 [details]
Patch for mediawiki.js
Comment 2 Erwin Dokter 2011-06-26 01:24:36 UTC
Created attachment 8706 [details]
Patch for mediawiki.js

Corrected error.
Comment 3 Erwin Dokter 2011-06-26 01:26:06 UTC
Created attachment 8707 [details]
Patch for mediawiki.js

Forgot to mark as patch.
Comment 4 Krinkle 2011-06-26 01:33:25 UTC
See also:
* bug 27561
* bug 27535

Support for loading loose wiki pages as scripts is not intended to not be added to ResourceLoader. The legacy functions importScript and importStylesheet provide this for existing scripts that don't use ResourceLoader yet.

Those wishing to switch to resourceloader should register themselfs as a module and load it through mw.loader.loader( 'modulename' ).

User created scripts (ie. not server side extensions) can registery modules through the Gadget interface by using the [ResourceLoader] keyword.

eg. MediaWiki:Gadgets-definition:
*foobar[ResourceLoader]|foobar.js|foobar.css

mw.loader.load( 'mw.ext.gadget.foobar' );

-

In ResourcerLoader 2.0 (MediaWiki 1.19 or 1.20) this will be further developed into an easy-to-use Special:GadgetManager in which modules can be created with more options and configuration. As well as cross-wiki gadgets.
Comment 5 Erwin Dokter 2011-06-26 02:54:00 UTC
Yes, I realize my method would load the script raw. I was concerned we would have no replacement for importScript before it is too late.

I will study the resourceloader and how to register modules. Ultimately, and as other bugs have suggested, the format of 'mw.loader.load("User:Edokter/MenuToTabs.js");' should be the goal.

I'll reopen this bug once I have a solution.
Comment 6 Krinkle 2011-06-26 03:04:30 UTC
I disagree the format of mw.loader.load("User:Edokter/MenuToTabs.js"); should be a goal.

It encourages users to harcode script references (be it filepaths, urls or wiki pagenames) which makes maintenance a nightmare. It also doesn't motivate or make it easy for users to:
* centralize
* share (rather than copy)
* translate
* modulize (ie. Foo:Bar/core.js, Foo:Bar/lorem.js, Foo:Bar/pluginBaz.js )
* etc.

The solution is to use modules which may or may not be loaded from a wiki page. Currently (MediaWiki 1.17) they can be created as a gadget by sysops (or anyone with access to MediaWiki:-namespace) and three of the most important module-features (minification, combination of scripts/styles and dependancies) are already supported.

In ResourceLoader 2.0 these will be editable by anyone with the editgadget (or whatever the name will be) userright (not just sysops, or perhaps not sysops at all and/or people like you) from the Special:GadgetManager page.

At that point support for the other module-features such as messages (for localizaton) will be implemented as well.
Comment 7 Erwin Dokter 2011-06-26 13:39:09 UTC
I'm still not sure where that leaves the literally *thousands* of userscripts on wikipedia. Are they all going to be converted to gadgets? Does everyone get some sort of personal gadget control panel? Are stand-alone userscripts going to be banned?

Sorry to aks so many questions, but it does help to understand how this framework is envisioned, and the documentation isn't very helpfull in this respect.

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


Navigation
Links