Fix some of those weird imports
This commit is contained in:
parent
6d2df119d8
commit
bd155622af
@ -1,14 +1,15 @@
|
|||||||
package categories
|
package categories
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/bouncepaw/mycorrhiza/internal/user"
|
|
||||||
"github.com/bouncepaw/mycorrhiza/util"
|
|
||||||
"github.com/bouncepaw/mycorrhiza/web/viewutil"
|
|
||||||
"github.com/gorilla/mux"
|
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/bouncepaw/mycorrhiza/internal/user"
|
||||||
|
"github.com/bouncepaw/mycorrhiza/util"
|
||||||
|
"github.com/bouncepaw/mycorrhiza/web/viewutil"
|
||||||
|
"github.com/gorilla/mux"
|
||||||
)
|
)
|
||||||
|
|
||||||
// InitHandlers initializes HTTP handlers for the given router. Call somewhere in package web.
|
// InitHandlers initializes HTTP handlers for the given router. Call somewhere in package web.
|
||||||
|
|||||||
@ -2,10 +2,9 @@ package categories
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"embed"
|
"embed"
|
||||||
viewutil2 "github.com/bouncepaw/mycorrhiza/web/viewutil"
|
|
||||||
"log"
|
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
|
||||||
|
"github.com/bouncepaw/mycorrhiza/web/viewutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
const ruTranslation = `
|
const ruTranslation = `
|
||||||
@ -31,46 +30,26 @@ const ruTranslation = `
|
|||||||
var (
|
var (
|
||||||
//go:embed *.html
|
//go:embed *.html
|
||||||
fs embed.FS
|
fs embed.FS
|
||||||
viewListChain, viewPageChain, viewCardChain, viewEditChain viewutil2.Chain
|
viewListChain, viewPageChain, viewCardChain, viewEditChain viewutil.Chain
|
||||||
)
|
)
|
||||||
|
|
||||||
func prepareViews() {
|
func prepareViews() {
|
||||||
viewCardChain = viewutil2.CopyEnRuWith(fs, "view_card.html", ruTranslation)
|
viewCardChain = viewutil.CopyEnRuWith(fs, "view_card.html", ruTranslation)
|
||||||
viewListChain = viewutil2.CopyEnRuWith(fs, "view_list.html", ruTranslation)
|
viewListChain = viewutil.CopyEnRuWith(fs, "view_list.html", ruTranslation)
|
||||||
viewPageChain = viewutil2.CopyEnRuWith(fs, "view_page.html", ruTranslation)
|
viewPageChain = viewutil.CopyEnRuWith(fs, "view_page.html", ruTranslation)
|
||||||
viewEditChain = viewutil2.CopyEnRuWith(fs, "view_edit.html", ruTranslation)
|
viewEditChain = viewutil.CopyEnRuWith(fs, "view_edit.html", ruTranslation)
|
||||||
}
|
|
||||||
|
|
||||||
type cardData struct {
|
|
||||||
HyphaName string
|
|
||||||
Categories []string
|
|
||||||
GivenPermissionToModify bool
|
|
||||||
}
|
|
||||||
|
|
||||||
// CategoryCard is the little sidebar that is shown nearby the hypha view.
|
|
||||||
func CategoryCard(meta viewutil2.Meta, hyphaName string) string {
|
|
||||||
var buf strings.Builder
|
|
||||||
err := viewCardChain.Get(meta).ExecuteTemplate(&buf, "category card", cardData{
|
|
||||||
HyphaName: hyphaName,
|
|
||||||
Categories: CategoriesWithHypha(hyphaName),
|
|
||||||
GivenPermissionToModify: meta.U.CanProceed("add-to-category"),
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
}
|
|
||||||
return buf.String()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type catData struct {
|
type catData struct {
|
||||||
*viewutil2.BaseData
|
*viewutil.BaseData
|
||||||
CatName string
|
CatName string
|
||||||
Hyphae []string
|
Hyphae []string
|
||||||
GivenPermissionToModify bool
|
GivenPermissionToModify bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func categoryEdit(meta viewutil2.Meta, catName string) {
|
func categoryEdit(meta viewutil.Meta, catName string) {
|
||||||
viewutil2.ExecutePage(meta, viewEditChain, catData{
|
viewutil.ExecutePage(meta, viewEditChain, catData{
|
||||||
BaseData: &viewutil2.BaseData{
|
BaseData: &viewutil.BaseData{
|
||||||
Addr: "/edit-category/" + catName,
|
Addr: "/edit-category/" + catName,
|
||||||
},
|
},
|
||||||
CatName: catName,
|
CatName: catName,
|
||||||
@ -79,9 +58,9 @@ func categoryEdit(meta viewutil2.Meta, catName string) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func categoryPage(meta viewutil2.Meta, catName string) {
|
func categoryPage(meta viewutil.Meta, catName string) {
|
||||||
viewutil2.ExecutePage(meta, viewPageChain, catData{
|
viewutil.ExecutePage(meta, viewPageChain, catData{
|
||||||
BaseData: &viewutil2.BaseData{
|
BaseData: &viewutil.BaseData{
|
||||||
Addr: "/category/" + catName,
|
Addr: "/category/" + catName,
|
||||||
},
|
},
|
||||||
CatName: catName,
|
CatName: catName,
|
||||||
@ -91,15 +70,15 @@ func categoryPage(meta viewutil2.Meta, catName string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type listData struct {
|
type listData struct {
|
||||||
*viewutil2.BaseData
|
*viewutil.BaseData
|
||||||
Categories []string
|
Categories []string
|
||||||
}
|
}
|
||||||
|
|
||||||
func categoryList(meta viewutil2.Meta) {
|
func categoryList(meta viewutil.Meta) {
|
||||||
cats := listOfCategories()
|
cats := listOfCategories()
|
||||||
sort.Strings(cats)
|
sort.Strings(cats)
|
||||||
viewutil2.ExecutePage(meta, viewListChain, listData{
|
viewutil.ExecutePage(meta, viewListChain, listData{
|
||||||
BaseData: &viewutil2.BaseData{
|
BaseData: &viewutil.BaseData{
|
||||||
Addr: "/category",
|
Addr: "/category",
|
||||||
},
|
},
|
||||||
Categories: cats,
|
Categories: cats,
|
||||||
|
|||||||
24
help/web.go
24
help/web.go
@ -2,19 +2,21 @@ package help
|
|||||||
|
|
||||||
// stuff.go is used for meta stuff about the wiki or all hyphae at once.
|
// stuff.go is used for meta stuff about the wiki or all hyphae at once.
|
||||||
import (
|
import (
|
||||||
"git.sr.ht/~bouncepaw/mycomarkup/v5"
|
|
||||||
"github.com/bouncepaw/mycorrhiza/mycoopts"
|
|
||||||
viewutil2 "github.com/bouncepaw/mycorrhiza/web/viewutil"
|
|
||||||
"github.com/gorilla/mux"
|
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/bouncepaw/mycorrhiza/mycoopts"
|
||||||
|
"github.com/bouncepaw/mycorrhiza/web/viewutil"
|
||||||
|
|
||||||
|
"git.sr.ht/~bouncepaw/mycomarkup/v5"
|
||||||
"git.sr.ht/~bouncepaw/mycomarkup/v5/mycocontext"
|
"git.sr.ht/~bouncepaw/mycomarkup/v5/mycocontext"
|
||||||
|
|
||||||
|
"github.com/gorilla/mux"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
chain viewutil2.Chain
|
chain viewutil.Chain
|
||||||
ruTranslation = `
|
ruTranslation = `
|
||||||
{{define "title"}}Справка{{end}}
|
{{define "title"}}Справка{{end}}
|
||||||
{{define "entry not found"}}Статья не найдена{{end}}
|
{{define "entry not found"}}Статья не найдена{{end}}
|
||||||
@ -46,14 +48,14 @@ var (
|
|||||||
|
|
||||||
func InitHandlers(r *mux.Router) {
|
func InitHandlers(r *mux.Router) {
|
||||||
r.PathPrefix("/help").HandlerFunc(handlerHelp)
|
r.PathPrefix("/help").HandlerFunc(handlerHelp)
|
||||||
chain = viewutil2.CopyEnRuWith(fs, "view_help.html", ruTranslation)
|
chain = viewutil.CopyEnRuWith(fs, "view_help.html", ruTranslation)
|
||||||
}
|
}
|
||||||
|
|
||||||
// handlerHelp gets the appropriate documentation or tells you where you (personally) have failed.
|
// handlerHelp gets the appropriate documentation or tells you where you (personally) have failed.
|
||||||
func handlerHelp(w http.ResponseWriter, rq *http.Request) {
|
func handlerHelp(w http.ResponseWriter, rq *http.Request) {
|
||||||
// See the history of this file to resurrect the old algorithm that supported multiple languages
|
// See the history of this file to resurrect the old algorithm that supported multiple languages
|
||||||
var (
|
var (
|
||||||
meta = viewutil2.MetaFrom(w, rq)
|
meta = viewutil.MetaFrom(w, rq)
|
||||||
articlePath = strings.TrimPrefix(strings.TrimPrefix(rq.URL.Path, "/help/"), "/help")
|
articlePath = strings.TrimPrefix(strings.TrimPrefix(rq.URL.Path, "/help/"), "/help")
|
||||||
lang = "en"
|
lang = "en"
|
||||||
)
|
)
|
||||||
@ -88,14 +90,14 @@ func handlerHelp(w http.ResponseWriter, rq *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type helpData struct {
|
type helpData struct {
|
||||||
*viewutil2.BaseData
|
*viewutil.BaseData
|
||||||
ContentsHTML string
|
ContentsHTML string
|
||||||
Lang string
|
Lang string
|
||||||
}
|
}
|
||||||
|
|
||||||
func viewHelp(meta viewutil2.Meta, lang, contentsHTML, articlePath string) {
|
func viewHelp(meta viewutil.Meta, lang, contentsHTML, articlePath string) {
|
||||||
viewutil2.ExecutePage(meta, chain, helpData{
|
viewutil.ExecutePage(meta, chain, helpData{
|
||||||
BaseData: &viewutil2.BaseData{
|
BaseData: &viewutil.BaseData{
|
||||||
Addr: "/help/" + articlePath,
|
Addr: "/help/" + articlePath,
|
||||||
},
|
},
|
||||||
ContentsHTML: contentsHTML,
|
ContentsHTML: contentsHTML,
|
||||||
|
|||||||
@ -2,7 +2,7 @@ package interwiki
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"embed"
|
"embed"
|
||||||
viewutil2 "github.com/bouncepaw/mycorrhiza/web/viewutil"
|
"github.com/bouncepaw/mycorrhiza/web/viewutil"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -29,13 +29,13 @@ var (
|
|||||||
{{define "edit separately."}}Изменяйте записи по отдельности.{{end}}
|
{{define "edit separately."}}Изменяйте записи по отдельности.{{end}}
|
||||||
{{define "add interwiki entry"}}Добавить запись в интеркарту{{end}}
|
{{define "add interwiki entry"}}Добавить запись в интеркарту{{end}}
|
||||||
`
|
`
|
||||||
chainInterwiki viewutil2.Chain
|
chainInterwiki viewutil.Chain
|
||||||
chainNameTaken viewutil2.Chain
|
chainNameTaken viewutil.Chain
|
||||||
)
|
)
|
||||||
|
|
||||||
func InitHandlers(rtr *mux.Router) {
|
func InitHandlers(rtr *mux.Router) {
|
||||||
chainInterwiki = viewutil2.CopyEnRuWith(fs, "view_interwiki.html", ruTranslation)
|
chainInterwiki = viewutil.CopyEnRuWith(fs, "view_interwiki.html", ruTranslation)
|
||||||
chainNameTaken = viewutil2.CopyEnRuWith(fs, "view_name_taken.html", ruTranslation)
|
chainNameTaken = viewutil.CopyEnRuWith(fs, "view_name_taken.html", ruTranslation)
|
||||||
rtr.HandleFunc("/interwiki", handlerInterwiki)
|
rtr.HandleFunc("/interwiki", handlerInterwiki)
|
||||||
rtr.HandleFunc("/interwiki/add-entry", handlerAddEntry).Methods(http.MethodPost)
|
rtr.HandleFunc("/interwiki/add-entry", handlerAddEntry).Methods(http.MethodPost)
|
||||||
rtr.HandleFunc("/interwiki/modify-entry/{target}", handlerModifyEntry).Methods(http.MethodPost)
|
rtr.HandleFunc("/interwiki/modify-entry/{target}", handlerModifyEntry).Methods(http.MethodPost)
|
||||||
@ -64,13 +64,13 @@ func handlerModifyEntry(w http.ResponseWriter, rq *http.Request) {
|
|||||||
|
|
||||||
if oldData, ok = entriesByName[name]; !ok {
|
if oldData, ok = entriesByName[name]; !ok {
|
||||||
log.Printf("Could not modify interwiki entry ‘%s’ because it does not exist", name)
|
log.Printf("Could not modify interwiki entry ‘%s’ because it does not exist", name)
|
||||||
viewutil2.HandlerNotFound(w, rq)
|
viewutil.HandlerNotFound(w, rq)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := replaceEntry(oldData, &newData); err != nil {
|
if err := replaceEntry(oldData, &newData); err != nil {
|
||||||
log.Printf("Could not modify interwiki entry ‘%s’ because one of the proposed aliases/name is taken\n", name)
|
log.Printf("Could not modify interwiki entry ‘%s’ because one of the proposed aliases/name is taken\n", name)
|
||||||
viewNameTaken(viewutil2.MetaFrom(w, rq), oldData, err.Error(), "modify-entry/"+name)
|
viewNameTaken(viewutil.MetaFrom(w, rq), oldData, err.Error(), "modify-entry/"+name)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,7 +82,7 @@ func handlerModifyEntry(w http.ResponseWriter, rq *http.Request) {
|
|||||||
func handlerAddEntry(w http.ResponseWriter, rq *http.Request) {
|
func handlerAddEntry(w http.ResponseWriter, rq *http.Request) {
|
||||||
wiki := readInterwikiEntryFromRequest(rq)
|
wiki := readInterwikiEntryFromRequest(rq)
|
||||||
if err := addEntry(&wiki); err != nil {
|
if err := addEntry(&wiki); err != nil {
|
||||||
viewNameTaken(viewutil2.MetaFrom(w, rq), &wiki, err.Error(), "add-entry")
|
viewNameTaken(viewutil.MetaFrom(w, rq), &wiki, err.Error(), "add-entry")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
saveInterwikiJson()
|
saveInterwikiJson()
|
||||||
@ -90,15 +90,15 @@ func handlerAddEntry(w http.ResponseWriter, rq *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type nameTakenData struct {
|
type nameTakenData struct {
|
||||||
*viewutil2.BaseData
|
*viewutil.BaseData
|
||||||
*Wiki
|
*Wiki
|
||||||
TakenName string
|
TakenName string
|
||||||
Action string
|
Action string
|
||||||
}
|
}
|
||||||
|
|
||||||
func viewNameTaken(meta viewutil2.Meta, wiki *Wiki, takenName, action string) {
|
func viewNameTaken(meta viewutil.Meta, wiki *Wiki, takenName, action string) {
|
||||||
viewutil2.ExecutePage(meta, chainNameTaken, nameTakenData{
|
viewutil.ExecutePage(meta, chainNameTaken, nameTakenData{
|
||||||
BaseData: &viewutil2.BaseData{},
|
BaseData: &viewutil.BaseData{},
|
||||||
Wiki: wiki,
|
Wiki: wiki,
|
||||||
TakenName: takenName,
|
TakenName: takenName,
|
||||||
Action: action,
|
Action: action,
|
||||||
@ -106,19 +106,19 @@ func viewNameTaken(meta viewutil2.Meta, wiki *Wiki, takenName, action string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func handlerInterwiki(w http.ResponseWriter, rq *http.Request) {
|
func handlerInterwiki(w http.ResponseWriter, rq *http.Request) {
|
||||||
viewInterwiki(viewutil2.MetaFrom(w, rq))
|
viewInterwiki(viewutil.MetaFrom(w, rq))
|
||||||
}
|
}
|
||||||
|
|
||||||
type interwikiData struct {
|
type interwikiData struct {
|
||||||
*viewutil2.BaseData
|
*viewutil.BaseData
|
||||||
Entries []*Wiki
|
Entries []*Wiki
|
||||||
CanEdit bool
|
CanEdit bool
|
||||||
Error string
|
Error string
|
||||||
}
|
}
|
||||||
|
|
||||||
func viewInterwiki(meta viewutil2.Meta) {
|
func viewInterwiki(meta viewutil.Meta) {
|
||||||
viewutil2.ExecutePage(meta, chainInterwiki, interwikiData{
|
viewutil.ExecutePage(meta, chainInterwiki, interwikiData{
|
||||||
BaseData: &viewutil2.BaseData{},
|
BaseData: &viewutil.BaseData{},
|
||||||
Entries: listOfEntries,
|
Entries: listOfEntries,
|
||||||
CanEdit: meta.U.Group == "admin",
|
CanEdit: meta.U.Group == "admin",
|
||||||
Error: "",
|
Error: "",
|
||||||
|
|||||||
@ -2,13 +2,6 @@
|
|||||||
package misc
|
package misc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/bouncepaw/mycorrhiza/internal/backlinks"
|
|
||||||
"github.com/bouncepaw/mycorrhiza/internal/cfg"
|
|
||||||
hyphae2 "github.com/bouncepaw/mycorrhiza/internal/hyphae"
|
|
||||||
shroom2 "github.com/bouncepaw/mycorrhiza/internal/shroom"
|
|
||||||
"github.com/bouncepaw/mycorrhiza/internal/user"
|
|
||||||
"github.com/bouncepaw/mycorrhiza/web/static"
|
|
||||||
viewutil2 "github.com/bouncepaw/mycorrhiza/web/viewutil"
|
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
@ -18,9 +11,16 @@ import (
|
|||||||
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
|
|
||||||
|
"github.com/bouncepaw/mycorrhiza/internal/backlinks"
|
||||||
|
"github.com/bouncepaw/mycorrhiza/internal/cfg"
|
||||||
"github.com/bouncepaw/mycorrhiza/internal/files"
|
"github.com/bouncepaw/mycorrhiza/internal/files"
|
||||||
|
"github.com/bouncepaw/mycorrhiza/internal/hyphae"
|
||||||
|
"github.com/bouncepaw/mycorrhiza/internal/shroom"
|
||||||
|
"github.com/bouncepaw/mycorrhiza/internal/user"
|
||||||
"github.com/bouncepaw/mycorrhiza/l18n"
|
"github.com/bouncepaw/mycorrhiza/l18n"
|
||||||
"github.com/bouncepaw/mycorrhiza/util"
|
"github.com/bouncepaw/mycorrhiza/util"
|
||||||
|
"github.com/bouncepaw/mycorrhiza/web/static"
|
||||||
|
"github.com/bouncepaw/mycorrhiza/web/viewutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func InitAssetHandlers(rtr *mux.Router) {
|
func InitAssetHandlers(rtr *mux.Router) {
|
||||||
@ -49,22 +49,22 @@ func handlerList(w http.ResponseWriter, rq *http.Request) {
|
|||||||
// TODO: make this more effective, there are too many loops and vars
|
// TODO: make this more effective, there are too many loops and vars
|
||||||
var (
|
var (
|
||||||
hyphaNames = make(chan string)
|
hyphaNames = make(chan string)
|
||||||
sortedHypha = hyphae2.PathographicSort(hyphaNames)
|
sortedHypha = hyphae.PathographicSort(hyphaNames)
|
||||||
entries []listDatum
|
entries []listDatum
|
||||||
)
|
)
|
||||||
for hypha := range hyphae2.YieldExistingHyphae() {
|
for hypha := range hyphae.YieldExistingHyphae() {
|
||||||
hyphaNames <- hypha.CanonicalName()
|
hyphaNames <- hypha.CanonicalName()
|
||||||
}
|
}
|
||||||
close(hyphaNames)
|
close(hyphaNames)
|
||||||
for hyphaName := range sortedHypha {
|
for hyphaName := range sortedHypha {
|
||||||
switch h := hyphae2.ByName(hyphaName).(type) {
|
switch h := hyphae.ByName(hyphaName).(type) {
|
||||||
case *hyphae2.TextualHypha:
|
case *hyphae.TextualHypha:
|
||||||
entries = append(entries, listDatum{h.CanonicalName(), ""})
|
entries = append(entries, listDatum{h.CanonicalName(), ""})
|
||||||
case *hyphae2.MediaHypha:
|
case *hyphae.MediaHypha:
|
||||||
entries = append(entries, listDatum{h.CanonicalName(), filepath.Ext(h.MediaFilePath())[1:]})
|
entries = append(entries, listDatum{h.CanonicalName(), filepath.Ext(h.MediaFilePath())[1:]})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
viewList(viewutil2.MetaFrom(w, rq), entries)
|
viewList(viewutil.MetaFrom(w, rq), entries)
|
||||||
}
|
}
|
||||||
|
|
||||||
// handlerReindex reindexes all hyphae by checking the wiki storage directory anew.
|
// handlerReindex reindexes all hyphae by checking the wiki storage directory anew.
|
||||||
@ -72,13 +72,13 @@ func handlerReindex(w http.ResponseWriter, rq *http.Request) {
|
|||||||
util.PrepareRq(rq)
|
util.PrepareRq(rq)
|
||||||
if ok := user.CanProceed(rq, "reindex"); !ok {
|
if ok := user.CanProceed(rq, "reindex"); !ok {
|
||||||
var lc = l18n.FromRequest(rq)
|
var lc = l18n.FromRequest(rq)
|
||||||
viewutil2.HttpErr(viewutil2.MetaFrom(w, rq), http.StatusForbidden, cfg.HomeHypha, lc.Get("ui.reindex_no_rights"))
|
viewutil.HttpErr(viewutil.MetaFrom(w, rq), http.StatusForbidden, cfg.HomeHypha, lc.Get("ui.reindex_no_rights"))
|
||||||
log.Println("Rejected", rq.URL)
|
log.Println("Rejected", rq.URL)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
hyphae2.ResetCount()
|
hyphae.ResetCount()
|
||||||
log.Println("Reindexing hyphae in", files.HyphaeDir())
|
log.Println("Reindexing hyphae in", files.HyphaeDir())
|
||||||
hyphae2.Index(files.HyphaeDir())
|
hyphae.Index(files.HyphaeDir())
|
||||||
backlinks.IndexBacklinks()
|
backlinks.IndexBacklinks()
|
||||||
http.Redirect(w, rq, "/", http.StatusSeeOther)
|
http.Redirect(w, rq, "/", http.StatusSeeOther)
|
||||||
}
|
}
|
||||||
@ -88,11 +88,11 @@ func handlerUpdateHeaderLinks(w http.ResponseWriter, rq *http.Request) {
|
|||||||
util.PrepareRq(rq)
|
util.PrepareRq(rq)
|
||||||
if ok := user.CanProceed(rq, "update-header-links"); !ok {
|
if ok := user.CanProceed(rq, "update-header-links"); !ok {
|
||||||
var lc = l18n.FromRequest(rq)
|
var lc = l18n.FromRequest(rq)
|
||||||
viewutil2.HttpErr(viewutil2.MetaFrom(w, rq), http.StatusForbidden, cfg.HomeHypha, lc.Get("ui.header_no_rights"))
|
viewutil.HttpErr(viewutil.MetaFrom(w, rq), http.StatusForbidden, cfg.HomeHypha, lc.Get("ui.header_no_rights"))
|
||||||
log.Println("Rejected", rq.URL)
|
log.Println("Rejected", rq.URL)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
shroom2.SetHeaderLinks()
|
shroom.SetHeaderLinks()
|
||||||
http.Redirect(w, rq, "/", http.StatusSeeOther)
|
http.Redirect(w, rq, "/", http.StatusSeeOther)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,15 +101,15 @@ func handlerRandom(w http.ResponseWriter, rq *http.Request) {
|
|||||||
util.PrepareRq(rq)
|
util.PrepareRq(rq)
|
||||||
var (
|
var (
|
||||||
randomHyphaName string
|
randomHyphaName string
|
||||||
amountOfHyphae = hyphae2.Count()
|
amountOfHyphae = hyphae.Count()
|
||||||
)
|
)
|
||||||
if amountOfHyphae == 0 {
|
if amountOfHyphae == 0 {
|
||||||
var lc = l18n.FromRequest(rq)
|
var lc = l18n.FromRequest(rq)
|
||||||
viewutil2.HttpErr(viewutil2.MetaFrom(w, rq), http.StatusNotFound, cfg.HomeHypha, lc.Get("ui.random_no_hyphae_tip"))
|
viewutil.HttpErr(viewutil.MetaFrom(w, rq), http.StatusNotFound, cfg.HomeHypha, lc.Get("ui.random_no_hyphae_tip"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
i := rand.Intn(amountOfHyphae)
|
i := rand.Intn(amountOfHyphae)
|
||||||
for h := range hyphae2.YieldExistingHyphae() {
|
for h := range hyphae.YieldExistingHyphae() {
|
||||||
if i == 0 {
|
if i == 0 {
|
||||||
randomHyphaName = h.CanonicalName()
|
randomHyphaName = h.CanonicalName()
|
||||||
}
|
}
|
||||||
@ -126,8 +126,8 @@ func handlerAbout(w http.ResponseWriter, rq *http.Request) {
|
|||||||
lc = l18n.FromRequest(rq)
|
lc = l18n.FromRequest(rq)
|
||||||
title = lc.Get("ui.about_title", &l18n.Replacements{"name": cfg.WikiName})
|
title = lc.Get("ui.about_title", &l18n.Replacements{"name": cfg.WikiName})
|
||||||
)
|
)
|
||||||
_, err := io.WriteString(w, viewutil2.Base(
|
_, err := io.WriteString(w, viewutil.Base(
|
||||||
viewutil2.MetaFrom(w, rq),
|
viewutil.MetaFrom(w, rq),
|
||||||
title,
|
title,
|
||||||
AboutHTML(lc),
|
AboutHTML(lc),
|
||||||
map[string]string{},
|
map[string]string{},
|
||||||
@ -174,12 +174,12 @@ func handlerTitleSearch(w http.ResponseWriter, rq *http.Request) {
|
|||||||
var (
|
var (
|
||||||
query = rq.FormValue("q")
|
query = rq.FormValue("q")
|
||||||
hyphaName = util.CanonicalName(query)
|
hyphaName = util.CanonicalName(query)
|
||||||
_, nameFree = hyphae2.AreFreeNames(hyphaName)
|
_, nameFree = hyphae.AreFreeNames(hyphaName)
|
||||||
results []string
|
results []string
|
||||||
)
|
)
|
||||||
for hyphaName := range shroom2.YieldHyphaNamesContainingString(query) {
|
for hyphaName := range shroom.YieldHyphaNamesContainingString(query) {
|
||||||
results = append(results, hyphaName)
|
results = append(results, hyphaName)
|
||||||
}
|
}
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
viewTitleSearch(viewutil2.MetaFrom(w, rq), query, hyphaName, !nameFree, results)
|
viewTitleSearch(viewutil.MetaFrom(w, rq), query, hyphaName, !nameFree, results)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,13 +3,13 @@ package misc
|
|||||||
import (
|
import (
|
||||||
"embed"
|
"embed"
|
||||||
"github.com/bouncepaw/mycorrhiza/internal/hyphae"
|
"github.com/bouncepaw/mycorrhiza/internal/hyphae"
|
||||||
viewutil2 "github.com/bouncepaw/mycorrhiza/web/viewutil"
|
"github.com/bouncepaw/mycorrhiza/web/viewutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
//go:embed *html
|
//go:embed *html
|
||||||
fs embed.FS
|
fs embed.FS
|
||||||
chainList, chainTitleSearch viewutil2.Chain
|
chainList, chainTitleSearch viewutil.Chain
|
||||||
ruTranslation = `
|
ruTranslation = `
|
||||||
{{define "list of hyphae"}}Список гиф{{end}}
|
{{define "list of hyphae"}}Список гиф{{end}}
|
||||||
{{define "search:"}}Поиск: {{.}}{{end}}
|
{{define "search:"}}Поиск: {{.}}{{end}}
|
||||||
@ -21,8 +21,8 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func initViews() {
|
func initViews() {
|
||||||
chainList = viewutil2.CopyEnRuWith(fs, "view_list.html", ruTranslation)
|
chainList = viewutil.CopyEnRuWith(fs, "view_list.html", ruTranslation)
|
||||||
chainTitleSearch = viewutil2.CopyEnRuWith(fs, "view_title_search.html", ruTranslation)
|
chainTitleSearch = viewutil.CopyEnRuWith(fs, "view_title_search.html", ruTranslation)
|
||||||
}
|
}
|
||||||
|
|
||||||
type listDatum struct {
|
type listDatum struct {
|
||||||
@ -31,30 +31,30 @@ type listDatum struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type listData struct {
|
type listData struct {
|
||||||
*viewutil2.BaseData
|
*viewutil.BaseData
|
||||||
Entries []listDatum
|
Entries []listDatum
|
||||||
HyphaCount int
|
HyphaCount int
|
||||||
}
|
}
|
||||||
|
|
||||||
func viewList(meta viewutil2.Meta, entries []listDatum) {
|
func viewList(meta viewutil.Meta, entries []listDatum) {
|
||||||
viewutil2.ExecutePage(meta, chainList, listData{
|
viewutil.ExecutePage(meta, chainList, listData{
|
||||||
BaseData: &viewutil2.BaseData{},
|
BaseData: &viewutil.BaseData{},
|
||||||
Entries: entries,
|
Entries: entries,
|
||||||
HyphaCount: hyphae.Count(),
|
HyphaCount: hyphae.Count(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
type titleSearchData struct {
|
type titleSearchData struct {
|
||||||
*viewutil2.BaseData
|
*viewutil.BaseData
|
||||||
Query string
|
Query string
|
||||||
Results []string
|
Results []string
|
||||||
MatchedHyphaName string
|
MatchedHyphaName string
|
||||||
HasExactMatch bool
|
HasExactMatch bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func viewTitleSearch(meta viewutil2.Meta, query string, hyphaName string, hasExactMatch bool, results []string) {
|
func viewTitleSearch(meta viewutil.Meta, query string, hyphaName string, hasExactMatch bool, results []string) {
|
||||||
viewutil2.ExecutePage(meta, chainTitleSearch, titleSearchData{
|
viewutil.ExecutePage(meta, chainTitleSearch, titleSearchData{
|
||||||
BaseData: &viewutil2.BaseData{},
|
BaseData: &viewutil.BaseData{},
|
||||||
Query: query,
|
Query: query,
|
||||||
Results: results,
|
Results: results,
|
||||||
MatchedHyphaName: hyphaName,
|
MatchedHyphaName: hyphaName,
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"git.sr.ht/~bouncepaw/mycomarkup/v5/options"
|
"git.sr.ht/~bouncepaw/mycomarkup/v5/options"
|
||||||
"github.com/bouncepaw/mycorrhiza/internal/cfg"
|
"github.com/bouncepaw/mycorrhiza/internal/cfg"
|
||||||
hyphae2 "github.com/bouncepaw/mycorrhiza/internal/hyphae"
|
"github.com/bouncepaw/mycorrhiza/internal/hyphae"
|
||||||
"github.com/bouncepaw/mycorrhiza/interwiki"
|
"github.com/bouncepaw/mycorrhiza/interwiki"
|
||||||
"github.com/bouncepaw/mycorrhiza/util"
|
"github.com/bouncepaw/mycorrhiza/util"
|
||||||
)
|
)
|
||||||
@ -17,26 +17,26 @@ func MarkupOptions(hyphaName string) options.Options {
|
|||||||
RedLinksSupported: true,
|
RedLinksSupported: true,
|
||||||
InterwikiSupported: true,
|
InterwikiSupported: true,
|
||||||
HyphaExists: func(hyphaName string) bool {
|
HyphaExists: func(hyphaName string) bool {
|
||||||
switch hyphae2.ByName(hyphaName).(type) {
|
switch hyphae.ByName(hyphaName).(type) {
|
||||||
case *hyphae2.EmptyHypha:
|
case *hyphae.EmptyHypha:
|
||||||
return false
|
return false
|
||||||
default:
|
default:
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
IterateHyphaNamesWith: func(λ func(string)) {
|
IterateHyphaNamesWith: func(λ func(string)) {
|
||||||
for h := range hyphae2.YieldExistingHyphae() {
|
for h := range hyphae.YieldExistingHyphae() {
|
||||||
λ(h.CanonicalName())
|
λ(h.CanonicalName())
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
HyphaHTMLData: func(hyphaName string) (rawText, binaryBlock string, err error) {
|
HyphaHTMLData: func(hyphaName string) (rawText, binaryBlock string, err error) {
|
||||||
switch h := hyphae2.ByName(hyphaName).(type) {
|
switch h := hyphae.ByName(hyphaName).(type) {
|
||||||
case *hyphae2.EmptyHypha:
|
case *hyphae.EmptyHypha:
|
||||||
err = errors.New("Hypha " + hyphaName + " does not exist")
|
err = errors.New("Hypha " + hyphaName + " does not exist")
|
||||||
case *hyphae2.TextualHypha:
|
case *hyphae.TextualHypha:
|
||||||
rawText, err = hyphae2.FetchMycomarkupFile(h)
|
rawText, err = hyphae.FetchMycomarkupFile(h)
|
||||||
case *hyphae2.MediaHypha:
|
case *hyphae.MediaHypha:
|
||||||
rawText, err = hyphae2.FetchMycomarkupFile(h)
|
rawText, err = hyphae.FetchMycomarkupFile(h)
|
||||||
binaryBlock = mediaRaw(h)
|
binaryBlock = mediaRaw(h)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
|||||||
@ -2,7 +2,7 @@ package web
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
user2 "github.com/bouncepaw/mycorrhiza/internal/user"
|
"github.com/bouncepaw/mycorrhiza/internal/user"
|
||||||
"github.com/bouncepaw/mycorrhiza/util"
|
"github.com/bouncepaw/mycorrhiza/util"
|
||||||
"github.com/bouncepaw/mycorrhiza/web/viewutil"
|
"github.com/bouncepaw/mycorrhiza/web/viewutil"
|
||||||
"mime"
|
"mime"
|
||||||
@ -11,9 +11,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func handlerUserChangePassword(w http.ResponseWriter, rq *http.Request) {
|
func handlerUserChangePassword(w http.ResponseWriter, rq *http.Request) {
|
||||||
u := user2.FromRequest(rq)
|
u := user.FromRequest(rq)
|
||||||
// TODO: is there a better way?
|
// TODO: is there a better way?
|
||||||
if reflect.DeepEqual(u, user2.EmptyUser()) || u == nil {
|
if reflect.DeepEqual(u, user.EmptyUser()) || u == nil {
|
||||||
util.HTTP404Page(w, "404 page not found")
|
util.HTTP404Page(w, "404 page not found")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -21,7 +21,7 @@ func handlerUserChangePassword(w http.ResponseWriter, rq *http.Request) {
|
|||||||
f := util.FormDataFromRequest(rq, []string{"current_password", "password", "password_confirm"})
|
f := util.FormDataFromRequest(rq, []string{"current_password", "password", "password_confirm"})
|
||||||
currentPassword := f.Get("current_password")
|
currentPassword := f.Get("current_password")
|
||||||
|
|
||||||
if user2.CredentialsOK(u.Name, currentPassword) {
|
if user.CredentialsOK(u.Name, currentPassword) {
|
||||||
password := f.Get("password")
|
password := f.Get("password")
|
||||||
passwordConfirm := f.Get("password_confirm")
|
passwordConfirm := f.Get("password_confirm")
|
||||||
// server side validation
|
// server side validation
|
||||||
@ -34,7 +34,7 @@ func handlerUserChangePassword(w http.ResponseWriter, rq *http.Request) {
|
|||||||
if err := u.ChangePassword(password); err != nil {
|
if err := u.ChangePassword(password); err != nil {
|
||||||
f = f.WithError(err)
|
f = f.WithError(err)
|
||||||
} else {
|
} else {
|
||||||
if err := user2.SaveUserDatabase(); err != nil {
|
if err := user.SaveUserDatabase(); err != nil {
|
||||||
u.Password = previousPassword
|
u.Password = previousPassword
|
||||||
f = f.WithError(err)
|
f = f.WithError(err)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user