fixed bugs on Wiki and resolved #667 (#674)

tokarchuk/v1.17
Lunny Xiao 8 years ago committed by GitHub
parent 369972b116
commit f8c2903484
  1. 30
      models/wiki.go
  2. 24
      routers/repo/wiki.go

@ -89,7 +89,7 @@ func discardLocalWikiChanges(localPath string) error {
} }
// updateWikiPage adds new page to repository wiki. // updateWikiPage adds new page to repository wiki.
func (repo *Repository) updateWikiPage(doer *User, oldTitle, title, content, message string, isNew bool) (err error) { func (repo *Repository) updateWikiPage(doer *User, oldWikiPath, wikiPath, content, message string, isNew bool) (err error) {
wikiWorkingPool.CheckIn(com.ToStr(repo.ID)) wikiWorkingPool.CheckIn(com.ToStr(repo.ID))
defer wikiWorkingPool.CheckOut(com.ToStr(repo.ID)) defer wikiWorkingPool.CheckOut(com.ToStr(repo.ID))
@ -104,8 +104,8 @@ func (repo *Repository) updateWikiPage(doer *User, oldTitle, title, content, mes
return fmt.Errorf("UpdateLocalWiki: %v", err) return fmt.Errorf("UpdateLocalWiki: %v", err)
} }
title = ToWikiPageName(title) title := ToWikiPageName(wikiPath)
filename := path.Join(localPath, title+".md") filename := path.Join(localPath, wikiPath+".md")
// If not a new file, show perform update not create. // If not a new file, show perform update not create.
if isNew { if isNew {
@ -113,7 +113,7 @@ func (repo *Repository) updateWikiPage(doer *User, oldTitle, title, content, mes
return ErrWikiAlreadyExist{filename} return ErrWikiAlreadyExist{filename}
} }
} else { } else {
file := path.Join(localPath, oldTitle+".md") file := path.Join(localPath, oldWikiPath+".md")
if err := os.Remove(file); err != nil { if err := os.Remove(file); err != nil {
return fmt.Errorf("Fail to remove %s: %v", file, err) return fmt.Errorf("Fail to remove %s: %v", file, err)
@ -149,19 +149,19 @@ func (repo *Repository) updateWikiPage(doer *User, oldTitle, title, content, mes
return nil return nil
} }
// AddWikiPage adds a new wiki page with a given title. // AddWikiPage adds a new wiki page with a given wikiPath.
func (repo *Repository) AddWikiPage(doer *User, title, content, message string) error { func (repo *Repository) AddWikiPage(doer *User, wikiPath, content, message string) error {
return repo.updateWikiPage(doer, "", title, content, message, true) return repo.updateWikiPage(doer, "", wikiPath, content, message, true)
} }
// EditWikiPage updates a wiki page identified by its title, // EditWikiPage updates a wiki page identified by its wikiPath,
// optionally also changing title. // optionally also changing wikiPath.
func (repo *Repository) EditWikiPage(doer *User, oldTitle, title, content, message string) error { func (repo *Repository) EditWikiPage(doer *User, oldWikiPath, wikiPath, content, message string) error {
return repo.updateWikiPage(doer, oldTitle, title, content, message, false) return repo.updateWikiPage(doer, oldWikiPath, wikiPath, content, message, false)
} }
// DeleteWikiPage deletes a wiki page identified by its title. // DeleteWikiPage deletes a wiki page identified by its wikiPath.
func (repo *Repository) DeleteWikiPage(doer *User, title string) (err error) { func (repo *Repository) DeleteWikiPage(doer *User, wikiPath string) (err error) {
wikiWorkingPool.CheckIn(com.ToStr(repo.ID)) wikiWorkingPool.CheckIn(com.ToStr(repo.ID))
defer wikiWorkingPool.CheckOut(com.ToStr(repo.ID)) defer wikiWorkingPool.CheckOut(com.ToStr(repo.ID))
@ -172,13 +172,13 @@ func (repo *Repository) DeleteWikiPage(doer *User, title string) (err error) {
return fmt.Errorf("UpdateLocalWiki: %v", err) return fmt.Errorf("UpdateLocalWiki: %v", err)
} }
title = ToWikiPageName(title) filename := path.Join(localPath, wikiPath+".md")
filename := path.Join(localPath, title+".md")
if err := os.Remove(filename); err != nil { if err := os.Remove(filename); err != nil {
return fmt.Errorf("Fail to remove %s: %v", filename, err) return fmt.Errorf("Fail to remove %s: %v", filename, err)
} }
title := ToWikiPageName(wikiPath)
message := "Delete page '" + title + "'" message := "Delete page '" + title + "'"
if err = git.AddChanges(localPath, true); err != nil { if err = git.AddChanges(localPath, true); err != nil {

@ -89,7 +89,7 @@ func renderWikiPage(ctx *context.Context, isViewPage bool) (*git.Repository, str
ctx.Data["title"] = pageName ctx.Data["title"] = pageName
ctx.Data["RequireHighlightJS"] = true ctx.Data["RequireHighlightJS"] = true
blob, err := commit.GetBlobByPath(pageName + ".md") blob, err := commit.GetBlobByPath(pageURL + ".md")
if err != nil { if err != nil {
if git.IsErrNotExist(err) { if git.IsErrNotExist(err) {
ctx.Redirect(ctx.Repo.RepoLink + "/wiki/_pages") ctx.Redirect(ctx.Repo.RepoLink + "/wiki/_pages")
@ -114,7 +114,7 @@ func renderWikiPage(ctx *context.Context, isViewPage bool) (*git.Repository, str
ctx.Data["content"] = string(data) ctx.Data["content"] = string(data)
} }
return wikiRepo, pageName return wikiRepo, pageURL
} }
// Wiki render wiki page // Wiki render wiki page
@ -127,13 +127,13 @@ func Wiki(ctx *context.Context) {
return return
} }
wikiRepo, pageName := renderWikiPage(ctx, true) wikiRepo, pagePath := renderWikiPage(ctx, true)
if ctx.Written() { if ctx.Written() {
return return
} }
// Get last change information. // Get last change information.
lastCommit, err := wikiRepo.GetCommitByPath(pageName + ".md") lastCommit, err := wikiRepo.GetCommitByPath(pagePath + ".md")
if err != nil { if err != nil {
ctx.Handle(500, "GetCommitByPath", err) ctx.Handle(500, "GetCommitByPath", err)
return return
@ -214,7 +214,9 @@ func NewWikiPost(ctx *context.Context, form auth.NewWikiForm) {
return return
} }
if err := ctx.Repo.Repository.AddWikiPage(ctx.User, form.Title, form.Content, form.Message); err != nil { wikiPath := models.ToWikiPageURL(form.Title)
if err := ctx.Repo.Repository.AddWikiPage(ctx.User, wikiPath, form.Content, form.Message); err != nil {
if models.IsErrWikiAlreadyExist(err) { if models.IsErrWikiAlreadyExist(err) {
ctx.Data["Err_Title"] = true ctx.Data["Err_Title"] = true
ctx.RenderWithErr(ctx.Tr("repo.wiki.page_already_exists"), tplWikiNew, &form) ctx.RenderWithErr(ctx.Tr("repo.wiki.page_already_exists"), tplWikiNew, &form)
@ -224,7 +226,7 @@ func NewWikiPost(ctx *context.Context, form auth.NewWikiForm) {
return return
} }
ctx.Redirect(ctx.Repo.RepoLink + "/wiki/" + models.ToWikiPageURL(form.Title)) ctx.Redirect(ctx.Repo.RepoLink + "/wiki/" + wikiPath)
} }
// EditWiki render wiki modify page // EditWiki render wiki modify page
@ -257,12 +259,15 @@ func EditWikiPost(ctx *context.Context, form auth.NewWikiForm) {
return return
} }
if err := ctx.Repo.Repository.EditWikiPage(ctx.User, form.OldTitle, form.Title, form.Content, form.Message); err != nil { oldWikiPath := ctx.Params(":page")
newWikiPath := models.ToWikiPageURL(form.Title)
if err := ctx.Repo.Repository.EditWikiPage(ctx.User, oldWikiPath, newWikiPath, form.Content, form.Message); err != nil {
ctx.Handle(500, "EditWikiPage", err) ctx.Handle(500, "EditWikiPage", err)
return return
} }
ctx.Redirect(ctx.Repo.RepoLink + "/wiki/" + models.ToWikiPageURL(form.Title)) ctx.Redirect(ctx.Repo.RepoLink + "/wiki/" + newWikiPath)
} }
// DeleteWikiPagePost delete wiki page // DeleteWikiPagePost delete wiki page
@ -272,8 +277,7 @@ func DeleteWikiPagePost(ctx *context.Context) {
pageURL = "Home" pageURL = "Home"
} }
pageName := models.ToWikiPageName(pageURL) if err := ctx.Repo.Repository.DeleteWikiPage(ctx.User, pageURL); err != nil {
if err := ctx.Repo.Repository.DeleteWikiPage(ctx.User, pageName); err != nil {
ctx.Handle(500, "DeleteWikiPage", err) ctx.Handle(500, "DeleteWikiPage", err)
return return
} }

Loading…
Cancel
Save