mirror of https://github.com/go-gitea/gitea.git
Merge pull request #2746 from joshfng/feature-delete-wiki-pages
Add ability to delete single wiki pages.
This commit is contained in:
commit
4d5911dbcf
|
@ -495,6 +495,7 @@ func runWeb(ctx *cli.Context) {
|
||||||
Post(bindIgnErr(auth.NewWikiForm{}), repo.NewWikiPost)
|
Post(bindIgnErr(auth.NewWikiForm{}), repo.NewWikiPost)
|
||||||
m.Combo("/:page/_edit").Get(repo.EditWiki).
|
m.Combo("/:page/_edit").Get(repo.EditWiki).
|
||||||
Post(bindIgnErr(auth.NewWikiForm{}), repo.EditWikiPost)
|
Post(bindIgnErr(auth.NewWikiForm{}), repo.EditWikiPost)
|
||||||
|
m.Post("/:page/delete", bindIgnErr(auth.NewWikiForm{}), repo.DeleteWikiPagePost)
|
||||||
}, reqSignIn, reqRepoPusher)
|
}, reqSignIn, reqRepoPusher)
|
||||||
}, repo.MustEnableWiki, middleware.RepoRef())
|
}, repo.MustEnableWiki, middleware.RepoRef())
|
||||||
|
|
||||||
|
|
|
@ -560,6 +560,8 @@ wiki.save_page = Save Page
|
||||||
wiki.last_commit_info = %s edited this page %s
|
wiki.last_commit_info = %s edited this page %s
|
||||||
wiki.edit_page_button = Edit
|
wiki.edit_page_button = Edit
|
||||||
wiki.new_page_button = New Page
|
wiki.new_page_button = New Page
|
||||||
|
wiki.delete_page_button = Delete Page
|
||||||
|
wiki.delete_page_notice_1 = This will delete the page <code>"%s"</code>. Please be certain.
|
||||||
wiki.page_already_exists = Wiki page with same name already exists.
|
wiki.page_already_exists = Wiki page with same name already exists.
|
||||||
wiki.pages = Pages
|
wiki.pages = Pages
|
||||||
wiki.last_updated = Last updated %s
|
wiki.last_updated = Last updated %s
|
||||||
|
|
|
@ -178,3 +178,40 @@ func (repo *Repository) AddWikiPage(doer *User, title, content, message string)
|
||||||
func (repo *Repository) EditWikiPage(doer *User, oldTitle, title, content, message string) error {
|
func (repo *Repository) EditWikiPage(doer *User, oldTitle, title, content, message string) error {
|
||||||
return repo.updateWikiPage(doer, oldTitle, title, content, message, false)
|
return repo.updateWikiPage(doer, oldTitle, title, content, message, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (repo *Repository) DeleteWikiPage(doer *User, title string) (err error) {
|
||||||
|
wikiWorkingPool.CheckIn(com.ToStr(repo.ID))
|
||||||
|
defer wikiWorkingPool.CheckOut(com.ToStr(repo.ID))
|
||||||
|
|
||||||
|
localPath := repo.LocalWikiPath()
|
||||||
|
|
||||||
|
// Discard local commits make sure even to remote when local copy exists.
|
||||||
|
if com.IsExist(localPath) {
|
||||||
|
// No need to check if nothing in the repository.
|
||||||
|
if git.IsBranchExist(localPath, "master") {
|
||||||
|
if err = git.ResetHEAD(localPath, true, "origin/master"); err != nil {
|
||||||
|
return fmt.Errorf("Reset: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = repo.UpdateLocalWiki(); err != nil {
|
||||||
|
return fmt.Errorf("UpdateLocalWiki: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
filename := path.Join(localPath, title+".md")
|
||||||
|
|
||||||
|
os.Remove(filename)
|
||||||
|
|
||||||
|
message := "Delete page '" + title + "'"
|
||||||
|
|
||||||
|
if err = git.AddChanges(localPath, true); err != nil {
|
||||||
|
return fmt.Errorf("AddChanges: %v", err)
|
||||||
|
} else if err = git.CommitChanges(localPath, message, doer.NewGitSig()); err != nil {
|
||||||
|
return fmt.Errorf("CommitChanges: %v", err)
|
||||||
|
} else if err = git.Push(localPath, "origin", "master"); err != nil {
|
||||||
|
return fmt.Errorf("Push: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -256,3 +256,21 @@ func EditWikiPost(ctx *middleware.Context, form auth.NewWikiForm) {
|
||||||
|
|
||||||
ctx.Redirect(ctx.Repo.RepoLink + "/wiki/" + models.ToWikiPageURL(form.Title))
|
ctx.Redirect(ctx.Repo.RepoLink + "/wiki/" + models.ToWikiPageURL(form.Title))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func DeleteWikiPagePost(ctx *middleware.Context, form auth.NewWikiForm) {
|
||||||
|
pageURL := ctx.Params(":page")
|
||||||
|
if len(pageURL) == 0 {
|
||||||
|
pageURL = "Home"
|
||||||
|
}
|
||||||
|
|
||||||
|
pageName := models.ToWikiPageName(pageURL)
|
||||||
|
|
||||||
|
if err := ctx.Repo.Repository.DeleteWikiPage(ctx.User, pageName); err != nil {
|
||||||
|
ctx.Handle(500, "DeleteWikiPage", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.JSON(200, map[string]interface{}{
|
||||||
|
"redirect": ctx.Repo.RepoLink + "/wiki/",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
|
@ -50,6 +50,7 @@
|
||||||
<div class="ui right">
|
<div class="ui right">
|
||||||
<a class="ui small button" href="{{.RepoLink}}/wiki/{{.PageURL}}/_edit">{{.i18n.Tr "repo.wiki.edit_page_button"}}</a>
|
<a class="ui small button" href="{{.RepoLink}}/wiki/{{.PageURL}}/_edit">{{.i18n.Tr "repo.wiki.edit_page_button"}}</a>
|
||||||
<a class="ui green small button" href="{{.RepoLink}}/wiki/_new">{{.i18n.Tr "repo.wiki.new_page_button"}}</a>
|
<a class="ui green small button" href="{{.RepoLink}}/wiki/_new">{{.i18n.Tr "repo.wiki.new_page_button"}}</a>
|
||||||
|
<a class="ui red small button delete-button" href="" data-url="{{.RepoLink}}/wiki/{{.PageURL}}/delete" data-id="{{.PageURL}}">{{.i18n.Tr "repo.wiki.delete_page_button"}}</a>
|
||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
<div class="ui sub header">
|
<div class="ui sub header">
|
||||||
|
@ -62,4 +63,16 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="ui small basic delete modal">
|
||||||
|
<div class="ui icon header">
|
||||||
|
<i class="trash icon"></i>
|
||||||
|
{{.i18n.Tr "repo.wiki.delete_page_button"}}
|
||||||
|
</div>
|
||||||
|
<div class="content">
|
||||||
|
<p>{{.i18n.Tr "repo.wiki.delete_page_notice_1" .title | Safe}}</p>
|
||||||
|
</div>
|
||||||
|
{{template "base/delete_modal_actions" .}}
|
||||||
|
</div>
|
||||||
|
|
||||||
{{template "base/footer" .}}
|
{{template "base/footer" .}}
|
||||||
|
|
Loading…
Reference in New Issue