Skip to content

Commit

Permalink
add wiki page revision list
Browse files Browse the repository at this point in the history
- list who, how often and when a wiki page was changed

fix go-gitea#7

Signed-off-by: Michael Gnehr <michael@gnehr.de>
  • Loading branch information
Cherrg committed Jul 7, 2019
1 parent 8baa2dc commit c102abe
Show file tree
Hide file tree
Showing 7 changed files with 194 additions and 7 deletions.
2 changes: 2 additions & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1032,6 +1032,8 @@ wiki.save_page = Save Page
wiki.last_commit_info = %s edited this page %s
wiki.edit_page_button = Edit
wiki.new_page_button = New Page
wiki.file_revision = Page Revision
wiki.back_to_wiki = Back to wiki page
wiki.delete_page_button = Delete Page
wiki.delete_page_notice_1 = Deleting the wiki page '%s' cannot be undone. Continue?
wiki.page_already_exists = A wiki page with the same name already exists.
Expand Down
2 changes: 2 additions & 0 deletions public/css/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ footer .ui.left,footer .ui.right{line-height:40px}
.markdown:not(code) .csv-data tr{border-top:0}
.markdown:not(code) .csv-data th{font-weight:700;background:#f8f8f8;border-top:0}
.markdown:not(code) .ui.list .list,.markdown:not(code) ol.ui.list ol,.markdown:not(code) ul.ui.list ul{padding-left:2em}
.file-revisions-btn{display:block;float:left;padding:11px!important;margin-right:10px!important}
.file-revisions-btn i{-webkit-touch-callout:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}
.home .logo{max-width:220px}
@media only screen and (max-width:767px){.home .hero h1{font-size:3.5em}
.home .hero h2{font-size:2em}
Expand Down
16 changes: 16 additions & 0 deletions public/less/_markdown.less
Original file line number Diff line number Diff line change
Expand Up @@ -494,3 +494,19 @@
padding-left: 2em;
}
}

.file-revisions-btn {
display: block;
float: left;
padding: 11px !important;
margin-right: 10px !important;

i {
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
}
76 changes: 69 additions & 7 deletions routers/repo/wiki.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ import (
)

const (
tplWikiStart base.TplName = "repo/wiki/start"
tplWikiView base.TplName = "repo/wiki/view"
tplWikiNew base.TplName = "repo/wiki/new"
tplWikiPages base.TplName = "repo/wiki/pages"
tplWikiStart base.TplName = "repo/wiki/start"
tplWikiView base.TplName = "repo/wiki/view"
tplWikiRevision base.TplName = "repo/wiki/revision"
tplWikiNew base.TplName = "repo/wiki/new"
tplWikiPages base.TplName = "repo/wiki/pages"
)

// MustEnableWiki check if wiki is enabled, if external then redirect
Expand Down Expand Up @@ -118,7 +119,7 @@ func wikiContentsByName(ctx *context.Context, commit *git.Commit, wikiName strin
return wikiContentsByEntry(ctx, entry), true
}

func renderWikiPage(ctx *context.Context, isViewPage bool) (*git.Repository, *git.TreeEntry) {
func renderWikiPage(ctx *context.Context, isViewPage bool, isFileHistory bool) (*git.Repository, *git.TreeEntry) {
wikiRepo, commit, err := findWikiRepoCommit(ctx)
if err != nil {
if !git.IsErrNotExist(err) {
Expand Down Expand Up @@ -177,11 +178,39 @@ func renderWikiPage(ctx *context.Context, isViewPage bool) (*git.Repository, *gi
ctx.Redirect(ctx.Repo.RepoLink + "/wiki/_pages")
return nil, nil
}

data := wikiContentsByEntry(ctx, entry)
if ctx.Written() {
return nil, nil
}

// get commit count - wiki revisions
commitsCount, _ := wikiRepo.FileCommitsCount("master", pageFilename)
ctx.Data["CommitCount"] = commitsCount

if isFileHistory {
// get page
page := ctx.QueryInt("page")
if page <= 1 {
page = 1
}

// get Commit Count
commitsHistory, err := wikiRepo.CommitsByFileAndRange("master", pageFilename, page)
if err != nil {
ctx.ServerError("CommitsByFileAndRange", err)
return nil, nil
}
commitsHistory = models.ValidateCommitsWithEmails(commitsHistory)
commitsHistory = models.ParseCommitsWithSignature(commitsHistory)

ctx.Data["Commits"] = commitsHistory

pager := context.NewPagination(int(commitsCount), git.CommitsRangeSize, page, 5)
pager.SetDefaultParams(ctx)
ctx.Data["Page"] = pager
}

if isViewPage {
sidebarContent, sidebarPresent := wikiContentsByName(ctx, commit, "_Sidebar")
if ctx.Written() {
Expand Down Expand Up @@ -221,7 +250,7 @@ func Wiki(ctx *context.Context) {
return
}

wikiRepo, entry := renderWikiPage(ctx, true)
wikiRepo, entry := renderWikiPage(ctx, true, false)
if ctx.Written() {
return
}
Expand All @@ -247,6 +276,39 @@ func Wiki(ctx *context.Context) {
ctx.HTML(200, tplWikiView)
}

// Wiki renders file revision list of wiki page
func WikiRevision(ctx *context.Context) {
ctx.Data["PageIsWiki"] = true
ctx.Data["CanWriteWiki"] = ctx.Repo.CanWrite(models.UnitTypeWiki) && !ctx.Repo.Repository.IsArchived

if !ctx.Repo.Repository.HasWiki() {
ctx.Data["Title"] = ctx.Tr("repo.wiki")
ctx.HTML(200, tplWikiStart)
return
}

wikiRepo, entry := renderWikiPage(ctx, false, true)
if ctx.Written() {
return
}
if entry == nil {
ctx.Data["Title"] = ctx.Tr("repo.wiki")
ctx.HTML(200, tplWikiStart)
return
}

// Get last change information.
wikiPath := entry.Name()
lastCommit, err := wikiRepo.GetCommitByPath(wikiPath)
if err != nil {
ctx.ServerError("GetCommitByPath", err)
return
}
ctx.Data["Author"] = lastCommit.Author

ctx.HTML(200, tplWikiRevision)
}

// WikiPages render wiki pages list page
func WikiPages(ctx *context.Context) {
if !ctx.Repo.Repository.HasWiki() {
Expand Down Expand Up @@ -399,7 +461,7 @@ func EditWiki(ctx *context.Context) {
return
}

renderWikiPage(ctx, false)
renderWikiPage(ctx, false, false)
if ctx.Written() {
return
}
Expand Down
1 change: 1 addition & 0 deletions routers/routes/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,7 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Group("/wiki", func() {
m.Get("/?:page", repo.Wiki)
m.Get("/_pages", repo.WikiPages)
m.Get("/:page/_revision", repo.WikiRevision)

m.Group("", func() {
m.Combo("/_new").Get(repo.NewWiki).
Expand Down
103 changes: 103 additions & 0 deletions templates/repo/wiki/revision.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
{{template "base/head" .}}
<div class="repository wiki revisions">
{{template "repo/header" .}}
{{ $title := .title}}
<div class="ui container">
<div class="ui stackable grid">
<div class="ui header ten wide column">
<a class="file-revisions-btn ui basic button" title="{{.i18n.Tr "repo.wiki.back_to_wiki"}}" href="{{.RepoLink}}/wiki/{{.PageURL}}" ><span>{{.revision}}</span> <i class="fa fa-fw fa-file-text-o"></i></a>
{{$title}}
<div class="ui sub header">
{{$timeSince := TimeSince .Author.When $.Lang}}
{{.i18n.Tr "repo.wiki.last_commit_info" .Author.Name $timeSince | Safe}}
</div>
</div>
<div class="ui six wide column">
<div class="ui action small input" id="clone-panel">
{{if not $.DisableHTTP}}
<button class="ui basic clone button" id="repo-clone-https" data-link="{{.WikiCloneLink.HTTPS}}">
{{if UseHTTPS}}HTTPS{{else}}HTTP{{end}}
</button>
{{end}}
{{if and (not $.DisableSSH) (or $.IsSigned $.ExposeAnonSSH)}}
<button class="ui basic clone button" id="repo-clone-ssh" data-link="{{.WikiCloneLink.SSH}}">
SSH
</button>
{{end}}
{{if not $.DisableHTTP}}
<input id="repo-clone-url" value="{{$.WikiCloneLink.HTTPS}}" readonly>
{{else if and (not $.DisableSSH) (or $.IsSigned $.ExposeAnonSSH)}}
<input id="repo-clone-url" value="{{$.WikiCloneLink.SSH}}" readonly>
{{end}}
{{if or ((not $.DisableHTTP) (and (not $.DisableSSH) (or $.IsSigned $.ExposeAnonSSH)))}}
<button class="ui basic icon button poping up clipboard" id="clipboard-btn" data-original="{{.i18n.Tr "repo.copy_link"}}" data-success="{{.i18n.Tr "repo.copy_link_success"}}" data-error="{{.i18n.Tr "repo.copy_link_error"}}" data-content="{{.i18n.Tr "repo.copy_link"}}" data-variation="inverted tiny" data-clipboard-target="#repo-clone-url">
<i class="octicon octicon-clippy"></i>
</button>
{{end}}
</div>
</div>
</div>
<div class="ui" style="margin-top: 1rem;">
<h4 class="ui top attached header">
<div class="ui stackable grid">
<div class="sixteen wide column">
{{.CommitCount}} {{.i18n.Tr "repo.commits.commits"}}
</div>
</div>
</h4>

{{if and .Commits (gt .CommitCount 0)}}
<div class="ui attached table segment">
<table class="ui very basic striped fixed table single line" id="commits-table">
<thead>
<tr>
<th class="eight wide">{{.i18n.Tr "repo.commits.author"}}</th>
<th class="four wide sha">SHA1</th>
<th class="four wide">{{.i18n.Tr "repo.commits.date"}}</th>
</tr>
</thead>
<tbody class="commit-list">
{{ $r:= List .Commits}}
{{range $r}}
<tr>
<td class="author">
{{if .User}}
{{if .User.FullName}}
<img class="ui avatar image" src="{{.User.RelAvatarLink}}" alt=""/>&nbsp;&nbsp;<a href="{{AppSubUrl}}/{{.User.Name}}">{{.User.FullName}}</a>
{{else}}
<img class="ui avatar image" src="{{.User.RelAvatarLink}}" alt=""/>&nbsp;&nbsp;<a href="{{AppSubUrl}}/{{.User.Name}}">{{.Author.Name}}</a>
{{end}}
{{else}}
<img class="ui avatar image" src="{{AvatarLink .Author.Email}}" alt=""/>&nbsp;&nbsp;{{.Author.Name}}
{{end}}
</td>
<td class="sha">
<label rel="nofollow" class="ui sha label {{if .Signature}} isSigned {{if .Verification.Verified }} isVerified {{end}}{{end}}">
{{ShortSha .ID.String}}
{{if .Signature}}
<div class="ui detail icon button">
{{if .Verification.Verified}}
<i title="{{.Verification.Reason}}" class="lock green icon"></i>
{{else}}
<i title="{{$.i18n.Tr .Verification.Reason}}" class="unlock icon"></i>
{{end}}
</div>
{{end}}
</label>
</td>
<td class="grey text">{{TimeSince .Author.When $.Lang}}</td>
</tr>
{{end}}
</tbody>
</table>
</div>
{{end}}

{{template "base/paginate" .}}

</div>
</div>
</div>


{{template "base/footer" .}}
1 change: 1 addition & 0 deletions templates/repo/wiki/view.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
<div class="ui dividing header">
<div class="ui stackable grid">
<div class="eight wide column">
<a class="file-revisions-btn ui basic button" title="{{.i18n.Tr "repo.wiki.file_revision"}}" href="{{.RepoLink}}/wiki/{{.PageURL}}/_revision" ><span>{{.CommitCount}}</span> <i class="fa fa-fw fa-history"></i></a>
{{$title}}
<div class="ui sub header">
{{$timeSince := TimeSince .Author.When $.Lang}}
Expand Down

0 comments on commit c102abe

Please sign in to comment.