mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2025-04-29 22:03:10 +00:00
Interwiki: Change the fields of the entries
This commit is contained in:
parent
ee9602c745
commit
8c52e1efee
@ -20,11 +20,11 @@ func Init() {
|
|||||||
wiki := wiki // This line is required
|
wiki := wiki // This line is required
|
||||||
wiki.canonize()
|
wiki.canonize()
|
||||||
theMap.list = append(theMap.list, &wiki)
|
theMap.list = append(theMap.list, &wiki)
|
||||||
for _, prefix := range wiki.Names {
|
for _, name := range append(wiki.Aliases, wiki.Name) {
|
||||||
if _, found := theMap.byName[prefix]; found {
|
if _, found := theMap.byName[name]; found {
|
||||||
log.Fatalf("There are multiple uses of the same prefix ‘%s’\n", prefix)
|
log.Fatalf("There are multiple uses of the same name ‘%s’\n", name)
|
||||||
} else {
|
} else {
|
||||||
theMap.byName[prefix] = &wiki
|
theMap.byName[name] = &wiki
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,20 +1,23 @@
|
|||||||
{{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 "static map"}}{{$emojies := .Emojies}}
|
{{define "static map"}}
|
||||||
{{if len .Entries}}
|
{{if len .Entries}}
|
||||||
<ul>
|
<ul>
|
||||||
{{range $i, $wiki := .Entries}}
|
{{range $i, $wiki := .Entries}}
|
||||||
<li>
|
<li>
|
||||||
<dl>
|
<dl>
|
||||||
<dt>Names</dt>
|
<dt>Name</dt>
|
||||||
{{range .Names}}<dd>{{.}}</dd>{{end}}
|
<dd>{{.Name}}</dd>
|
||||||
|
|
||||||
|
<dt>Aliases</dt>
|
||||||
|
{{range .Aliases}}<dd>{{.}}</dd>{{end}}
|
||||||
|
|
||||||
<dt>Description</dt>
|
<dt>Description</dt>
|
||||||
<dd>{{.Description}}</dd>
|
<dd>{{.Description}}</dd>
|
||||||
|
|
||||||
<dt>Engine</dt>
|
<dt>Engine</dt>
|
||||||
<dd>{{index $emojies $i}}</dd>
|
<dd>{{.Engine}}</dd>
|
||||||
|
|
||||||
<dt>URL</dt>
|
<dt>URL</dt>
|
||||||
<dd><a href="{{.URL}}">{{.URL}}</a></dd>
|
<dd><a href="{{.URL}}">{{.URL}}</a></dd>
|
||||||
@ -37,14 +40,22 @@
|
|||||||
{{if .Error}}
|
{{if .Error}}
|
||||||
<p class="error">{{.Error}}</p>
|
<p class="error">{{.Error}}</p>
|
||||||
{{end}}
|
{{end}}
|
||||||
{{template "static map" .}}
|
{{if len .Entries}}
|
||||||
|
{{range $i, $wiki := .Entries}}
|
||||||
|
<!-- todo -->
|
||||||
|
{{end}}
|
||||||
|
{{end}}
|
||||||
<form method="post" action="/interwiki/add-entry">
|
<form method="post" action="/interwiki/add-entry">
|
||||||
<h2>Add interwiki entry</h2>
|
<h2>Add interwiki entry</h2>
|
||||||
<p><a href="/help/en/interwiki">Documentation.</a></p>
|
|
||||||
<p>
|
<p>
|
||||||
<label for="names" class="required-field">Names (separated by commas):</label>
|
<label for="name" class="required-field">Name:</label>
|
||||||
<input type="text" id="names" name="names" required
|
<input type="text" id="name" name="name" required
|
||||||
placeholder="home_wiki, hw">
|
placeholder="home_wiki">
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<label for="aliases">Aliases (separated by commas):</label>
|
||||||
|
<input type="text" id="aliases" name="aliases"
|
||||||
|
placeholder="homewiki, hw">
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<label for="url" class="required-field">URL:</label>
|
<label for="url" class="required-field">URL:</label>
|
||||||
@ -77,6 +88,7 @@
|
|||||||
{{define "body"}}
|
{{define "body"}}
|
||||||
<main class="main-width">
|
<main class="main-width">
|
||||||
<h1>{{template "interwiki map"}}</h1>
|
<h1>{{template "interwiki map"}}</h1>
|
||||||
|
<p><a href="/help/en/interwiki">Documentation.</a></p>
|
||||||
{{if .CanEdit}}
|
{{if .CanEdit}}
|
||||||
{{template "authorized map" .}}
|
{{template "authorized map" .}}
|
||||||
{{else}}
|
{{else}}
|
||||||
|
@ -26,8 +26,6 @@ func handlerInterwiki(w http.ResponseWriter, rq *http.Request) {
|
|||||||
type interwikiData struct {
|
type interwikiData struct {
|
||||||
*viewutil.BaseData
|
*viewutil.BaseData
|
||||||
Entries []*Wiki
|
Entries []*Wiki
|
||||||
// Emojies contains emojies that represent wiki engines. Emojies[i] is an emoji for Entries[i].Engine
|
|
||||||
Emojies []string
|
|
||||||
CanEdit bool
|
CanEdit bool
|
||||||
Error string
|
Error string
|
||||||
}
|
}
|
||||||
@ -36,15 +34,7 @@ func viewInterwiki(meta viewutil.Meta) {
|
|||||||
viewutil.ExecutePage(meta, chainInterwiki, interwikiData{
|
viewutil.ExecutePage(meta, chainInterwiki, interwikiData{
|
||||||
BaseData: &viewutil.BaseData{},
|
BaseData: &viewutil.BaseData{},
|
||||||
Entries: theMap.list,
|
Entries: theMap.list,
|
||||||
Emojies: emojiesForEngines(theMap.list),
|
|
||||||
CanEdit: meta.U.Group == "admin",
|
CanEdit: meta.U.Group == "admin",
|
||||||
Error: "",
|
Error: "",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func emojiesForEngines(list []*Wiki) (emojies []string) {
|
|
||||||
for _, entry := range list {
|
|
||||||
emojies = append(emojies, entry.Engine.EmojiWithName())
|
|
||||||
}
|
|
||||||
return emojies
|
|
||||||
}
|
|
||||||
|
@ -7,93 +7,69 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// WikiEngine is an enumeration of supported interwiki targets.
|
// WikiEngine is an enumeration of supported interwiki targets.
|
||||||
type WikiEngine int
|
type WikiEngine string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Mycorrhiza WikiEngine = iota
|
Mycorrhiza WikiEngine = "mycorrhiza"
|
||||||
Agora
|
Agora WikiEngine = "agora"
|
||||||
// Generic is any website.
|
// Generic is any website.
|
||||||
Generic
|
Generic WikiEngine = "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.
|
func (we WikiEngine) Valid() bool {
|
||||||
// TODO: reconsider
|
|
||||||
func (we WikiEngine) EmojiWithName() string {
|
|
||||||
switch we {
|
switch we {
|
||||||
case Mycorrhiza:
|
case Mycorrhiza, Agora, Generic:
|
||||||
return "🍄 Mycorrhiza"
|
return true
|
||||||
case Agora:
|
|
||||||
return "ἀ Agora"
|
|
||||||
/*case OddMuse: Might return them in the future
|
|
||||||
return "🐫 OddMuse"
|
|
||||||
case MediaWiki:
|
|
||||||
return "🌻 MediaWiki"
|
|
||||||
case MoinMoin1:
|
|
||||||
return "Ⓜ️ MoinMoin 1.9"
|
|
||||||
case MoinMoin2:
|
|
||||||
return "Ⓜ️ MoinMoin 2.*"
|
|
||||||
case DokuWiki:
|
|
||||||
return "📝 DokuWiki"*/
|
|
||||||
default:
|
|
||||||
return "🌐 Generic"
|
|
||||||
}
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wiki is an entry in the interwiki map.
|
// Wiki is an entry in the interwiki map.
|
||||||
type Wiki struct {
|
type Wiki struct {
|
||||||
// Names is a slice of link prefices that correspond to this wiki.
|
// Name is the name of the wiki, and is also one of the possible prefices.
|
||||||
Names []string `json:"names"`
|
Name string `json:"name"`
|
||||||
|
|
||||||
|
// Aliases are alternative prefices you can use instead of Name. This slice can be empty.
|
||||||
|
Aliases []string `json:"aliases,omitempty"`
|
||||||
|
|
||||||
// URL is the address of the wiki.
|
// URL is the address of the wiki.
|
||||||
URL string `json:"url"`
|
URL string `json:"url"`
|
||||||
|
|
||||||
// LinkHrefFormat is a format string for interwiki links. See Mycomarkup internal docs hidden deep inside for more information.
|
// LinkHrefFormat is a format string for interwiki links. See Mycomarkup internal docs hidden deep inside for more information.
|
||||||
//
|
//
|
||||||
// This field is optional. For other wikis, it is automatically set to <URL>/{NAME}; for Mycorrhiza wikis, it is automatically set to <URL>/hypha/{NAME}}.
|
// This field is optional. If it is not set, it is derived from other data. See the code.
|
||||||
LinkHrefFormat string `json:"link_href_format"`
|
LinkHrefFormat string `json:"link_href_format"`
|
||||||
|
|
||||||
ImgSrcFormat string `json:"img_src_format"`
|
ImgSrcFormat string `json:"img_src_format"`
|
||||||
|
|
||||||
// Description is a plain-text description of the wiki.
|
// Description is a plain-text description of the wiki. Can be empty.
|
||||||
Description string `json:"description"`
|
Description string `json:"description,omitempty"`
|
||||||
|
|
||||||
// Engine is the engine of the wiki. This field is not set in JSON.
|
// Engine is the engine of the wiki. Invalid values will result in a start-up error.
|
||||||
Engine WikiEngine `json:"-"`
|
Engine WikiEngine `json:"engine"`
|
||||||
|
|
||||||
// EngineString is a string name of the engine. It is then converted to Engine. See the code to learn the supported values. All other values will result in an error.
|
|
||||||
EngineString string `json:"engine"`
|
|
||||||
}
|
|
||||||
|
|
||||||
var wikiEnginesLookup = map[string]WikiEngine{
|
|
||||||
"mycorrhiza": Mycorrhiza,
|
|
||||||
"agora": Agora,
|
|
||||||
"generic": Generic,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Wiki) canonize() {
|
func (w *Wiki) canonize() {
|
||||||
if engine, ok := wikiEnginesLookup[w.EngineString]; ok {
|
switch {
|
||||||
w.Engine = engine
|
case w.Name == "":
|
||||||
w.EngineString = "" // Ain't gonna need it anymore
|
|
||||||
} else {
|
|
||||||
log.Fatalf("Unknown engine ‘%s’\n", w.EngineString)
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(w.Names) == 0 {
|
|
||||||
log.Fatalln("Cannot have a wiki in the interwiki map with no name")
|
log.Fatalln("Cannot have a wiki in the interwiki map with no name")
|
||||||
|
case w.URL == "":
|
||||||
|
log.Fatalf("Wiki ‘%s’ has no URL\n", w.Name)
|
||||||
|
case !w.Engine.Valid():
|
||||||
|
log.Fatalf("Unknown engine ‘%s’ for wiki ‘%s’\n", w.Engine, w.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
if w.URL == "" {
|
w.Name = util.CanonicalName(w.Name)
|
||||||
log.Fatalf("Wiki ‘%s’ has no URL\n", w.Names[0])
|
for i, alias := range w.Aliases {
|
||||||
}
|
w.Aliases[i] = util.CanonicalName(alias)
|
||||||
|
|
||||||
for i, prefix := range w.Names {
|
|
||||||
w.Names[i] = util.CanonicalName(prefix)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if w.LinkHrefFormat == "" {
|
if w.LinkHrefFormat == "" {
|
||||||
switch w.Engine {
|
switch w.Engine {
|
||||||
case Mycorrhiza:
|
case Mycorrhiza:
|
||||||
w.LinkHrefFormat = fmt.Sprintf("%s/hypha/{NAME}", w.URL)
|
w.LinkHrefFormat = fmt.Sprintf("%s/hypha/{NAME}", w.URL)
|
||||||
|
case Agora:
|
||||||
|
w.LinkHrefFormat = fmt.Sprintf("%s/node/{NAME}", w.URL)
|
||||||
default:
|
default:
|
||||||
w.LinkHrefFormat = fmt.Sprintf("%s/{NAME}", w.URL)
|
w.LinkHrefFormat = fmt.Sprintf("%s/{NAME}", w.URL)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user