Content deleted Content added
Polygnotus (talk | contribs) No edit summary |
Polygnotus (talk | contribs) No edit summary |
||
(One intermediate revision by the same user not shown) | |||
Line 1:
//https://en.wikipedia.org/wiki/Wikipedia_talk:Twinkle#Twinkle_feature_request_--_look_for_previous_XfDs
// Add AfD search functionality to Wikipedia
$(document).ready(function() {
Line 102 ⟶ 104:
function getAfDDates(pages, articleTitle) {
var api = new mw.Api();
var pagesWithDates = [];
var mostRecentDate = null;
var mostRecentTimestamp = 0;
var completedRequests = 0;
console.log('Fetching dates for:',
//
if (pages.length === 0) {
displayAfDResults(pages, articleTitle);
}
// Fetch date for each page individually
pages.forEach(function(page) {
action: 'query',
prop: 'revisions',
rvprop: 'timestamp'
}).then(function(data) {
var pageData = null;
var hasDate = false;
if (data.query && data.query.pages) {
var pageId = Object.keys(data.query.pages)[0];
pageData = data.query.pages[pageId];
if (pageData && !pageData.missing && pageData.revisions && pageData.revisions.length > 0) {
var timestamp = pageData.revisions[0].timestamp;
Line 133 ⟶ 140:
var timestampMs = date.getTime();
console.log('Page:', pageData.title, 'Date:', date.toDateString());
pagesWithDates.push({
Line 146 ⟶ 153:
mostRecentDate = date;
}
}
}
// If no date found, add page without date
if (!hasDate) {
console.log('No date found for:', page.title);
pagesWithDates.push({
title: page.title,
date: null,
timestamp: 0
});
}
completedRequests++;
// When all requests are complete, display results
if (completedRequests === pages.length) {
// Sort by date (most recent first, pages without dates last)
pagesWithDates.sort(function(a, b) {
if (!a.timestamp && !b.timestamp) return 0;
if (!a.timestamp) return 1;
if (!b.timestamp) return -1;
return b.timestamp - a.timestamp;
});
// Check if most recent is within 3 months
var threeMonthsAgo = new Date();
threeMonthsAgo.setMonth(threeMonthsAgo.getMonth() - 3);
var isRecent = mostRecentDate && mostRecentDate > threeMonthsAgo;
console.log('Most recent date:', mostRecentDate ? mostRecentDate.toDateString() : 'none', 'Is recent:', isRecent);
displayAfDResults(pagesWithDates, articleTitle, mostRecentDate, isRecent);
}
}).catch(function(error) {
console.log('API error for', page.title, ':', error);
// Add page without date on error
pagesWithDates.push({
title: page.title,
date: null,
timestamp: 0
});
completedRequests++;
// When all requests are complete (including errors), display results
displayAfDResults(pagesWithDates, articleTitle, mostRecentDate, false);
}
});
});
}
|