Skip to content

Latest commit

 

History

History
198 lines (175 loc) · 5.97 KB

wikipedia_jun-2024.md

File metadata and controls

198 lines (175 loc) · 5.97 KB

Wikipedia POTD

Images can have arbitrary proportions. Both portrait and album and square. So for wallpapers is appropriate images with album proportions only. POTD can be video. Be aware of File:{}.jpg extension.

POTD Filename

https://en.wikipedia.org/w/api.php?action=query&format=json&formatversion=2&prop=images&titles=Template:POTD/2024-06-06

https://en.wikipedia.org/w/api.php
    ? action        = query
    & format        = json
    & formatversion = 2
    & prop          = images
    & titles        = Template:POTD
    / 2024-06-06

If the requested image file is present then the following JSON response will be returned:

{
    "batchcomplete": true,
    "query": {
        "pages": [
            {
                "pageid": 77085108,
                "ns": 10,
                "title": "Template:POTD/2024-06-06",
                "images": [
                    {
                        "ns": 6,
                        "title": "File:Martial eagle (Polemaetus bellicosus).jpg"
                    }
                ]
            }
        ]
    }
}

Multiple filenames are possible:

{
    "batchcomplete": true,
    "query": {
        "pages": [
            {
                "pageid": 75711497,
                "ns": 10,
                "title": "Template:POTD/2024-01-14",
                "images": [
                    {
                        "ns": 6,
                        "title": "File:NNC-US-1849-G$1-Liberty head (Ty1).jpg"
                    },
                    {
                        "ns": 6,
                        "title": "File:NNC-US-1854-G$1-Indian head (Ty2).jpg"
                    },
                    {
                        "ns": 6,
                        "title": "File:NNC-US-1856-G$1-Indian head (Ty3).jpg"
                    }
                ]
            }
        ]
    }
}

In turn if the image file is missing:

{
    "batchcomplete": true,
    "query": {
        "pages": [
            {
                "ns": 10,
                "title": "Template:POTD/2024-08-24",
                "missing": true
            }
        ]
    }
}

Full Image URL

titles = File:{url-encoded-filename.jpg}

https://en.wikipedia.org/w/api.php
    ? action        = query
    & format        = json
    & formatversion = 2
    & prop          = imageinfo
    & iiprop        = url
    & titles        = File:Martial%20eagle%20(Polemaetus%20bellicosus).jpg

Response JSON:

query → pages[0] → imageinfo[0] → url

{
    ...
    "query": {
        "pages": [
            {
                "pageid": 69915226,
                "ns": 6,
                "title": "File:Martial eagle (Polemaetus bellicosus).jpg",
                "imagerepository": "shared",
                "imageinfo": [
                    {
                        "url": "https://upload.wikimedia.org/wikipedia/commons/6/61/Martial_eagle_%28Polemaetus_bellicosus%29.jpg",
                        "descriptionurl": "https://commons.wikimedia.org/wiki/File:Martial_eagle_(Polemaetus_bellicosus).jpg",
                        "descriptionshorturl": "https://commons.wikimedia.org/w/index.php?curid=67819541"
                    }
                ]
            }
        ]
    }
}

Title and Credits

http://en.wikipedia.org/w/api.php
    ? action        = query
    & format        = json
    & formatversion = 2
    & prop          = imageinfo
    & iiprop        = extmetadata
    & titles        = File:Martial%20eagle%20(Polemaetus%20bellicosus).jpg
  • imageinfo
    • extmetadata
      • ObjectName → value
      • Credit → value
      • Artist → value

All values could contain HTML formated content. ImageDescription could contain a very long html formatted text.

Example of JSON response:

{
    ...
    "query": {
        "pages": [
            {
                "pageid": 69915226,
                "ns": 6,
                "title": "File:Martial eagle (Polemaetus bellicosus).jpg",
                "imagerepository": "shared",
                "imageinfo": [
                    {
                        "extmetadata": {
                            "ObjectName": {
                                "value": "Martial eagle (Polemaetus bellicosus)",
                                "source": "mediawiki-metadata"
                            },
                            "ImageDescription": {
                                "value": "Martial eagle (<i>Polemaetus bellicosus</i>), Matetsi Safari Area, Zimbabwe",
                                "source": "commons-desc-page"
                            },
                            "Credit": {
                                "value": "<span class=\"int-own-work\" lang=\"en\">Own work</span>, from <a rel=\"nofollow\" class=\"external text\" href=\"https://www.sharpphotography.co.uk/\">Sharp Photography, sharpphotography.co.uk</a>",
                                "source": "commons-desc-page"
                            },
                            "Artist": {
                                "value": "<bdi><a href=\"https://www.wikidata.org/wiki/Q54800218\" class=\"extiw\" title=\"d:Q54800218\"><span title=\"Scottish wildlife photographer\">Charles J. Sharp</span></a>\n</bdi>",
                                "source": "commons-desc-page"
                            },
                            "Copyrighted": {
                                "value": "True",
                                "source": "commons-desc-page",
                                "hidden": ""
                            },
                            ...
                        }
                    }
                ]
            }
        ]
    }
}