1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-12-04 18:19:54 +00:00

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 "title"}}{{template "interwiki map"}}{{end}}
{{define "body"}}
<main class="main-width">
<h1>{{template "interwiki map"}}</h1>{{$emojies := .Emojies}}
{{if len .Entries}}
<ul>
{{range $i, $wiki := .Entries}}
{{define "static map"}}{{$emojies := .Emojies}}
{{if len .Entries}}
<ul>
{{range $i, $wiki := .Entries}}
<li>
<dl>
<dt>Names</dt>
{{range .Names}}<dd>{{.}}</dd>{{end}}
{{range .Names}}<dd>{{.}}</dd>{{end}}
<dt>Description</dt>
<dd>{{.Description}}</dd>
@ -21,14 +19,68 @@
<dt>URL</dt>
<dd><a href="{{.URL}}">{{.URL}}</a></dd>
<dt>Link format</dt>
<dd>{{.LinkFormat}}</dd>
<dt>Link href format</dt>
<dd>{{.LinkHrefFormat}}</dd>
<dt>Img src format</dt>
<dd>{{.ImgSrcFormat}}</dd>
</dl>
</li>
{{end}}
</ul>
{{end}}
</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}}
<p>No interwiki map set.</p>
{{template "static map" .}}
{{end}}
</main>
{{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 []string
CanEdit bool
Error string
}
func viewInterwiki(meta viewutil.Meta) {
@ -37,6 +38,7 @@ func viewInterwiki(meta viewutil.Meta) {
Entries: theMap.list,
Emojies: emojiesForEngines(theMap.list),
CanEdit: meta.U.Group == "admin",
Error: "",
})
}

View File

@ -11,21 +11,20 @@ type WikiEngine int
const (
Mycorrhiza WikiEngine = iota
OddMuse
MediaWiki
MoinMoin1
MoinMoin2
DokuWiki
Agora
// Generic is any website.
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.
// TODO: reconsider
func (we WikiEngine) EmojiWithName() string {
switch we {
case Mycorrhiza:
return "🍄 Mycorrhiza"
case OddMuse:
case Agora:
return "ἀ Agora"
/*case OddMuse: Might return them in the future
return "🐫 OddMuse"
case MediaWiki:
return "🌻 MediaWiki"
@ -34,7 +33,7 @@ func (we WikiEngine) EmojiWithName() string {
case MoinMoin2:
return "Ⓜ️ MoinMoin 2.*"
case DokuWiki:
return "📝 DokuWiki"
return "📝 DokuWiki"*/
default:
return "🌐 Generic"
}
@ -67,11 +66,7 @@ type Wiki struct {
var wikiEnginesLookup = map[string]WikiEngine{
"mycorrhiza": Mycorrhiza,
"oddmuse": OddMuse,
"mediawiki": MediaWiki,
"moin1": MoinMoin1,
"moin2": MoinMoin2,
"dokuwiki": DokuWiki,
"agora": Agora,
"generic": Generic,
}

View File

@ -865,4 +865,21 @@ dt {
}
dd + dt {
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;
}