Question

Our corporate wiki is Mediawiki. I have no problem to put iframe into my site to refer for some article on wiki.

But my own site have a lot of widgets and own style. I don't want to include Mediawiki navigation/search/login widgets, logo image.

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

Was it helpful?

Solution

Yes, it is. You'll probably want to use the action=render url parameter, for example: http://en.wikipedia.org/w/index.php?action=render&title=Main_Page. Note that the stylesheets from the wiki aren't included, so you'll need to copy the relevant rules to your site's css files. See also this.

OTHER TIPS

Thank waldir for answer!

After asking question I perform own research and end 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 https://github.com/cscott/instaview/blob/master/main.js project which is enhanced http://en.wikipedia.org/wiki/User:Pilaf to transform json output to HTML on browser side.

The reason for this code because our wiki is old or misconfigured and action=render is not available. But I trap into cross-domain scripting issue so I think that iframe with action=render is better solution.

See also How do you grab an article including the links in a usable format?

Another suggestion to use action=parse (http://en.wikipedia.org/w/api.php?action=parse&title=Linux) lead to 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

Perfect solution just append query action=render to any valid wiki URL like:

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top