Content deleted Content added
Polygnotus (talk | contribs) No edit summary |
Polygnotus (talk | contribs) No edit summary |
||
Line 102:
function getAfDDates(pages, articleTitle) {
var api = new mw.Api();
var mostRecentDate = null;
var mostRecentTimestamp = 0;
var completedRequests = 0;
console.log('Fetching dates for:',
//
if (pages.length === 0) {
displayAfDResults(pages, articleTitle);▼
action: 'query',▼
// Fetch date for each page individually
rvprop: 'timestamp',▼
▲ action: 'query',
▲ }).then(function(data) {
prop: 'revisions',
rvprop: 'timestamp'
if (data.query && data.query.pages) {▼
var hasDate = false;
Object.keys(data.query.pages).forEach(function(pageId) {▼
▲ if (data.query && data.query.pages) {
pageData = data.query.pages[pageId];
// Check if page exists and has revisions▼
if (pageData && !pageData.missing && pageData.revisions && pageData.revisions.length > 0) {
var timestamp = pageData.revisions[0].timestamp;
Line 133 ⟶ 138:
var timestampMs = date.getTime();
console.log('Page:', pageData.title, 'Date:', date.toDateString());
pagesWithDates.push({
Line 146 ⟶ 151:
mostRecentDate = date;
}
console.log('No revisions found for:', pageData ? pageData.title : 'unknown page');▼
// Still add the page without date▼
pagesWithDates.push({▼
title: pageData ? pageData.title : 'Unknown page',▼
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;▼
return b.timestamp - a.timestamp;
});
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) {
// Add page without date on error
pagesWithDates.push({
title: page.title,
date: null,
});
completedRequests++;
// When all requests are complete (including errors), display results
▲ if (pagesWithDates.length === 0) {
displayAfDResults(pagesWithDates, articleTitle, mostRecentDate, false);
▲ }
}
▲ // 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;
});
▲ 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); // Debug log
▲ displayAfDResults(pagesWithDates, articleTitle, mostRecentDate, isRecent);
▲ }).catch(function(error) {
▲ console.log('API error:', error); // Debug log
▲ displayAfDResults(pages, articleTitle);
});
}
|