MediaWiki:Common.js
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Press Ctrl-F5.
/* Any JavaScript here will be loaded for all users on every page load. */
$(function () {
const namespace = mw.config.get('wgNamespaceNumber');
const now = new Date();
const day = String(now.getDate()).padStart(2, '0');
const month = String(now.getMonth() + 1).padStart(2, '0');
const year = now.getFullYear();
var messageCurrentDate = `${day}.${month}.${year}`;
/* Prepare information about current Namespace Number; namespace_info can be added to the message below and displayed on all of the pages.*/
/*
var namespace_info = 'ID obecnego namespace: ' + namespace;
*/
/* Add a message to all of the pages regardless of the Namespace Number.*/
/*
var message = 'Referując do WikiHum należy używać <b>identyfikatorów Dariah.lab</b> (ang. Dariah.lab. ID).';
$('<div class="global-site-message">' + message + '</div>')
.prependTo('#content');
*/
if( namespace === 120 ){
const pageName = mw.config.get('wgPageName');
const entityId = mw.config.get('wgTitle');
const propertyId = 'P187'; /*ID of the property "Dariah.lab ID"*/
var messageLabel = '';
var messageEdit = '';
var messageDariahLab = '';
const userLang = mw.config.get('wgUserLanguage');
$.getJSON(mw.util.wikiScript('api'), {
action: 'wbgetentities',
ids: entityId,
props: 'labels',
languages: userLang,
format: 'json'
}, function (data) {
const entity = data.entities[entityId];
messageLabel = entity.labels[userLang].value;
/* $('<div class="global-site-message">' + messageLabel + userLang + '</div>').prependTo('#content'); */
});
$.getJSON(mw.util.wikiScript('api'), {
action: 'query',
prop: 'revisions',
titles: pageName,
rvprop: 'timestamp',
format: 'json'
}, function (data) {
var pages = data.query.pages;
var page = pages[Object.keys(pages)[0]];
if (page && page.revisions && page.revisions.length > 0) {
const lastEdit = new Date(page.revisions[0].timestamp);
const editDay = String(lastEdit.getDate()).padStart(2, '0');
const editMonth = String(lastEdit.getMonth() + 1).padStart(2, '0');
const editYear = lastEdit.getFullYear();
messageEdit = `${editDay}.${editMonth}.${editYear}`;
}
});
$.getJSON(mw.util.wikiScript('api'), {
action: 'wbgetentities',
ids: entityId,
format: 'json',
props: 'claims'
}, function (data) {
const entity = data.entities[entityId];
const claims = entity && entity.claims && entity.claims[propertyId];
if (claims && claims.length > 0) {
var dariahLabValue = claims[0].mainsnak.datavalue.value;
messageDariahLab = '<a href="http://hdl.handle.net/' + dariahLabValue + '" target="_blank">http://hdl.handle.net/' + dariahLabValue + '</a>';
}
let option1 = "<div>Referując do tego elementu użyj poniższego formatu zapisu (więcej informacji na stronie -> Referowanie do WikiHum).</div>";
let option2 = "<div>Referując do tego elementu w przypisie lub bibliografii użyj poniższego formatu zapisu (więcej informacji na stronie -> Referowanie do WikiHum).</div>";
let option3 = "<div>Referując do tego elementu należy użyć poniższego formatu zapisu (więcej informacji na stronie -> Referowanie do WikiHum).</div>";
let option4 = "<div>Referując do tego elementu w przypisie lub bibliografii należy użyć poniższego formatu zapisu (więcej informacji na stronie -> Referowanie do WikiHum).</div>";
let option5 = "<div>Jeśli chcesz dodać referencję do tego elementu, użyj poniższego formatu zapisu (więcej informacji na stronie -> Referowanie do WikiHum).</div>";
let option6 = "<div>Jeśli chcesz dodać referencję do tego elementu w przypisie lub bibliografii, użyj poniższego formatu zapisu (więcej informacji na stronie -> Referowanie do WikiHum).</div>";
$('<div class="global-site-message">' + option1 + messageLabel + ', ' + messageDariahLab + ', [ostatnia edycja strony: ' + messageEdit + ', dostęp: ' + messageCurrentDate + '].</div>
<div class="global-site-message">' + option2 + messageLabel + ', ' + messageDariahLab + ', [ostatnia edycja strony: ' + messageEdit + ', dostęp: ' + messageCurrentDate + '].</div>
<div class="global-site-message">' + option3 + messageLabel + ', ' + messageDariahLab + ', [ostatnia edycja strony: ' + messageEdit + ', dostęp: ' + messageCurrentDate + '].</div>
<div class="global-site-message">' + option4 + messageLabel + ', ' + messageDariahLab + ', [ostatnia edycja strony: ' + messageEdit + ', dostęp: ' + messageCurrentDate + '].</div>
<div class="global-site-message">' + option5 + messageLabel + ', ' + messageDariahLab + ', [ostatnia edycja strony: ' + messageEdit + ', dostęp: ' + messageCurrentDate + '].</div>
<div class="global-site-message">' + option6 + messageLabel + ', ' + messageDariahLab + ', [ostatnia edycja strony: ' + messageEdit + ', dostęp: ' + messageCurrentDate + '].</div>')
.prependTo('#content');
});
}
});