User:Polygnotus/Scripts/SortByLastEdit.js
// <nowiki>
/**
* User Last Edit Sorter (Meta, EnWiki, Commons)
* Location: [[Special:BlankPage/LastEditSorter]]
*/
$(document).ready(function() {
const pageName = 'Special:BlankPage/LastEditSorter';
mw.util.addPortletLink(
'p-tb',
mw.util.getUrl(pageName),
'Last Edit Sorter (3-Wiki)',
't-lasteditsort',
'Sort users by last edit on Meta, EnWiki, and Commons'
);
if (mw.config.get('wgPageName') === pageName) {
document.title = 'User Last Edit Sorter (M-E-C)';
$('#firstHeading').text('User Last Edit Sorter (Meta, EnWiki, Commons)');
mw.loader.using(['oojs-ui-core', 'oojs-ui-widgets', 'mediawiki.api']).then(function() {
renderSorterInterface();
});
}
});
function renderSorterInterface() {
const $body = $('#mw-content-text');
$body.empty();
const inputField = new OO.ui.MultilineTextInputWidget({
placeholder: 'Enter usernames (one per line)',
rows: 10
});
const outputField = new OO.ui.MultilineTextInputWidget({
placeholder: 'Results will appear here...',
rows: 10,
readOnly: true
});
const progressBar = new OO.ui.ProgressBarWidget({ progress: 0 });
progressBar.toggle(false);
const statusLabel = new OO.ui.LabelWidget({ label: 'Ready.' });
const sortButton = new OO.ui.ButtonWidget({ label: 'Check 3 Wikis', flags: ['primary', 'progressive'] });
const fieldset = new OO.ui.FieldsetLayout({ label: 'Target: Meta, English Wikipedia, Commons' });
fieldset.addItems([
new OO.ui.FieldLayout(inputField, { label: 'Input Usernames', align: 'top' }),
new OO.ui.FieldLayout(outputField, { label: 'Results', align: 'top' })
]);
$body.append(
fieldset.$element,
$('<div style="margin-top: 10px;">').append(statusLabel.$element),
$('<div style="margin-top: 10px;">').append(progressBar.$element),
$('<div style="margin-top: 20px;">').append(sortButton.$element)
);
sortButton.on('click', async function() {
const users = parseUserList(inputField.getValue());
if (!users.length) return;
sortButton.setDisabled(true);
progressBar.toggle(true);
const targetWikis = [
{ name: 'enwiki', url: 'https://en.wikipedia.org/w/api.php' },
{ name: 'metawiki', url: 'https://meta.wikimedia.org/w/api.php' },
{ name: 'commonswiki', url: 'https://commons.wikimedia.org/w/api.php' }
];
const results = [];
for (let i = 0; i < users.length; i++) {
const user = users[i];
statusLabel.setLabel(`Checking ${user}...`);
let absoluteLatestTs = '0000-00-00T00:00:00Z';
let absoluteLatestWiki = 'None';
for (const wiki of targetWikis) {
try {
const data = await $.ajax({
url: wiki.url,
data: {
action: 'query',
list: 'usercontribs',
ucuser: user,
uclimit: 1,
ucprop: 'timestamp',
format: 'json',
origin: '*'
},
dataType: 'json'
});
if (data.query && data.query.usercontribs && data.query.usercontribs[0]) {
const ts = data.query.usercontribs[0].timestamp;
if (ts > absoluteLatestTs) {
absoluteLatestTs = ts;
absoluteLatestWiki = wiki.name;
}
}
} catch (e) {
console.error(`Error checking ${user} on ${wiki.name}`, e);
}
}
results.push({ name: user, ts: absoluteLatestTs, wiki: absoluteLatestWiki });
progressBar.setProgress(((i + 1) / users.length) * 100);
}
// Sort descending
results.sort((a, b) => b.ts.localeCompare(a.ts));
const finalOutput = results.map(r => {
const displayDate = r.ts === '0000-00-00T00:00:00Z' ? 'No edits found' : r.ts;
return `${r.name} | ${displayDate} (${r.wiki})`;
}).join('\n');
outputField.setValue(finalOutput);
statusLabel.setLabel('Done.');
sortButton.setDisabled(false);
});
}
function parseUserList(text) {
return [...new Set(
text.split('\n')
.map(l => l.trim().replace(/^\[\[User:/i, '').replace(/\]\]$/, '').split('|')[0].trim())
.filter(n => n)
)];
}
// </nowiki>
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.