MediaWiki:Common.js: Difference between revisions
Appearance
No edit summary |
No edit summary |
||
| Line 7: | Line 7: | ||
if (title && title.startsWith('Dashboard:')) { | if (title && title.startsWith('Dashboard:')) { | ||
// Only purge once | // Only purge once | ||
if (! | if (!location.search.includes('purged=1')) { | ||
// | // Get a CSRF token first | ||
new mw.Api().get({ | |||
action: 'purge', | action: 'query', | ||
meta: 'tokens', | |||
type: 'csrf' | |||
}).done(function (data) { | |||
const token = data.query.tokens.csrftoken; | |||
// Perform the silent purge | |||
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, { purged: 1 }); | |||
location.replace(url); | |||
}); | |||
}); | }); | ||
} | } | ||
} | } | ||
}); | }); | ||
Revision as of 21:27, 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('purged=1')) {
// Get a CSRF token first
new mw.Api().get({
action: 'query',
meta: 'tokens',
type: 'csrf'
}).done(function (data) {
const token = data.query.tokens.csrftoken;
// Perform the silent purge
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, { 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();
});