Upload files to "renderer"

This commit is contained in:
2026-11-11 00:09:12 +00:00
parent b2e527f8e7
commit 82de74d545
5 changed files with 1465 additions and 0 deletions
+160
View File
@@ -0,0 +1,160 @@
// Snippets menu: common wikitext pieces, grouped, with a filter box.
(function () {
'use strict';
const NEEDS = {
Cite: 'This needs the Cite extension (the references app). If your wiki does not have it installed, the tags will show up as plain text instead of working footnotes.',
SyntaxHighlight: 'This needs the SyntaxHighlight extension on your wiki.',
Math: 'This needs the Math extension on your wiki.',
Poem: 'This needs the Poem feature (built in on recent MediaWiki, an extension on old ones).',
ParserFunctions: 'This needs the ParserFunctions extension on your wiki.',
Gallery: 'Gallery tags are built in, but the files you list must exist on your wiki.'
};
const W = (g, label, a, b, ph, extra) => Object.assign({ g, label, kind: 'wrap', a, b, ph }, extra || {});
const T = (g, label, text, extra) => Object.assign({ g, label, kind: 'text', text }, extra || {});
const B = (g, label, text, extra) => Object.assign({ g, label, kind: 'block', text }, extra || {});
const ITEMS = [
W('Escaping', 'nowiki', '<nowiki>', '</nowiki>', 'plain text'),
W('Escaping', 'pre (preformatted)', '<pre>', '</pre>', 'preformatted text'),
W('Escaping', 'Comment', '<!-- ', ' -->', 'a note only editors see'),
W('Escaping', 'kbd (keyboard key)', '<kbd>', '</kbd>', 'Ctrl'),
W('Escaping', 'code', '<code>', '</code>', 'code'),
T('Escaping', 'Non-breaking space', '&nbsp;'),
T('Escaping', 'Line break', '<br />'),
T('Escaping', 'Clear floats', '<div style="clear:both"></div>'),
W('References', 'ref (footnote)', '<ref>', '</ref>', 'Reference text', { needs: 'Cite' }),
W('References', 'Named ref', '<ref name="name">', '</ref>', 'Reference text', { needs: 'Cite' }),
T('References', 'Reuse a named ref', '<ref name="name" />', { needs: 'Cite' }),
W('References', 'Grouped ref', '<ref group="note">', '</ref>', 'Note text', { needs: 'Cite' }),
B('References', 'references list', '<references />', { needs: 'Cite' }),
B('References', 'references for a group', '<references group="note" />', { needs: 'Cite' }),
B('References', 'Reflist template', '{{Reflist}}', { needs: 'Cite', hint: 'Needs the Reflist template as well.' }),
W('Page control', 'noinclude', '<noinclude>', '</noinclude>', 'only on this page'),
W('Page control', 'includeonly', '<includeonly>', '</includeonly>', 'only where transcluded'),
W('Page control', 'onlyinclude', '<onlyinclude>', '</onlyinclude>', 'the part that is transcluded'),
B('Page control', '#REDIRECT', '#REDIRECT [[Target page]]'),
B('Page control', 'Category', '[[Category:Name]]'),
T('Page control', 'Link to a category', '[[:Category:Name]]'),
B('Page control', 'DEFAULTSORT', '{{DEFAULTSORT:Sort key}}'),
B('Page control', '__TOC__', '__TOC__'),
B('Page control', '__NOTOC__', '__NOTOC__'),
B('Page control', '__FORCETOC__', '__FORCETOC__'),
B('Page control', '__NOEDITSECTION__', '__NOEDITSECTION__'),
T('Magic words', 'Signature and date', '~~~~'),
T('Magic words', 'PAGENAME', '{{PAGENAME}}'),
T('Magic words', 'SITENAME', '{{SITENAME}}'),
T('Magic words', 'CURRENTYEAR', '{{CURRENTYEAR}}'),
T('Magic words', 'Anchor', '<span id="anchor-name"></span>'),
T('Magic words', 'Link to a section', '[[#Section name|link text]]'),
T('Magic words', 'Link to a page section', '[[Page name#Section name|link text]]'),
B('Layout', 'Definition list', '; Term\n: Definition'),
B('Layout', 'Collapsible box', '{| class="wikitable mw-collapsible mw-collapsed"\n! Click to expand\n|-\n| Hidden content\n|}'),
B('Layout', 'Gallery', '<gallery>\nFile:Example1.jpg|Caption one\nFile:Example2.jpg|Caption two\n</gallery>', { needs: 'Gallery' }),
B('Layout', 'Two columns', '{| style="width:100%"\n| style="width:50%; vertical-align:top" |\nLeft column\n| style="width:50%; vertical-align:top" |\nRight column\n|}'),
B('Layout', 'Side box (floats right)', '<div style="float:right; width:250px; border:1px solid #aaa; background:#f9f9f9; padding:8px; margin:0 0 8px 12px">\nSide box text\n</div>'),
B('Layout', 'Note box', '<div style="border:1px solid #a2a9b1; background:#eaf3ff; padding:8px 12px; margin:8px 0">\n\'\'\'Note:\'\'\' Text of the note.\n</div>'),
B('Layout', 'Warning box', '<div style="border:1px solid #d33; background:#fee7e6; padding:8px 12px; margin:8px 0">\n\'\'\'Warning:\'\'\' Text of the warning.\n</div>'),
W('Extensions', 'syntaxhighlight', '<syntaxhighlight lang="text">', '</syntaxhighlight>', 'code', { needs: 'SyntaxHighlight' }),
W('Extensions', 'math', '<math>', '</math>', 'x^2 + y^2 = z^2', { needs: 'Math' }),
W('Extensions', 'poem', '<poem>', '</poem>', 'Line one\nLine two', { needs: 'Poem' }),
T('Extensions', '#if', '{{#if: condition | then | else }}', { needs: 'ParserFunctions' }),
T('Extensions', '#switch', '{{#switch: value\n | a = result a\n | b = result b\n | #default = other\n}}', { needs: 'ParserFunctions' }),
T('Extensions', '#expr', '{{#expr: 1 + 2 }}', { needs: 'ParserFunctions' })
];
function init(opts) {
const api = opts.api;
const toast = opts.toast;
const btn = document.getElementById('btnSnippets');
if (!btn) return;
const pop = document.createElement('div');
pop.className = 'pop snippets';
pop.hidden = true;
document.body.appendChild(pop);
function close() { pop.hidden = true; }
function insertItem(it) {
close();
if (it.kind === 'wrap') api.toggleWrap(it.a, it.b, it.ph);
else if (it.kind === 'block') api.insertBlock(it.text);
else api.insert(it.text);
if (it.needs) toast(NEEDS[it.needs], 7000);
}
function build(filter) {
const list = pop.querySelector('.snList');
list.innerHTML = '';
const f = filter.trim().toLowerCase();
let group = null;
ITEMS.forEach((it) => {
const hay = (it.label + ' ' + it.g + ' ' + (it.needs || '') + ' ' + (it.text || it.a || '')).toLowerCase();
if (f && hay.indexOf(f) < 0) return;
if (it.g !== group) {
group = it.g;
const h = document.createElement('div');
h.className = 'snGroup';
h.textContent = group;
list.appendChild(h);
}
const b = document.createElement('button');
b.className = 'tm';
b.textContent = it.label + (it.needs ? ' *' : '');
b.title = it.needs ? NEEDS[it.needs] : (it.hint || '');
b.addEventListener('mousedown', (e) => { if (e.target === b) e.preventDefault(); });
b.addEventListener('click', () => insertItem(it));
list.appendChild(b);
});
if (!list.children.length) {
const n = document.createElement('div');
n.className = 'snGroup';
n.textContent = 'Nothing matches.';
list.appendChild(n);
}
}
function open() {
pop.innerHTML = '';
const t = document.createElement('div');
t.className = 'popTitle';
t.textContent = 'Snippets';
pop.appendChild(t);
const q = document.createElement('input');
q.type = 'search';
q.placeholder = 'Filter snippets';
q.className = 'snFilter';
q.addEventListener('input', () => build(q.value));
pop.appendChild(q);
const list = document.createElement('div');
list.className = 'snList';
pop.appendChild(list);
const note = document.createElement('div');
note.className = 'snNote';
note.textContent = '* Needs an extension on your wiki. Footnotes (<ref> and <references />) need the Cite extension, the references app. If your wiki does not have it installed, they will not work and show as plain text.';
pop.appendChild(note);
build('');
pop.hidden = false;
const r = btn.getBoundingClientRect();
pop.style.left = Math.max(6, Math.min(r.left, window.innerWidth - pop.offsetWidth - 8)) + 'px';
pop.style.top = (r.bottom + 4) + 'px';
q.focus();
}
btn.addEventListener('mousedown', (e) => e.preventDefault());
btn.addEventListener('click', () => { if (pop.hidden) open(); else close(); });
document.addEventListener('mousedown', (e) => {
if (!pop.hidden && !pop.contains(e.target) && e.target !== btn) close();
});
document.addEventListener('keydown', (e) => { if (e.key === 'Escape' && !pop.hidden) close(); });
}
window.SwiftSnippets = { init, ITEMS };
})();