How to embed the contents of a MediaWiki page on my website?

Our corporate wiki is Mediawiki. I have no problem posting an iframe to my site to link to a wiki article.

But my own site has many widgets and its own style. I do not want to include the navigation / search / login widgets in the Mediawiki logo.

Is it possible and how to get the contents of a Mediawiki page without widgets (only the body of the article)?

+4
source share
2 answers

Yes it is. You probably want to use the url parameter action=render , for example: http://en.wikipedia.org/w/index.php?action=render&title=Main_Page . Please note that style sheets from the wiki are not included, so you need to copy the corresponding rules into the css files of your site. See also this .

+5
source

Thank Valdir for the answer!

After asking a question, I do my own research and end up with code:

 window.onload = function() { httpRequest = new XMLHttpRequest(); httpRequest.onreadystatechange = function() { if (httpRequest.readyState !== 4) { console.log("Not ready, code: %o", httpRequest.readyState); return; } if (httpRequest.status !== 200) { console.log("Server error: %o", httpRequest.status); return; } var json = JSON.parse(httpRequest.responseText); console.log("json: %o", json); var wiki = json.query.pages["1"].revisions[0]["*"]; console.log("wiki: %o", wiki); var html = InstaView.convert(wiki); console.log("html: %o", html); document.getElementById('area').innerHTML = html; }; var url = 'https://wiki.evil-company.com/api.php?action=query&prop=revisions&format=json&titles=Main_page&rvprop=timestamp|user|comment|content'; httpRequest.open('GET', url, true); httpRequest.send(null); } 

Here I use the https://github.com/cscott/instaview/blob/master/main.js project, which is extended by http://en.wikipedia.org/wiki/User:Pilaf to convert json output to HTML on the side browser.

The reason for this code is because our wiki is old or incorrectly configured and action = render is not available. But I am trapped in the cross-domain scripting problem, so I think that an iframe with action = render is the best solution.

See also. How do you grab an article, including links in an easy-to-use format?

Another suggestion to use action = parse ( http://en.wikipedia.org/w/api.php?action=parse&title=Linux ) leads to a warning:

 You are looking at the HTML representation of the XML format. HTML is good for debugging, but is unsuitable for application use. Specify the format parameter to change the output format. 

UPDATE

The perfect solution is simply adding an action = render request to any valid wiki url, for example:

http://en.wikipedia.org/wiki/Linux?action=render

+1
source

Source: https://habr.com/ru/post/1494438/


All Articles