如何将MediaWiki页面内容嵌入到我的站点中?

时间:2021-09-04 10:43:02

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

我们的企业wiki是Mediawiki。我可以把iframe放到我的网站上,以参考维基上的一些文章。

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.

但是我自己的网站有很多小部件和自己的风格。我不想包含Mediawiki导航/搜索/登录小部件、徽标图像。

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

是否可能并且如何获得Mediawiki页面内容而不使用小部件(只有文章正文)?

2 个解决方案

#1


5  

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.

是的,它是。您可能希望使用action=render url参数,例如:http://en.wikipedia.org/w/index.php?注意,wiki中的样式表不包括在内,因此需要将相关规则复制到站点的css文件中。也看到这一点。

#2


1  

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.

在这里,我使用https://github.com/cscott/instaview/blob/master/main.js项目,该项目增强了http://en.wikipedia.org/wiki/User:Pilaf,将json输出转换为浏览器端的HTML。

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.

这段代码的原因是因为我们的wiki是旧的或配置错误的,并且action=render不可用。但是我陷入了跨域脚本问题,所以我认为使用action=render的iframe是更好的解决方案。

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:

使用action=parse (http://en.wikipedia.org/w/api.php?action=parse&title=Linux)的另一个建议是:

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:

完美的解决方案只是将查询操作=呈现给任何有效的wiki URL,比如:

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

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

#1


5  

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.

是的,它是。您可能希望使用action=render url参数,例如:http://en.wikipedia.org/w/index.php?注意,wiki中的样式表不包括在内,因此需要将相关规则复制到站点的css文件中。也看到这一点。

#2


1  

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.

在这里,我使用https://github.com/cscott/instaview/blob/master/main.js项目,该项目增强了http://en.wikipedia.org/wiki/User:Pilaf,将json输出转换为浏览器端的HTML。

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.

这段代码的原因是因为我们的wiki是旧的或配置错误的,并且action=render不可用。但是我陷入了跨域脚本问题,所以我认为使用action=render的iframe是更好的解决方案。

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:

使用action=parse (http://en.wikipedia.org/w/api.php?action=parse&title=Linux)的另一个建议是:

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:

完美的解决方案只是将查询操作=呈现给任何有效的wiki URL,比如:

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

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