Interwiki: Add the add entry form

This commit is contained in:
Timur Ismagilov 2022-06-06 19:12:56 +03:00
parent 5e2c20c559
commit ee9602c745
4 changed files with 90 additions and 24 deletions

View File

@ -1,16 +1,14 @@
{{define "interwiki map"}}Interwiki map{{end}} {{define "interwiki map"}}Interwiki map{{end}}
{{define "title"}}{{template "interwiki map"}}{{end}} {{define "title"}}{{template "interwiki map"}}{{end}}
{{define "body"}} {{define "static map"}}{{$emojies := .Emojies}}
<main class="main-width"> {{if len .Entries}}
<h1>{{template "interwiki map"}}</h1>{{$emojies := .Emojies}} <ul>
{{if len .Entries}} {{range $i, $wiki := .Entries}}
<ul>
{{range $i, $wiki := .Entries}}
<li> <li>
<dl> <dl>
<dt>Names</dt> <dt>Names</dt>
{{range .Names}}<dd>{{.}}</dd>{{end}} {{range .Names}}<dd>{{.}}</dd>{{end}}
<dt>Description</dt> <dt>Description</dt>
<dd>{{.Description}}</dd> <dd>{{.Description}}</dd>
@ -21,14 +19,68 @@
<dt>URL</dt> <dt>URL</dt>
<dd><a href="{{.URL}}">{{.URL}}</a></dd> <dd><a href="{{.URL}}">{{.URL}}</a></dd>
<dt>Link format</dt> <dt>Link href format</dt>
<dd>{{.LinkFormat}}</dd> <dd>{{.LinkHrefFormat}}</dd>
<dt>Img src format</dt>
<dd>{{.ImgSrcFormat}}</dd>
</dl> </dl>
</li> </li>
{{end}} {{end}}
</ul> </ul>
{{else}}
<p>No interwiki map set.</p>
{{end}}
{{end}}
{{define "authorized map"}}
{{if .Error}}
<p class="error">{{.Error}}</p>
{{end}}
{{template "static map" .}}
<form method="post" action="/interwiki/add-entry">
<h2>Add interwiki entry</h2>
<p><a href="/help/en/interwiki">Documentation.</a></p>
<p>
<label for="names" class="required-field">Names (separated by commas):</label>
<input type="text" id="names" name="names" required
placeholder="home_wiki, hw">
</p>
<p>
<label for="url" class="required-field">URL:</label>
<input type="url" id="url" name="url" required
placeholder="https://wiki.example.org">
</p>
<p>
<label for="engine" class="required-field">Engine:</label>
<select name="engine" id="engine" required>
<option value="mycorrhiza">Mycorrhiza 🍄</option>
<option value="agora">Agora ἀ</option>
<option value="generic">Generic (any website)</option>
</select>
</p>
<p>Fill the next two fields if you have chosen <kbd>Generic</kbd> in the previous field.</p>
<p>
<label for="link-href-format">Link href attribute format string:</label>
<input type="url" id="link-href-format" name="link-href-format"
placeholder="https://wiki.example.org/view/{NAME}">
</p>
<p>
<label for="img-src-format">Image src attribute format string:</label>
<input type="url" id="img-src-format" name="img-src-format"
placeholder="https://wiki.example.org/media/{NAME}">
</p>
<input type="submit">
</form>
{{end}}
{{define "body"}}
<main class="main-width">
<h1>{{template "interwiki map"}}</h1>
{{if .CanEdit}}
{{template "authorized map" .}}
{{else}} {{else}}
<p>No interwiki map set.</p> {{template "static map" .}}
{{end}} {{end}}
</main> </main>
{{end}} {{end}}

View File

@ -29,6 +29,7 @@ type interwikiData struct {
// Emojies contains emojies that represent wiki engines. Emojies[i] is an emoji for Entries[i].Engine // Emojies contains emojies that represent wiki engines. Emojies[i] is an emoji for Entries[i].Engine
Emojies []string Emojies []string
CanEdit bool CanEdit bool
Error string
} }
func viewInterwiki(meta viewutil.Meta) { func viewInterwiki(meta viewutil.Meta) {
@ -37,6 +38,7 @@ func viewInterwiki(meta viewutil.Meta) {
Entries: theMap.list, Entries: theMap.list,
Emojies: emojiesForEngines(theMap.list), Emojies: emojiesForEngines(theMap.list),
CanEdit: meta.U.Group == "admin", CanEdit: meta.U.Group == "admin",
Error: "",
}) })
} }

View File

@ -11,21 +11,20 @@ type WikiEngine int
const ( const (
Mycorrhiza WikiEngine = iota Mycorrhiza WikiEngine = iota
OddMuse Agora
MediaWiki
MoinMoin1
MoinMoin2
DokuWiki
// Generic is any website. // Generic is any website.
Generic Generic
) )
// EmojiWithName returns a Unicode emoji that kinda represents the engine and the engine name. One day we might move to actual images. OK for now. // EmojiWithName returns a Unicode emoji that kinda represents the engine and the engine name. One day we might move to actual images. OK for now.
// TODO: reconsider
func (we WikiEngine) EmojiWithName() string { func (we WikiEngine) EmojiWithName() string {
switch we { switch we {
case Mycorrhiza: case Mycorrhiza:
return "🍄 Mycorrhiza" return "🍄 Mycorrhiza"
case OddMuse: case Agora:
return "ἀ Agora"
/*case OddMuse: Might return them in the future
return "🐫 OddMuse" return "🐫 OddMuse"
case MediaWiki: case MediaWiki:
return "🌻 MediaWiki" return "🌻 MediaWiki"
@ -34,7 +33,7 @@ func (we WikiEngine) EmojiWithName() string {
case MoinMoin2: case MoinMoin2:
return "Ⓜ️ MoinMoin 2.*" return "Ⓜ️ MoinMoin 2.*"
case DokuWiki: case DokuWiki:
return "📝 DokuWiki" return "📝 DokuWiki"*/
default: default:
return "🌐 Generic" return "🌐 Generic"
} }
@ -67,11 +66,7 @@ type Wiki struct {
var wikiEnginesLookup = map[string]WikiEngine{ var wikiEnginesLookup = map[string]WikiEngine{
"mycorrhiza": Mycorrhiza, "mycorrhiza": Mycorrhiza,
"oddmuse": OddMuse, "agora": Agora,
"mediawiki": MediaWiki,
"moin1": MoinMoin1,
"moin2": MoinMoin2,
"dokuwiki": DokuWiki,
"generic": Generic, "generic": Generic,
} }

View File

@ -866,3 +866,20 @@ dt {
dd + dt { dd + dt {
margin-top: .5rem; margin-top: .5rem;
} }
/*
* Interwiki page
* A possible improvement: show those two fields when Generic is selected, hide otherwise
*/
body[data-rrh-addr^="/interwiki"] label,
body[data-rrh-addr^="/interwiki"] input[type="text"],
body[data-rrh-addr^="/interwiki"] input[type="url"] {
display: block;
width: 100%;
max-width: 20rem;
}
.required-field::after {
color: red;
content: "*";
margin-left: .25rem;
}