2

On our website when a user adds a link to a Wikipedia page we automatically present them with the N biggest images of the page. We then embed an appropriate Wikipedia thumb image (not the full sized image). If they link to a File: page we understand that directly and use the referenced image.

However, different language versions of Wikipedia use different "File:" prefixes. Is there another easy way to detect a Wikipedia File: page? Is there a comprehensive list of the File: prefix in all languages? I found these so far:

File:
Image:
Datei:
Bild:
ملف: or %D9%85%D9%84%D9%81:
Imagen:
Irudi:
Fichier:
Ficheiro:
Датотека: or %D0%94%D0%B0%D1%82%D0%BE%D1%82%D0%B5%D0%BA%D0%B0:
Fil:
Файл: or %D0%A4%D0%B0%D0%B9%D0%BB:
Immagine:
Податотека: or %D0%9F%D0%BE%D0%B4%D0%B0%D1%82%D0%BE%D1%82%D0%B5%D0%BA%D0%B0:
പ്രമാണം: or %E0%B4%AA%E0%B5%8D%E0%B4%B0%E0%B4%AE%E0%B4%BE%E0%B4%A3%E0%B4%82:
ファイル: or %E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB:
Слика: or %D0%A1%D0%BB%D0%B8%D0%BA%D0%B0:
Датотека: or %D0%94%D0%B0%D1%82%D0%BE%D1%82%D0%B5%D0%BA%D0%B0:
దస్త్రం: or %E0%B0%A6%E0%B0%B8%E0%B1%8D%E0%B0%A4%E0%B1%8D%E0%B0%B0%E0%B0%82:
Файл: or %D0%A4%D0%B0%D0%B9%D0%BB:
4

1 回答 1

0

您不应该尝试解析 URL。跨不同项目的本地化命名空间名称不断变化,很难获得最新列表。在某些情况下,一个本地化名称引用两个项目上的两个不同名称空间。

您应该能够通过查询其属性来告诉链接的名称空间。

https://en.wikipedia.org/w/api.php?action=query&prop=info&format=json&titles=File%3AWiki.png

寻找 ns 属性。

{
    "query": {
        "pages": {
            "28680696": {
                "pageid": 28680696,
                "ns": 6,
                "title": "File:Wiki.png",
                "contentmodel": "wikitext",
                "pagelanguage": "en",
                "touched": "2013-07-18T14:04:38Z",
                "lastrevid": 560201242,
                "counter": "",
                "length": 786
            }
        }
    }
}
于 2013-07-21T07:10:53.823 回答