0

Marvin JS (downloaded from http://dl.chemaxon.com/marvinjs/15.2.16/marvinjs-15.2.16-all.zip) is a JavaScript-based chemical structure editing program that I would like to be able to embed into MediaWiki articles on my local server. I have read https://www.mediawiki.org/wiki/Manual:Developing_extensions but my understanding of PHP is very rudimentary so it wasn't particularly helpful.

I would like such an extension to create the following parser extension tag:

<marvin src = URL width = W height = H></marvin>

where URL is the location (on the local server) of the file being loaded by the Marvin JS program, W is the width of the applet and H is its height.

My efforts to date to add Marvin JS to articles via other means

I have seen several examples of how this applet can be embedded into HTML pages and as I knew writing an extension would be very difficult for me with my lack of PHP knowledge I did attempt to embed this applet as a Widget and via the AddScriptCss extension, both have failed me.

AddScriptCss

For AddScriptCss after installing the extension I added:

<addScript src = "Marvin/js/lib/jquery-1.9.1.min.js"></addScript>
<addScript src="Marvin/js/lib/rainbow/rainbow-custom.min.js"></addScript>
<addScript src="Marvin/gui/lib/promise-0.1.1.min.js"></addScript>
<addScript src="Marvin/js/marvinjslauncher.js"></addScript>

to an article and received this output on the page after I saved this:

UNIQ5d2750bb5e9527b2-addScript-00000004-QINU UNIQ5d2750bb5e9527b2-addScript-00000005-QINU UNIQ5d2750bb5e9527b2-addScript-00000006-QINU UNIQ5d2750bb5e9527b2-addScript-00000007-QINU

adding the rest of the URL to the src field (e.g., http://127.0.0.1/mediawiki/) doesn't seem to correct this problem. Opening up 'Developer tools' (I'm using Chrome) shows two errors:

Uncaught SyntaxError: Unexpected string (@ index.php line 154. Which is a WikEd line)
http://ads.dfgio.com/loader.js?client=topaz0001 Failed to load resource: net::ERR_BLOCKED_BY_CLIENT

I also saw this Mediawiki Extension add Javascript in Header stackoverflow question so I attempted following 2nd's answer (Mediawiki Extension add Javascript in Header) and after replacing script with addHeadItem and saving the page all I was left with was my original wikitext except with the URLs hyperlinked.

Widgets

As far as Widgets go I tried adding:

<includeonly><script type = "text/javascript" src="http://127.0.0.1/mediawiki/Marvin/gui/lib/promise-0.1.1.min.js"></script>
<script type = "text/javascript" src="http://127.0.0.1/mediawiki/Marvin/js/marvinjslauncher.js"></script></includeonly>

To Widget:Marvin, then I added {{#widget:Marvin}} to a page with no results (quite literally; when I loaded the page after saving this edit there was nothing there). Here is a screenshot showing the screen that came up upon opening developers tools on this page.

enter image description here

Community
  • 1
  • 1
Josh Pinto
  • 1,453
  • 4
  • 20
  • 37

1 Answers1

0

Try the Gadgets extension. It's the one Wikipedia uses; well-maintained and fairly easy to use.

Or, is this is a local wiki, only accessible to you, and you don't care about security at all, you can just enable arbitrary HTML in wikitext via $wgRawHtml.

Tgr
  • 27,442
  • 12
  • 81
  • 118
  • How do I use gadgets? I read the MediaWiki page and I have saved marvinjslauncher.js at MediaWiki:Gadget-marvin.js and added the line `* marvin|marvin.js` to MediaWiki:Gadgets-definition and clicked the box next to it in my Special:Preferences page to enable it but now what do I do? – Josh Pinto Feb 20 '15 at 13:56
  • That's all you need to do to load marvinjslauncher on every article. I imagine you need to load the other scripts as well. – Tgr Feb 20 '15 at 22:21
  • Well it didn't load it on every article for me and I didn't want it to load it on every article anyway because only some articles require Marvin. Plus I would like to be able to control which files it loads on each page. – Josh Pinto Feb 21 '15 at 06:43
  • You can put the logic whether to load it or not into javascript. You can define each file as a separate gadget, add `ResourceLoader` to the gadget definition (like this: `* marvin[ResourceLoader]|marvin.js`), then you can load them with `mw.loader.using( 'ext.gadget.', function () { /* code to run after file has loaded */ } );`. – Tgr Feb 21 '15 at 21:41
  • OK, I did that with the mw code within `` parser tags with `` replaced by `marvin` and the `, function() {...` omitted for simplicity and upon submitting this edit I was directed to an otherwise blank page with this line on it: `[c3aab38b] 2015-02-22 16:07:00: Fatal exception of type MWException` – Josh Pinto Feb 22 '15 at 16:09