1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2025-01-21 07:46:52 +00:00

Write the whitelist help article and fix some help bugs

The bugs were introduced by the new routing system...
This commit is contained in:
Timur Ismagilov 2021-07-24 16:30:28 +05:00
parent 6241350e8b
commit 87e0045d80
5 changed files with 204 additions and 170 deletions

15
help/en/whitelist.myco Normal file
View File

@ -0,0 +1,15 @@
# Whitelist
If you want to limit what people can authorize to your wiki, you may want to use the **whitelist**.
In `config.ini`, in the `[Authorization]` section, enable the white list in `UseWhiteList` and list all allowed usernames in the `WhiteList` field separated by comma:
```
...
[Authorization]
UseWhiteList = true
WhiteList = fish,pesce,рыба
...
```
Reload the wiki.
From now on, only these usernames can be used, ie you can only register and log in with these names. Others will be rejected.

View File

@ -416,22 +416,22 @@ func StreamLockHTML(qw422016 *qt422016.Writer) {
<p class="locked-notice__lock">🔒</p>
<h1 class="locked-notice__title">Locked</h1>
<form class="locked-notice__login-form" method="post" action="/login-data" id="login-form" enctype="multipart/form-data" autocomplete="on">
<label for="login-form__username">Username</label>
<br>
<input type="text" required autofocus id="login-form__username" name="username" autocomplete="username">
<br>
<label for="login-form__password">Password</label>
<br>
<input type="password" required name="password" autocomplete="current-password">
<br>
<input class="btn" type="submit" value="Log in">
</form>
</section>
`)
//line views/auth.qtpl:140
<label for="login-form__username">Username</label>
<br>
<input type="text" required autofocus id="login-form__username" name="username" autocomplete="username">
<br>
<label for="login-form__password">Password</label>
<br>
<input type="password" required name="password" autocomplete="current-password">
<br>
<input class="btn" type="submit" value="Log in">
</form>
`)
//line views/auth.qtpl:139
streamtelegramWidgetHTML(qw422016)
//line views/auth.qtpl:140
//line views/auth.qtpl:139
qw422016.N().S(`
</section>
</main>
</body>
</html>

View File

@ -152,6 +152,14 @@ It outputs a poorly formatted JSON, but it works and is valid.
</li>
</ul
</li>
<li>
Configuration
<ul>
<li>
<a href="/help/en/whitelist">Whitelist</a>
</li>
</ul>
</li>
</ul>
</aside>
{% endfunc %}

View File

@ -501,47 +501,55 @@ func streamhelpTopicsHTML(qw422016 *qt422016.Writer) {
</li>
</ul
</li>
<li>
Configuration
<ul>
<li>
<a href="/help/en/whitelist">Whitelist</a>
</li>
</ul>
</li>
</ul>
</aside>
`)
//line views/stuff.qtpl:157
//line views/stuff.qtpl:165
}
//line views/stuff.qtpl:157
//line views/stuff.qtpl:165
func writehelpTopicsHTML(qq422016 qtio422016.Writer) {
//line views/stuff.qtpl:157
//line views/stuff.qtpl:165
qw422016 := qt422016.AcquireWriter(qq422016)
//line views/stuff.qtpl:157
//line views/stuff.qtpl:165
streamhelpTopicsHTML(qw422016)
//line views/stuff.qtpl:157
//line views/stuff.qtpl:165
qt422016.ReleaseWriter(qw422016)
//line views/stuff.qtpl:157
//line views/stuff.qtpl:165
}
//line views/stuff.qtpl:157
//line views/stuff.qtpl:165
func helpTopicsHTML() string {
//line views/stuff.qtpl:157
//line views/stuff.qtpl:165
qb422016 := qt422016.AcquireByteBuffer()
//line views/stuff.qtpl:157
//line views/stuff.qtpl:165
writehelpTopicsHTML(qb422016)
//line views/stuff.qtpl:157
//line views/stuff.qtpl:165
qs422016 := string(qb422016.B)
//line views/stuff.qtpl:157
//line views/stuff.qtpl:165
qt422016.ReleaseByteBuffer(qb422016)
//line views/stuff.qtpl:157
//line views/stuff.qtpl:165
return qs422016
//line views/stuff.qtpl:157
//line views/stuff.qtpl:165
}
//line views/stuff.qtpl:159
//line views/stuff.qtpl:167
func StreamUserListHTML(qw422016 *qt422016.Writer) {
//line views/stuff.qtpl:159
//line views/stuff.qtpl:167
qw422016.N().S(`
<div class="layout">
<main class="main-width user-list">
<h1>List of users</h1>
`)
//line views/stuff.qtpl:164
//line views/stuff.qtpl:172
var (
admins = make([]string, 0)
moderators = make([]string, 0)
@ -558,345 +566,345 @@ func StreamUserListHTML(qw422016 *qt422016.Writer) {
}
}
//line views/stuff.qtpl:179
//line views/stuff.qtpl:187
qw422016.N().S(`
<section>
<h2>Admins</h2>
<ol>`)
//line views/stuff.qtpl:182
//line views/stuff.qtpl:190
for _, name := range admins {
//line views/stuff.qtpl:182
//line views/stuff.qtpl:190
qw422016.N().S(`
<li><a href="/hypha/`)
//line views/stuff.qtpl:183
//line views/stuff.qtpl:191
qw422016.E().S(cfg.UserHypha)
//line views/stuff.qtpl:183
//line views/stuff.qtpl:191
qw422016.N().S(`/`)
//line views/stuff.qtpl:183
//line views/stuff.qtpl:191
qw422016.E().S(name)
//line views/stuff.qtpl:183
//line views/stuff.qtpl:191
qw422016.N().S(`">`)
//line views/stuff.qtpl:183
//line views/stuff.qtpl:191
qw422016.E().S(name)
//line views/stuff.qtpl:183
//line views/stuff.qtpl:191
qw422016.N().S(`</a></li>
`)
//line views/stuff.qtpl:184
//line views/stuff.qtpl:192
}
//line views/stuff.qtpl:184
//line views/stuff.qtpl:192
qw422016.N().S(`</ol>
</section>
<section>
<h2>Moderators</h2>
<ol>`)
//line views/stuff.qtpl:188
//line views/stuff.qtpl:196
for _, name := range moderators {
//line views/stuff.qtpl:188
//line views/stuff.qtpl:196
qw422016.N().S(`
<li><a href="/hypha/`)
//line views/stuff.qtpl:189
//line views/stuff.qtpl:197
qw422016.E().S(cfg.UserHypha)
//line views/stuff.qtpl:189
//line views/stuff.qtpl:197
qw422016.N().S(`/`)
//line views/stuff.qtpl:189
//line views/stuff.qtpl:197
qw422016.E().S(name)
//line views/stuff.qtpl:189
//line views/stuff.qtpl:197
qw422016.N().S(`">`)
//line views/stuff.qtpl:189
//line views/stuff.qtpl:197
qw422016.E().S(name)
//line views/stuff.qtpl:189
//line views/stuff.qtpl:197
qw422016.N().S(`</a></li>
`)
//line views/stuff.qtpl:190
//line views/stuff.qtpl:198
}
//line views/stuff.qtpl:190
//line views/stuff.qtpl:198
qw422016.N().S(`</ol>
</section>
<section>
<h2>Editors</h2>
<ol>`)
//line views/stuff.qtpl:194
//line views/stuff.qtpl:202
for _, name := range editors {
//line views/stuff.qtpl:194
//line views/stuff.qtpl:202
qw422016.N().S(`
<li><a href="/hypha/`)
//line views/stuff.qtpl:195
//line views/stuff.qtpl:203
qw422016.E().S(cfg.UserHypha)
//line views/stuff.qtpl:195
//line views/stuff.qtpl:203
qw422016.N().S(`/`)
//line views/stuff.qtpl:195
//line views/stuff.qtpl:203
qw422016.E().S(name)
//line views/stuff.qtpl:195
//line views/stuff.qtpl:203
qw422016.N().S(`">`)
//line views/stuff.qtpl:195
//line views/stuff.qtpl:203
qw422016.E().S(name)
//line views/stuff.qtpl:195
//line views/stuff.qtpl:203
qw422016.N().S(`</a></li>
`)
//line views/stuff.qtpl:196
//line views/stuff.qtpl:204
}
//line views/stuff.qtpl:196
//line views/stuff.qtpl:204
qw422016.N().S(`</ol>
</section>
</main>
</div>
`)
//line views/stuff.qtpl:200
//line views/stuff.qtpl:208
}
//line views/stuff.qtpl:200
//line views/stuff.qtpl:208
func WriteUserListHTML(qq422016 qtio422016.Writer) {
//line views/stuff.qtpl:200
//line views/stuff.qtpl:208
qw422016 := qt422016.AcquireWriter(qq422016)
//line views/stuff.qtpl:200
//line views/stuff.qtpl:208
StreamUserListHTML(qw422016)
//line views/stuff.qtpl:200
//line views/stuff.qtpl:208
qt422016.ReleaseWriter(qw422016)
//line views/stuff.qtpl:200
//line views/stuff.qtpl:208
}
//line views/stuff.qtpl:200
//line views/stuff.qtpl:208
func UserListHTML() string {
//line views/stuff.qtpl:200
//line views/stuff.qtpl:208
qb422016 := qt422016.AcquireByteBuffer()
//line views/stuff.qtpl:200
//line views/stuff.qtpl:208
WriteUserListHTML(qb422016)
//line views/stuff.qtpl:200
//line views/stuff.qtpl:208
qs422016 := string(qb422016.B)
//line views/stuff.qtpl:200
//line views/stuff.qtpl:208
qt422016.ReleaseByteBuffer(qb422016)
//line views/stuff.qtpl:200
//line views/stuff.qtpl:208
return qs422016
//line views/stuff.qtpl:200
//line views/stuff.qtpl:208
}
//line views/stuff.qtpl:202
//line views/stuff.qtpl:210
func StreamHyphaListHTML(qw422016 *qt422016.Writer) {
//line views/stuff.qtpl:202
//line views/stuff.qtpl:210
qw422016.N().S(`
<div class="layout">
<main class="main-width">
<h1>List of hyphae</h1>
<p>This wiki has `)
//line views/stuff.qtpl:206
//line views/stuff.qtpl:214
qw422016.N().D(hyphae.Count())
//line views/stuff.qtpl:206
//line views/stuff.qtpl:214
qw422016.N().S(` hyphae.</p>
<ul class="hypha-list">
`)
//line views/stuff.qtpl:208
//line views/stuff.qtpl:216
for h := range hyphae.YieldExistingHyphae() {
//line views/stuff.qtpl:208
//line views/stuff.qtpl:216
qw422016.N().S(`
<li class="hypha-list__entry">
<a class="hypha-list__link" href="/hypha/`)
//line views/stuff.qtpl:210
//line views/stuff.qtpl:218
qw422016.E().S(h.Name)
//line views/stuff.qtpl:210
//line views/stuff.qtpl:218
qw422016.N().S(`">`)
//line views/stuff.qtpl:210
//line views/stuff.qtpl:218
qw422016.E().S(util.BeautifulName(h.Name))
//line views/stuff.qtpl:210
//line views/stuff.qtpl:218
qw422016.N().S(`</a>
`)
//line views/stuff.qtpl:211
//line views/stuff.qtpl:219
if h.BinaryPath != "" {
//line views/stuff.qtpl:211
//line views/stuff.qtpl:219
qw422016.N().S(`
<span class="hypha-list__amnt-type">`)
//line views/stuff.qtpl:212
//line views/stuff.qtpl:220
qw422016.E().S(filepath.Ext(h.BinaryPath)[1:])
//line views/stuff.qtpl:212
//line views/stuff.qtpl:220
qw422016.N().S(`</span>
`)
//line views/stuff.qtpl:213
//line views/stuff.qtpl:221
}
//line views/stuff.qtpl:213
//line views/stuff.qtpl:221
qw422016.N().S(`
</li>
`)
//line views/stuff.qtpl:215
//line views/stuff.qtpl:223
}
//line views/stuff.qtpl:215
//line views/stuff.qtpl:223
qw422016.N().S(`
</ul>
</main>
</div>
`)
//line views/stuff.qtpl:219
//line views/stuff.qtpl:227
}
//line views/stuff.qtpl:219
//line views/stuff.qtpl:227
func WriteHyphaListHTML(qq422016 qtio422016.Writer) {
//line views/stuff.qtpl:219
//line views/stuff.qtpl:227
qw422016 := qt422016.AcquireWriter(qq422016)
//line views/stuff.qtpl:219
//line views/stuff.qtpl:227
StreamHyphaListHTML(qw422016)
//line views/stuff.qtpl:219
//line views/stuff.qtpl:227
qt422016.ReleaseWriter(qw422016)
//line views/stuff.qtpl:219
//line views/stuff.qtpl:227
}
//line views/stuff.qtpl:219
//line views/stuff.qtpl:227
func HyphaListHTML() string {
//line views/stuff.qtpl:219
//line views/stuff.qtpl:227
qb422016 := qt422016.AcquireByteBuffer()
//line views/stuff.qtpl:219
//line views/stuff.qtpl:227
WriteHyphaListHTML(qb422016)
//line views/stuff.qtpl:219
//line views/stuff.qtpl:227
qs422016 := string(qb422016.B)
//line views/stuff.qtpl:219
//line views/stuff.qtpl:227
qt422016.ReleaseByteBuffer(qb422016)
//line views/stuff.qtpl:219
//line views/stuff.qtpl:227
return qs422016
//line views/stuff.qtpl:219
//line views/stuff.qtpl:227
}
//line views/stuff.qtpl:221
//line views/stuff.qtpl:229
func StreamAboutHTML(qw422016 *qt422016.Writer) {
//line views/stuff.qtpl:221
//line views/stuff.qtpl:229
qw422016.N().S(`
<div class="layout">
<main class="main-width">
<section>
<h1>About `)
//line views/stuff.qtpl:225
//line views/stuff.qtpl:233
qw422016.E().S(cfg.WikiName)
//line views/stuff.qtpl:225
//line views/stuff.qtpl:233
qw422016.N().S(`</h1>
<ul>
<li><b><a href="https://mycorrhiza.wiki">Mycorrhiza Wiki</a> version:</b> 1.3.0</li>
`)
//line views/stuff.qtpl:228
//line views/stuff.qtpl:236
if cfg.UseAuth {
//line views/stuff.qtpl:228
//line views/stuff.qtpl:236
qw422016.N().S(` <li><b>User count:</b> `)
//line views/stuff.qtpl:229
//line views/stuff.qtpl:237
qw422016.N().DUL(user.Count())
//line views/stuff.qtpl:229
//line views/stuff.qtpl:237
qw422016.N().S(`</li>
<li><b>Home page:</b> <a href="/">`)
//line views/stuff.qtpl:230
//line views/stuff.qtpl:238
qw422016.E().S(cfg.HomeHypha)
//line views/stuff.qtpl:230
//line views/stuff.qtpl:238
qw422016.N().S(`</a></li>
<li><b>Administrators:</b>`)
//line views/stuff.qtpl:231
//line views/stuff.qtpl:239
for i, username := range user.ListUsersWithGroup("admin") {
//line views/stuff.qtpl:232
//line views/stuff.qtpl:240
if i > 0 {
//line views/stuff.qtpl:232
//line views/stuff.qtpl:240
qw422016.N().S(`<span aria-hidden="true">, </span>
`)
//line views/stuff.qtpl:233
//line views/stuff.qtpl:241
}
//line views/stuff.qtpl:233
//line views/stuff.qtpl:241
qw422016.N().S(` <a href="/hypha/`)
//line views/stuff.qtpl:234
//line views/stuff.qtpl:242
qw422016.E().S(cfg.UserHypha)
//line views/stuff.qtpl:234
//line views/stuff.qtpl:242
qw422016.N().S(`/`)
//line views/stuff.qtpl:234
//line views/stuff.qtpl:242
qw422016.E().S(username)
//line views/stuff.qtpl:234
//line views/stuff.qtpl:242
qw422016.N().S(`">`)
//line views/stuff.qtpl:234
//line views/stuff.qtpl:242
qw422016.E().S(username)
//line views/stuff.qtpl:234
//line views/stuff.qtpl:242
qw422016.N().S(`</a>`)
//line views/stuff.qtpl:234
//line views/stuff.qtpl:242
}
//line views/stuff.qtpl:234
//line views/stuff.qtpl:242
qw422016.N().S(`</li>
`)
//line views/stuff.qtpl:235
//line views/stuff.qtpl:243
} else {
//line views/stuff.qtpl:235
//line views/stuff.qtpl:243
qw422016.N().S(` <li>This wiki does not use authorization</li>
`)
//line views/stuff.qtpl:237
//line views/stuff.qtpl:245
}
//line views/stuff.qtpl:237
//line views/stuff.qtpl:245
qw422016.N().S(` </ul>
<p>See <a href="/list">/list</a> for information about hyphae on this wiki.</p>
</section>
</main>
</div>
`)
//line views/stuff.qtpl:243
//line views/stuff.qtpl:251
}
//line views/stuff.qtpl:243
//line views/stuff.qtpl:251
func WriteAboutHTML(qq422016 qtio422016.Writer) {
//line views/stuff.qtpl:243
//line views/stuff.qtpl:251
qw422016 := qt422016.AcquireWriter(qq422016)
//line views/stuff.qtpl:243
//line views/stuff.qtpl:251
StreamAboutHTML(qw422016)
//line views/stuff.qtpl:243
//line views/stuff.qtpl:251
qt422016.ReleaseWriter(qw422016)
//line views/stuff.qtpl:243
//line views/stuff.qtpl:251
}
//line views/stuff.qtpl:243
//line views/stuff.qtpl:251
func AboutHTML() string {
//line views/stuff.qtpl:243
//line views/stuff.qtpl:251
qb422016 := qt422016.AcquireByteBuffer()
//line views/stuff.qtpl:243
//line views/stuff.qtpl:251
WriteAboutHTML(qb422016)
//line views/stuff.qtpl:243
//line views/stuff.qtpl:251
qs422016 := string(qb422016.B)
//line views/stuff.qtpl:243
//line views/stuff.qtpl:251
qt422016.ReleaseByteBuffer(qb422016)
//line views/stuff.qtpl:243
//line views/stuff.qtpl:251
return qs422016
//line views/stuff.qtpl:243
//line views/stuff.qtpl:251
}
//line views/stuff.qtpl:245
//line views/stuff.qtpl:253
func StreamCommonScripts(qw422016 *qt422016.Writer) {
//line views/stuff.qtpl:245
//line views/stuff.qtpl:253
qw422016.N().S(`
`)
//line views/stuff.qtpl:246
//line views/stuff.qtpl:254
for _, scriptPath := range cfg.CommonScripts {
//line views/stuff.qtpl:246
//line views/stuff.qtpl:254
qw422016.N().S(`
<script src="`)
//line views/stuff.qtpl:247
//line views/stuff.qtpl:255
qw422016.E().S(scriptPath)
//line views/stuff.qtpl:247
//line views/stuff.qtpl:255
qw422016.N().S(`"></script>
`)
//line views/stuff.qtpl:248
//line views/stuff.qtpl:256
}
//line views/stuff.qtpl:248
//line views/stuff.qtpl:256
qw422016.N().S(`
`)
//line views/stuff.qtpl:249
//line views/stuff.qtpl:257
}
//line views/stuff.qtpl:249
//line views/stuff.qtpl:257
func WriteCommonScripts(qq422016 qtio422016.Writer) {
//line views/stuff.qtpl:249
//line views/stuff.qtpl:257
qw422016 := qt422016.AcquireWriter(qq422016)
//line views/stuff.qtpl:249
//line views/stuff.qtpl:257
StreamCommonScripts(qw422016)
//line views/stuff.qtpl:249
//line views/stuff.qtpl:257
qt422016.ReleaseWriter(qw422016)
//line views/stuff.qtpl:249
//line views/stuff.qtpl:257
}
//line views/stuff.qtpl:249
//line views/stuff.qtpl:257
func CommonScripts() string {
//line views/stuff.qtpl:249
//line views/stuff.qtpl:257
qb422016 := qt422016.AcquireByteBuffer()
//line views/stuff.qtpl:249
//line views/stuff.qtpl:257
WriteCommonScripts(qb422016)
//line views/stuff.qtpl:249
//line views/stuff.qtpl:257
qs422016 := string(qb422016.B)
//line views/stuff.qtpl:249
//line views/stuff.qtpl:257
qt422016.ReleaseByteBuffer(qb422016)
//line views/stuff.qtpl:249
//line views/stuff.qtpl:257
return qs422016
//line views/stuff.qtpl:249
//line views/stuff.qtpl:257
}

View File

@ -24,7 +24,7 @@ import (
)
func initStuff(r *mux.Router) {
r.PathPrefix("/help/").HandlerFunc(handlerHelp)
r.PathPrefix("/help").HandlerFunc(handlerHelp)
r.HandleFunc("/list", handlerList)
r.HandleFunc("/reindex", handlerReindex)
r.HandleFunc("/update-header-links", handlerUpdateHeaderLinks)
@ -37,7 +37,11 @@ func initStuff(r *mux.Router) {
// handlerHelp gets the appropriate documentation or tells you where you (personally) have failed.
func handlerHelp(w http.ResponseWriter, rq *http.Request) {
content, err := help.Get(rq.URL.Path[6:]) // Drop /help/
articlePath := strings.TrimPrefix(strings.TrimPrefix(rq.URL.Path, "/help/"), "/help")
if articlePath == "" {
articlePath = "en"
}
content, err := help.Get(articlePath)
if err != nil && strings.HasPrefix(err.Error(), "open") {
w.WriteHeader(http.StatusNotFound)
_, _ = io.WriteString(
@ -60,10 +64,9 @@ func handlerHelp(w http.ResponseWriter, rq *http.Request) {
}
// TODO: change for the function that uses byte array when there is such function in mycomarkup.
ctx, _ := mycocontext.ContextFromStringInput(rq.URL.Path[1:3], string(content))
ctx, _ := mycocontext.ContextFromStringInput(articlePath, string(content))
ast := mycomarkup.BlockTree(ctx)
result := mycomarkup.BlocksToHTML(ctx, ast)
// TODO: styled output idk
w.WriteHeader(http.StatusOK)
_, _ = io.WriteString(
w,