Content deleted Content added
Polygnotus (talk | contribs) No edit summary |
Polygnotus (talk | contribs) No edit summary |
||
Line 84:
});
// Get creation dates for all found pages
if (allMatches.length > 0) {
getAfDDates(allMatches, articleTitle);
} else {
displayAfDResults(allMatches, articleTitle);
}
}).fail(function() {
// If search fails, just show exact matches
Line 95 ⟶ 100:
}
function
var api = new mw.Api();
var pageTitles = pages.map(function(page) { return page.title; });
// Get creation dates for all pages
api.get({
action: 'query',
titles: pageTitles.join('|'),
prop: 'revisions',
rvlimit: 1,
rvdir: 'newer', // Get the first revision (creation)
rvprop: 'timestamp',
format: 'json'
}).done(function(data) {
var pagesWithDates = [];
var mostRecentDate = null;
var mostRecentTimestamp = 0;
// Process each page and add creation date
Object.keys(data.query.pages).forEach(function(pageId) {
var pageData = data.query.pages[pageId];
if (pageData.revisions && pageData.revisions.length > 0) {
var timestamp = pageData.revisions[0].timestamp;
var date = new Date(timestamp);
var timestampMs = date.getTime();
pagesWithDates.push({
title: pageData.title,
date: date,
timestamp: timestampMs
});
// Track most recent
if (timestampMs > mostRecentTimestamp) {
mostRecentTimestamp = timestampMs;
mostRecentDate = date;
}
}
});
// Sort by date (most recent first)
pagesWithDates.sort(function(a, b) { 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;
displayAfDResults(pagesWithDates, articleTitle, mostRecentDate, isRecent);
}).fail(function() {
// If date fetching fails, display without dates
displayAfDResults(pages, articleTitle);
});
}
function displayAfDResults(pages, articleTitle, mostRecentDate, isRecent) {
// Reset button
$('#afd-search-btn').text('Search AfD').css('color', '#0645ad');
Line 116 ⟶ 176:
} else {
var $title = $('<strong>').text('Previous AfD discussions for "' + articleTitle + '":');
// Add warning if recent AfD
if (isRecent && mostRecentDate) {
var $warning = $('<div>')
.css({
'color': '#d33',
'font-weight': 'bold',
'margin': '5px 0',
'padding': '5px',
'background-color': '#fee',
'border': '1px solid #fcc',
'border-radius': '3px'
})
.html('⚠️ <strong>Warning:</strong> Most recent AfD was on ' +
mostRecentDate.toLocaleDateString() + ' (within last 3 months)');
$resultsDiv.append($warning);
}
var $list = $('<ul>').css('margin', '10px 0');
Line 123 ⟶ 201:
.text(page.title);
var $
// Add date if available
if (page.date) {
var dateStr = page.date.toLocaleDateString() + ' (' + getTimeAgo(page.date) + ')';
$listItem.append($('<span>').css('color', '#666').text(' - ' + dateStr));
}
$list.append($listItem);
});
Line 145 ⟶ 231:
// Insert results after the button
$('#afd-search-btn').parent().after($resultsDiv);
}
function getTimeAgo(date) {
var now = new Date();
var diffMs = now - date;
var diffDays = Math.floor(diffMs / (1000 * 60 * 60 * 24));
var diffMonths = Math.floor(diffDays / 30);
var diffYears = Math.floor(diffDays / 365);
if (diffDays < 1) {
return 'today';
} else if (diffDays < 30) {
return diffDays + ' day' + (diffDays === 1 ? '' : 's') + ' ago';
} else if (diffMonths < 12) {
return diffMonths + ' month' + (diffMonths === 1 ? '' : 's') + ' ago';
} else {
return diffYears + ' year' + (diffYears === 1 ? '' : 's') + ' ago';
}
}
|