İstifadəçi:Qədir/AllMoveLogsDemo.js
(İstifadəçi:Gadir/AllMoveLogsDemo.js səhifəsindən istiqamətləndirilmişdir)
(function() {
const modalId = 'moveHistoryModal';
// Modal yaratmaq və göstərmək
function showModal() {
if (!document.getElementById(modalId)) {
const modal = document.createElement('div');
modal.id = modalId;
modal.style.cssText = `
display: block;
position: fixed;
top: 0; left: 0; width: 100vw; height: 100vh;
background: rgba(0,0,0,0.7);
color: #222;
overflow-y: auto;
z-index: 99999;
padding: 20px;
box-sizing: border-box;
font-family: sans-serif;
`;
modal.innerHTML = `
<button id="${modalId}_close" style="
position: fixed; top: 20px; right: 20px;
font-size: 30px; background: transparent; border: none; color: white; cursor: pointer;
z-index: 100000;
" title="Bağla">×</button>
<div id="${modalId}_content" style="
background: white; border-radius: 8px; padding: 20px;
max-width: 900px; margin: 60px auto 40px auto; color: black;
font-size: 14px; min-height: 200px;
"></div>
`;
document.body.appendChild(modal);
document.getElementById(modalId + '_close').onclick = () => {
modal.style.display = 'none';
};
} else {
document.getElementById(modalId).style.display = 'block';
}
}
// MediaWiki API ilə move loglarını almaq
async function getMoveLogs(title) {
const api = new mw.Api();
const logs = [];
let lecontinue = null;
do {
const params = {
action: 'query',
list: 'logevents',
letype: 'move',
letitle: title,
lelimit: '500',
format: 'json',
origin: '*',
};
if (lecontinue) params.lecontinue = lecontinue;
const data = await api.get(params);
if (data.query && data.query.logevents) {
logs.push(...data.query.logevents);
}
lecontinue = data.continue?.lecontinue;
} while (lecontinue);
return logs;
}
// Verilmiş ad üçün bütün ad dəyişmələrini zəncirvari tapmaq
async function traceTitleHistory(title) {
let currentTitle = title;
const allLogs = [];
while (true) {
const logs = await getMoveLogs(currentTitle);
if (!logs.length) break;
allLogs.push(...logs);
// Köhnə adı tap, yoxdursa dayandır
const oldTitle = logs[0].params?.old_title || logs[0].old_title || null;
if (!oldTitle || oldTitle === currentTitle) break;
currentTitle = oldTitle;
}
return allLogs;
}
// Nəticələri göstərmək
function renderResults(title, logs) {
showModal();
const content = document.getElementById(modalId + '_content');
if (!logs.length) {
content.innerHTML = `<h2>${title} üçün ad dəyişmə jurnalı tapılmadı</h2>`;
return;
}
content.innerHTML = `<h2>${title} üçün bütün ad dəyişmə jurnalları (${logs.length} dəfə)</h2>`;
const ul = document.createElement('ul');
ul.style.listStyle = 'none';
ul.style.padding = '0';
logs.forEach(log => {
const userLink = `https://az.wikipedia.org/wiki/İstifadəçi:${encodeURIComponent(log.user)}`;
const time = new Date(log.timestamp).toLocaleString('az-AZ', { timeZone: 'UTC' });
const li = document.createElement('li');
li.style.padding = '8px 0';
li.style.borderBottom = '1px solid #ddd';
li.innerHTML = `
<div><strong>${time} (UTC)</strong></div>
<div>İstifadəçi: <a href="${userLink}" target="_blank">${log.user}</a></div>
<div>Əvvəlki ad: <em>${log.params?.old_title || log.old_title || ''}</em></div>
<div>Yeni ad: <em>${log.params?.new_title || log.new_title || ''}</em></div>
`;
ul.appendChild(li);
});
content.appendChild(ul);
}
// İstifadəçidən səhifə adı soruşmaq və işlətmək
function showInputPrompt() {
const title = prompt('Səhifə adını daxil edin (boş buraxmaq üçün ləğv et):');
if (!title) return;
const formattedTitle = title.charAt(0).toUpperCase() + title.slice(1).replace(/_/g, ' ');
renderResults(formattedTitle, []);
traceTitleHistory(formattedTitle).then(logs => renderResults(formattedTitle, logs));
}
// Səhifəyə düymə əlavə et
function addSidebarButton() {
const sidebar = document.getElementById('p-cactions');
if (!sidebar || document.getElementById('showMoveHistoryBtn')) return;
const li = document.createElement('li');
const a = document.createElement('a');
a.href = '#';
a.id = 'showMoveHistoryBtn';
a.textContent = 'Addəyişmə jurnallarını göstər';
a.style.cursor = 'pointer';
a.addEventListener('click', e => {
e.preventDefault();
showInputPrompt();
});
li.appendChild(a);
const ul = sidebar.querySelector('ul');
if (ul) ul.appendChild(li);
}
// Başla
$(document).ready(() => {
addSidebarButton();
});
})();