From c102abeeb91bbcb9c9efa599362f5dcf145d4969 Mon Sep 17 00:00:00 2001 From: Michael Gnehr Date: Sun, 7 Jul 2019 03:56:59 +0200 Subject: [PATCH 1/5] add wiki page revision list - list who, how often and when a wiki page was changed fix #7 Signed-off-by: Michael Gnehr --- options/locale/locale_en-US.ini | 2 + public/css/index.css | 2 + public/less/_markdown.less | 16 +++++ routers/repo/wiki.go | 76 ++++++++++++++++++++-- routers/routes/routes.go | 1 + templates/repo/wiki/revision.tmpl | 103 ++++++++++++++++++++++++++++++ templates/repo/wiki/view.tmpl | 1 + 7 files changed, 194 insertions(+), 7 deletions(-) create mode 100644 templates/repo/wiki/revision.tmpl diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 223df91fda469..99af4a8393265 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -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. diff --git a/public/css/index.css b/public/css/index.css index 437605e1d31f0..f888ff848be9e 100644 --- a/public/css/index.css +++ b/public/css/index.css @@ -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} diff --git a/public/less/_markdown.less b/public/less/_markdown.less index e971248f6ffca..4b3867f934a67 100644 --- a/public/less/_markdown.less +++ b/public/less/_markdown.less @@ -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; + } +} diff --git a/routers/repo/wiki.go b/routers/repo/wiki.go index 43149c034061b..518a12f7d58d8 100644 --- a/routers/repo/wiki.go +++ b/routers/repo/wiki.go @@ -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 @@ -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) { @@ -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() { @@ -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 } @@ -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() { @@ -399,7 +461,7 @@ func EditWiki(ctx *context.Context) { return } - renderWikiPage(ctx, false) + renderWikiPage(ctx, false, false) if ctx.Written() { return } diff --git a/routers/routes/routes.go b/routers/routes/routes.go index 744088a9d7b1e..ec57e8f5fdac7 100644 --- a/routers/routes/routes.go +++ b/routers/routes/routes.go @@ -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). diff --git a/templates/repo/wiki/revision.tmpl b/templates/repo/wiki/revision.tmpl new file mode 100644 index 0000000000000..473d5ddb3c5e5 --- /dev/null +++ b/templates/repo/wiki/revision.tmpl @@ -0,0 +1,103 @@ +{{template "base/head" .}} +
+ {{template "repo/header" .}} + {{ $title := .title}} +
+
+
+ {{.revision}} + {{$title}} +
+ {{$timeSince := TimeSince .Author.When $.Lang}} + {{.i18n.Tr "repo.wiki.last_commit_info" .Author.Name $timeSince | Safe}} +
+
+
+
+ {{if not $.DisableHTTP}} + + {{end}} + {{if and (not $.DisableSSH) (or $.IsSigned $.ExposeAnonSSH)}} + + {{end}} + {{if not $.DisableHTTP}} + + {{else if and (not $.DisableSSH) (or $.IsSigned $.ExposeAnonSSH)}} + + {{end}} + {{if or ((not $.DisableHTTP) (and (not $.DisableSSH) (or $.IsSigned $.ExposeAnonSSH)))}} + + {{end}} +
+
+
+
+

+
+
+ {{.CommitCount}} {{.i18n.Tr "repo.commits.commits"}} +
+
+

+ + {{if and .Commits (gt .CommitCount 0)}} +
+ + + + + + + + + + {{ $r:= List .Commits}} + {{range $r}} + + + + + + {{end}} + +
{{.i18n.Tr "repo.commits.author"}}SHA1{{.i18n.Tr "repo.commits.date"}}
+ {{if .User}} + {{if .User.FullName}} +   {{.User.FullName}} + {{else}} +   {{.Author.Name}} + {{end}} + {{else}} +   {{.Author.Name}} + {{end}} + + + {{TimeSince .Author.When $.Lang}}
+
+ {{end}} + + {{template "base/paginate" .}} + +
+
+
+ + +{{template "base/footer" .}} diff --git a/templates/repo/wiki/view.tmpl b/templates/repo/wiki/view.tmpl index dd2de2a041380..f775ac9429200 100644 --- a/templates/repo/wiki/view.tmpl +++ b/templates/repo/wiki/view.tmpl @@ -56,6 +56,7 @@
+ {{.CommitCount}} {{$title}}
{{$timeSince := TimeSince .Author.When $.Lang}} From 417b010c478d3f3e36c0cf88bd46e48f95561d84 Mon Sep 17 00:00:00 2001 From: Michael Gnehr Date: Sun, 7 Jul 2019 06:00:46 +0200 Subject: [PATCH 2/5] mobile improvements + build fix Signed-off-by: Michael Gnehr --- options/locale/locale_en-US.ini | 1 + public/css/index.css | 2 ++ public/less/_markdown.less | 11 +++++++++++ routers/repo/wiki.go | 2 +- templates/repo/wiki/revision.tmpl | 19 ++++++++++--------- 5 files changed, 25 insertions(+), 10 deletions(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 99af4a8393265..8713b06599c76 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -1033,6 +1033,7 @@ 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.wiki_page_revisions = Wiki Page Revisions 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? diff --git a/public/css/index.css b/public/css/index.css index f888ff848be9e..be050adcd15b6 100644 --- a/public/css/index.css +++ b/public/css/index.css @@ -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} +.repository.wiki.revisions .ui.container>.ui.stackable.grid{flex-direction:row-reverse} +.repository.wiki.revisions .ui.container>.ui.stackable.grid>.header{margin-top:0} .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} diff --git a/public/less/_markdown.less b/public/less/_markdown.less index 4b3867f934a67..ecbc9aaab177e 100644 --- a/public/less/_markdown.less +++ b/public/less/_markdown.less @@ -495,6 +495,17 @@ } } +.repository.wiki.revisions { + .ui.container > .ui.stackable.grid { + -ms-flex-direction: row-reverse; + flex-direction: row-reverse; + + > .header { + margin-top: 0; + } + } +} + .file-revisions-btn { display: block; float: left; diff --git a/routers/repo/wiki.go b/routers/repo/wiki.go index 518a12f7d58d8..ef26a288d7fe6 100644 --- a/routers/repo/wiki.go +++ b/routers/repo/wiki.go @@ -276,7 +276,7 @@ func Wiki(ctx *context.Context) { ctx.HTML(200, tplWikiView) } -// Wiki renders file revision list of wiki page +// WikiRevision 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 diff --git a/templates/repo/wiki/revision.tmpl b/templates/repo/wiki/revision.tmpl index 473d5ddb3c5e5..a64c386edcade 100644 --- a/templates/repo/wiki/revision.tmpl +++ b/templates/repo/wiki/revision.tmpl @@ -4,15 +4,7 @@ {{ $title := .title}}
-
- {{.revision}} - {{$title}} -
- {{$timeSince := TimeSince .Author.When $.Lang}} - {{.i18n.Tr "repo.wiki.last_commit_info" .Author.Name $timeSince | Safe}} -
-
-
+
{{if not $.DisableHTTP}}
+
+ {{.revision}} + {{$title}} +
+ {{$timeSince := TimeSince .Author.When $.Lang}} + {{.i18n.Tr "repo.wiki.last_commit_info" .Author.Name $timeSince | Safe}} +
+
+

{{.i18n.Tr "repo.wiki.wiki_page_revisions"}}

From 278fec83212fefead9caac0f0967e964f33c6939 Mon Sep 17 00:00:00 2001 From: Michael Gnehr Date: Sun, 7 Jul 2019 06:51:56 +0200 Subject: [PATCH 3/5] css improvements for long usernames Signed-off-by: Michael Gnehr --- public/css/index.css | 3 ++- public/less/_markdown.less | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/public/css/index.css b/public/css/index.css index be050adcd15b6..267099d4a051c 100644 --- a/public/css/index.css +++ b/public/css/index.css @@ -289,7 +289,8 @@ footer .ui.left,footer .ui.right{line-height:40px} .markdown:not(code) .ui.list .list,.markdown:not(code) ol.ui.list ol,.markdown:not(code) ul.ui.list ul{padding-left:2em} .repository.wiki.revisions .ui.container>.ui.stackable.grid{flex-direction:row-reverse} .repository.wiki.revisions .ui.container>.ui.stackable.grid>.header{margin-top:0} -.file-revisions-btn{display:block;float:left;padding:11px!important;margin-right:10px!important} +.repository.wiki.revisions .ui.container>.ui.stackable.grid>.header .sub.header{padding-left:52px} +.file-revisions-btn{display:block;float:left;margin-bottom:2px!important;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} diff --git a/public/less/_markdown.less b/public/less/_markdown.less index ecbc9aaab177e..1dcc2caf94356 100644 --- a/public/less/_markdown.less +++ b/public/less/_markdown.less @@ -502,6 +502,10 @@ > .header { margin-top: 0; + + .sub.header { + padding-left: 52px; + } } } } @@ -509,6 +513,7 @@ .file-revisions-btn { display: block; float: left; + margin-bottom: 2px !important; padding: 11px !important; margin-right: 10px !important; From 3331335acf0a597b4c9415170d320fbc97ebc7a0 Mon Sep 17 00:00:00 2001 From: Michael Gnehr Date: Sun, 7 Jul 2019 16:10:45 +0200 Subject: [PATCH 4/5] move functions 1 Signed-off-by: Michael Gnehr --- routers/repo/wiki.go | 78 +++++++++++++++++++++----------------------- 1 file changed, 37 insertions(+), 41 deletions(-) diff --git a/routers/repo/wiki.go b/routers/repo/wiki.go index ef26a288d7fe6..53736d237ae66 100644 --- a/routers/repo/wiki.go +++ b/routers/repo/wiki.go @@ -108,15 +108,17 @@ func wikiContentsByEntry(ctx *context.Context, entry *git.TreeEntry) []byte { // wikiContentsByName returns the contents of a wiki page, along with a boolean // indicating whether the page exists. Writes to ctx if an error occurs. -func wikiContentsByName(ctx *context.Context, commit *git.Commit, wikiName string) ([]byte, bool) { - entry, err := findEntryForFile(commit, models.WikiNameToFilename(wikiName)) - if err != nil { +func wikiContentsByName(ctx *context.Context, commit *git.Commit, wikiName string) ([]byte, *git.TreeEntry, string, bool) { + var entry *git.TreeEntry + var err error + pageFilename := models.WikiNameToFilename(wikiName) + if entry, err = findEntryForFile(commit, pageFilename); err != nil { ctx.ServerError("findEntryForFile", err) - return nil, false + return nil, nil, "", false } else if entry == nil { - return nil, false + return nil, nil, "", true } - return wikiContentsByEntry(ctx, entry), true + return wikiContentsByEntry(ctx, entry), entry, pageFilename, false } func renderWikiPage(ctx *context.Context, isViewPage bool, isFileHistory bool) (*git.Repository, *git.TreeEntry) { @@ -158,30 +160,49 @@ func renderWikiPage(ctx *context.Context, isViewPage bool, isFileHistory bool) ( ctx.Data["Pages"] = pages } + // get requested pagename pageName := models.NormalizeWikiName(ctx.Params(":page")) if len(pageName) == 0 { pageName = "Home" } ctx.Data["PageURL"] = models.WikiNameToSubURL(pageName) - ctx.Data["old_title"] = pageName ctx.Data["Title"] = pageName ctx.Data["title"] = pageName ctx.Data["RequireHighlightJS"] = true - pageFilename := models.WikiNameToFilename(pageName) - var entry *git.TreeEntry - if entry, err = findEntryForFile(commit, pageFilename); err != nil { - ctx.ServerError("findEntryForFile", err) - return nil, nil - } else if entry == nil { + //lookup filename in wiki - get filecontent, gitTree entry , real filename + data, entry, pageFilename, noEntry := wikiContentsByName(ctx, commit, pageName) + if noEntry { ctx.Redirect(ctx.Repo.RepoLink + "/wiki/_pages") + } + if entry == nil || ctx.Written() { return nil, nil } - data := wikiContentsByEntry(ctx, entry) - if ctx.Written() { - return nil, nil + if isViewPage { + sidebarContent, _, _, _ := wikiContentsByName(ctx, commit, "_Sidebar") + if ctx.Written() { + return nil, nil + } + + footerContent, _, _, _ := wikiContentsByName(ctx, commit, "_Footer") + if ctx.Written() { + return nil, nil + } + + metas := ctx.Repo.Repository.ComposeMetas() + ctx.Data["content"] = markdown.RenderWiki(data, ctx.Repo.RepoLink, metas) + ctx.Data["sidebarPresent"] = sidebarContent != nil + ctx.Data["sidebarContent"] = markdown.RenderWiki(sidebarContent, ctx.Repo.RepoLink, metas) + ctx.Data["footerPresent"] = footerContent != nil + ctx.Data["footerContent"] = markdown.RenderWiki(footerContent, ctx.Repo.RepoLink, metas) + } else { + ctx.Data["content"] = string(data) + ctx.Data["sidebarPresent"] = false + ctx.Data["sidebarContent"] = "" + ctx.Data["footerPresent"] = false + ctx.Data["footerContent"] = "" } // get commit count - wiki revisions @@ -211,31 +232,6 @@ func renderWikiPage(ctx *context.Context, isViewPage bool, isFileHistory bool) ( ctx.Data["Page"] = pager } - if isViewPage { - sidebarContent, sidebarPresent := wikiContentsByName(ctx, commit, "_Sidebar") - if ctx.Written() { - return nil, nil - } - - footerContent, footerPresent := wikiContentsByName(ctx, commit, "_Footer") - if ctx.Written() { - return nil, nil - } - - metas := ctx.Repo.Repository.ComposeMetas() - ctx.Data["content"] = markdown.RenderWiki(data, ctx.Repo.RepoLink, metas) - ctx.Data["sidebarPresent"] = sidebarPresent - ctx.Data["sidebarContent"] = markdown.RenderWiki(sidebarContent, ctx.Repo.RepoLink, metas) - ctx.Data["footerPresent"] = footerPresent - ctx.Data["footerContent"] = markdown.RenderWiki(footerContent, ctx.Repo.RepoLink, metas) - } else { - ctx.Data["content"] = string(data) - ctx.Data["sidebarPresent"] = false - ctx.Data["sidebarContent"] = "" - ctx.Data["footerPresent"] = false - ctx.Data["footerContent"] = "" - } - return wikiRepo, entry } From 706411f12eb2c1ee6dc9e781a83527bd4c681025 Mon Sep 17 00:00:00 2001 From: Michael Gnehr Date: Sun, 7 Jul 2019 16:56:48 +0200 Subject: [PATCH 5/5] split renderWikiPage into 3 functions Signed-off-by: Michael Gnehr --- routers/repo/wiki.go | 196 +++++++++++++++++++++++++++++-------------- 1 file changed, 131 insertions(+), 65 deletions(-) diff --git a/routers/repo/wiki.go b/routers/repo/wiki.go index 53736d237ae66..0fdf8536307e7 100644 --- a/routers/repo/wiki.go +++ b/routers/repo/wiki.go @@ -121,7 +121,7 @@ func wikiContentsByName(ctx *context.Context, commit *git.Commit, wikiName strin return wikiContentsByEntry(ctx, entry), entry, pageFilename, false } -func renderWikiPage(ctx *context.Context, isViewPage bool, isFileHistory bool) (*git.Repository, *git.TreeEntry) { +func renderViewPage(ctx *context.Context) (*git.Repository, *git.TreeEntry) { wikiRepo, commit, err := findWikiRepoCommit(ctx) if err != nil { if !git.IsErrNotExist(err) { @@ -131,34 +131,32 @@ func renderWikiPage(ctx *context.Context, isViewPage bool, isFileHistory bool) ( } // Get page list. - if isViewPage { - entries, err := commit.ListEntries() - if err != nil { - ctx.ServerError("ListEntries", err) - return nil, nil + entries, err := commit.ListEntries() + if err != nil { + ctx.ServerError("ListEntries", err) + return nil, nil + } + pages := make([]PageMeta, 0, len(entries)) + for _, entry := range entries { + if !entry.IsRegular() { + continue } - pages := make([]PageMeta, 0, len(entries)) - for _, entry := range entries { - if !entry.IsRegular() { - continue - } - wikiName, err := models.WikiFilenameToName(entry.Name()) - if err != nil { - if models.IsErrWikiInvalidFileName(err) { - continue - } - ctx.ServerError("WikiFilenameToName", err) - return nil, nil - } else if wikiName == "_Sidebar" || wikiName == "_Footer" { + wikiName, err := models.WikiFilenameToName(entry.Name()) + if err != nil { + if models.IsErrWikiInvalidFileName(err) { continue } - pages = append(pages, PageMeta{ - Name: wikiName, - SubURL: models.WikiNameToSubURL(wikiName), - }) + ctx.ServerError("WikiFilenameToName", err) + return nil, nil + } else if wikiName == "_Sidebar" || wikiName == "_Footer" { + continue } - ctx.Data["Pages"] = pages + pages = append(pages, PageMeta{ + Name: wikiName, + SubURL: models.WikiNameToSubURL(wikiName), + }) } + ctx.Data["Pages"] = pages // get requested pagename pageName := models.NormalizeWikiName(ctx.Params(":page")) @@ -180,59 +178,127 @@ func renderWikiPage(ctx *context.Context, isViewPage bool, isFileHistory bool) ( return nil, nil } - if isViewPage { - sidebarContent, _, _, _ := wikiContentsByName(ctx, commit, "_Sidebar") - if ctx.Written() { - return nil, nil - } + sidebarContent, _, _, _ := wikiContentsByName(ctx, commit, "_Sidebar") + if ctx.Written() { + return nil, nil + } - footerContent, _, _, _ := wikiContentsByName(ctx, commit, "_Footer") - if ctx.Written() { - return nil, nil + footerContent, _, _, _ := wikiContentsByName(ctx, commit, "_Footer") + if ctx.Written() { + return nil, nil + } + + metas := ctx.Repo.Repository.ComposeMetas() + ctx.Data["content"] = markdown.RenderWiki(data, ctx.Repo.RepoLink, metas) + ctx.Data["sidebarPresent"] = sidebarContent != nil + ctx.Data["sidebarContent"] = markdown.RenderWiki(sidebarContent, ctx.Repo.RepoLink, metas) + ctx.Data["footerPresent"] = footerContent != nil + ctx.Data["footerContent"] = markdown.RenderWiki(footerContent, ctx.Repo.RepoLink, metas) + + // get commit count - wiki revisions + commitsCount, _ := wikiRepo.FileCommitsCount("master", pageFilename) + ctx.Data["CommitCount"] = commitsCount + + return wikiRepo, entry +} + +func renderRevisionPage(ctx *context.Context) (*git.Repository, *git.TreeEntry) { + wikiRepo, commit, err := findWikiRepoCommit(ctx) + if err != nil { + if !git.IsErrNotExist(err) { + ctx.ServerError("GetBranchCommit", err) } + return nil, nil + } - metas := ctx.Repo.Repository.ComposeMetas() - ctx.Data["content"] = markdown.RenderWiki(data, ctx.Repo.RepoLink, metas) - ctx.Data["sidebarPresent"] = sidebarContent != nil - ctx.Data["sidebarContent"] = markdown.RenderWiki(sidebarContent, ctx.Repo.RepoLink, metas) - ctx.Data["footerPresent"] = footerContent != nil - ctx.Data["footerContent"] = markdown.RenderWiki(footerContent, ctx.Repo.RepoLink, metas) - } else { - ctx.Data["content"] = string(data) - ctx.Data["sidebarPresent"] = false - ctx.Data["sidebarContent"] = "" - ctx.Data["footerPresent"] = false - ctx.Data["footerContent"] = "" + // get requested pagename + pageName := models.NormalizeWikiName(ctx.Params(":page")) + if len(pageName) == 0 { + pageName = "Home" } + ctx.Data["PageURL"] = models.WikiNameToSubURL(pageName) + ctx.Data["old_title"] = pageName + ctx.Data["Title"] = pageName + ctx.Data["title"] = pageName + ctx.Data["RequireHighlightJS"] = true + + //lookup filename in wiki - get filecontent, gitTree entry , real filename + data, entry, pageFilename, noEntry := wikiContentsByName(ctx, commit, pageName) + if noEntry { + ctx.Redirect(ctx.Repo.RepoLink + "/wiki/_pages") + } + if entry == nil || ctx.Written() { + return nil, nil + } + + ctx.Data["content"] = string(data) + ctx.Data["sidebarPresent"] = false + ctx.Data["sidebarContent"] = "" + ctx.Data["footerPresent"] = false + ctx.Data["footerContent"] = "" // 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 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 + // 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 + + return wikiRepo, entry +} + +func renderEditPage(ctx *context.Context) { + _, commit, err := findWikiRepoCommit(ctx) + if err != nil { + if !git.IsErrNotExist(err) { + ctx.ServerError("GetBranchCommit", err) } - commitsHistory = models.ValidateCommitsWithEmails(commitsHistory) - commitsHistory = models.ParseCommitsWithSignature(commitsHistory) + return + } - ctx.Data["Commits"] = commitsHistory + // get requested pagename + pageName := models.NormalizeWikiName(ctx.Params(":page")) + if len(pageName) == 0 { + pageName = "Home" + } + ctx.Data["PageURL"] = models.WikiNameToSubURL(pageName) + ctx.Data["old_title"] = pageName + ctx.Data["Title"] = pageName + ctx.Data["title"] = pageName + ctx.Data["RequireHighlightJS"] = true - pager := context.NewPagination(int(commitsCount), git.CommitsRangeSize, page, 5) - pager.SetDefaultParams(ctx) - ctx.Data["Page"] = pager + //lookup filename in wiki - get filecontent, gitTree entry , real filename + data, entry, _, noEntry := wikiContentsByName(ctx, commit, pageName) + if noEntry { + ctx.Redirect(ctx.Repo.RepoLink + "/wiki/_pages") + } + if entry == nil || ctx.Written() { + return } - return wikiRepo, entry + ctx.Data["content"] = string(data) + ctx.Data["sidebarPresent"] = false + ctx.Data["sidebarContent"] = "" + ctx.Data["footerPresent"] = false + ctx.Data["footerContent"] = "" } // Wiki renders single wiki page @@ -246,7 +312,7 @@ func Wiki(ctx *context.Context) { return } - wikiRepo, entry := renderWikiPage(ctx, true, false) + wikiRepo, entry := renderViewPage(ctx) if ctx.Written() { return } @@ -283,7 +349,7 @@ func WikiRevision(ctx *context.Context) { return } - wikiRepo, entry := renderWikiPage(ctx, false, true) + wikiRepo, entry := renderRevisionPage(ctx) if ctx.Written() { return } @@ -457,7 +523,7 @@ func EditWiki(ctx *context.Context) { return } - renderWikiPage(ctx, false, false) + renderEditPage(ctx) if ctx.Written() { return }