Page MenuHomePhabricator

thumb getmagicword should return local names
Closed, InvalidPublic

Description

Feature summary:

site.getmagicwords('thumb') should return the local name for the "thumb" image parameter as the first list element.

Currently it only returns the standard ["thumb"] string list...

site=pywikibot.Site('fr')
site.getmagicwords('thumb')

It returns ['thumb']

It should instead return ['vignette', 'thumb']
For wp.de it should return ['mini', 'thumb']
For any language it should return the local language thumb equivalent.

Use case(s):
I want to update Wikipedias with the local language "thumb" parameter.

Benefits:

Bots and Pywikibot script could insert images to Wikipedia the same way as the Visual Editor does.

Event Timeline

Reedy subscribed.

https://fr.wikipedia.org/w/api.php?action=query&meta=siteinfo&siprop=magicwords

This looks like a pywikibot issue, they are returned by the API in the same order as they're defined in the Messages file:

{
    "name": "img_manualthumb",
    "aliases": [
        "vignette=$1",
        "thumbnail=$1",
        "thumb=$1"
    ],
    "case-sensitive": ""
},
{
    "name": "img_thumbnail",
    "aliases": [
        "vignette",
        "thumb",
        "thumbnail"
    ],
    "case-sensitive": ""
},
	'img_manualthumb'           => [ '1', 'vignette=$1', 'thumbnail=$1', 'thumb=$1' ],
	'img_thumbnail'             => [ '1', 'vignette', 'thumb', 'thumbnail' ],

And specifically, if you're asking for one that doesn't exist (which thumb doesn't), getmagicwords just returns you the same back verbatim:

def getmagicwords(self, word: str) -> list[str]:
    """Return list of localized "word" magic words for the site."""
    if not hasattr(self, '_magicwords'):
        magicwords = self.siteinfo.get('magicwords', cache=False)
        self._magicwords = {item['name']: item['aliases']
                            for item in magicwords}

    if word in self._magicwords:
        return self._magicwords[word]
    return [word]

Which probably explains why for site.getmagicwords('thumb') you're getting ['thumb'] back...

Reedy changed the subtype of this task from "Feature Request" to "Task".Jan 3 2024, 12:50 AM
JJMC89 subscribed.
>>> import pywikibot
>>> site = pywikibot.Site('fr', 'wikipedia')
>>> site.getmagicwords('img_thumbnail')
['vignette', 'thumb', 'thumbnail']
This comment was removed by Geertivp.