Skip to content

Fixed bugs on Uncyclo and resolved #667 #958

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions models/wiki.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func discardLocalUncycloChanges(localPath string) error {
}

// updateUncycloPage adds new page to repository wiki.
func (repo *Repository) updateUncycloPage(doer *User, oldTitle, title, content, message string, isNew bool) (err error) {
func (repo *Repository) updateUncycloPage(doer *User, oldUncycloPath, wikiPath, content, message string, isNew bool) (err error) {
wikiWorkingPool.CheckIn(com.ToStr(repo.ID))
defer wikiWorkingPool.CheckOut(com.ToStr(repo.ID))

Expand All @@ -104,16 +104,16 @@ func (repo *Repository) updateUncycloPage(doer *User, oldTitle, title, content, mes
return fmt.Errorf("UpdateLocalUncyclo: %v", err)
}

title = ToUncycloPageName(title)
filename := path.Join(localPath, title+".md")
title := ToUncycloPageName(wikiPath)
filename := path.Join(localPath, wikiPath+".md")

// If not a new file, show perform update not create.
if isNew {
if com.IsExist(filename) {
return ErrUncycloAlreadyExist{filename}
}
} else {
file := path.Join(localPath, oldTitle+".md")
file := path.Join(localPath, oldUncycloPath+".md")

if err := os.Remove(file); err != nil {
return fmt.Errorf("Fail to remove %s: %v", file, err)
Expand Down Expand Up @@ -149,19 +149,19 @@ func (repo *Repository) updateUncycloPage(doer *User, oldTitle, title, content, mes
return nil
}

// AddUncycloPage adds a new wiki page with a given title.
func (repo *Repository) AddUncycloPage(doer *User, title, content, message string) error {
return repo.updateUncycloPage(doer, "", title, content, message, true)
// AddUncycloPage adds a new wiki page with a given wikiPath.
func (repo *Repository) AddUncycloPage(doer *User, wikiPath, content, message string) error {
return repo.updateUncycloPage(doer, "", wikiPath, content, message, true)
}

// EditUncycloPage updates a wiki page identified by its title,
// optionally also changing title.
func (repo *Repository) EditUncycloPage(doer *User, oldTitle, title, content, message string) error {
return repo.updateUncycloPage(doer, oldTitle, title, content, message, false)
// EditUncycloPage updates a wiki page identified by its wikiPath,
// optionally also changing wikiPath.
func (repo *Repository) EditUncycloPage(doer *User, oldUncycloPath, wikiPath, content, message string) error {
return repo.updateUncycloPage(doer, oldUncycloPath, wikiPath, content, message, false)
}

// DeleteUncycloPage deletes a wiki page identified by its title.
func (repo *Repository) DeleteUncycloPage(doer *User, title string) (err error) {
// DeleteUncycloPage deletes a wiki page identified by its wikiPath.
func (repo *Repository) DeleteUncycloPage(doer *User, wikiPath string) (err error) {
wikiWorkingPool.CheckIn(com.ToStr(repo.ID))
defer wikiWorkingPool.CheckOut(com.ToStr(repo.ID))

Expand All @@ -172,13 +172,13 @@ func (repo *Repository) DeleteUncycloPage(doer *User, title string) (err error) {
return fmt.Errorf("UpdateLocalUncyclo: %v", err)
}

title = ToUncycloPageName(title)
filename := path.Join(localPath, title+".md")
filename := path.Join(localPath, wikiPath+".md")

if err := os.Remove(filename); err != nil {
return fmt.Errorf("Fail to remove %s: %v", filename, err)
}

title := ToUncycloPageName(wikiPath)
message := "Delete page '" + title + "'"

if err = git.AddChanges(localPath, true); err != nil {
Expand Down
24 changes: 14 additions & 10 deletions routers/repo/wiki.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func renderUncycloPage(ctx *context.Context, isViewPage bool) (*git.Repository, str
ctx.Data["title"] = pageName
ctx.Data["RequireHighlightJS"] = true

blob, err := commit.GetBlobByPath(pageName + ".md")
blob, err := commit.GetBlobByPath(pageURL + ".md")
if err != nil {
if git.IsErrNotExist(err) {
ctx.Redirect(ctx.Repo.RepoLink + "/wiki/_pages")
Expand All @@ -114,7 +114,7 @@ func renderUncycloPage(ctx *context.Context, isViewPage bool) (*git.Repository, str
ctx.Data["content"] = string(data)
}

return wikiRepo, pageName
return wikiRepo, pageURL
}

// Uncyclo render wiki page
Expand All @@ -127,13 +127,13 @@ func Uncyclo(ctx *context.Context) {
return
}

wikiRepo, pageName := renderUncycloPage(ctx, true)
wikiRepo, pagePath := renderUncycloPage(ctx, true)
if ctx.Written() {
return
}

// Get last change information.
lastCommit, err := wikiRepo.GetCommitByPath(pageName + ".md")
lastCommit, err := wikiRepo.GetCommitByPath(pagePath + ".md")
if err != nil {
ctx.Handle(500, "GetCommitByPath", err)
return
Expand Down Expand Up @@ -214,7 +214,9 @@ func NewUncycloPost(ctx *context.Context, form auth.NewUncycloForm) {
return
}

if err := ctx.Repo.Repository.AddUncycloPage(ctx.User, form.Title, form.Content, form.Message); err != nil {
wikiPath := models.ToUncycloPageURL(form.Title)

if err := ctx.Repo.Repository.AddUncycloPage(ctx.User, wikiPath, form.Content, form.Message); err != nil {
if models.IsErrUncycloAlreadyExist(err) {
ctx.Data["Err_Title"] = true
ctx.RenderWithErr(ctx.Tr("repo.wiki.page_already_exists"), tplUncycloNew, &form)
Expand All @@ -224,7 +226,7 @@ func NewUncycloPost(ctx *context.Context, form auth.NewUncycloForm) {
return
}

ctx.Redirect(ctx.Repo.RepoLink + "/wiki/" + models.ToUncycloPageURL(form.Title))
ctx.Redirect(ctx.Repo.RepoLink + "/wiki/" + wikiPath)
}

// EditUncyclo render wiki modify page
Expand Down Expand Up @@ -257,12 +259,15 @@ func EditUncycloPost(ctx *context.Context, form auth.NewUncycloForm) {
return
}

if err := ctx.Repo.Repository.EditUncycloPage(ctx.User, form.OldTitle, form.Title, form.Content, form.Message); err != nil {
oldUncycloPath := ctx.Params(":page")
newUncycloPath := models.ToUncycloPageURL(form.Title)

if err := ctx.Repo.Repository.EditUncycloPage(ctx.User, oldUncycloPath, newUncycloPath, form.Content, form.Message); err != nil {
ctx.Handle(500, "EditUncycloPage", err)
return
}

ctx.Redirect(ctx.Repo.RepoLink + "/wiki/" + models.ToUncycloPageURL(form.Title))
ctx.Redirect(ctx.Repo.RepoLink + "/wiki/" + newUncycloPath)
}

// DeleteUncycloPagePost delete wiki page
Expand All @@ -272,8 +277,7 @@ func DeleteUncycloPagePost(ctx *context.Context) {
pageURL = "Home"
}

pageName := models.ToUncycloPageName(pageURL)
if err := ctx.Repo.Repository.DeleteUncycloPage(ctx.User, pageName); err != nil {
if err := ctx.Repo.Repository.DeleteUncycloPage(ctx.User, pageURL); err != nil {
ctx.Handle(500, "DeleteUncycloPage", err)
return
}
Expand Down