2015-11-26 02:10:25 +01:00
|
|
|
// Copyright 2015 The Gogs Authors. All rights reserved.
|
2018-11-28 12:26:14 +01:00
|
|
|
// Copyright 2018 The Gitea Authors. All rights reserved.
|
2015-11-26 02:10:25 +01:00
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package repo
|
|
|
|
|
|
|
|
import (
|
2021-04-20 00:25:08 +02:00
|
|
|
"bytes"
|
2017-02-14 02:13:59 +01:00
|
|
|
"fmt"
|
2021-09-22 07:38:34 +02:00
|
|
|
"io"
|
2021-04-05 17:30:52 +02:00
|
|
|
"net/http"
|
2019-10-09 20:49:37 +02:00
|
|
|
"net/url"
|
2017-02-14 02:13:59 +01:00
|
|
|
"path/filepath"
|
2015-11-27 07:50:38 +01:00
|
|
|
"strings"
|
2022-05-09 17:54:51 +02:00
|
|
|
"time"
|
2015-11-27 06:24:24 +01:00
|
|
|
|
2016-11-10 17:24:48 +01:00
|
|
|
"code.gitea.io/gitea/models"
|
2021-11-09 20:57:58 +01:00
|
|
|
"code.gitea.io/gitea/models/unit"
|
2016-11-10 17:24:48 +01:00
|
|
|
"code.gitea.io/gitea/modules/base"
|
2022-01-07 02:18:52 +01:00
|
|
|
"code.gitea.io/gitea/modules/charset"
|
2016-11-10 17:24:48 +01:00
|
|
|
"code.gitea.io/gitea/modules/context"
|
2019-03-27 10:33:00 +01:00
|
|
|
"code.gitea.io/gitea/modules/git"
|
2019-04-22 22:40:51 +02:00
|
|
|
"code.gitea.io/gitea/modules/log"
|
2017-04-21 09:01:08 +02:00
|
|
|
"code.gitea.io/gitea/modules/markup"
|
2017-09-21 07:20:14 +02:00
|
|
|
"code.gitea.io/gitea/modules/markup/markdown"
|
2021-06-26 13:28:55 +02:00
|
|
|
"code.gitea.io/gitea/modules/setting"
|
2019-08-15 16:46:21 +02:00
|
|
|
"code.gitea.io/gitea/modules/timeutil"
|
2017-12-13 14:46:56 +01:00
|
|
|
"code.gitea.io/gitea/modules/util"
|
2021-01-26 16:36:53 +01:00
|
|
|
"code.gitea.io/gitea/modules/web"
|
2021-06-09 01:33:54 +02:00
|
|
|
"code.gitea.io/gitea/routers/common"
|
2021-04-06 21:44:05 +02:00
|
|
|
"code.gitea.io/gitea/services/forms"
|
2020-01-07 19:27:36 +01:00
|
|
|
wiki_service "code.gitea.io/gitea/services/wiki"
|
2015-11-26 02:10:25 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2019-07-08 10:20:22 +02:00
|
|
|
tplWikiStart base.TplName = "repo/wiki/start"
|
|
|
|
tplWikiView base.TplName = "repo/wiki/view"
|
|
|
|
tplWikiRevision base.TplName = "repo/wiki/revision"
|
|
|
|
tplWikiNew base.TplName = "repo/wiki/new"
|
|
|
|
tplWikiPages base.TplName = "repo/wiki/pages"
|
2015-11-26 02:10:25 +01:00
|
|
|
)
|
|
|
|
|
2016-11-21 11:03:42 +01:00
|
|
|
// MustEnableWiki check if wiki is enabled, if external then redirect
|
2016-03-11 17:56:52 +01:00
|
|
|
func MustEnableWiki(ctx *context.Context) {
|
2021-11-09 20:57:58 +01:00
|
|
|
if !ctx.Repo.CanRead(unit.TypeWiki) &&
|
|
|
|
!ctx.Repo.CanRead(unit.TypeExternalWiki) {
|
2019-04-22 22:40:51 +02:00
|
|
|
if log.IsTrace() {
|
|
|
|
log.Trace("Permission Denied: User %-v cannot read %-v or %-v of repo %-v\n"+
|
|
|
|
"User in repo has Permissions: %-+v",
|
2022-03-22 08:03:22 +01:00
|
|
|
ctx.Doer,
|
2021-11-09 20:57:58 +01:00
|
|
|
unit.TypeWiki,
|
|
|
|
unit.TypeExternalWiki,
|
2019-04-22 22:40:51 +02:00
|
|
|
ctx.Repo.Repository,
|
|
|
|
ctx.Repo.Permission)
|
|
|
|
}
|
2018-01-10 22:34:17 +01:00
|
|
|
ctx.NotFound("MustEnableWiki", nil)
|
2015-12-11 10:55:08 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-11-09 20:57:58 +01:00
|
|
|
unit, err := ctx.Repo.Repository.GetUnit(unit.TypeExternalWiki)
|
2017-02-04 16:53:46 +01:00
|
|
|
if err == nil {
|
|
|
|
ctx.Redirect(unit.ExternalWikiConfig().ExternalWikiURL)
|
2015-12-11 10:55:08 +01:00
|
|
|
return
|
2015-12-05 03:30:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-02 22:02:04 +02:00
|
|
|
// PageMeta wiki page meta information
|
2015-11-27 07:50:38 +01:00
|
|
|
type PageMeta struct {
|
2017-12-13 14:46:56 +01:00
|
|
|
Name string
|
|
|
|
SubURL string
|
2019-08-15 16:46:21 +02:00
|
|
|
UpdatedUnix timeutil.TimeStamp
|
2015-11-27 07:50:38 +01:00
|
|
|
}
|
2015-11-26 02:10:25 +01:00
|
|
|
|
2017-11-28 10:43:51 +01:00
|
|
|
// findEntryForFile finds the tree entry for a target filepath.
|
|
|
|
func findEntryForFile(commit *git.Commit, target string) (*git.TreeEntry, error) {
|
2020-01-28 10:44:08 +01:00
|
|
|
entry, err := commit.GetTreeEntryByPath(target)
|
|
|
|
if err != nil && !git.IsErrNotExist(err) {
|
2017-02-14 02:13:59 +01:00
|
|
|
return nil, err
|
|
|
|
}
|
2020-01-28 10:44:08 +01:00
|
|
|
if entry != nil {
|
|
|
|
return entry, nil
|
2017-02-14 02:13:59 +01:00
|
|
|
}
|
2020-01-28 10:44:08 +01:00
|
|
|
|
2019-10-09 20:49:37 +02:00
|
|
|
// Then the unescaped, shortest alternative
|
|
|
|
var unescapedTarget string
|
|
|
|
if unescapedTarget, err = url.QueryUnescape(target); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-01-28 10:44:08 +01:00
|
|
|
return commit.GetTreeEntryByPath(unescapedTarget)
|
2017-02-14 02:13:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func findWikiRepoCommit(ctx *context.Context) (*git.Repository, *git.Commit, error) {
|
2022-03-29 21:13:41 +02:00
|
|
|
wikiRepo, err := git.OpenRepository(ctx, ctx.Repo.Repository.WikiPath())
|
2015-11-27 06:24:24 +01:00
|
|
|
if err != nil {
|
2018-01-10 22:34:17 +01:00
|
|
|
ctx.ServerError("OpenRepository", err)
|
2017-02-14 02:13:59 +01:00
|
|
|
return nil, nil, err
|
2015-11-27 06:24:24 +01:00
|
|
|
}
|
2017-03-20 14:36:19 +01:00
|
|
|
|
2015-12-10 02:46:05 +01:00
|
|
|
commit, err := wikiRepo.GetBranchCommit("master")
|
2015-11-27 06:24:24 +01:00
|
|
|
if err != nil {
|
2017-02-14 02:13:59 +01:00
|
|
|
return wikiRepo, nil, err
|
|
|
|
}
|
|
|
|
return wikiRepo, commit, nil
|
|
|
|
}
|
|
|
|
|
2017-11-28 10:43:51 +01:00
|
|
|
// wikiContentsByEntry returns the contents of the wiki page referenced by the
|
|
|
|
// given tree entry. Writes to ctx if an error occurs.
|
|
|
|
func wikiContentsByEntry(ctx *context.Context, entry *git.TreeEntry) []byte {
|
2019-04-19 14:17:27 +02:00
|
|
|
reader, err := entry.Blob().DataAsync()
|
2017-11-28 10:43:51 +01:00
|
|
|
if err != nil {
|
2018-01-10 22:34:17 +01:00
|
|
|
ctx.ServerError("Blob.Data", err)
|
2017-11-28 10:43:51 +01:00
|
|
|
return nil
|
|
|
|
}
|
2019-04-19 14:17:27 +02:00
|
|
|
defer reader.Close()
|
2021-09-22 07:38:34 +02:00
|
|
|
content, err := io.ReadAll(reader)
|
2017-11-28 10:43:51 +01:00
|
|
|
if err != nil {
|
2018-01-10 22:34:17 +01:00
|
|
|
ctx.ServerError("ReadAll", err)
|
2017-11-28 10:43:51 +01:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return content
|
|
|
|
}
|
|
|
|
|
|
|
|
// wikiContentsByName returns the contents of a wiki page, along with a boolean
|
|
|
|
// indicating whether the page exists. Writes to ctx if an error occurs.
|
2019-07-08 10:20:22 +02:00
|
|
|
func wikiContentsByName(ctx *context.Context, commit *git.Commit, wikiName string) ([]byte, *git.TreeEntry, string, bool) {
|
2020-01-07 19:27:36 +01:00
|
|
|
pageFilename := wiki_service.NameToFilename(wikiName)
|
2020-01-28 10:44:08 +01:00
|
|
|
entry, err := findEntryForFile(commit, pageFilename)
|
|
|
|
if err != nil && !git.IsErrNotExist(err) {
|
2018-01-10 22:34:17 +01:00
|
|
|
ctx.ServerError("findEntryForFile", err)
|
2019-07-08 10:20:22 +02:00
|
|
|
return nil, nil, "", false
|
2017-11-28 10:43:51 +01:00
|
|
|
} else if entry == nil {
|
2019-07-08 10:20:22 +02:00
|
|
|
return nil, nil, "", true
|
2017-11-28 10:43:51 +01:00
|
|
|
}
|
2019-07-08 10:20:22 +02:00
|
|
|
return wikiContentsByEntry(ctx, entry), entry, pageFilename, false
|
2017-11-28 10:43:51 +01:00
|
|
|
}
|
|
|
|
|
2019-07-08 10:20:22 +02:00
|
|
|
func renderViewPage(ctx *context.Context) (*git.Repository, *git.TreeEntry) {
|
2017-02-14 02:13:59 +01:00
|
|
|
wikiRepo, commit, err := findWikiRepoCommit(ctx)
|
|
|
|
if err != nil {
|
2021-08-30 22:50:35 +02:00
|
|
|
if wikiRepo != nil {
|
|
|
|
wikiRepo.Close()
|
|
|
|
}
|
2018-12-09 23:45:44 +01:00
|
|
|
if !git.IsErrNotExist(err) {
|
|
|
|
ctx.ServerError("GetBranchCommit", err)
|
|
|
|
}
|
2017-02-14 02:13:59 +01:00
|
|
|
return nil, nil
|
2015-11-27 07:50:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get page list.
|
2019-07-08 10:20:22 +02:00
|
|
|
entries, err := commit.ListEntries()
|
|
|
|
if err != nil {
|
2019-11-13 08:01:19 +01:00
|
|
|
if wikiRepo != nil {
|
|
|
|
wikiRepo.Close()
|
|
|
|
}
|
2019-07-08 10:20:22 +02:00
|
|
|
ctx.ServerError("ListEntries", err)
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
pages := make([]PageMeta, 0, len(entries))
|
|
|
|
for _, entry := range entries {
|
|
|
|
if !entry.IsRegular() {
|
|
|
|
continue
|
2015-11-27 07:50:38 +01:00
|
|
|
}
|
2020-01-07 19:27:36 +01:00
|
|
|
wikiName, err := wiki_service.FilenameToName(entry.Name())
|
2019-07-08 10:20:22 +02:00
|
|
|
if err != nil {
|
|
|
|
if models.IsErrWikiInvalidFileName(err) {
|
2017-11-28 10:43:51 +01:00
|
|
|
continue
|
|
|
|
}
|
2019-11-13 08:01:19 +01:00
|
|
|
if wikiRepo != nil {
|
|
|
|
wikiRepo.Close()
|
|
|
|
}
|
2019-07-08 10:20:22 +02:00
|
|
|
ctx.ServerError("WikiFilenameToName", err)
|
|
|
|
return nil, nil
|
|
|
|
} else if wikiName == "_Sidebar" || wikiName == "_Footer" {
|
|
|
|
continue
|
2015-11-27 07:50:38 +01:00
|
|
|
}
|
2019-07-08 10:20:22 +02:00
|
|
|
pages = append(pages, PageMeta{
|
|
|
|
Name: wikiName,
|
2020-01-07 19:27:36 +01:00
|
|
|
SubURL: wiki_service.NameToSubURL(wikiName),
|
2019-07-08 10:20:22 +02:00
|
|
|
})
|
2015-11-27 06:24:24 +01:00
|
|
|
}
|
2019-07-08 10:20:22 +02:00
|
|
|
ctx.Data["Pages"] = pages
|
2015-11-27 06:24:24 +01:00
|
|
|
|
2019-07-08 10:20:22 +02:00
|
|
|
// get requested pagename
|
2021-11-16 19:18:25 +01:00
|
|
|
pageName := wiki_service.NormalizeWikiName(ctx.Params("*"))
|
2017-11-28 10:43:51 +01:00
|
|
|
if len(pageName) == 0 {
|
|
|
|
pageName = "Home"
|
2015-11-27 06:24:24 +01:00
|
|
|
}
|
2020-01-07 19:27:36 +01:00
|
|
|
ctx.Data["PageURL"] = wiki_service.NameToSubURL(pageName)
|
2015-11-27 07:50:38 +01:00
|
|
|
ctx.Data["old_title"] = pageName
|
|
|
|
ctx.Data["Title"] = pageName
|
|
|
|
ctx.Data["title"] = pageName
|
2015-11-27 06:24:24 +01:00
|
|
|
|
2022-04-27 01:24:20 +02:00
|
|
|
isSideBar := pageName == "_Sidebar"
|
|
|
|
isFooter := pageName == "_Footer"
|
|
|
|
|
2022-01-20 18:46:10 +01:00
|
|
|
// lookup filename in wiki - get filecontent, gitTree entry , real filename
|
2019-07-08 10:20:22 +02:00
|
|
|
data, entry, pageFilename, noEntry := wikiContentsByName(ctx, commit, pageName)
|
|
|
|
if noEntry {
|
2021-11-16 19:18:25 +01:00
|
|
|
ctx.Redirect(ctx.Repo.RepoLink + "/wiki/?action=_pages")
|
2019-07-08 10:20:22 +02:00
|
|
|
}
|
|
|
|
if entry == nil || ctx.Written() {
|
2019-11-13 08:01:19 +01:00
|
|
|
if wikiRepo != nil {
|
|
|
|
wikiRepo.Close()
|
|
|
|
}
|
2017-02-14 02:13:59 +01:00
|
|
|
return nil, nil
|
2015-11-27 06:24:24 +01:00
|
|
|
}
|
2019-07-08 10:20:22 +02:00
|
|
|
|
2022-04-27 01:24:20 +02:00
|
|
|
var sidebarContent []byte
|
|
|
|
if !isSideBar {
|
|
|
|
sidebarContent, _, _, _ = wikiContentsByName(ctx, commit, "_Sidebar")
|
|
|
|
if ctx.Written() {
|
|
|
|
if wikiRepo != nil {
|
|
|
|
wikiRepo.Close()
|
|
|
|
}
|
|
|
|
return nil, nil
|
2019-11-13 08:01:19 +01:00
|
|
|
}
|
2022-04-27 01:24:20 +02:00
|
|
|
} else {
|
|
|
|
sidebarContent = data
|
2017-02-14 02:13:59 +01:00
|
|
|
}
|
2017-11-28 10:43:51 +01:00
|
|
|
|
2022-04-27 01:24:20 +02:00
|
|
|
var footerContent []byte
|
|
|
|
if !isFooter {
|
|
|
|
footerContent, _, _, _ = wikiContentsByName(ctx, commit, "_Footer")
|
|
|
|
if ctx.Written() {
|
|
|
|
if wikiRepo != nil {
|
|
|
|
wikiRepo.Close()
|
|
|
|
}
|
|
|
|
return nil, nil
|
2019-11-13 08:01:19 +01:00
|
|
|
}
|
2022-04-27 01:24:20 +02:00
|
|
|
} else {
|
|
|
|
footerContent = data
|
2019-07-08 10:20:22 +02:00
|
|
|
}
|
2017-11-28 10:43:51 +01:00
|
|
|
|
2022-01-20 18:46:10 +01:00
|
|
|
rctx := &markup.RenderContext{
|
2022-01-20 00:26:57 +01:00
|
|
|
Ctx: ctx,
|
2021-04-20 00:25:08 +02:00
|
|
|
URLPrefix: ctx.Repo.RepoLink,
|
|
|
|
Metas: ctx.Repo.Repository.ComposeDocumentMetas(),
|
|
|
|
IsWiki: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
var buf strings.Builder
|
|
|
|
if err := markdown.Render(rctx, bytes.NewReader(data), &buf); err != nil {
|
2021-08-30 22:50:35 +02:00
|
|
|
if wikiRepo != nil {
|
|
|
|
wikiRepo.Close()
|
|
|
|
}
|
2021-04-20 00:25:08 +02:00
|
|
|
ctx.ServerError("Render", err)
|
|
|
|
return nil, nil
|
|
|
|
}
|
2022-01-07 02:18:52 +01:00
|
|
|
|
|
|
|
ctx.Data["EscapeStatus"], ctx.Data["content"] = charset.EscapeControlString(buf.String())
|
2021-04-20 00:25:08 +02:00
|
|
|
|
2022-04-27 01:24:20 +02:00
|
|
|
if !isSideBar {
|
|
|
|
buf.Reset()
|
|
|
|
if err := markdown.Render(rctx, bytes.NewReader(sidebarContent), &buf); err != nil {
|
|
|
|
if wikiRepo != nil {
|
|
|
|
wikiRepo.Close()
|
|
|
|
}
|
|
|
|
ctx.ServerError("Render", err)
|
|
|
|
return nil, nil
|
2021-08-30 22:50:35 +02:00
|
|
|
}
|
2022-04-27 01:24:20 +02:00
|
|
|
ctx.Data["sidebarPresent"] = sidebarContent != nil
|
|
|
|
ctx.Data["sidebarEscapeStatus"], ctx.Data["sidebarContent"] = charset.EscapeControlString(buf.String())
|
|
|
|
} else {
|
|
|
|
ctx.Data["sidebarPresent"] = false
|
2021-04-20 00:25:08 +02:00
|
|
|
}
|
|
|
|
|
2022-04-27 01:24:20 +02:00
|
|
|
if !isFooter {
|
|
|
|
buf.Reset()
|
|
|
|
if err := markdown.Render(rctx, bytes.NewReader(footerContent), &buf); err != nil {
|
|
|
|
if wikiRepo != nil {
|
|
|
|
wikiRepo.Close()
|
|
|
|
}
|
|
|
|
ctx.ServerError("Render", err)
|
|
|
|
return nil, nil
|
2021-08-30 22:50:35 +02:00
|
|
|
}
|
2022-04-27 01:24:20 +02:00
|
|
|
ctx.Data["footerPresent"] = footerContent != nil
|
|
|
|
ctx.Data["footerEscapeStatus"], ctx.Data["footerContent"] = charset.EscapeControlString(buf.String())
|
|
|
|
} else {
|
|
|
|
ctx.Data["footerPresent"] = false
|
2021-04-20 00:25:08 +02:00
|
|
|
}
|
2019-07-08 10:20:22 +02:00
|
|
|
|
|
|
|
// get commit count - wiki revisions
|
|
|
|
commitsCount, _ := wikiRepo.FileCommitsCount("master", pageFilename)
|
|
|
|
ctx.Data["CommitCount"] = commitsCount
|
|
|
|
|
|
|
|
return wikiRepo, entry
|
|
|
|
}
|
|
|
|
|
|
|
|
func renderRevisionPage(ctx *context.Context) (*git.Repository, *git.TreeEntry) {
|
|
|
|
wikiRepo, commit, err := findWikiRepoCommit(ctx)
|
|
|
|
if err != nil {
|
2019-11-13 08:01:19 +01:00
|
|
|
if wikiRepo != nil {
|
|
|
|
wikiRepo.Close()
|
|
|
|
}
|
2019-07-08 10:20:22 +02:00
|
|
|
if !git.IsErrNotExist(err) {
|
|
|
|
ctx.ServerError("GetBranchCommit", err)
|
2017-02-14 02:13:59 +01:00
|
|
|
}
|
2019-07-08 10:20:22 +02:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// get requested pagename
|
2021-11-16 19:18:25 +01:00
|
|
|
pageName := wiki_service.NormalizeWikiName(ctx.Params("*"))
|
2019-07-08 10:20:22 +02:00
|
|
|
if len(pageName) == 0 {
|
|
|
|
pageName = "Home"
|
|
|
|
}
|
2020-01-07 19:27:36 +01:00
|
|
|
ctx.Data["PageURL"] = wiki_service.NameToSubURL(pageName)
|
2019-07-08 10:20:22 +02:00
|
|
|
ctx.Data["old_title"] = pageName
|
|
|
|
ctx.Data["Title"] = pageName
|
|
|
|
ctx.Data["title"] = pageName
|
2020-05-16 18:38:40 +02:00
|
|
|
ctx.Data["Username"] = ctx.Repo.Owner.Name
|
|
|
|
ctx.Data["Reponame"] = ctx.Repo.Repository.Name
|
2017-11-28 10:43:51 +01:00
|
|
|
|
2022-01-20 18:46:10 +01:00
|
|
|
// lookup filename in wiki - get filecontent, gitTree entry , real filename
|
2019-07-08 10:20:22 +02:00
|
|
|
data, entry, pageFilename, noEntry := wikiContentsByName(ctx, commit, pageName)
|
|
|
|
if noEntry {
|
2021-11-16 19:18:25 +01:00
|
|
|
ctx.Redirect(ctx.Repo.RepoLink + "/wiki/?action=_pages")
|
2019-07-08 10:20:22 +02:00
|
|
|
}
|
|
|
|
if entry == nil || ctx.Written() {
|
2019-11-13 08:01:19 +01:00
|
|
|
if wikiRepo != nil {
|
|
|
|
wikiRepo.Close()
|
|
|
|
}
|
2019-07-08 10:20:22 +02:00
|
|
|
return nil, nil
|
2015-11-27 07:50:38 +01:00
|
|
|
}
|
|
|
|
|
2019-07-08 10:20:22 +02:00
|
|
|
ctx.Data["content"] = string(data)
|
|
|
|
ctx.Data["sidebarPresent"] = false
|
|
|
|
ctx.Data["sidebarContent"] = ""
|
|
|
|
ctx.Data["footerPresent"] = false
|
|
|
|
ctx.Data["footerContent"] = ""
|
|
|
|
|
|
|
|
// get commit count - wiki revisions
|
|
|
|
commitsCount, _ := wikiRepo.FileCommitsCount("master", pageFilename)
|
|
|
|
ctx.Data["CommitCount"] = commitsCount
|
|
|
|
|
|
|
|
// get page
|
2021-07-29 03:42:15 +02:00
|
|
|
page := ctx.FormInt("page")
|
2019-07-08 10:20:22 +02:00
|
|
|
if page <= 1 {
|
|
|
|
page = 1
|
|
|
|
}
|
|
|
|
|
|
|
|
// get Commit Count
|
2019-07-11 16:45:10 +02:00
|
|
|
commitsHistory, err := wikiRepo.CommitsByFileAndRangeNoFollow("master", pageFilename, page)
|
2019-07-08 10:20:22 +02:00
|
|
|
if err != nil {
|
2019-11-13 08:01:19 +01:00
|
|
|
if wikiRepo != nil {
|
|
|
|
wikiRepo.Close()
|
|
|
|
}
|
2019-07-11 16:45:10 +02:00
|
|
|
ctx.ServerError("CommitsByFileAndRangeNoFollow", err)
|
2019-07-08 10:20:22 +02:00
|
|
|
return nil, nil
|
|
|
|
}
|
2021-08-09 20:08:51 +02:00
|
|
|
ctx.Data["Commits"] = models.ConvertFromGitCommit(commitsHistory, ctx.Repo.Repository)
|
2019-07-08 10:20:22 +02:00
|
|
|
|
2021-06-26 13:28:55 +02:00
|
|
|
pager := context.NewPagination(int(commitsCount), setting.Git.CommitsRangeSize, page, 5)
|
2019-07-08 10:20:22 +02:00
|
|
|
pager.SetDefaultParams(ctx)
|
|
|
|
ctx.Data["Page"] = pager
|
|
|
|
|
2017-02-14 02:13:59 +01:00
|
|
|
return wikiRepo, entry
|
2015-11-27 07:50:38 +01:00
|
|
|
}
|
|
|
|
|
2019-07-08 10:20:22 +02:00
|
|
|
func renderEditPage(ctx *context.Context) {
|
2019-11-13 08:01:19 +01:00
|
|
|
wikiRepo, commit, err := findWikiRepoCommit(ctx)
|
2019-07-08 10:20:22 +02:00
|
|
|
if err != nil {
|
2019-11-13 08:01:19 +01:00
|
|
|
if wikiRepo != nil {
|
|
|
|
wikiRepo.Close()
|
|
|
|
}
|
2019-07-08 10:20:22 +02:00
|
|
|
if !git.IsErrNotExist(err) {
|
|
|
|
ctx.ServerError("GetBranchCommit", err)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
2019-11-13 08:01:19 +01:00
|
|
|
defer func() {
|
|
|
|
if wikiRepo != nil {
|
|
|
|
wikiRepo.Close()
|
|
|
|
}
|
|
|
|
}()
|
2019-07-08 10:20:22 +02:00
|
|
|
|
|
|
|
// get requested pagename
|
2021-11-16 19:18:25 +01:00
|
|
|
pageName := wiki_service.NormalizeWikiName(ctx.Params("*"))
|
2019-07-08 10:20:22 +02:00
|
|
|
if len(pageName) == 0 {
|
|
|
|
pageName = "Home"
|
|
|
|
}
|
2020-01-07 19:27:36 +01:00
|
|
|
ctx.Data["PageURL"] = wiki_service.NameToSubURL(pageName)
|
2019-07-08 10:20:22 +02:00
|
|
|
ctx.Data["old_title"] = pageName
|
|
|
|
ctx.Data["Title"] = pageName
|
|
|
|
ctx.Data["title"] = pageName
|
|
|
|
|
2022-01-20 18:46:10 +01:00
|
|
|
// lookup filename in wiki - get filecontent, gitTree entry , real filename
|
2019-07-08 10:20:22 +02:00
|
|
|
data, entry, _, noEntry := wikiContentsByName(ctx, commit, pageName)
|
|
|
|
if noEntry {
|
2021-11-16 19:18:25 +01:00
|
|
|
ctx.Redirect(ctx.Repo.RepoLink + "/wiki/?action=_pages")
|
2019-07-08 10:20:22 +02:00
|
|
|
}
|
|
|
|
if entry == nil || ctx.Written() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.Data["content"] = string(data)
|
|
|
|
ctx.Data["sidebarPresent"] = false
|
|
|
|
ctx.Data["sidebarContent"] = ""
|
|
|
|
ctx.Data["footerPresent"] = false
|
|
|
|
ctx.Data["footerContent"] = ""
|
|
|
|
}
|
|
|
|
|
2021-11-16 19:18:25 +01:00
|
|
|
// WikiPost renders post of wiki page
|
|
|
|
func WikiPost(ctx *context.Context) {
|
|
|
|
switch ctx.FormString("action") {
|
|
|
|
case "_new":
|
|
|
|
if !ctx.Repo.CanWrite(unit.TypeWiki) {
|
|
|
|
ctx.NotFound(ctx.Req.URL.RequestURI(), nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
NewWikiPost(ctx)
|
|
|
|
return
|
|
|
|
case "_delete":
|
|
|
|
if !ctx.Repo.CanWrite(unit.TypeWiki) {
|
|
|
|
ctx.NotFound(ctx.Req.URL.RequestURI(), nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
DeleteWikiPagePost(ctx)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if !ctx.Repo.CanWrite(unit.TypeWiki) {
|
|
|
|
ctx.NotFound(ctx.Req.URL.RequestURI(), nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
EditWikiPost(ctx)
|
|
|
|
}
|
|
|
|
|
2017-02-14 02:13:59 +01:00
|
|
|
// Wiki renders single wiki page
|
2016-03-11 17:56:52 +01:00
|
|
|
func Wiki(ctx *context.Context) {
|
2021-11-09 20:57:58 +01:00
|
|
|
ctx.Data["CanWriteWiki"] = ctx.Repo.CanWrite(unit.TypeWiki) && !ctx.Repo.Repository.IsArchived
|
2015-11-27 07:50:38 +01:00
|
|
|
|
2021-11-16 19:18:25 +01:00
|
|
|
switch ctx.FormString("action") {
|
|
|
|
case "_pages":
|
|
|
|
WikiPages(ctx)
|
|
|
|
return
|
|
|
|
case "_revision":
|
|
|
|
WikiRevision(ctx)
|
|
|
|
return
|
|
|
|
case "_edit":
|
|
|
|
if !ctx.Repo.CanWrite(unit.TypeWiki) {
|
|
|
|
ctx.NotFound(ctx.Req.URL.RequestURI(), nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
EditWiki(ctx)
|
|
|
|
return
|
|
|
|
case "_new":
|
|
|
|
if !ctx.Repo.CanWrite(unit.TypeWiki) {
|
|
|
|
ctx.NotFound(ctx.Req.URL.RequestURI(), nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
NewWiki(ctx)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-12-03 20:46:11 +01:00
|
|
|
if !ctx.Repo.Repository.HasWiki() {
|
|
|
|
ctx.Data["Title"] = ctx.Tr("repo.wiki")
|
|
|
|
ctx.HTML(http.StatusOK, tplWikiStart)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-07-08 10:20:22 +02:00
|
|
|
wikiRepo, entry := renderViewPage(ctx)
|
2019-11-13 08:01:19 +01:00
|
|
|
defer func() {
|
|
|
|
if wikiRepo != nil {
|
|
|
|
wikiRepo.Close()
|
|
|
|
}
|
|
|
|
}()
|
2021-08-30 22:50:35 +02:00
|
|
|
if ctx.Written() {
|
|
|
|
return
|
|
|
|
}
|
2017-03-20 14:36:19 +01:00
|
|
|
if entry == nil {
|
|
|
|
ctx.Data["Title"] = ctx.Tr("repo.wiki")
|
2021-04-05 17:30:52 +02:00
|
|
|
ctx.HTML(http.StatusOK, tplWikiStart)
|
2017-03-20 14:36:19 +01:00
|
|
|
return
|
|
|
|
}
|
2015-11-27 06:24:24 +01:00
|
|
|
|
2017-11-28 10:43:51 +01:00
|
|
|
wikiPath := entry.Name()
|
|
|
|
if markup.Type(wikiPath) != markdown.MarkupName {
|
|
|
|
ext := strings.ToUpper(filepath.Ext(wikiPath))
|
2017-02-14 02:13:59 +01:00
|
|
|
ctx.Data["FormatWarning"] = fmt.Sprintf("%s rendering is not supported at the moment. Rendered as Markdown.", ext)
|
|
|
|
}
|
2015-11-27 06:24:24 +01:00
|
|
|
// Get last change information.
|
2017-11-28 10:43:51 +01:00
|
|
|
lastCommit, err := wikiRepo.GetCommitByPath(wikiPath)
|
2015-11-27 06:24:24 +01:00
|
|
|
if err != nil {
|
2018-01-10 22:34:17 +01:00
|
|
|
ctx.ServerError("GetCommitByPath", err)
|
2015-11-27 06:24:24 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
ctx.Data["Author"] = lastCommit.Author
|
|
|
|
|
2021-04-05 17:30:52 +02:00
|
|
|
ctx.HTML(http.StatusOK, tplWikiView)
|
2015-11-26 02:10:25 +01:00
|
|
|
}
|
|
|
|
|
2019-07-08 10:20:22 +02:00
|
|
|
// WikiRevision renders file revision list of wiki page
|
|
|
|
func WikiRevision(ctx *context.Context) {
|
2021-11-09 20:57:58 +01:00
|
|
|
ctx.Data["CanWriteWiki"] = ctx.Repo.CanWrite(unit.TypeWiki) && !ctx.Repo.Repository.IsArchived
|
2019-07-08 10:20:22 +02:00
|
|
|
|
|
|
|
if !ctx.Repo.Repository.HasWiki() {
|
|
|
|
ctx.Data["Title"] = ctx.Tr("repo.wiki")
|
2021-04-05 17:30:52 +02:00
|
|
|
ctx.HTML(http.StatusOK, tplWikiStart)
|
2019-07-08 10:20:22 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
wikiRepo, entry := renderRevisionPage(ctx)
|
2019-11-13 08:01:19 +01:00
|
|
|
defer func() {
|
|
|
|
if wikiRepo != nil {
|
|
|
|
wikiRepo.Close()
|
|
|
|
}
|
|
|
|
}()
|
2021-08-30 22:50:35 +02:00
|
|
|
|
|
|
|
if ctx.Written() {
|
|
|
|
return
|
|
|
|
}
|
2019-07-08 10:20:22 +02:00
|
|
|
if entry == nil {
|
|
|
|
ctx.Data["Title"] = ctx.Tr("repo.wiki")
|
2021-04-05 17:30:52 +02:00
|
|
|
ctx.HTML(http.StatusOK, tplWikiStart)
|
2019-07-08 10:20:22 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get last change information.
|
|
|
|
wikiPath := entry.Name()
|
|
|
|
lastCommit, err := wikiRepo.GetCommitByPath(wikiPath)
|
|
|
|
if err != nil {
|
|
|
|
ctx.ServerError("GetCommitByPath", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
ctx.Data["Author"] = lastCommit.Author
|
|
|
|
|
2021-04-05 17:30:52 +02:00
|
|
|
ctx.HTML(http.StatusOK, tplWikiRevision)
|
2019-07-08 10:20:22 +02:00
|
|
|
}
|
|
|
|
|
2016-11-21 11:03:42 +01:00
|
|
|
// WikiPages render wiki pages list page
|
2016-03-11 17:56:52 +01:00
|
|
|
func WikiPages(ctx *context.Context) {
|
2015-11-27 08:16:12 +01:00
|
|
|
if !ctx.Repo.Repository.HasWiki() {
|
|
|
|
ctx.Redirect(ctx.Repo.RepoLink + "/wiki")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-11-28 12:26:14 +01:00
|
|
|
ctx.Data["Title"] = ctx.Tr("repo.wiki.pages")
|
2021-11-09 20:57:58 +01:00
|
|
|
ctx.Data["CanWriteWiki"] = ctx.Repo.CanWrite(unit.TypeWiki) && !ctx.Repo.Repository.IsArchived
|
2018-11-28 12:26:14 +01:00
|
|
|
|
2017-02-14 02:13:59 +01:00
|
|
|
wikiRepo, commit, err := findWikiRepoCommit(ctx)
|
2015-11-27 08:16:12 +01:00
|
|
|
if err != nil {
|
2019-11-13 08:01:19 +01:00
|
|
|
if wikiRepo != nil {
|
|
|
|
wikiRepo.Close()
|
|
|
|
}
|
2015-11-27 08:16:12 +01:00
|
|
|
return
|
|
|
|
}
|
2021-08-30 22:50:35 +02:00
|
|
|
defer func() {
|
2019-11-13 08:01:19 +01:00
|
|
|
if wikiRepo != nil {
|
|
|
|
wikiRepo.Close()
|
|
|
|
}
|
2021-08-30 22:50:35 +02:00
|
|
|
}()
|
2019-11-13 08:01:19 +01:00
|
|
|
|
2021-08-30 22:50:35 +02:00
|
|
|
entries, err := commit.ListEntries()
|
|
|
|
if err != nil {
|
2018-01-10 22:34:17 +01:00
|
|
|
ctx.ServerError("ListEntries", err)
|
2015-11-27 08:16:12 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
pages := make([]PageMeta, 0, len(entries))
|
2017-11-28 10:43:51 +01:00
|
|
|
for _, entry := range entries {
|
2019-04-19 14:17:27 +02:00
|
|
|
if !entry.IsRegular() {
|
2017-11-28 10:43:51 +01:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
c, err := wikiRepo.GetCommitByPath(entry.Name())
|
|
|
|
if err != nil {
|
2018-01-10 22:34:17 +01:00
|
|
|
ctx.ServerError("GetCommit", err)
|
2017-11-28 10:43:51 +01:00
|
|
|
return
|
|
|
|
}
|
2020-01-07 19:27:36 +01:00
|
|
|
wikiName, err := wiki_service.FilenameToName(entry.Name())
|
2017-11-28 10:43:51 +01:00
|
|
|
if err != nil {
|
2018-02-05 15:56:30 +01:00
|
|
|
if models.IsErrWikiInvalidFileName(err) {
|
|
|
|
continue
|
|
|
|
}
|
2018-01-10 22:34:17 +01:00
|
|
|
ctx.ServerError("WikiFilenameToName", err)
|
2017-11-28 10:43:51 +01:00
|
|
|
return
|
2015-11-27 08:16:12 +01:00
|
|
|
}
|
2017-11-28 10:43:51 +01:00
|
|
|
pages = append(pages, PageMeta{
|
2017-12-13 14:46:56 +01:00
|
|
|
Name: wikiName,
|
2020-01-07 19:27:36 +01:00
|
|
|
SubURL: wiki_service.NameToSubURL(wikiName),
|
2019-08-15 16:46:21 +02:00
|
|
|
UpdatedUnix: timeutil.TimeStamp(c.Author.When.Unix()),
|
2017-11-28 10:43:51 +01:00
|
|
|
})
|
2015-11-27 08:16:12 +01:00
|
|
|
}
|
|
|
|
ctx.Data["Pages"] = pages
|
2015-11-27 06:24:24 +01:00
|
|
|
|
2021-04-05 17:30:52 +02:00
|
|
|
ctx.HTML(http.StatusOK, tplWikiPages)
|
2015-11-27 06:24:24 +01:00
|
|
|
}
|
|
|
|
|
2017-02-14 02:13:59 +01:00
|
|
|
// WikiRaw outputs raw blob requested by user (image for example)
|
|
|
|
func WikiRaw(ctx *context.Context) {
|
|
|
|
wikiRepo, commit, err := findWikiRepoCommit(ctx)
|
2021-08-30 22:50:35 +02:00
|
|
|
defer func() {
|
2017-02-14 02:13:59 +01:00
|
|
|
if wikiRepo != nil {
|
2021-08-30 22:50:35 +02:00
|
|
|
wikiRepo.Close()
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
if git.IsErrNotExist(err) {
|
|
|
|
ctx.NotFound("findEntryForFile", nil)
|
2017-02-14 02:13:59 +01:00
|
|
|
return
|
|
|
|
}
|
2021-08-30 22:50:35 +02:00
|
|
|
ctx.ServerError("findEntryForfile", err)
|
|
|
|
return
|
2017-02-14 02:13:59 +01:00
|
|
|
}
|
2019-02-06 02:58:55 +01:00
|
|
|
|
2017-11-28 10:43:51 +01:00
|
|
|
providedPath := ctx.Params("*")
|
2019-02-06 02:58:55 +01:00
|
|
|
|
2017-02-14 02:13:59 +01:00
|
|
|
var entry *git.TreeEntry
|
|
|
|
if commit != nil {
|
2019-02-06 02:58:55 +01:00
|
|
|
// Try to find a file with that name
|
|
|
|
entry, err = findEntryForFile(commit, providedPath)
|
2020-01-28 10:44:08 +01:00
|
|
|
if err != nil && !git.IsErrNotExist(err) {
|
2019-02-06 02:58:55 +01:00
|
|
|
ctx.ServerError("findFile", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if entry == nil {
|
|
|
|
// Try to find a wiki page with that name
|
2021-08-30 22:50:35 +02:00
|
|
|
providedPath = strings.TrimSuffix(providedPath, ".md")
|
2019-02-06 02:58:55 +01:00
|
|
|
|
2020-01-07 19:27:36 +01:00
|
|
|
wikiPath := wiki_service.NameToFilename(providedPath)
|
2019-02-06 02:58:55 +01:00
|
|
|
entry, err = findEntryForFile(commit, wikiPath)
|
2020-01-28 10:44:08 +01:00
|
|
|
if err != nil && !git.IsErrNotExist(err) {
|
2019-02-06 02:58:55 +01:00
|
|
|
ctx.ServerError("findFile", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2017-02-14 02:13:59 +01:00
|
|
|
}
|
2019-02-06 02:58:55 +01:00
|
|
|
|
|
|
|
if entry != nil {
|
2022-05-09 17:54:51 +02:00
|
|
|
if err = common.ServeBlob(ctx, entry.Blob(), time.Time{}); err != nil {
|
2019-02-06 02:58:55 +01:00
|
|
|
ctx.ServerError("ServeBlob", err)
|
|
|
|
}
|
2017-11-28 10:43:51 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-02-06 02:58:55 +01:00
|
|
|
ctx.NotFound("findEntryForFile", nil)
|
2017-02-14 02:13:59 +01:00
|
|
|
}
|
|
|
|
|
2016-11-21 11:03:42 +01:00
|
|
|
// NewWiki render wiki create page
|
2016-03-11 17:56:52 +01:00
|
|
|
func NewWiki(ctx *context.Context) {
|
2015-11-26 02:10:25 +01:00
|
|
|
ctx.Data["Title"] = ctx.Tr("repo.wiki.new_page")
|
|
|
|
|
2015-11-26 23:33:45 +01:00
|
|
|
if !ctx.Repo.Repository.HasWiki() {
|
2015-11-26 02:10:25 +01:00
|
|
|
ctx.Data["title"] = "Home"
|
|
|
|
}
|
2021-12-03 08:28:54 +01:00
|
|
|
if ctx.FormString("title") != "" {
|
|
|
|
ctx.Data["title"] = ctx.FormString("title")
|
|
|
|
}
|
2015-11-26 02:10:25 +01:00
|
|
|
|
2021-04-05 17:30:52 +02:00
|
|
|
ctx.HTML(http.StatusOK, tplWikiNew)
|
2015-11-26 02:10:25 +01:00
|
|
|
}
|
|
|
|
|
2017-11-28 10:43:51 +01:00
|
|
|
// NewWikiPost response for wiki create request
|
2021-01-26 16:36:53 +01:00
|
|
|
func NewWikiPost(ctx *context.Context) {
|
2021-04-06 21:44:05 +02:00
|
|
|
form := web.GetForm(ctx).(*forms.NewWikiForm)
|
2015-11-26 23:33:45 +01:00
|
|
|
ctx.Data["Title"] = ctx.Tr("repo.wiki.new_page")
|
|
|
|
|
|
|
|
if ctx.HasError() {
|
2021-04-05 17:30:52 +02:00
|
|
|
ctx.HTML(http.StatusOK, tplWikiNew)
|
2015-11-26 23:33:45 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-01-21 12:45:32 +01:00
|
|
|
if util.IsEmptyString(form.Title) {
|
|
|
|
ctx.RenderWithErr(ctx.Tr("repo.issues.new.title_empty"), tplWikiNew, form)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-01-07 19:27:36 +01:00
|
|
|
wikiName := wiki_service.NormalizeWikiName(form.Title)
|
2020-05-22 15:14:02 +02:00
|
|
|
|
|
|
|
if len(form.Message) == 0 {
|
|
|
|
form.Message = ctx.Tr("repo.editor.add", form.Title)
|
|
|
|
}
|
|
|
|
|
2022-03-22 08:03:22 +01:00
|
|
|
if err := wiki_service.AddWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, wikiName, form.Content, form.Message); err != nil {
|
2017-11-28 10:43:51 +01:00
|
|
|
if models.IsErrWikiReservedName(err) {
|
|
|
|
ctx.Data["Err_Title"] = true
|
|
|
|
ctx.RenderWithErr(ctx.Tr("repo.wiki.reserved_page", wikiName), tplWikiNew, &form)
|
|
|
|
} else if models.IsErrWikiAlreadyExist(err) {
|
2015-11-27 07:50:38 +01:00
|
|
|
ctx.Data["Err_Title"] = true
|
2016-11-21 11:03:42 +01:00
|
|
|
ctx.RenderWithErr(ctx.Tr("repo.wiki.page_already_exists"), tplWikiNew, &form)
|
2015-11-27 07:50:38 +01:00
|
|
|
} else {
|
2018-01-10 22:34:17 +01:00
|
|
|
ctx.ServerError("AddWikiPage", err)
|
2015-11-27 07:50:38 +01:00
|
|
|
}
|
2015-11-26 23:33:45 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-01-07 19:27:36 +01:00
|
|
|
ctx.Redirect(ctx.Repo.RepoLink + "/wiki/" + wiki_service.NameToSubURL(wikiName))
|
2015-11-26 23:33:45 +01:00
|
|
|
}
|
|
|
|
|
2016-11-21 11:03:42 +01:00
|
|
|
// EditWiki render wiki modify page
|
2016-03-11 17:56:52 +01:00
|
|
|
func EditWiki(ctx *context.Context) {
|
2015-11-27 07:50:38 +01:00
|
|
|
ctx.Data["PageIsWikiEdit"] = true
|
|
|
|
|
|
|
|
if !ctx.Repo.Repository.HasWiki() {
|
|
|
|
ctx.Redirect(ctx.Repo.RepoLink + "/wiki")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-07-08 10:20:22 +02:00
|
|
|
renderEditPage(ctx)
|
2015-11-27 07:50:38 +01:00
|
|
|
if ctx.Written() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-04-05 17:30:52 +02:00
|
|
|
ctx.HTML(http.StatusOK, tplWikiNew)
|
2015-11-27 07:50:38 +01:00
|
|
|
}
|
|
|
|
|
2017-11-28 10:43:51 +01:00
|
|
|
// EditWikiPost response for wiki modify request
|
2021-01-26 16:36:53 +01:00
|
|
|
func EditWikiPost(ctx *context.Context) {
|
2021-04-06 21:44:05 +02:00
|
|
|
form := web.GetForm(ctx).(*forms.NewWikiForm)
|
2015-11-27 07:50:38 +01:00
|
|
|
ctx.Data["Title"] = ctx.Tr("repo.wiki.new_page")
|
|
|
|
|
|
|
|
if ctx.HasError() {
|
2021-04-05 17:30:52 +02:00
|
|
|
ctx.HTML(http.StatusOK, tplWikiNew)
|
2015-11-27 07:50:38 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-11-16 19:18:25 +01:00
|
|
|
oldWikiName := wiki_service.NormalizeWikiName(ctx.Params("*"))
|
2020-01-07 19:27:36 +01:00
|
|
|
newWikiName := wiki_service.NormalizeWikiName(form.Title)
|
2017-01-21 13:50:51 +01:00
|
|
|
|
2020-05-22 15:14:02 +02:00
|
|
|
if len(form.Message) == 0 {
|
|
|
|
form.Message = ctx.Tr("repo.editor.update", form.Title)
|
|
|
|
}
|
|
|
|
|
2022-03-22 08:03:22 +01:00
|
|
|
if err := wiki_service.EditWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, oldWikiName, newWikiName, form.Content, form.Message); err != nil {
|
2018-01-10 22:34:17 +01:00
|
|
|
ctx.ServerError("EditWikiPage", err)
|
2015-11-27 07:50:38 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-01-07 19:27:36 +01:00
|
|
|
ctx.Redirect(ctx.Repo.RepoLink + "/wiki/" + wiki_service.NameToSubURL(newWikiName))
|
2015-11-26 02:10:25 +01:00
|
|
|
}
|
2016-03-03 23:06:50 +01:00
|
|
|
|
2016-11-21 11:03:42 +01:00
|
|
|
// DeleteWikiPagePost delete wiki page
|
2016-03-11 17:56:52 +01:00
|
|
|
func DeleteWikiPagePost(ctx *context.Context) {
|
2021-11-16 19:18:25 +01:00
|
|
|
wikiName := wiki_service.NormalizeWikiName(ctx.Params("*"))
|
2017-11-28 10:43:51 +01:00
|
|
|
if len(wikiName) == 0 {
|
|
|
|
wikiName = "Home"
|
2016-03-03 23:06:50 +01:00
|
|
|
}
|
|
|
|
|
2022-03-22 08:03:22 +01:00
|
|
|
if err := wiki_service.DeleteWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, wikiName); err != nil {
|
2018-01-10 22:34:17 +01:00
|
|
|
ctx.ServerError("DeleteWikiPage", err)
|
2016-03-03 23:06:50 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-04-05 17:30:52 +02:00
|
|
|
ctx.JSON(http.StatusOK, map[string]interface{}{
|
2016-03-03 23:06:50 +01:00
|
|
|
"redirect": ctx.Repo.RepoLink + "/wiki/",
|
|
|
|
})
|
|
|
|
}
|