MediaWiki:Common.js: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| Line 51: | Line 51: | ||
messageDariahId = ` Wartość identyfikatora Dariah.lab: (${propertyId}): <strong>${dariahLabValue}</strong>`; | messageDariahId = ` Wartość identyfikatora Dariah.lab: (${propertyId}): <strong>${dariahLabValue}</strong>`; | ||
} | } | ||
$('<div class="global-site-message">' + pageName + ', http://hdl.handle.net/' + dariahLabValue + ', [ostatnia edycja strony: ' + messageEdit + 'dostęp ].</div>') | $('<div class="global-site-message">' + pageName + ', http://hdl.handle.net/' + dariahLabValue + ', [ostatnia edycja strony: ' + messageEdit + 'dostęp ].</div>') | ||
.prependTo('#content'); | .prependTo('#content'); | ||
}); | |||
} | } | ||
}); | }); | ||
Revision as of 13:05, 24 May 2025
/* Any JavaScript here will be loaded for all users on every page load. */
$(function () {
const namespace = mw.config.get('wgNamespaceNumber');
/* 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 dariahLabValue = '';
$.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) {
var lastEdit = new Date(page.revisions[0].timestamp);
messageEdit = 'Data ostatniej edycji: ' + lastEdit.toLocaleString();
}
});
$.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) {
dariahLabValue = claims[0].mainsnak.datavalue.value;
messageDariahId = ` Wartość identyfikatora Dariah.lab: (${propertyId}): <strong>${dariahLabValue}</strong>`;
}
$('<div class="global-site-message">' + pageName + ', http://hdl.handle.net/' + dariahLabValue + ', [ostatnia edycja strony: ' + messageEdit + 'dostęp ].</div>')
.prependTo('#content');
});
}
});