From d44e1565dadd09b4cdbb924479bf6e59a4d3c403 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Sun, 23 Apr 2023 07:38:25 +0800 Subject: [PATCH] Refactor `setting.Other` and remove unused `SHOW_FOOTER_BRANDING` (#24270) The `SHOW_FOOTER_BRANDING` came from year 2015, and it seems nobody ever uses it. It only shows an GitHub icon which seems unrelated to Gitea, it doesn't do what document says. So, remove it. ## :warning: Breaking Users can now remove the key `[other].SHOW_FOOTER_BRANDING` from their app.ini. --- custom/conf/app.example.ini | 1 - .../config-cheat-sheet.en-us.md | 1 - .../config-cheat-sheet.zh-cn.md | 1 - modules/context/context.go | 3 +-- modules/context/repo.go | 4 ++-- modules/setting/other.go | 23 +++++++++++-------- modules/templates/base.go | 3 +-- modules/templates/helper.go | 2 +- routers/web/repo/view.go | 2 +- routers/web/web.go | 10 ++++---- templates/base/footer_content.tmpl | 3 --- 11 files changed, 25 insertions(+), 28 deletions(-) diff --git a/custom/conf/app.example.ini b/custom/conf/app.example.ini index f9f207522c7d..29ebb4699bc1 100644 --- a/custom/conf/app.example.ini +++ b/custom/conf/app.example.ini @@ -2340,7 +2340,6 @@ ROUTER = console ;[other] ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;SHOW_FOOTER_BRANDING = false ;; Show version information about Gitea and Go in the footer ;SHOW_FOOTER_VERSION = true ;; Show template execution time in the footer diff --git a/docs/content/doc/administration/config-cheat-sheet.en-us.md b/docs/content/doc/administration/config-cheat-sheet.en-us.md index f26e7eaa085a..772e0535e91e 100644 --- a/docs/content/doc/administration/config-cheat-sheet.en-us.md +++ b/docs/content/doc/administration/config-cheat-sheet.en-us.md @@ -1391,7 +1391,6 @@ although Github don't support this form. ## Other (`other`) -- `SHOW_FOOTER_BRANDING`: **false**: Show Gitea branding in the footer. - `SHOW_FOOTER_VERSION`: **true**: Show Gitea and Go version information in the footer. - `SHOW_FOOTER_TEMPLATE_LOAD_TIME`: **true**: Show time of template execution in the footer. - `ENABLE_SITEMAP`: **true**: Generate sitemap. diff --git a/docs/content/doc/administration/config-cheat-sheet.zh-cn.md b/docs/content/doc/administration/config-cheat-sheet.zh-cn.md index 83e212f32b84..485d10623469 100644 --- a/docs/content/doc/administration/config-cheat-sheet.zh-cn.md +++ b/docs/content/doc/administration/config-cheat-sheet.zh-cn.md @@ -483,5 +483,4 @@ PROXY_HOSTS = *.github.com ## Other (`other`) -- `SHOW_FOOTER_BRANDING`: 为真则在页面底部显示Gitea的字样。 - `SHOW_FOOTER_VERSION`: 为真则在页面底部显示Gitea的版本。 diff --git a/modules/context/context.go b/modules/context/context.go index 7e986b0119e2..f262c7cce7cb 100644 --- a/modules/context/context.go +++ b/modules/context/context.go @@ -741,8 +741,7 @@ func Contexter(ctx context.Context) func(next http.Handler) http.Handler { ctx.Data["ShowRegistrationButton"] = setting.Service.ShowRegistrationButton ctx.Data["ShowMilestonesDashboardPage"] = setting.Service.ShowMilestonesDashboardPage - ctx.Data["ShowFooterBranding"] = setting.ShowFooterBranding - ctx.Data["ShowFooterVersion"] = setting.ShowFooterVersion + ctx.Data["ShowFooterVersion"] = setting.Other.ShowFooterVersion ctx.Data["EnableSwagger"] = setting.API.EnableSwagger ctx.Data["EnableOpenIDSignIn"] = setting.Service.EnableOpenIDSignIn diff --git a/modules/context/repo.go b/modules/context/repo.go index 1736de2e4bad..6b811054c231 100644 --- a/modules/context/repo.go +++ b/modules/context/repo.go @@ -452,7 +452,7 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) { userName := ctx.Params(":username") repoName := ctx.Params(":reponame") repoName = strings.TrimSuffix(repoName, ".git") - if setting.EnableFeed { + if setting.Other.EnableFeed { repoName = strings.TrimSuffix(repoName, ".rss") repoName = strings.TrimSuffix(repoName, ".atom") } @@ -540,7 +540,7 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) { ctx.Data["RepoLink"] = ctx.Repo.RepoLink ctx.Data["RepoRelPath"] = ctx.Repo.Owner.Name + "/" + ctx.Repo.Repository.Name - if setting.EnableFeed { + if setting.Other.EnableFeed { ctx.Data["EnableFeed"] = true ctx.Data["FeedURL"] = ctx.Repo.RepoLink } diff --git a/modules/setting/other.go b/modules/setting/other.go index 4fba754a0848..706cb1e3d9b8 100644 --- a/modules/setting/other.go +++ b/modules/setting/other.go @@ -3,20 +3,25 @@ package setting -var ( - // Other settings - ShowFooterBranding bool +import "code.gitea.io/gitea/modules/log" + +type OtherConfig struct { ShowFooterVersion bool ShowFooterTemplateLoadTime bool EnableFeed bool EnableSitemap bool -) +} + +var Other = OtherConfig{ + ShowFooterVersion: true, + ShowFooterTemplateLoadTime: true, + EnableSitemap: true, + EnableFeed: true, +} func loadOtherFrom(rootCfg ConfigProvider) { sec := rootCfg.Section("other") - ShowFooterBranding = sec.Key("SHOW_FOOTER_BRANDING").MustBool(false) - ShowFooterVersion = sec.Key("SHOW_FOOTER_VERSION").MustBool(true) - ShowFooterTemplateLoadTime = sec.Key("SHOW_FOOTER_TEMPLATE_LOAD_TIME").MustBool(true) - EnableSitemap = sec.Key("ENABLE_SITEMAP").MustBool(true) - EnableFeed = sec.Key("ENABLE_FEED").MustBool(true) + if err := sec.MapTo(&Other); err != nil { + log.Fatal("Failed to map [other] settings: %v", err) + } } diff --git a/modules/templates/base.go b/modules/templates/base.go index e95ce31cfcab..4254a569764e 100644 --- a/modules/templates/base.go +++ b/modules/templates/base.go @@ -33,8 +33,7 @@ func BaseVars() Vars { "ShowRegistrationButton": setting.Service.ShowRegistrationButton, "ShowMilestonesDashboardPage": setting.Service.ShowMilestonesDashboardPage, - "ShowFooterBranding": setting.ShowFooterBranding, - "ShowFooterVersion": setting.ShowFooterVersion, + "ShowFooterVersion": setting.Other.ShowFooterVersion, "DisableDownloadSourceArchives": setting.Repository.DisableDownloadSourceArchives, "EnableSwagger": setting.API.EnableSwagger, diff --git a/modules/templates/helper.go b/modules/templates/helper.go index c5b77989be24..c82f88a42f2a 100644 --- a/modules/templates/helper.go +++ b/modules/templates/helper.go @@ -181,7 +181,7 @@ func NewFuncMap() []template.FuncMap { return setting.UI.DefaultShowFullName }, "ShowFooterTemplateLoadTime": func() bool { - return setting.ShowFooterTemplateLoadTime + return setting.Other.ShowFooterTemplateLoadTime }, "AllowedReactions": func() []string { return setting.UI.Reactions diff --git a/routers/web/repo/view.go b/routers/web/repo/view.go index 5a11073ba9a4..63e534fec0fb 100644 --- a/routers/web/repo/view.go +++ b/routers/web/repo/view.go @@ -695,7 +695,7 @@ func checkCitationFile(ctx *context.Context, entry *git.TreeEntry) { // Home render repository home page func Home(ctx *context.Context) { - if setting.EnableFeed { + if setting.Other.EnableFeed { isFeed, _, showFeedType := feed.GetFeedType(ctx.Params(":reponame"), ctx.Req) if isFeed { feed.ShowRepoFeed(ctx, ctx.Repo.Repository, showFeedType) diff --git a/routers/web/web.go b/routers/web/web.go index fc484eed4cb7..49ea63b191ec 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -293,7 +293,7 @@ func RegisterRoutes(m *web.Route) { } sitemapEnabled := func(ctx *context.Context) { - if !setting.EnableSitemap { + if !setting.Other.EnableSitemap { ctx.Error(http.StatusNotFound) return } @@ -307,7 +307,7 @@ func RegisterRoutes(m *web.Route) { } feedEnabled := func(ctx *context.Context) { - if !setting.EnableFeed { + if !setting.Other.EnableFeed { ctx.Error(http.StatusNotFound) return } @@ -706,7 +706,7 @@ func RegisterRoutes(m *web.Route) { default: context_service.UserAssignmentWeb()(ctx) if !ctx.Written() { - ctx.Data["EnableFeed"] = setting.EnableFeed + ctx.Data["EnableFeed"] = setting.Other.EnableFeed user.Profile(ctx) } } @@ -1205,7 +1205,7 @@ func RegisterRoutes(m *web.Route) { m.Get(".rss", feedEnabled, repo.TagsListFeedRSS) m.Get(".atom", feedEnabled, repo.TagsListFeedAtom) }, func(ctx *context.Context) { - ctx.Data["EnableFeed"] = setting.EnableFeed + ctx.Data["EnableFeed"] = setting.Other.EnableFeed }, repo.MustBeNotEmpty, reqRepoCodeReader, context.RepoRefByType(context.RepoRefTag, true)) m.Group("/releases", func() { m.Get("/", repo.Releases) @@ -1214,7 +1214,7 @@ func RegisterRoutes(m *web.Route) { m.Get(".rss", feedEnabled, repo.ReleasesFeedRSS) m.Get(".atom", feedEnabled, repo.ReleasesFeedAtom) }, func(ctx *context.Context) { - ctx.Data["EnableFeed"] = setting.EnableFeed + ctx.Data["EnableFeed"] = setting.Other.EnableFeed }, repo.MustBeNotEmpty, reqRepoReleaseReader, context.RepoRefByType(context.RepoRefTag, true)) m.Get("/releases/attachments/{uuid}", repo.GetAttachment, repo.MustBeNotEmpty, reqRepoReleaseReader) m.Group("/releases", func() { diff --git a/templates/base/footer_content.tmpl b/templates/base/footer_content.tmpl index f282083d65d6..17c75c687405 100644 --- a/templates/base/footer_content.tmpl +++ b/templates/base/footer_content.tmpl @@ -15,9 +15,6 @@ {{end}}