Widget: DataExporter: Difference between revisions
From LINKS Community Center
Eschmidt (talk | contribs) No edit summary |
Eschmidt (talk | contribs) No edit summary |
||
Line 7: | Line 7: | ||
'use strict'; | 'use strict'; | ||
const | const permittedUsers = ['Eschmidt']; | ||
const dat = '/index.php?title=Category:Disaster_Community_Technology&action=raw'; | const dat = '/index.php?title=Category:Disaster_Community_Technology&action=raw'; | ||
const dat2 = '/index.php?title=Category:Use_Cases&action=raw'; | |||
const | |||
async function exportData() { | async function exportData() { | ||
const output = document.getElementById('output'); | const output = document.getElementById('output'); | ||
const usrData = await fetch( | // Check user. | ||
const usrData = await fetch('/api.php?action=query&meta=userinfo&format=json').then(rsp => rsp.json()); | |||
if (!permittedUsers.includes(usrData?.query?.userinfo?.name)) { | if (!permittedUsers.includes(usrData?.query?.userinfo?.name)) { | ||
output.innerHTML = '<span style="color:red; font-size:large">Access Denied</span>'; | output.innerHTML = '<span style="color:red; font-size:large">Access Denied</span>'; | ||
Line 21: | Line 21: | ||
} | } | ||
const schema = await fetch( | const schema = await fetch(dat2).then(rsp => rsp.text()); | ||
const doc = (new DOMParser).parseFromString(schema, 'text/xml'); | const doc = (new DOMParser).parseFromString(schema, 'text/xml'); | ||
Line 29: | Line 29: | ||
output.innerHTML += prop + ' | ' + label + '<br>'; | output.innerHTML += prop + ' | ' + label + '<br>'; | ||
} | } | ||
} | } | ||
</script> | </script> |