aboutsummaryrefslogtreecommitdiffstats
path: root/routers/repo
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2020-01-08 02:27:36 +0800
committerzeripath <art27@cantab.net>2020-01-07 18:27:36 +0000
commitb9309e52f0b08a554107d888029d62f9b7904ca0 (patch)
treed8eb24e40b5a65c16a3b2447bf0bef0e9e865a6a /routers/repo
parente5d8e2d10c6798e57ac855f71b025b087b664799 (diff)
downloadgitea-b9309e52f0b08a554107d888029d62f9b7904ca0.tar.gz
gitea-b9309e52f0b08a554107d888029d62f9b7904ca0.zip
Move wiki related funtions from models to services/wiki (#9355)
* Move wiki related funtions from models to services/wiki
Diffstat (limited to 'routers/repo')
-rw-r--r--routers/repo/wiki.go43
-rw-r--r--routers/repo/wiki_test.go3
2 files changed, 24 insertions, 22 deletions
diff --git a/routers/repo/wiki.go b/routers/repo/wiki.go
index 6cf1943658..b0bd8047b8 100644
--- a/routers/repo/wiki.go
+++ b/routers/repo/wiki.go
@@ -22,6 +22,7 @@ import (
"code.gitea.io/gitea/modules/markup/markdown"
"code.gitea.io/gitea/modules/timeutil"
"code.gitea.io/gitea/modules/util"
+ wiki_service "code.gitea.io/gitea/services/wiki"
)
const (
@@ -124,7 +125,7 @@ func wikiContentsByEntry(ctx *context.Context, entry *git.TreeEntry) []byte {
func wikiContentsByName(ctx *context.Context, commit *git.Commit, wikiName string) ([]byte, *git.TreeEntry, string, bool) {
var entry *git.TreeEntry
var err error
- pageFilename := models.WikiNameToFilename(wikiName)
+ pageFilename := wiki_service.NameToFilename(wikiName)
if entry, err = findEntryForFile(commit, pageFilename); err != nil {
ctx.ServerError("findEntryForFile", err)
return nil, nil, "", false
@@ -157,7 +158,7 @@ func renderViewPage(ctx *context.Context) (*git.Repository, *git.TreeEntry) {
if !entry.IsRegular() {
continue
}
- wikiName, err := models.WikiFilenameToName(entry.Name())
+ wikiName, err := wiki_service.FilenameToName(entry.Name())
if err != nil {
if models.IsErrWikiInvalidFileName(err) {
continue
@@ -172,17 +173,17 @@ func renderViewPage(ctx *context.Context) (*git.Repository, *git.TreeEntry) {
}
pages = append(pages, PageMeta{
Name: wikiName,
- SubURL: models.WikiNameToSubURL(wikiName),
+ SubURL: wiki_service.NameToSubURL(wikiName),
})
}
ctx.Data["Pages"] = pages
// get requested pagename
- pageName := models.NormalizeWikiName(ctx.Params(":page"))
+ pageName := wiki_service.NormalizeWikiName(ctx.Params(":page"))
if len(pageName) == 0 {
pageName = "Home"
}
- ctx.Data["PageURL"] = models.WikiNameToSubURL(pageName)
+ ctx.Data["PageURL"] = wiki_service.NameToSubURL(pageName)
ctx.Data["old_title"] = pageName
ctx.Data["Title"] = pageName
ctx.Data["title"] = pageName
@@ -243,11 +244,11 @@ func renderRevisionPage(ctx *context.Context) (*git.Repository, *git.TreeEntry)
}
// get requested pagename
- pageName := models.NormalizeWikiName(ctx.Params(":page"))
+ pageName := wiki_service.NormalizeWikiName(ctx.Params(":page"))
if len(pageName) == 0 {
pageName = "Home"
}
- ctx.Data["PageURL"] = models.WikiNameToSubURL(pageName)
+ ctx.Data["PageURL"] = wiki_service.NameToSubURL(pageName)
ctx.Data["old_title"] = pageName
ctx.Data["Title"] = pageName
ctx.Data["title"] = pageName
@@ -320,11 +321,11 @@ func renderEditPage(ctx *context.Context) {
}()
// get requested pagename
- pageName := models.NormalizeWikiName(ctx.Params(":page"))
+ pageName := wiki_service.NormalizeWikiName(ctx.Params(":page"))
if len(pageName) == 0 {
pageName = "Home"
}
- ctx.Data["PageURL"] = models.WikiNameToSubURL(pageName)
+ ctx.Data["PageURL"] = wiki_service.NameToSubURL(pageName)
ctx.Data["old_title"] = pageName
ctx.Data["Title"] = pageName
ctx.Data["title"] = pageName
@@ -474,7 +475,7 @@ func WikiPages(ctx *context.Context) {
ctx.ServerError("GetCommit", err)
return
}
- wikiName, err := models.WikiFilenameToName(entry.Name())
+ wikiName, err := wiki_service.FilenameToName(entry.Name())
if err != nil {
if models.IsErrWikiInvalidFileName(err) {
continue
@@ -488,7 +489,7 @@ func WikiPages(ctx *context.Context) {
}
pages = append(pages, PageMeta{
Name: wikiName,
- SubURL: models.WikiNameToSubURL(wikiName),
+ SubURL: wiki_service.NameToSubURL(wikiName),
UpdatedUnix: timeutil.TimeStamp(c.Author.When.Unix()),
})
}
@@ -528,7 +529,7 @@ func WikiRaw(ctx *context.Context) {
providedPath = providedPath[:len(providedPath)-3]
}
- wikiPath := models.WikiNameToFilename(providedPath)
+ wikiPath := wiki_service.NameToFilename(providedPath)
entry, err = findEntryForFile(commit, wikiPath)
if err != nil {
ctx.ServerError("findFile", err)
@@ -576,8 +577,8 @@ func NewWikiPost(ctx *context.Context, form auth.NewWikiForm) {
return
}
- wikiName := models.NormalizeWikiName(form.Title)
- if err := ctx.Repo.Repository.AddWikiPage(ctx.User, wikiName, form.Content, form.Message); err != nil {
+ wikiName := wiki_service.NormalizeWikiName(form.Title)
+ if err := wiki_service.AddWikiPage(ctx.User, ctx.Repo.Repository, 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)
@@ -590,7 +591,7 @@ func NewWikiPost(ctx *context.Context, form auth.NewWikiForm) {
return
}
- ctx.Redirect(ctx.Repo.RepoLink + "/wiki/" + models.WikiNameToSubURL(wikiName))
+ ctx.Redirect(ctx.Repo.RepoLink + "/wiki/" + wiki_service.NameToSubURL(wikiName))
}
// EditWiki render wiki modify page
@@ -623,25 +624,25 @@ func EditWikiPost(ctx *context.Context, form auth.NewWikiForm) {
return
}
- oldWikiName := models.NormalizeWikiName(ctx.Params(":page"))
- newWikiName := models.NormalizeWikiName(form.Title)
+ oldWikiName := wiki_service.NormalizeWikiName(ctx.Params(":page"))
+ newWikiName := wiki_service.NormalizeWikiName(form.Title)
- if err := ctx.Repo.Repository.EditWikiPage(ctx.User, oldWikiName, newWikiName, form.Content, form.Message); err != nil {
+ if err := wiki_service.EditWikiPage(ctx.User, ctx.Repo.Repository, oldWikiName, newWikiName, form.Content, form.Message); err != nil {
ctx.ServerError("EditWikiPage", err)
return
}
- ctx.Redirect(ctx.Repo.RepoLink + "/wiki/" + models.WikiNameToSubURL(newWikiName))
+ ctx.Redirect(ctx.Repo.RepoLink + "/wiki/" + wiki_service.NameToSubURL(newWikiName))
}
// DeleteWikiPagePost delete wiki page
func DeleteWikiPagePost(ctx *context.Context) {
- wikiName := models.NormalizeWikiName(ctx.Params(":page"))
+ wikiName := wiki_service.NormalizeWikiName(ctx.Params(":page"))
if len(wikiName) == 0 {
wikiName = "Home"
}
- if err := ctx.Repo.Repository.DeleteWikiPage(ctx.User, wikiName); err != nil {
+ if err := wiki_service.DeleteWikiPage(ctx.User, ctx.Repo.Repository, wikiName); err != nil {
ctx.ServerError("DeleteWikiPage", err)
return
}
diff --git a/routers/repo/wiki_test.go b/routers/repo/wiki_test.go
index 44fcd02035..843a8ddf2b 100644
--- a/routers/repo/wiki_test.go
+++ b/routers/repo/wiki_test.go
@@ -13,6 +13,7 @@ import (
"code.gitea.io/gitea/modules/auth"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/test"
+ wiki_service "code.gitea.io/gitea/services/wiki"
"github.com/stretchr/testify/assert"
)
@@ -29,7 +30,7 @@ func wikiEntry(t *testing.T, repo *models.Repository, wikiName string) *git.Tree
entries, err := commit.ListEntries()
assert.NoError(t, err)
for _, entry := range entries {
- if entry.Name() == models.WikiNameToFilename(wikiName) {
+ if entry.Name() == wiki_service.NameToFilename(wikiName) {
return entry
}
}