MediaWiki:Common.js: Difference between revisions
Appearance
No edit summary |
No edit summary |
||
| Line 8: | Line 8: | ||
// Only purge once | // Only purge once | ||
if (!location.search.includes(' | if (!location.search.includes('mw_purged=1')) { | ||
new mw.Api().get({ | new mw.Api().get({ | ||
action: 'query', | action: 'query', | ||
| Line 19: | Line 18: | ||
const token = data.query.tokens.csrftoken; | const token = data.query.tokens.csrftoken; | ||
new mw.Api().post({ | new mw.Api().post({ | ||
action: 'purge', | action: 'purge', | ||
| Line 27: | Line 25: | ||
// Reload the dashboard normally, marked as purged | // Reload the dashboard normally, marked as purged | ||
const url = mw.util.getUrl(title, { | const url = mw.util.getUrl(title, { mw_purged: 1 }); | ||
location.replace(url); | location.replace(url); | ||
}); | }); | ||
Revision as of 21:30, 14 February 2026
/************************************************************
* 1. AUTO‑PURGE FOR ALL DASHBOARD:* PAGES
************************************************************/
$(function () {
const title = mw.config.get('wgPageName');
if (title && title.startsWith('Dashboard:')) {
// Only purge once
if (!location.search.includes('mw_purged=1')) {
new mw.Api().get({
action: 'query',
meta: 'tokens',
type: 'csrf'
}).done(function (data) {
const token = data.query.tokens.csrftoken;
new mw.Api().post({
action: 'purge',
titles: title,
token: token
}).always(function () {
// Reload the dashboard normally, marked as purged
const url = mw.util.getUrl(title, { mw_purged: 1 });
location.replace(url);
});
});
}
}
});
/************************************************************
* 2. AUTOMATIC GEOCODING (your existing code, unchanged)
************************************************************/
$(function() {
const addr = $('input[name="Place[address]"]');
const lat = $('input[name="Place[latitude]"]');
const lon = $('input[name="Place[longitude]"]');
console.log("Address fields found:", addr.length);
if (addr.length === 0) {
console.log("Address field not found");
return;
}
addr.on('change', function() {
console.log("Address changed:", addr.val());
const q = encodeURIComponent(addr.val());
if (!q) return;
const url = 'https://nominatim.openstreetmap.org/search?format=json&q=' + q;
$.getJSON(url, function(data) {
if (data && data.length > 0) {
lat.val(data[0].lat);
lon.val(data[0].lon);
}
});
});
});
/************************************************************
* 3. OSM LINK BELOW LONGITUDE FIELD (your existing code)
************************************************************/
$(function() {
const lat = $('input[name="Place[latitude]"]');
const lon = $('input[name="Place[longitude]"]');
// Add a small container under the longitude field
const linkBox = $('<div id="pf-osm-link" style="margin-top:4px;"></div>');
lon.closest('td').append(linkBox);
function updateOSMLink() {
const la = lat.val();
const lo = lon.val();
if (la && lo) {
const url = 'https://www.openstreetmap.org/?mlat=' + la + '&mlon=' + lo;
linkBox.html('<a href="' + url + '" target="_blank">View on OpenStreetMap</a>');
} else {
linkBox.empty();
}
}
// Update whenever coordinates change
lat.on('change keyup', updateOSMLink);
lon.on('change keyup', updateOSMLink);
// Initial update (for editing existing pages)
updateOSMLink();
});