0

I'm creating a wiki using Mediawiki for the first time. I would like to include automatically all backlinks of the current page in a template (like the "See also" section). I tried to play with the API, successfully, but I still haven't succeed in including the useful section of the result in my template.

I have been querying Google and Stackoverflow for days (maybe in the wrong way) but I'm still stuck.

Can somebody help me?

svick
  • 236,525
  • 50
  • 385
  • 514
hazelnut
  • 15
  • 1
  • 8

3 Answers3

1

As far as I know, there is no reasonable way to do that. Probably the closest you could get is to write a JavaScript code that reacts on the presence of a specific HTML element in the page, makes the API request and then updates the HTML to include the result.

svick
  • 236,525
  • 50
  • 385
  • 514
  • 1
    Also, Scribunto/Lua templates may have access to the API in question, if the OP is lucky. – Nemo Nov 10 '15 at 07:29
1

It’s not possible in wiki text to execute any JavaScript or use even more uncommon HTML. As such you won’t be able to use the MediaWiki API like that.

There are multiple different options you have to achieve something like this though:

You could use the API by including custom JavaScript code on MediaWiki:Common.js. The code there will be included automatically and can be used to enhance the wiki experience. This obviously requires JavaScript on the client so it might not be the best option; but at least you could use the API directly. You would have to add something to figure out where to place the results correctly though.

A better option would be to use an extension that gives you this output. You can either try to find an extension that already provides this functionality, or write your own that uses the internal MediaWiki API (not the JS one) to access that content.

One extension I could personally recommend you that does this (and many other things), is DynamicPageList (full disclosure: I’m somewhat affiliated with that project). It allows you to perform complex page selections.

For example what you are trying to do is to find all pages which link to your page. This can be easily done by DPL like this:

{{ #dpl: linksto = {{FULLPAGENAME}} }}
poke
  • 369,085
  • 72
  • 557
  • 602
  • Thanks for the reply. You gave me really useful things to explore. As I said, I'm a wiki beginner and until I read your post, I was quite disapointed by Mediawiki since I thought it was tough. I'm going to study a bit further how to write extensions and try the one your part of. Thanks you again ! – hazelnut May 05 '13 at 23:09
1

I wrote a blog post recently showing how to call the API to get the job queue size and display that inside of the wiki page. You can read about it at Display MediaWiki job queue size inside your wiki. This solution does require the External Data extension however. The code looks like:

{{#get_web_data: url={{SERVER}}{{SCRIPTPATH}}/api.php?action=query&meta=siteinfo&siprop=statistics&format=json
  | format=JSON
  | data=jobs=jobs}}
{{#external_value:jobs}}

You could easily swap in a different API call to get other data. For the specific item your looking for, @poke's answer above is probably better.

  • It seems to be powerful. Another thing to test :) With your suggestion, and poke's, I'm convinced that I have the right tools. I just need to learn them. Thank you a lot. – hazelnut May 05 '13 at 23:15