Widget:Autofill
From The Observatory
<script> const button = document.querySelector('#autofill');
button.addEventListener('click', function () { // Disable button during request button.disabled = true; button.textContent = 'Loading...';
// Extract ea-title from URL query string const urlParams = new URLSearchParams(window.location.search); const eaTitle = urlParams.get('ea-title') || ;
// Build the template string using ea-title as a parameter const templateCall = `No contact email addresses were found. Please ensure that each author has a user account with a valid email address or a notification contact.}`; // Use MediaWiki API to expand the template const params = new URLSearchParams({ action: 'expandtemplates', format: 'json', text: templateCall, prop: 'wikitext' });
fetch(mw.util.wikiScript('api') + '?' + params.toString(), { method: 'GET', credentials: 'same-origin', headers: { 'Accept': 'application/json' } }) .then(response => response.json()) .then(data => { const expanded = data?.expandtemplates?.wikitext || ; const textarea = document.querySelector('textarea[name="ea-to"]'); if (textarea) { textarea.value = expanded; } else { console.warn('Textarea not found: textarea[name="ea-to"]'); } }) .catch(error => { console.error('Error expanding template:', error); alert('Failed to load template content.'); }) .finally(() => { button.disabled = false; button.textContent = 'Autofill'; }); }); </script>