Browse Source

fix wiki bugs (#1294)

tags/v1.2.0-rc1
Lunny Xiao 7 years ago
parent
commit
bd8fe49076
2 changed files with 21 additions and 5 deletions
  1. 5
    1
      models/wiki.go
  2. 16
    4
      routers/repo/wiki.go

+ 5
- 1
models/wiki.go View File

func (repo *Repository) UpdateLocalWiki() error { func (repo *Repository) UpdateLocalWiki() error {
// Don't pass branch name here because it fails to clone and // Don't pass branch name here because it fails to clone and
// checkout to a specific branch when wiki is an empty repository. // checkout to a specific branch when wiki is an empty repository.
return UpdateLocalCopyBranch(repo.WikiPath(), repo.LocalWikiPath(), "")
var branch = ""
if com.IsExist(repo.LocalWikiPath()) {
branch = "master"
}
return UpdateLocalCopyBranch(repo.WikiPath(), repo.LocalWikiPath(), branch)
} }


func discardLocalWikiChanges(localPath string) error { func discardLocalWikiChanges(localPath string) error {

+ 16
- 4
routers/repo/wiki.go View File

// ctx.Handle(500, "OpenRepository", err) // ctx.Handle(500, "OpenRepository", err)
return nil, nil, err return nil, nil, err
} }
if !wikiRepo.IsBranchExist("master") {
return wikiRepo, nil, nil
}

commit, err := wikiRepo.GetBranchCommit("master") commit, err := wikiRepo.GetBranchCommit("master")
if err != nil { if err != nil {
ctx.Handle(500, "GetBranchCommit", err) ctx.Handle(500, "GetBranchCommit", err)
if err != nil { if err != nil {
return nil, nil return nil, nil
} }
if commit == nil {
return wikiRepo, nil
}


// Get page list. // Get page list.
if isViewPage { if isViewPage {
} }
pages = append(pages, PageMeta{ pages = append(pages, PageMeta{
Name: models.ToWikiPageName(name), Name: models.ToWikiPageName(name),
URL: models.ToWikiPageURL(name),
URL: name,
}) })
} }
} }
if ctx.Written() { if ctx.Written() {
return return
} }
if entry == nil {
ctx.Data["Title"] = ctx.Tr("repo.wiki")
ctx.HTML(200, tplWikiStart)
return
}


ename := entry.Name() ename := entry.Name()
if !markdown.IsMarkdownFile(ename) { if !markdown.IsMarkdownFile(ename) {
} }
pages = append(pages, PageMeta{ pages = append(pages, PageMeta{
Name: models.ToWikiPageName(name), Name: models.ToWikiPageName(name),
URL: models.ToWikiPageURL(name),
URL: name,
Updated: c.Author.When, Updated: c.Author.When,
}) })
} }
return return
} }


oldWikiPath := ctx.Params(":page")
oldWikiPath := models.ToWikiPageURL(ctx.Params(":page"))
newWikiPath := models.ToWikiPageURL(form.Title) newWikiPath := models.ToWikiPageURL(form.Title)


if err := ctx.Repo.Repository.EditWikiPage(ctx.User, oldWikiPath, newWikiPath, form.Content, form.Message); err != nil { if err := ctx.Repo.Repository.EditWikiPage(ctx.User, oldWikiPath, newWikiPath, form.Content, form.Message); err != nil {


// DeleteWikiPagePost delete wiki page // DeleteWikiPagePost delete wiki page
func DeleteWikiPagePost(ctx *context.Context) { func DeleteWikiPagePost(ctx *context.Context) {
pageURL := ctx.Params(":page")
pageURL := models.ToWikiPageURL(ctx.Params(":page"))
if len(pageURL) == 0 { if len(pageURL) == 0 {
pageURL = "Home" pageURL = "Home"
} }

Loading…
Cancel
Save