ميدياويكي:Common.js: الفرق بين النسختين
المظهر
لا ملخص تعديل |
لا ملخص تعديل |
||
| سطر ١: | سطر ١: | ||
/* | /* محرك موسوعة الأنساب الديناميكي الشامل والمستقر 100% (معالج النصوص الخام الحديث) */ | ||
/ | // 1️⃣ أولاً: محرك جدول المعرفات المتسلسل (صفحة المعرفات) | ||
$(document).ready(function() { | $(document).ready(function() { | ||
if (mw.config.get('wgPageName') === 'المعرفات') { | if (mw.config.get('wgPageName') === 'المعرفات') { | ||
| سطر ١٠: | سطر ١٠: | ||
} | } | ||
var askQuery = "[[معرف_الشخص::+]]|?معرف_الشخص|limit=500"; | var askQuery = "[[معرف_الشخص::+]]|?معرف_الشخص|limit=500"; | ||
var apiUrl = '/api.php?action=ask&format=json&query=' + encodeURIComponent(askQuery); | var apiUrl = '/api.php?action=ask&format=json&query=' + encodeURIComponent(askQuery); | ||
| سطر ١٨: | سطر ١٧: | ||
if (results && Object.keys(results).length > 0) { | if (results && Object.keys(results).length > 0) { | ||
var rowsHtml = ''; | var rowsHtml = ''; | ||
var queue = []; | |||
$.each(results, function(title, pageData) { | $.each(results, function(title, pageData) { | ||
| سطر ٢٥: | سطر ٢٥: | ||
var pageId = pageData.pageid || ''; | var pageId = pageData.pageid || ''; | ||
var rawIdAttr = printouts["معرف الشخص"] || printouts["معرف_الشخص"]; | var rawIdAttr = printouts["معرف الشخص"] || printouts["معرف_الشخص"]; | ||
var currentId = (rawIdAttr && rawIdAttr.length > 0) ? rawIdAttr.fulltext || rawIdAttr : pageId; | var currentId = (rawIdAttr && rawIdAttr.length > 0) ? rawIdAttr.fulltext || rawIdAttr : pageId; | ||
| سطر ٣٢: | سطر ٣١: | ||
var pageTitleId = "Person:" + currentId; | var pageTitleId = "Person:" + currentId; | ||
var rowId = "row-id-table-" + currentId; | |||
var displayMask = title.replace(/Person_/g, '').replace(/Person:/g, '').replace(/\s*\(.*?\)\s*/g, '').trim(); | var displayMask = title.replace(/Person_/g, '').replace(/Person:/g, '').replace(/\s*\(.*?\)\s*/g, '').trim(); | ||
if (!isNaN(displayMask) && displayMask !== '') { displayMask = "فرد رقم (" + displayMask + ")"; } | |||
if (!isNaN(displayMask) && displayMask !== '') { | |||
rowsHtml += '<tr>' + | rowsHtml += '<tr id="' + rowId + '">' + | ||
'<td style="padding: 8px 12px; font-family: monospace; font-size: 14px; font-weight: bold;"><a href="/index.php?title=' + encodeURIComponent(title) + '" style="color: #2a4b7c;">' + pageTitleId + '</a></td>' + | '<td style="padding: 8px 12px; font-family: monospace; font-size: 14px; font-weight: bold;"><a href="/index.php?title=' + encodeURIComponent(title) + '" style="color: #2a4b7c;">' + pageTitleId + '</a></td>' + | ||
'<td style="padding: 8px 12px; font-weight: bold; color: #27ae60;"> | '<td class="mask-cell" style="padding: 8px 12px; font-weight: bold; color: #27ae60;">جاري القراءة...</td>' + | ||
'</tr>'; | '</tr>'; | ||
queue.push({ title: title, rowId: rowId }); | |||
}); | }); | ||
$table.find('tbody').html(rowsHtml); | $table.find('tbody').html(rowsHtml); | ||
if ($.fn.tablesorter) { $table.tablesorter(); } | |||
function processQueue(index) { | |||
if (index >= queue.length) { | |||
if ($.fn.tablesorter) { $table.tablesorter(); } | |||
return; | |||
} | |||
var item = queue[index]; | |||
var contentUrl = '/api.php?action=query&titles=' + encodeURIComponent(item.title) + '&prop=revisions&rvprop=content&rvslots=main&format=json'; | |||
$.getJSON(contentUrl, function(contentData) { | |||
if (contentData && contentData.query && contentData.query.pages) { | |||
var pagesObj = contentData.query.pages; | |||
var pKey = Object.keys(pagesObj); | |||
var page = pagesObj[pKey]; | |||
var text = ''; | |||
if (page.revisions && page.revisions[0]) { | |||
if (typeof page.revisions[0] === 'string') { text = page.revisions[0]; } | |||
else if (page.revisions[0]['*']) { text = page.revisions[0]['*']; } | |||
else if (page.revisions[0]['slots'] && page.revisions[0]['slots']['main'] && page.revisions[0]['slots']['main']['*']) { | |||
text = page.revisions[0]['slots']['main']['*']; | |||
} | |||
} | |||
if (text) { | |||
var match = text.match(/\|\s*اسم_الشخص\s*=\s*([^\|\}]+)/); | |||
if (match && match[1]) { | |||
var finalName = match[1].trim().replace(/\s*\(.*?\)\s*/g, '').trim(); | |||
if (finalName !== '') { $('#' + item.rowId).find('.mask-cell').text(finalName); } | |||
} | |||
} | |||
} | |||
processQueue(index + 1); | |||
}).fail(function() { processQueue(index + 1); }); | |||
} | |||
processQueue(0); | |||
} | } | ||
}); | }); | ||
| سطر ٥٥: | سطر ٨٧: | ||
/ | // 2️⃣ ثانياً: محرك شجرة الأنساب المتسلسل المستقر (صفحات المشجرات) | ||
$(document).ready(function() { | $(document).ready(function() { | ||
$('.family-tree-api-render').each(function() { | $('.family-tree-api-render').each(function() { | ||
| سطر ٦١: | سطر ٩٣: | ||
var rootId = $container.data('rootid'); | var rootId = $container.data('rootid'); | ||
if (rootId) { | if (rootId) { rootId = parseInt(rootId.toString().replace(/[^0-9]/g, ''), 10); } | ||
if (!rootId || isNaN(rootId)) return; | if (!rootId || isNaN(rootId)) return; | ||
var maxGenerations = 12; | var maxGenerations = 12; | ||
var pageTitle = mw.config.get("wgPageName").replace(/_/g, " "); | var pageTitle = mw.config.get("wgPageName").replace(/_/g, " "); | ||
var rootCleanTitle = $('#firstHeading').text().replace(/Person_/g, '').replace(/Person:/g, '').trim(); | var rootCleanTitle = $('#firstHeading').text().replace(/Person_/g, '').replace(/Person:/g, '').trim(); | ||
var askQuery = "[[معرف الشخص::+]]|?معرف الشخص|?معرف الأب|limit=500"; | var askQuery = "[[معرف الشخص::+]]|?معرف الشخص|?معرف الأب|limit=500"; | ||
var apiUrl = '/api.php?action=ask&format=json&query=' + encodeURIComponent(askQuery); | var apiUrl = '/api.php?action=ask&format=json&query=' + encodeURIComponent(askQuery); | ||
| سطر ٨٣: | سطر ١٠٨: | ||
if (results && Object.keys(results).length > 0) { | if (results && Object.keys(results).length > 0) { | ||
var rawNodes = []; | var rawNodes = []; | ||
var | var queue = []; | ||
var currentRootPage = "Person:" + rootId; | var currentRootPage = "Person:" + rootId; | ||
queue.push({ title: currentRootPage, isRoot: true }); | |||
$.each(results, function(title, pageData) { | $.each(results, function(title, pageData) { | ||
| سطر ٩٢: | سطر ١١٧: | ||
var printouts = pageData.printouts || {}; | var printouts = pageData.printouts || {}; | ||
var tempName = title.replace(/Person_/g, '').replace(/Person:/g, '').replace(/\s*\(.*?\)\s*/g, '').trim(); | var tempName = title.replace(/Person_/g, '').replace(/Person:/g, '').replace(/\s*\(.*?\)\s*/g, '').trim(); | ||
if (!isNaN(tempName) && tempName !== '') { | if (!isNaN(tempName) && tempName !== '') { tempName = "فرد رقم (" + tempName + ")"; } | ||
var currentIdAttr = printouts["معرف الشخص"]; | var currentIdAttr = printouts["معرف الشخص"]; | ||
| سطر ١١٢: | سطر ١٣٣: | ||
if (currentId) { | if (currentId) { | ||
var nodeObj = { id: currentId, parentId: fatherId, title: tempName, pageName: title }; | |||
rawNodes.push(nodeObj); | |||
var checkTitleClean = title.replace(/Person_/g, '').replace(/Person:/g, '').trim(); | |||
if (!isNaN(checkTitleClean) && checkTitleClean !== '') { | |||
queue.push({ title: title, node: nodeObj, isRoot: false }); | |||
} | |||
} | } | ||
}); | }); | ||
function processTreeQueue(index) { | |||
if (index >= queue.length) { | |||
renderFinalTree(); | |||
return; | |||
} | |||
var item = queue[index]; | |||
var contentUrl = '/api.php?action=query&titles=' + encodeURIComponent(item.title) + '&prop=revisions&rvprop=content&rvslots=main&format=json'; | |||
if ( | $.getJSON(contentUrl, function(contentData) { | ||
if (contentData && contentData.query && contentData.query.pages) { | |||
var | var pagesObj = contentData.query.pages; | ||
var | var pKey = Object.keys(pagesObj); | ||
var page = pagesObj[pKey]; | |||
var text = ''; | |||
if (page.revisions && page.revisions) { | |||
if (typeof page.revisions === 'string') { text = page.revisions; } | |||
else if (page.revisions['*']) { text = page.revisions['*']; } | |||
else if (page.revisions['slots'] && page.revisions['slots']['main'] && page.revisions['slots']['main']['*']) { | |||
text = page.revisions['slots']['main']['*']; | |||
} | |||
} | |||
if ( | if (text) { | ||
var match = text.match(/\|\s*اسم_الشخص\s*=\s*([^\|\}]+)/); | var match = text.match(/\|\s*اسم_الشخص\s*=\s*([^\|\}]+)/); | ||
if (match && match | if (match && match) { | ||
finalName = match[1].trim().replace(/\s*\(.*?\)\s*/g, '').trim(); | var finalName = match[1].trim().replace(/\s*\(.*?\)\s*/g, '').trim(); | ||
if (finalName !== '') { | |||
if (item.isRoot) { rootCleanTitle = finalName; } | |||
else { item.node.title = finalName; } | |||
} | |||
} | } | ||
} | } | ||
} | } | ||
}); | processTreeQueue(index + 1); | ||
}).fail(function() { processTreeQueue(index + 1); }); | |||
} | |||
function renderFinalTree() { | |||
function buildTreeHtml(currentParentId, depth) { | function buildTreeHtml(currentParentId, depth) { | ||
if (depth > maxGenerations) return ""; | if (depth > maxGenerations) return ""; | ||
var children = rawNodes.filter(function(node) { return node.parentId === currentParentId; }); | var children = rawNodes.filter(function(node) { return node.parentId === currentParentId; }); | ||
if (children.length === 0) return ""; | if (children.length === 0) return ""; | ||
| سطر ١٧١: | سطر ٢٠٠: | ||
var childrenHtml = buildTreeHtml(rootId, 1); | var childrenHtml = buildTreeHtml(rootId, 1); | ||
if (childrenHtml) { | if (childrenHtml) { $container.html("• '''" + rootCleanTitle + "'''" + childrenHtml); } | ||
else { $container.html("• '''" + rootCleanTitle + "'''<br /> ← <span style='color:#666;'>لا توجد فروع أو ذرية مسجلة نزولاً لهذا المعرف الرقمي في النظام.</span>"); } | |||
} | |||
} | |||
processTreeQueue(0); | |||
} | } | ||
}); | }); | ||
}); | }); | ||
}); | }); | ||
مراجعة ١٧:٤٦، ١٥ أكتوبر ٢٠٢٦
/* محرك موسوعة الأنساب الديناميكي الشامل والمستقر 100% (معالج النصوص الخام الحديث) */
// 1️⃣ أولاً: محرك جدول المعرفات المتسلسل (صفحة المعرفات)
$(document).ready(function() {
if (mw.config.get('wgPageName') === 'المعرفات') {
var $table = $('#table-ids-mw');
if ($table.length > 0) {
$table.find('th').eq(0).text('اسم الصفحة (page_id)');
$table.find('th').eq(1).text('اسم الصفحة (القناع)');
}
var askQuery = "[[معرف_الشخص::+]]|?معرف_الشخص|limit=500";
var apiUrl = '/api.php?action=ask&format=json&query=' + encodeURIComponent(askQuery);
$.getJSON(apiUrl, function(data) {
var results = (data && data.query) ? data.query.results : null;
if (results && Object.keys(results).length > 0) {
var rowsHtml = '';
var queue = [];
$.each(results, function(title, pageData) {
if (title === 'المعرفات' || title.indexOf('قالب:') !== -1) return;
var printouts = pageData.printouts || {};
var pageId = pageData.pageid || '';
var rawIdAttr = printouts["معرف الشخص"] || printouts["معرف_الشخص"];
var currentId = (rawIdAttr && rawIdAttr.length > 0) ? rawIdAttr.fulltext || rawIdAttr : pageId;
if (currentId) currentId = currentId.toString().replace(/[^0-9]/g, '').trim();
if (!currentId) currentId = pageId;
var pageTitleId = "Person:" + currentId;
var rowId = "row-id-table-" + currentId;
var displayMask = title.replace(/Person_/g, '').replace(/Person:/g, '').replace(/\s*\(.*?\)\s*/g, '').trim();
if (!isNaN(displayMask) && displayMask !== '') { displayMask = "فرد رقم (" + displayMask + ")"; }
rowsHtml += '<tr id="' + rowId + '">' +
'<td style="padding: 8px 12px; font-family: monospace; font-size: 14px; font-weight: bold;"><a href="/index.php?title=' + encodeURIComponent(title) + '" style="color: #2a4b7c;">' + pageTitleId + '</a></td>' +
'<td class="mask-cell" style="padding: 8px 12px; font-weight: bold; color: #27ae60;">جاري القراءة...</td>' +
'</tr>';
queue.push({ title: title, rowId: rowId });
});
$table.find('tbody').html(rowsHtml);
function processQueue(index) {
if (index >= queue.length) {
if ($.fn.tablesorter) { $table.tablesorter(); }
return;
}
var item = queue[index];
var contentUrl = '/api.php?action=query&titles=' + encodeURIComponent(item.title) + '&prop=revisions&rvprop=content&rvslots=main&format=json';
$.getJSON(contentUrl, function(contentData) {
if (contentData && contentData.query && contentData.query.pages) {
var pagesObj = contentData.query.pages;
var pKey = Object.keys(pagesObj);
var page = pagesObj[pKey];
var text = '';
if (page.revisions && page.revisions[0]) {
if (typeof page.revisions[0] === 'string') { text = page.revisions[0]; }
else if (page.revisions[0]['*']) { text = page.revisions[0]['*']; }
else if (page.revisions[0]['slots'] && page.revisions[0]['slots']['main'] && page.revisions[0]['slots']['main']['*']) {
text = page.revisions[0]['slots']['main']['*'];
}
}
if (text) {
var match = text.match(/\|\s*اسم_الشخص\s*=\s*([^\|\}]+)/);
if (match && match[1]) {
var finalName = match[1].trim().replace(/\s*\(.*?\)\s*/g, '').trim();
if (finalName !== '') { $('#' + item.rowId).find('.mask-cell').text(finalName); }
}
}
}
processQueue(index + 1);
}).fail(function() { processQueue(index + 1); });
}
processQueue(0);
}
});
}
});
// 2️⃣ ثانياً: محرك شجرة الأنساب المتسلسل المستقر (صفحات المشجرات)
$(document).ready(function() {
$('.family-tree-api-render').each(function() {
var $container = $(this);
var rootId = $container.data('rootid');
if (rootId) { rootId = parseInt(rootId.toString().replace(/[^0-9]/g, ''), 10); }
if (!rootId || isNaN(rootId)) return;
var maxGenerations = 12;
var pageTitle = mw.config.get("wgPageName").replace(/_/g, " ");
var rootCleanTitle = $('#firstHeading').text().replace(/Person_/g, '').replace(/Person:/g, '').trim();
var askQuery = "[[معرف الشخص::+]]|?معرف الشخص|?معرف الأب|limit=500";
var apiUrl = '/api.php?action=ask&format=json&query=' + encodeURIComponent(askQuery);
$.getJSON(apiUrl, function(data) {
var results = (data && data.query && data.query.results) ? data.query.results : null;
if (results && Object.keys(results).length > 0) {
var rawNodes = [];
var queue = [];
var currentRootPage = "Person:" + rootId;
queue.push({ title: currentRootPage, isRoot: true });
$.each(results, function(title, pageData) {
var pageId = parseInt(pageData.pageid || pageData.id, 10);
var printouts = pageData.printouts || {};
var tempName = title.replace(/Person_/g, '').replace(/Person:/g, '').replace(/\s*\(.*?\)\s*/g, '').trim();
if (!isNaN(tempName) && tempName !== '') { tempName = "فرد رقم (" + tempName + ")"; }
var currentIdAttr = printouts["معرف الشخص"];
var currentId = (currentIdAttr && currentIdAttr.length > 0) ? currentIdAttr.fulltext || currentIdAttr : pageId;
if (currentId) currentId = parseInt(currentId.toString().replace(/[^0-9]/g, ''), 10);
var fatherIdAttr = printouts["معرف الأب"];
var fatherId = null;
if (fatherIdAttr && fatherIdAttr.length > 0) {
var rawFather = fatherIdAttr.fulltext || fatherIdAttr;
fatherId = parseInt(rawFather.toString().replace(/[^0-9]/g, ''), 10);
if (isNaN(fatherId)) fatherId = null;
}
if (currentId) {
var nodeObj = { id: currentId, parentId: fatherId, title: tempName, pageName: title };
rawNodes.push(nodeObj);
var checkTitleClean = title.replace(/Person_/g, '').replace(/Person:/g, '').trim();
if (!isNaN(checkTitleClean) && checkTitleClean !== '') {
queue.push({ title: title, node: nodeObj, isRoot: false });
}
}
});
function processTreeQueue(index) {
if (index >= queue.length) {
renderFinalTree();
return;
}
var item = queue[index];
var contentUrl = '/api.php?action=query&titles=' + encodeURIComponent(item.title) + '&prop=revisions&rvprop=content&rvslots=main&format=json';
$.getJSON(contentUrl, function(contentData) {
if (contentData && contentData.query && contentData.query.pages) {
var pagesObj = contentData.query.pages;
var pKey = Object.keys(pagesObj);
var page = pagesObj[pKey];
var text = '';
if (page.revisions && page.revisions) {
if (typeof page.revisions === 'string') { text = page.revisions; }
else if (page.revisions['*']) { text = page.revisions['*']; }
else if (page.revisions['slots'] && page.revisions['slots']['main'] && page.revisions['slots']['main']['*']) {
text = page.revisions['slots']['main']['*'];
}
}
if (text) {
var match = text.match(/\|\s*اسم_الشخص\s*=\s*([^\|\}]+)/);
if (match && match) {
var finalName = match[1].trim().replace(/\s*\(.*?\)\s*/g, '').trim();
if (finalName !== '') {
if (item.isRoot) { rootCleanTitle = finalName; }
else { item.node.title = finalName; }
}
}
}
}
processTreeQueue(index + 1);
}).fail(function() { processTreeQueue(index + 1); });
}
function renderFinalTree() {
function buildTreeHtml(currentParentId, depth) {
if (depth > maxGenerations) return "";
var children = rawNodes.filter(function(node) { return node.parentId === currentParentId; });
if (children.length === 0) return "";
children.sort(function(a, b) { return a.title.localeCompare(b.title, 'ar'); });
var html = "";
var indent = Array(depth + 1).join(" ");
children.forEach(function(child) {
html += "<br />" + indent + "← <a href='/index.php?title=" + encodeURIComponent(child.pageName) + "' style='color: #2a4b7c; font-weight: bold;'> " + child.title + "</a>";
html += buildTreeHtml(child.id, depth + 1);
});
return html;
}
var childrenHtml = buildTreeHtml(rootId, 1);
if (childrenHtml) { $container.html("• '''" + rootCleanTitle + "'''" + childrenHtml); }
else { $container.html("• '''" + rootCleanTitle + "'''<br /> ← <span style='color:#666;'>لا توجد فروع أو ذرية مسجلة نزولاً لهذا المعرف الرقمي في النظام.</span>"); }
}
processTreeQueue(0);
}
});
});
});