2

I have a MediaWiki up and running, and I added SemanticMediaWiki to be able to do some more stuff. Now I want the data that I added using SMW to generate some fancy graphics using JavaScript. My problem is as follows.

I can't find much in the way of information how to embed JavaScript in MediaWiki.

In my case, all I need is a way to call a JavaScript, that picks up an array from the ask array (SMW), take that data to generate some boxes with links and throw some CSS at it.

So far I haven't even figured out a way of running it (other than throwing it in common.js, which isn't awfully helpful).

Nemo
  • 2,441
  • 2
  • 29
  • 63
vrghost
  • 1,084
  • 2
  • 19
  • 42

2 Answers2

0

I'm not sure what you mean by "page-specific". If you want to run this JS only on one page, you can simply add to your Common.js something like

if ( mw.config.get( 'wgPageName' ) === 'Pagename' ) {
    [dostuff]
}

If you want to leverage ResourceLoader (please read, that's the main entry point for MediaWiki JavaScript docs), what about a gadget?

Nemo
  • 2,441
  • 2
  • 29
  • 63
  • 1
    Great simple solution, except of course your if-statement will be executed on *every* page. Would be great if you could share steps using a gadget :) – johny why Jun 26 '18 at 03:18
0

In the end I ended up writing an article on how to do it. So if anyone else want to do something similar, this is one option.

https://semantic-mediawiki.org/wiki/How_to_write_a_JavaScript_to_display_data_in_a_Semantic_MediaWiki

vrghost
  • 1,084
  • 2
  • 19
  • 42