2015-11-25 20:10:25 -05:00
|
|
|
// Copyright 2015 The Gogs Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package repo
|
|
|
|
|
|
|
|
import (
|
2017-02-13 20:13:59 -05:00
|
|
|
"fmt"
|
2015-11-27 00:24:24 -05:00
|
|
|
"io/ioutil"
|
2017-02-13 20:13:59 -05:00
|
|
|
"path/filepath"
|
2015-11-27 01:50:38 -05:00
|
|
|
"strings"
|
2015-11-27 02:16:12 -05:00
|
|
|
"time"
|
2015-11-27 00:24:24 -05:00
|
|
|
|
2016-11-10 11:24:48 -05:00
|
|
|
"code.gitea.io/git"
|
2015-11-27 00:24:24 -05:00
|
|
|
|
2016-11-10 11:24:48 -05:00
|
|
|
"code.gitea.io/gitea/models"
|
|
|
|
"code.gitea.io/gitea/modules/auth"
|
|
|
|
"code.gitea.io/gitea/modules/base"
|
|
|
|
"code.gitea.io/gitea/modules/context"
|
2017-04-21 03:01:08 -04:00
|
|
|
"code.gitea.io/gitea/modules/markup"
|
2017-09-21 01:20:14 -04:00
|
|
|
"code.gitea.io/gitea/modules/markup/markdown"
|
2015-11-25 20:10:25 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2016-11-21 05:03:42 -05:00
|
|
|
tplWikiStart base.TplName = "repo/wiki/start"
|
|
|
|
tplWikiView base.TplName = "repo/wiki/view"
|
|
|
|
tplWikiNew base.TplName = "repo/wiki/new"
|
|
|
|
tplWikiPages base.TplName = "repo/wiki/pages"
|
2015-11-25 20:10:25 -05:00
|
|
|
)
|
|
|
|
|
2016-11-21 05:03:42 -05:00
|
|
|
// MustEnableWiki check if wiki is enabled, if external then redirect
|
2016-03-11 11:56:52 -05:00
|
|
|
func MustEnableWiki(ctx *context.Context) {
|
2017-08-02 04:46:54 -04:00
|
|
|
if !ctx.Repo.Repository.UnitEnabled(models.UnitTypeWiki) &&
|
|
|
|
!ctx.Repo.Repository.UnitEnabled(models.UnitTypeExternalWiki) {
|
2015-12-04 21:30:33 -05:00
|
|
|
ctx.Handle(404, "MustEnableWiki", nil)
|
2015-12-11 04:55:08 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-02-04 10:53:46 -05:00
|
|
|
unit, err := ctx.Repo.Repository.GetUnit(models.UnitTypeExternalWiki)
|
|
|
|
if err == nil {
|
|
|
|
ctx.Redirect(unit.ExternalWikiConfig().ExternalWikiURL)
|
2015-12-11 04:55:08 -05:00
|
|
|
return
|
2015-12-04 21:30:33 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-21 05:03:42 -05:00
|
|
|
// PageMeta wiki page meat information
|
2015-11-27 01:50:38 -05:00
|
|
|
type PageMeta struct {
|
2015-11-27 02:16:12 -05:00
|
|
|
Name string
|
2017-11-28 04:43:51 -05:00
|
|
|
SubURL string
|
2015-11-27 02:16:12 -05:00
|
|
|
Updated time.Time
|
2015-11-27 01:50:38 -05:00
|
|
|
}
|
2015-11-25 20:10:25 -05:00
|
|
|
|
2017-11-28 04:43:51 -05:00
|
|
|
// findEntryForFile finds the tree entry for a target filepath.
|
|
|
|
func findEntryForFile(commit *git.Commit, target string) (*git.TreeEntry, error) {
|
2017-02-13 20:13:59 -05:00
|
|
|
entries, err := commit.ListEntries()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2017-11-28 04:43:51 -05:00
|
|
|
for _, entry := range entries {
|
|
|
|
if entry.Type == git.ObjectBlob && entry.Name() == target {
|
|
|
|
return entry, nil
|
2017-02-13 20:13:59 -05:00
|
|
|
}
|
|
|
|
}
|
2017-11-28 04:43:51 -05:00
|
|
|
return nil, nil
|
2017-02-13 20:13:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func findWikiRepoCommit(ctx *context.Context) (*git.Repository, *git.Commit, error) {
|
2015-11-27 00:24:24 -05:00
|
|
|
wikiRepo, err := git.OpenRepository(ctx.Repo.Repository.WikiPath())
|
|
|
|
if err != nil {
|
2017-11-28 04:43:51 -05:00
|
|
|
ctx.Handle(500, "OpenRepository", err)
|
2017-02-13 20:13:59 -05:00
|
|
|
return nil, nil, err
|
2015-11-27 00:24:24 -05:00
|
|
|
}
|
2017-03-20 09:36:19 -04:00
|
|
|
|
2015-12-09 20:46:05 -05:00
|
|
|
commit, err := wikiRepo.GetBranchCommit("master")
|
2015-11-27 00:24:24 -05:00
|
|
|
if err != nil {
|
2015-12-09 20:46:05 -05:00
|
|
|
ctx.Handle(500, "GetBranchCommit", err)
|
2017-02-13 20:13:59 -05:00
|
|
|
return wikiRepo, nil, err
|
|
|
|
}
|
|
|
|
return wikiRepo, commit, nil
|
|
|
|
}
|
|
|
|
|
2017-11-28 04:43:51 -05: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 {
|
|
|
|
reader, err := entry.Blob().Data()
|
|
|
|
if err != nil {
|
|
|
|
ctx.Handle(500, "Blob.Data", err)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
content, err := ioutil.ReadAll(reader)
|
|
|
|
if err != nil {
|
|
|
|
ctx.Handle(500, "ReadAll", err)
|
|
|
|
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.
|
|
|
|
func wikiContentsByName(ctx *context.Context, commit *git.Commit, wikiName string) ([]byte, bool) {
|
|
|
|
entry, err := findEntryForFile(commit, models.WikiNameToFilename(wikiName))
|
|
|
|
if err != nil {
|
|
|
|
ctx.Handle(500, "findEntryForFile", err)
|
|
|
|
return nil, false
|
|
|
|
} else if entry == nil {
|
|
|
|
return nil, false
|
|
|
|
}
|
|
|
|
return wikiContentsByEntry(ctx, entry), true
|
|
|
|
}
|
|
|
|
|
2017-02-13 20:13:59 -05:00
|
|
|
func renderWikiPage(ctx *context.Context, isViewPage bool) (*git.Repository, *git.TreeEntry) {
|
|
|
|
wikiRepo, commit, err := findWikiRepoCommit(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil
|
2015-11-27 01:50:38 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get page list.
|
|
|
|
if isViewPage {
|
|
|
|
entries, err := commit.ListEntries()
|
|
|
|
if err != nil {
|
|
|
|
ctx.Handle(500, "ListEntries", err)
|
2017-02-13 20:13:59 -05:00
|
|
|
return nil, nil
|
2015-11-27 01:50:38 -05:00
|
|
|
}
|
2017-11-28 04:43:51 -05:00
|
|
|
pages := make([]PageMeta, 0, len(entries))
|
|
|
|
for _, entry := range entries {
|
|
|
|
if entry.Type != git.ObjectBlob {
|
|
|
|
continue
|
2015-11-27 01:50:38 -05:00
|
|
|
}
|
2017-11-28 04:43:51 -05:00
|
|
|
wikiName, err := models.WikiFilenameToName(entry.Name())
|
|
|
|
if err != nil {
|
|
|
|
ctx.Handle(500, "WikiFilenameToName", err)
|
|
|
|
return nil, nil
|
|
|
|
} else if wikiName == "_Sidebar" || wikiName == "_Footer" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
pages = append(pages, PageMeta{
|
|
|
|
Name: wikiName,
|
|
|
|
SubURL: models.WikiNameToSubURL(wikiName),
|
|
|
|
})
|
2015-11-27 01:50:38 -05:00
|
|
|
}
|
|
|
|
ctx.Data["Pages"] = pages
|
2015-11-27 00:24:24 -05:00
|
|
|
}
|
|
|
|
|
2017-11-28 04:43:51 -05:00
|
|
|
pageName := models.NormalizeWikiName(ctx.Params(":page"))
|
|
|
|
if len(pageName) == 0 {
|
|
|
|
pageName = "Home"
|
2015-11-27 00:24:24 -05:00
|
|
|
}
|
2017-11-28 04:43:51 -05:00
|
|
|
ctx.Data["PageURL"] = models.WikiNameToSubURL(pageName)
|
2015-11-27 01:50:38 -05:00
|
|
|
|
|
|
|
ctx.Data["old_title"] = pageName
|
|
|
|
ctx.Data["Title"] = pageName
|
|
|
|
ctx.Data["title"] = pageName
|
2015-11-27 00:24:24 -05:00
|
|
|
ctx.Data["RequireHighlightJS"] = true
|
|
|
|
|
2017-11-28 04:43:51 -05:00
|
|
|
pageFilename := models.WikiNameToFilename(pageName)
|
2017-02-13 20:13:59 -05:00
|
|
|
var entry *git.TreeEntry
|
2017-11-28 04:43:51 -05:00
|
|
|
if entry, err = findEntryForFile(commit, pageFilename); err != nil {
|
|
|
|
ctx.Handle(500, "findEntryForFile", err)
|
2017-02-13 20:13:59 -05:00
|
|
|
return nil, nil
|
2017-11-28 04:43:51 -05:00
|
|
|
} else if entry == nil {
|
2017-02-13 20:13:59 -05:00
|
|
|
ctx.Redirect(ctx.Repo.RepoLink + "/wiki/_pages")
|
|
|
|
return nil, nil
|
2015-11-27 00:24:24 -05:00
|
|
|
}
|
2017-11-28 04:43:51 -05:00
|
|
|
data := wikiContentsByEntry(ctx, entry)
|
|
|
|
if ctx.Written() {
|
2017-02-13 20:13:59 -05:00
|
|
|
return nil, nil
|
|
|
|
}
|
2017-11-28 04:43:51 -05:00
|
|
|
|
|
|
|
if isViewPage {
|
|
|
|
sidebarContent, sidebarPresent := wikiContentsByName(ctx, commit, "_Sidebar")
|
|
|
|
if ctx.Written() {
|
|
|
|
return nil, nil
|
2017-02-13 20:13:59 -05:00
|
|
|
}
|
2017-11-28 04:43:51 -05:00
|
|
|
|
|
|
|
footerContent, footerPresent := wikiContentsByName(ctx, commit, "_Footer")
|
|
|
|
if ctx.Written() {
|
|
|
|
return nil, nil
|
2017-02-13 20:13:59 -05:00
|
|
|
}
|
2017-11-28 04:43:51 -05:00
|
|
|
|
2017-02-13 20:13:59 -05:00
|
|
|
metas := ctx.Repo.Repository.ComposeMetas()
|
|
|
|
ctx.Data["content"] = markdown.RenderWiki(data, ctx.Repo.RepoLink, metas)
|
|
|
|
ctx.Data["sidebarPresent"] = sidebarPresent
|
|
|
|
ctx.Data["sidebarContent"] = markdown.RenderWiki(sidebarContent, ctx.Repo.RepoLink, metas)
|
|
|
|
ctx.Data["footerPresent"] = footerPresent
|
|
|
|
ctx.Data["footerContent"] = markdown.RenderWiki(footerContent, ctx.Repo.RepoLink, metas)
|
2015-11-27 01:50:38 -05:00
|
|
|
} else {
|
|
|
|
ctx.Data["content"] = string(data)
|
2017-02-13 20:13:59 -05:00
|
|
|
ctx.Data["sidebarPresent"] = false
|
|
|
|
ctx.Data["sidebarContent"] = ""
|
|
|
|
ctx.Data["footerPresent"] = false
|
|
|
|
ctx.Data["footerContent"] = ""
|
2015-11-27 01:50:38 -05:00
|
|
|
}
|
|
|
|
|
2017-02-13 20:13:59 -05:00
|
|
|
return wikiRepo, entry
|
2015-11-27 01:50:38 -05:00
|
|
|
}
|
|
|
|
|
2017-02-13 20:13:59 -05:00
|
|
|
// Wiki renders single wiki page
|
2016-03-11 11:56:52 -05:00
|
|
|
func Wiki(ctx *context.Context) {
|
2015-11-27 01:50:38 -05:00
|
|
|
ctx.Data["PageIsWiki"] = true
|
|
|
|
|
|
|
|
if !ctx.Repo.Repository.HasWiki() {
|
|
|
|
ctx.Data["Title"] = ctx.Tr("repo.wiki")
|
2016-11-21 05:03:42 -05:00
|
|
|
ctx.HTML(200, tplWikiStart)
|
2015-11-27 01:50:38 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-02-13 20:13:59 -05:00
|
|
|
wikiRepo, entry := renderWikiPage(ctx, true)
|
2015-11-27 01:50:38 -05:00
|
|
|
if ctx.Written() {
|
2015-11-27 00:24:24 -05:00
|
|
|
return
|
|
|
|
}
|
2017-03-20 09:36:19 -04:00
|
|
|
if entry == nil {
|
|
|
|
ctx.Data["Title"] = ctx.Tr("repo.wiki")
|
|
|
|
ctx.HTML(200, tplWikiStart)
|
|
|
|
return
|
|
|
|
}
|
2015-11-27 00:24:24 -05:00
|
|
|
|
2017-11-28 04:43:51 -05:00
|
|
|
wikiPath := entry.Name()
|
|
|
|
if markup.Type(wikiPath) != markdown.MarkupName {
|
|
|
|
ext := strings.ToUpper(filepath.Ext(wikiPath))
|
2017-02-13 20:13:59 -05:00
|
|
|
ctx.Data["FormatWarning"] = fmt.Sprintf("%s rendering is not supported at the moment. Rendered as Markdown.", ext)
|
|
|
|
}
|
2015-11-27 00:24:24 -05:00
|
|
|
// Get last change information.
|
2017-11-28 04:43:51 -05:00
|
|
|
lastCommit, err := wikiRepo.GetCommitByPath(wikiPath)
|
2015-11-27 00:24:24 -05:00
|
|
|
if err != nil {
|
|
|
|
ctx.Handle(500, "GetCommitByPath", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
ctx.Data["Author"] = lastCommit.Author
|
|
|
|
|
2016-11-21 05:03:42 -05:00
|
|
|
ctx.HTML(200, tplWikiView)
|
2015-11-25 20:10:25 -05:00
|
|
|
}
|
|
|
|
|
2016-11-21 05:03:42 -05:00
|
|
|
// WikiPages render wiki pages list page
|
2016-03-11 11:56:52 -05:00
|
|
|
func WikiPages(ctx *context.Context) {
|
2015-11-27 02:16:12 -05:00
|
|
|
ctx.Data["Title"] = ctx.Tr("repo.wiki.pages")
|
|
|
|
ctx.Data["PageIsWiki"] = true
|
|
|
|
|
|
|
|
if !ctx.Repo.Repository.HasWiki() {
|
|
|
|
ctx.Redirect(ctx.Repo.RepoLink + "/wiki")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-02-13 20:13:59 -05:00
|
|
|
wikiRepo, commit, err := findWikiRepoCommit(ctx)
|
2015-11-27 02:16:12 -05:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
entries, err := commit.ListEntries()
|
|
|
|
if err != nil {
|
|
|
|
ctx.Handle(500, "ListEntries", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
pages := make([]PageMeta, 0, len(entries))
|
2017-11-28 04:43:51 -05:00
|
|
|
for _, entry := range entries {
|
|
|
|
if entry.Type != git.ObjectBlob {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
c, err := wikiRepo.GetCommitByPath(entry.Name())
|
|
|
|
if err != nil {
|
|
|
|
ctx.Handle(500, "GetCommit", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
wikiName, err := models.WikiFilenameToName(entry.Name())
|
|
|
|
if err != nil {
|
|
|
|
ctx.Handle(500, "WikiFilenameToName", err)
|
|
|
|
return
|
2015-11-27 02:16:12 -05:00
|
|
|
}
|
2017-11-28 04:43:51 -05:00
|
|
|
pages = append(pages, PageMeta{
|
|
|
|
Name: wikiName,
|
|
|
|
SubURL: models.WikiNameToSubURL(wikiName),
|
|
|
|
Updated: c.Author.When,
|
|
|
|
})
|
2015-11-27 02:16:12 -05:00
|
|
|
}
|
|
|
|
ctx.Data["Pages"] = pages
|
2015-11-27 00:24:24 -05:00
|
|
|
|
2016-11-21 05:03:42 -05:00
|
|
|
ctx.HTML(200, tplWikiPages)
|
2015-11-27 00:24:24 -05:00
|
|
|
}
|
|
|
|
|
2017-02-13 20:13:59 -05:00
|
|
|
// WikiRaw outputs raw blob requested by user (image for example)
|
|
|
|
func WikiRaw(ctx *context.Context) {
|
|
|
|
wikiRepo, commit, err := findWikiRepoCommit(ctx)
|
|
|
|
if err != nil {
|
|
|
|
if wikiRepo != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2017-11-28 04:43:51 -05:00
|
|
|
providedPath := ctx.Params("*")
|
|
|
|
if strings.HasSuffix(providedPath, ".md") {
|
|
|
|
providedPath = providedPath[:len(providedPath)-3]
|
|
|
|
}
|
|
|
|
wikiPath := models.WikiNameToFilename(providedPath)
|
2017-02-13 20:13:59 -05:00
|
|
|
var entry *git.TreeEntry
|
|
|
|
if commit != nil {
|
2017-11-28 04:43:51 -05:00
|
|
|
entry, err = findEntryForFile(commit, wikiPath)
|
2017-02-13 20:13:59 -05:00
|
|
|
}
|
2017-11-28 04:43:51 -05:00
|
|
|
if err != nil {
|
|
|
|
ctx.Handle(500, "findFile", err)
|
|
|
|
return
|
|
|
|
} else if entry == nil {
|
|
|
|
ctx.Handle(404, "findEntryForFile", nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-02-13 20:13:59 -05:00
|
|
|
if err = ServeBlob(ctx, entry.Blob()); err != nil {
|
|
|
|
ctx.Handle(500, "ServeBlob", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-21 05:03:42 -05:00
|
|
|
// NewWiki render wiki create page
|
2016-03-11 11:56:52 -05:00
|
|
|
func NewWiki(ctx *context.Context) {
|
2015-11-25 20:10:25 -05:00
|
|
|
ctx.Data["Title"] = ctx.Tr("repo.wiki.new_page")
|
|
|
|
ctx.Data["PageIsWiki"] = true
|
|
|
|
ctx.Data["RequireSimpleMDE"] = true
|
|
|
|
|
2015-11-26 17:33:45 -05:00
|
|
|
if !ctx.Repo.Repository.HasWiki() {
|
2015-11-25 20:10:25 -05:00
|
|
|
ctx.Data["title"] = "Home"
|
|
|
|
}
|
|
|
|
|
2016-11-21 05:03:42 -05:00
|
|
|
ctx.HTML(200, tplWikiNew)
|
2015-11-25 20:10:25 -05:00
|
|
|
}
|
|
|
|
|
2017-11-28 04:43:51 -05:00
|
|
|
// NewWikiPost response for wiki create request
|
2016-03-11 11:56:52 -05:00
|
|
|
func NewWikiPost(ctx *context.Context, form auth.NewWikiForm) {
|
2015-11-26 17:33:45 -05:00
|
|
|
ctx.Data["Title"] = ctx.Tr("repo.wiki.new_page")
|
|
|
|
ctx.Data["PageIsWiki"] = true
|
|
|
|
ctx.Data["RequireSimpleMDE"] = true
|
|
|
|
|
|
|
|
if ctx.HasError() {
|
2016-11-21 05:03:42 -05:00
|
|
|
ctx.HTML(200, tplWikiNew)
|
2015-11-26 17:33:45 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-11-28 04:43:51 -05:00
|
|
|
wikiName := models.NormalizeWikiName(form.Title)
|
|
|
|
if err := ctx.Repo.Repository.AddWikiPage(ctx.User, wikiName, form.Content, form.Message); err != nil {
|
|
|
|
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 01:50:38 -05:00
|
|
|
ctx.Data["Err_Title"] = true
|
2016-11-21 05:03:42 -05:00
|
|
|
ctx.RenderWithErr(ctx.Tr("repo.wiki.page_already_exists"), tplWikiNew, &form)
|
2015-11-27 01:50:38 -05:00
|
|
|
} else {
|
|
|
|
ctx.Handle(500, "AddWikiPage", err)
|
|
|
|
}
|
2015-11-26 17:33:45 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-11-28 04:43:51 -05:00
|
|
|
ctx.Redirect(ctx.Repo.RepoLink + "/wiki/" + models.WikiNameToFilename(wikiName))
|
2015-11-26 17:33:45 -05:00
|
|
|
}
|
|
|
|
|
2016-11-21 05:03:42 -05:00
|
|
|
// EditWiki render wiki modify page
|
2016-03-11 11:56:52 -05:00
|
|
|
func EditWiki(ctx *context.Context) {
|
2015-11-27 01:50:38 -05:00
|
|
|
ctx.Data["PageIsWiki"] = true
|
|
|
|
ctx.Data["PageIsWikiEdit"] = true
|
|
|
|
ctx.Data["RequireSimpleMDE"] = true
|
|
|
|
|
|
|
|
if !ctx.Repo.Repository.HasWiki() {
|
|
|
|
ctx.Redirect(ctx.Repo.RepoLink + "/wiki")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
renderWikiPage(ctx, false)
|
|
|
|
if ctx.Written() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2016-11-21 05:03:42 -05:00
|
|
|
ctx.HTML(200, tplWikiNew)
|
2015-11-27 01:50:38 -05:00
|
|
|
}
|
|
|
|
|
2017-11-28 04:43:51 -05:00
|
|
|
// EditWikiPost response for wiki modify request
|
2016-03-11 11:56:52 -05:00
|
|
|
func EditWikiPost(ctx *context.Context, form auth.NewWikiForm) {
|
2015-11-27 01:50:38 -05:00
|
|
|
ctx.Data["Title"] = ctx.Tr("repo.wiki.new_page")
|
|
|
|
ctx.Data["PageIsWiki"] = true
|
|
|
|
ctx.Data["RequireSimpleMDE"] = true
|
|
|
|
|
|
|
|
if ctx.HasError() {
|
2016-11-21 05:03:42 -05:00
|
|
|
ctx.HTML(200, tplWikiNew)
|
2015-11-27 01:50:38 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-11-28 04:43:51 -05:00
|
|
|
oldWikiName := models.NormalizeWikiName(ctx.Params(":page"))
|
|
|
|
newWikiName := models.NormalizeWikiName(form.Title)
|
2017-01-21 07:50:51 -05:00
|
|
|
|
2017-11-28 04:43:51 -05:00
|
|
|
if err := ctx.Repo.Repository.EditWikiPage(ctx.User, oldWikiName, newWikiName, form.Content, form.Message); err != nil {
|
2015-11-27 01:50:38 -05:00
|
|
|
ctx.Handle(500, "EditWikiPage", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-11-28 04:43:51 -05:00
|
|
|
ctx.Redirect(ctx.Repo.RepoLink + "/wiki/" + models.WikiNameToFilename(newWikiName))
|
2015-11-25 20:10:25 -05:00
|
|
|
}
|
2016-03-03 17:06:50 -05:00
|
|
|
|
2016-11-21 05:03:42 -05:00
|
|
|
// DeleteWikiPagePost delete wiki page
|
2016-03-11 11:56:52 -05:00
|
|
|
func DeleteWikiPagePost(ctx *context.Context) {
|
2017-11-28 04:43:51 -05:00
|
|
|
wikiName := models.NormalizeWikiName(ctx.Params(":page"))
|
|
|
|
if len(wikiName) == 0 {
|
|
|
|
wikiName = "Home"
|
2016-03-03 17:06:50 -05:00
|
|
|
}
|
|
|
|
|
2017-11-28 04:43:51 -05:00
|
|
|
if err := ctx.Repo.Repository.DeleteWikiPage(ctx.User, wikiName); err != nil {
|
2016-03-03 17:06:50 -05:00
|
|
|
ctx.Handle(500, "DeleteWikiPage", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.JSON(200, map[string]interface{}{
|
|
|
|
"redirect": ctx.Repo.RepoLink + "/wiki/",
|
|
|
|
})
|
|
|
|
}
|