Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
const api = new mw.Api();
const reason = 'Renaming translations with incorrect language code';
const namespace = 1198;
const user = 'Aamrs';
const startDate = '2019-01-06T18:00:00.000Z';
const wrongLanguage = 'en-gb';
const correctLanguage = 'pt';
api.get({
action: 'query',
meta: 'tokens'
}).done((data) => {
console.log(data);
const token = data.query.tokens.csrftoken;
api.get({
action: 'query',
list: 'usercontribs',
ucuser: user,
ucstart: startDate,
ucnamespace: namespace,
ucdir: 'newer',
uclimit: 'max'
}).done((data) => {
const dataToProceed = data.query.usercontribs.filter(item => item.title.endsWith('/' + wrongLanguage));
dataToProceed.forEach(item => {
const pageFrom = item.title;
const pageTo = pageFrom.replace(new RegExp(`/${wrongLanguage}$`), '/' + correctLanguage);
api.post({
action: 'move',
from: pageFrom,
to: pageTo,
reason: reason,
token: token,
noredirect: 1
}).done((data) => {
console.log(pageFrom + ' must has been moved to ' + pageTo);
});
});
});
});