MediaWiki:Common.js: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| Line 7: | Line 7: | ||
const month = String(now.getMonth() + 1).padStart(2, '0'); | const month = String(now.getMonth() + 1).padStart(2, '0'); | ||
const year = now.getFullYear(); | const year = now.getFullYear(); | ||
const messageCurrentDate = ` | const 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.*/ | /* Prepare information about current Namespace Number; namespace_info can be added to the message below and displayed on all of the pages.*/ | ||
| Line 43: | Line 43: | ||
const editMonth = String(editDate.getMonth() + 1).padStart(2, '0'); | const editMonth = String(editDate.getMonth() + 1).padStart(2, '0'); | ||
const editYear = editDate.getFullYear(); | const editYear = editDate.getFullYear(); | ||
messageEdit = | messageEdit = `${editDay}.${editMonth}.${editYear}`; | ||
} | } | ||
}); | }); | ||
| Line 57: | Line 57: | ||
if (claims && claims.length > 0) { | if (claims && claims.length > 0) { | ||
var dariahLabValue = claims[0].mainsnak.datavalue.value; | var dariahLabValue = claims[0].mainsnak.datavalue.value; | ||
messageDariahLab = ' | messageDariahLab = '<a href="http://hdl.handle.net/' + dariahLabValue + '" target="_blank">http://hdl.handle.net/' + dariahLabValue + '</a>'; | ||
} | } | ||
$('<div class="global-site-message">' + pageName + messageDariahLab + messageEdit + messageCurrentDate + '].</div>') | $('<div class="global-site-message">' + pageName + ',' + messageDariahLab + ', [ostatnia edycja strony: ' + messageEdit + ' dostęp: ' + messageCurrentDate + '].</div>') | ||
.prependTo('#content'); | .prependTo('#content'); | ||
}); | }); | ||
} | } | ||
}); | }); | ||
Revision as of 16:52, 24 May 2025
/* 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();
const 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 messageEdit = '';
var messageDariahLab = '';
$.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(editDate.getDate()).padStart(2, '0');
const editMonth = String(editDate.getMonth() + 1).padStart(2, '0');
const editYear = editDate.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>';
}
$('<div class="global-site-message">' + pageName + ',' + messageDariahLab + ', [ostatnia edycja strony: ' + messageEdit + ' dostęp: ' + messageCurrentDate + '].</div>')
.prependTo('#content');
});
}
});