I've been doing some reading recently on the MediaWiki wiki about ResourceManager and how to use it to use JavaScript in MediaWiki extensions. Perhaps because it is new the documentation is not complete, or perhaps I just didn't quite understand the examples, but either way, I've been left quite confused.
Would anyone mind giving me a easier to follow example of how to properly make use of ResourceManager to use JavaScript in MediaWiki extensions?
I'm currently building a MediaWiki extension for the company I work for. This will make my third MediaWiki extension for them and my fourth or fifth overall.
Thank you,
Derric Atzrott
Computer Specialist
Alizee Pathology
On Fri, May 25, 2012 at 12:32 PM, Derric Atzrott datzrott@alizeepathology.com wrote:
I've been doing some reading recently on the MediaWiki wiki about ResourceManager and how to use it to use JavaScript in MediaWiki extensions. Perhaps because it is new the documentation is not complete, or perhaps I just didn't quite understand the examples, but either way, I've been left quite confused.
Could you tell us what you're confused about specifically? Just saying "I don't understand, please explain everything" is not very helpful. Also, if you've been searching for "ResourceManager", you may not have found the docs you were looking for, because the subsystem is called "ResourceLoader".
Would anyone mind giving me a easier to follow example of how to properly make use of ResourceManager to use JavaScript in MediaWiki extensions?
Have you read https://www.mediawiki.org/wiki/ResourceLoader/Migration_guide_for_extension_... ? Is there anything on that page that's confusing you?
Roan
Could you tell us what you're confused about specifically? Just saying "I
don't understand, please explain everything" is not very helpful.
Also, if you've been searching for "ResourceManager", you may not have
found the docs you were looking for, because the subsystem is called "ResourceLoader".
Sorry. You are right, I should have been more specific. The mistake with calling ResourceLoader ResourceManager was just me mistyping it.
Have you read
https://www.mediawiki.org/wiki/ResourceLoader/Migration_guide_for_extension_ developers
? Is there anything on that page that's confusing you?
I have read the Migration Guide for Extension Developers; I actually still have it open right now. It lead me to believe that if I were to do the following, I could expect to see some sort of result.
Add the following to the end of MasterPlanForm.php: http://pastebin.com/gwB8X2cj Create the following directory: /extensions/MasterPlanForm/js Create the following file: /extensions/MasterPlanForm/js/ext.MasterPlanForm.core.js Add the following to the newly created file: http://pastebin.com/kyiLiysJ
If I understand correctly, which it appears I do not, that should have changed the element with the ID " firstHeading" to "Test".
Sorry that I couldn't give a better explanation. As I said, I seem to have found myself rather confused.
Thank you, Derric Atzrott
On Fri, May 25, 2012 at 12:47 PM, Derric Atzrott datzrott@alizeepathology.com wrote:
I have read the Migration Guide for Extension Developers; I actually still have it open right now. It lead me to believe that if I were to do the following, I could expect to see some sort of result.
Add the following to the end of MasterPlanForm.php: http://pastebin.com/gwB8X2cj Create the following directory: /extensions/MasterPlanForm/js Create the following file: /extensions/MasterPlanForm/js/ext.MasterPlanForm.core.js Add the following to the newly created file: http://pastebin.com/kyiLiysJ
If I understand correctly, which it appears I do not, that should have changed the element with the ID " firstHeading" to "Test".
You created a module, but you didn't actually add it to the page anywhere. See https://www.mediawiki.org/wiki/ResourceLoader/Migration_guide_for_extension_... . Basically, you need a BeforePageDisplay hook that calls $out->addModules( 'ext.MasterPlanForm' ); .
Roan
Ah. That would do it. I had forgotten to mention this, but in SpecialMasterPlanForm.php I have a line "$wgOut->addModules( 'ext.MasterPlanForm.core');" but if I need put that in a BeforePageDisplay hook, that would explain it.
If I understand correctly then, removing the aforementioned line from SpecialMasterPlanForm.php and adding the following to MasterPlanForm.php should fix the issue: http://pastebin.com/Ajh3JJn8
Again my apologies for having a hard time with this. I usually have a much easier time understanding how to do things.
Thank you, Derric Atzrott
-----Original Message----- From: wikitech-l-bounces@lists.wikimedia.org [mailto:wikitech-l-bounces@lists.wikimedia.org] On Behalf Of Roan Kattouw Sent: 25 May 2012 16:00 To: Wikimedia developers Subject: Re: [Wikitech-l] ResourceManager and Javascript in Mediawiki
On Fri, May 25, 2012 at 12:47 PM, Derric Atzrott datzrott@alizeepathology.com wrote:
I have read the Migration Guide for Extension Developers; I actually still have it open right now. It lead me to believe that if I were to do the following, I could expect to see some sort of result.
Add the following to the end of MasterPlanForm.php: http://pastebin.com/gwB8X2cj Create the following directory: /extensions/MasterPlanForm/js Create the following file: /extensions/MasterPlanForm/js/ext.MasterPlanForm.core.js Add the following to the newly created file: http://pastebin.com/kyiLiysJ
If I understand correctly, which it appears I do not, that should have changed the element with the ID " firstHeading" to "Test".
You created a module, but you didn't actually add it to the page anywhere. See https://www.mediawiki.org/wiki/ResourceLoader/Migration_guide_for_extension_ developers#Adding_a_module_to_the_page . Basically, you need a BeforePageDisplay hook that calls $out->addModules( 'ext.MasterPlanForm' ); .
Roan
_______________________________________________ Wikitech-l mailing list Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l
On May 25, 2012 10:11 PM, "Derric Atzrott" datzrott@alizeepathology.com wrote:
Ah. That would do it. I had forgotten to mention this, but in SpecialMasterPlanForm.php I have a line "$wgOut->addModules( 'ext.MasterPlanForm.core');" but if I need put that in a BeforePageDisplay hook, that would explain it.
No, the way you did it is right, I didn't know you had a special page. If the module names match, then it should work: your JS should load, but only on the special page. Use alert() to test if your JS is running.
Roan
Hmmm.... does not appear to work for me. I added window.alert("Test"); to the JavaScript file to make sure.
The relevant sections of each file are listed out below. All of these sections are in sections of their respective files that are being executed.
SpecialMasterPlanForm.php: http://pastebin.com/qKmTUvYd MasterPlanForm.php: http://pastebin.com/GaqhP55g js/ext.MasterPlanForm.core.js: http://pastebin.com/sNcbrYRW
I imagine I'm likely missing something rather obvious. That usually seems to be the case in matters like these.
Also how does Mediawiki read these files? Does it make a request for them or does it directly read them off the disc. I'm wondering if I can use PHP to dynamically generate my JavaScript files at some point in the future (for now I'm just trying to get them executing even though).
Thank you, Derric Atzrott
-----Original Message----- From: wikitech-l-bounces@lists.wikimedia.org [mailto:wikitech-l-bounces@lists.wikimedia.org] On Behalf Of Roan Kattouw Sent: 25 May 2012 16:16 To: Wikimedia developers Subject: Re: [Wikitech-l] ResourceManager and Javascript in Mediawiki
On May 25, 2012 10:11 PM, "Derric Atzrott" datzrott@alizeepathology.com wrote:
Ah. That would do it. I had forgotten to mention this, but in SpecialMasterPlanForm.php I have a line "$wgOut->addModules( 'ext.MasterPlanForm.core');" but if I need put that in a BeforePageDisplay hook, that would explain it.
No, the way you did it is right, I didn't know you had a special page. If the module names match, then it should work: your JS should load, but only on the special page. Use alert() to test if your JS is running.
Roan _______________________________________________ Wikitech-l mailing list Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l
On May 25, 2012, at 10:37 PM, Derric Atzrott wrote:
Hmmm.... does not appear to work for me. I added window.alert("Test"); to the JavaScript file to make sure.
The relevant sections of each file are listed out below. All of these sections are in sections of their respective files that are being executed.
SpecialMasterPlanForm.php: http://pastebin.com/qKmTUvYd MasterPlanForm.php: http://pastebin.com/GaqhP55g js/ext.MasterPlanForm.core.js: http://pastebin.com/sNcbrYRW
Those files look generally OK.
Are you sure that Special page is working (is the HTML output working)?
A few things that may help you: * enable debugging in LocalSettings.php [1] * Check your php error_log and/or your apache error log * Check the browser console, perhaps there is an exeception thrown by ResourceLoader in the client side? * Enable debug mode in the front-end by appending [?&]debug=true to the url, then check the browser console again.
-- Krinkle
It appears the problem at this point was with my JavaScript code. I forgot to add a ) at the end of my JavaScript file. I also used getElementByID instead of getElementById.
Thank you for your help. I wouldn't have figured this out nearly as fast on my own.
Thank you, Derric Atzrott
-----Original Message----- From: wikitech-l-bounces@lists.wikimedia.org [mailto:wikitech-l-bounces@lists.wikimedia.org] On Behalf Of Krinkle Sent: 25 May 2012 21:19 To: Wikimedia developers Subject: Re: [Wikitech-l] ResourceManager and Javascript in Mediawiki
On May 25, 2012, at 10:37 PM, Derric Atzrott wrote:
Hmmm.... does not appear to work for me. I added window.alert("Test"); to the JavaScript file to make sure.
The relevant sections of each file are listed out below. All of these sections are in sections of their respective files that are being
executed.
SpecialMasterPlanForm.php: http://pastebin.com/qKmTUvYd MasterPlanForm.php: http://pastebin.com/GaqhP55g js/ext.MasterPlanForm.core.js: http://pastebin.com/sNcbrYRW
Those files look generally OK.
Are you sure that Special page is working (is the HTML output working)?
A few things that may help you: * enable debugging in LocalSettings.php [1] * Check your php error_log and/or your apache error log * Check the browser console, perhaps there is an exeception thrown by ResourceLoader in the client side? * Enable debug mode in the front-end by appending [?&]debug=true to the url, then check the browser console again.
-- Krinkle
[1] https://www.mediawiki.org/wiki/Manual:How_to_debug
_______________________________________________ Wikitech-l mailing list Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l
wikitech-l@lists.wikimedia.org