以编程方式确定MediaWiki图像的URL [英] Programatically determining the URL of a MediaWiki image
问题描述
我正在尝试使用PHP脚本从特定的MediaWiki页面下载图像(或仅特定的图像).
I'm trying to download images from specific MediaWiki pages (Or just specific images) using a PHP script.
我可以通过在以下URL检索页面来通过api运行查询
I can run a query through the api, by retrieving the page at the following URL
.../w/action=query&prop=images&titles=Abakanskiy
并获得答复
<?xml version="1.0"?>
<api>
<query>
<pages>
<page pageid="260" ns="0" title="Abakanskiy">
<images>
<im ns="6" title="File:Abakanskiy.jpg" />
</images>
</page>
</pages>
</query>
</api>
到目前为止,很好.
现在,无论我对查询做了什么,我都没有弄清楚如何构造或检索图像的实际URL-在这种情况下,就是这样
Now, no matter what I've done with the query, I haven't figured out how I can construct, or retrieve the image's actual URL - in this case, it is
.../w/images/3/38/Abakanskiy.jpg
我缺少明显的东西吗?
我意识到存在一个幼稚的解决方案-获取包含图像的页面的源,将其解析为标记,然后从指定的URL获取图像-但是,如果可能的话,我宁愿使用API
I realise that there exists a naive solution - getting the source of the page containing the image, parsing it for the tag, and then getting the image from the specified URL - however, if possible, I'd rather use the API.
任何帮助将不胜感激!
推荐答案
一旦有了图像页面的名称,就可以执行以下操作:
Once you have the names of the image pages, you can do this:
action=query&prop=imageinfo&iiprop=url&titles=File:Foo.jpg|File:Bar.jpg
获取实际图像的URL.
to get the URLs of the actual images.
这篇关于以编程方式确定MediaWiki图像的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!