1

I upload images to Wikimedia Commons, each time I spend time selecting relevant categories.

How can I make the process faster by pre-filling or suggesting previously used categories?

For faster files uploading - without manually going to my uploads list.

2 Answers 2

1

This code adds categories from your previous file:

if (mw.config.get('wgPageName') == 'Special:UploadWizard') {
    setPreviousCategories()
}

function setPreviousCategories() {
    fetch(`https://commons.wikimedia.org/w/api.php?action=query&list=usercontribs&uclimit=1&ucuser=${mw.user.getName()}&format=json`)
        .then(resp => resp.json())
        .then(j => {
            const filename = j['query']['usercontribs'][0]['title']
            fetch(`https://commons.wikimedia.org/w/api.php?action=query&format=json&prop=categories&list=&meta=&titles=${filename}&formatversion=2&clprop=&clshow=!hidden`)
                .then(resp => resp.json())
                .then(j => {
                    const cats = j['query']['pages'][0]['categories']
                        .reduce(reducer, '')
                    document.querySelector('#ooui-29').innerText = 'Previous categories: \n' + cats
                })
        })
}
function reducer(acc, cur) {
    return acc += '\n'+cur['title'].replace('Category:', '')
}
    

How it looks: wikimedia commons file uploading: categories

You can use this code from your global.js

0

On Android, you can use the Wikimedia Commons Android app to achieve that.

It remembers categories you have used previously, and shows them so that you can select them with a single tap. It works that way by default, no configuration needed. It is super fast, much faster than sending API calls. However, it only shows recent categories used on that device, not on other devices.

For instance, on my phone here is the categories that get suggested, they are suggested because I used them recently:

enter image description here

Disclaimer: I put that app on Google Play and was its maintainer for a few years.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.