מדיה ויקי:סקריפטים/109.js – הבדלי גרסאות
תוכן שנמחק תוכן שנוסף
אין תקציר עריכה |
בהתאם לדברי קיפודנחש בדף שיחתי |
||
שורה 11: | שורה 11: | ||
'use strict'; |
'use strict'; |
||
var |
var pageID = mw.config.get('wgArticleId'); |
||
function checkForTemplate() { |
function checkForTemplate() { |
||
mw.loader.using('mediawiki.api').then(function () { |
mw.loader.using('mediawiki.api').then(function () { |
||
api = new mw.Api(); |
var api = new mw.Api(); |
||
api.get({ |
api.get({ |
||
action: 'query', |
action: 'query', |
||
שורה 24: | שורה 24: | ||
}).done(data => { |
}).done(data => { |
||
if (Array.isArray(data.query.pages[pageID].templates)) { |
if (Array.isArray(data.query.pages[pageID].templates)) { |
||
showWarning(); |
showWarning(api); |
||
} |
} |
||
}); |
}); |
||
שורה 30: | שורה 30: | ||
} |
} |
||
function showWarning() { |
function showWarning(api) { |
||
// First, let's get the latest revision's editor and date. |
// First, let's get the latest revision's editor and date. |
גרסה מ־22:17, 27 ביולי 2018
/*
הצגת אזהרה בעת עריכת דף עם תבנית בעבודה
Written by: [[User:Guycn2]]
*/
$(function () {
'use strict';
var pageID = mw.config.get('wgArticleId');
function checkForTemplate() {
mw.loader.using('mediawiki.api').then(function () {
var api = new mw.Api();
api.get({
action: 'query',
prop: 'templates',
pageids: pageID,
tllimit: 1,
tltemplates: 'תבנית:בעבודה'
}).done(data => {
if (Array.isArray(data.query.pages[pageID].templates)) {
showWarning(api);
}
});
});
}
function showWarning(api) {
// First, let's get the latest revision's editor and date.
// We need this information to check if the page's editor is actually the logged-in user
// (in that case, there is no need to warn the editor).
// We may also use this information later to display details about the latest revision in the alert message.
api.get({
action: 'query',
prop: 'revisions',
pageids: pageID,
rvprop: 'user|timestamp',
rvlimit: 1
}).done(data => {
var revUser = data.query.pages[pageID].revisions[0].user,
revDate = new Date(data.query.pages[pageID].revisions[0].timestamp).toLocaleDateString();
if (revUser === mw.config.get('wgUserName')) return;
// Now let's show the warning
mw.loader.using('oojs-ui-windows').then(function () {
OO.ui.alert($('<div>').html('<strong>לתשומת לבך</strong>: נראה שדף זה מכיל תבנית {\{בעבודה}\}. אם הוא אכן מכיל תבנית זו, יש להימנע מעריכתו.<br />הדף נערך לאחרונה על־ידי ' + revUser + ' בתאריך ' + revDate + '.'));
});
});
}
if (mw.config.get('wgAction') === 'edit') {
checkForTemplate();
}
else {
mw.hook('ve.activate').add(checkForTemplate);
}
});