From 022f0170acc3bf78d5322ffb433df9e611374be9 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Wed, 26 Oct 2022 12:33:39 +0800 Subject: [PATCH 1/5] fix lang --- docs/content/doc/installation/with-docker.en-us.md | 7 +++++++ modules/web/middleware/locale.go | 11 ++++++++++- routers/install/install.go | 2 +- web_src/js/features/common-global.js | 7 +++++-- 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/docs/content/doc/installation/with-docker.en-us.md b/docs/content/doc/installation/with-docker.en-us.md index 895f04804e2bc..1e4656ab69d9f 100644 --- a/docs/content/doc/installation/with-docker.en-us.md +++ b/docs/content/doc/installation/with-docker.en-us.md @@ -98,6 +98,13 @@ services: ## Databases +### SQLite3 database + +Use the above "basic" docker-compose config, set "Database Type" to SQLite3 on the installation page. + +SQLite3 is only suitable for small instance and for only a few users. +It's recommended to use other database servers for production instances. + ### MySQL database To start Gitea in combination with a MySQL database, apply these changes to the diff --git a/modules/web/middleware/locale.go b/modules/web/middleware/locale.go index f4018527c0295..89fa69b9e3f54 100644 --- a/modules/web/middleware/locale.go +++ b/modules/web/middleware/locale.go @@ -19,6 +19,7 @@ func Locale(resp http.ResponseWriter, req *http.Request) translation.Locale { // 1. Check URL arguments. lang := req.URL.Query().Get("lang") changeLang := lang != "" + skipHandler := req.URL.Query().Get("lang_skip_handler") != "" // 2. Get language information from cookies. if len(lang) == 0 { @@ -46,7 +47,15 @@ func Locale(resp http.ResponseWriter, req *http.Request) translation.Locale { SetLocaleCookie(resp, lang, 1<<31-1) } - return translation.NewLocale(lang) + err := translation.NewLocale(lang) + if err != nil { + return err + } + + if skipHandler { + resp.WriteHeader(http.StatusNoContent) + } + return nil } // SetLocaleCookie convenience function to set the locale cookie consistently diff --git a/routers/install/install.go b/routers/install/install.go index 962dee8c8609a..4f5b00a31cac2 100644 --- a/routers/install/install.go +++ b/routers/install/install.go @@ -113,7 +113,7 @@ func Install(ctx *context.Context) { } } if !isCurDBTypeSupported { - curDBType = "mysql" + curDBType = setting.SupportedDatabaseTypes[0] } ctx.Data["CurDbType"] = curDBType diff --git a/web_src/js/features/common-global.js b/web_src/js/features/common-global.js index a3aebc024625c..63c274a1b5e83 100644 --- a/web_src/js/features/common-global.js +++ b/web_src/js/features/common-global.js @@ -36,8 +36,11 @@ export function initHeadNavbarContentToggle() { export function initFootLanguageMenu() { function linkLanguageAction() { - const $this = $(this); - $.post($this.data('url')).always(() => { + let changeLangUrl = $(this).attr('data-url'); + changeLangUrl += changeLangUrl.includes('?') ? '&' : '?'; + // Only use "lang_skip_handler" for ajax. Page links should not have this parameter because crawlers need to get the full page + changeLangUrl += 'lang_skip_handler=1'; + $.get(changeLangUrl).always(() => { window.location.reload(); }); } From b870ac1f8ba6347fe241186e66db89f2970be734 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Thu, 27 Oct 2022 11:10:15 +0800 Subject: [PATCH 2/5] Update docs/content/doc/installation/with-docker.en-us.md Co-authored-by: delvh --- docs/content/doc/installation/with-docker.en-us.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/content/doc/installation/with-docker.en-us.md b/docs/content/doc/installation/with-docker.en-us.md index 1e4656ab69d9f..9d9992f649bf5 100644 --- a/docs/content/doc/installation/with-docker.en-us.md +++ b/docs/content/doc/installation/with-docker.en-us.md @@ -102,7 +102,7 @@ services: Use the above "basic" docker-compose config, set "Database Type" to SQLite3 on the installation page. -SQLite3 is only suitable for small instance and for only a few users. +SQLite3 is only suitable for small instances with few users. It's recommended to use other database servers for production instances. ### MySQL database From 516c140293d969d7172f4d945b13c90ee0346cbd Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Sun, 30 Oct 2022 16:06:07 +0800 Subject: [PATCH 3/5] Update modules/web/middleware/locale.go --- modules/web/middleware/locale.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/web/middleware/locale.go b/modules/web/middleware/locale.go index 89fa69b9e3f54..837a05297c496 100644 --- a/modules/web/middleware/locale.go +++ b/modules/web/middleware/locale.go @@ -19,6 +19,8 @@ func Locale(resp http.ResponseWriter, req *http.Request) translation.Locale { // 1. Check URL arguments. lang := req.URL.Query().Get("lang") changeLang := lang != "" + // If the request is sent from language menu by AJAX, then it should only set the language but not run the real handler. + // Otherwise the irrelevant code might be executed. skipHandler := req.URL.Query().Get("lang_skip_handler") != "" // 2. Get language information from cookies. From 495f6847bec54a0447595bd3f18628eae4283568 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Tue, 8 Nov 2022 11:27:30 +0800 Subject: [PATCH 4/5] simplify code, only use GET instead of POST and still call the real handler --- modules/web/middleware/locale.go | 13 +------------ web_src/js/features/common-global.js | 7 ++----- 2 files changed, 3 insertions(+), 17 deletions(-) diff --git a/modules/web/middleware/locale.go b/modules/web/middleware/locale.go index 837a05297c496..f4018527c0295 100644 --- a/modules/web/middleware/locale.go +++ b/modules/web/middleware/locale.go @@ -19,9 +19,6 @@ func Locale(resp http.ResponseWriter, req *http.Request) translation.Locale { // 1. Check URL arguments. lang := req.URL.Query().Get("lang") changeLang := lang != "" - // If the request is sent from language menu by AJAX, then it should only set the language but not run the real handler. - // Otherwise the irrelevant code might be executed. - skipHandler := req.URL.Query().Get("lang_skip_handler") != "" // 2. Get language information from cookies. if len(lang) == 0 { @@ -49,15 +46,7 @@ func Locale(resp http.ResponseWriter, req *http.Request) translation.Locale { SetLocaleCookie(resp, lang, 1<<31-1) } - err := translation.NewLocale(lang) - if err != nil { - return err - } - - if skipHandler { - resp.WriteHeader(http.StatusNoContent) - } - return nil + return translation.NewLocale(lang) } // SetLocaleCookie convenience function to set the locale cookie consistently diff --git a/web_src/js/features/common-global.js b/web_src/js/features/common-global.js index 63c274a1b5e83..b00b4aea9c075 100644 --- a/web_src/js/features/common-global.js +++ b/web_src/js/features/common-global.js @@ -36,11 +36,8 @@ export function initHeadNavbarContentToggle() { export function initFootLanguageMenu() { function linkLanguageAction() { - let changeLangUrl = $(this).attr('data-url'); - changeLangUrl += changeLangUrl.includes('?') ? '&' : '?'; - // Only use "lang_skip_handler" for ajax. Page links should not have this parameter because crawlers need to get the full page - changeLangUrl += 'lang_skip_handler=1'; - $.get(changeLangUrl).always(() => { + const $this = $(this); + $.get($this.data('url')).always(() => { window.location.reload(); }); } From 663bf33902e25ab7c513148197f4c091f0bbb8b1 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Tue, 8 Nov 2022 11:28:42 +0800 Subject: [PATCH 5/5] reset --- docs/content/doc/installation/with-docker.en-us.md | 7 ------- routers/install/install.go | 2 +- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/docs/content/doc/installation/with-docker.en-us.md b/docs/content/doc/installation/with-docker.en-us.md index 9d9992f649bf5..895f04804e2bc 100644 --- a/docs/content/doc/installation/with-docker.en-us.md +++ b/docs/content/doc/installation/with-docker.en-us.md @@ -98,13 +98,6 @@ services: ## Databases -### SQLite3 database - -Use the above "basic" docker-compose config, set "Database Type" to SQLite3 on the installation page. - -SQLite3 is only suitable for small instances with few users. -It's recommended to use other database servers for production instances. - ### MySQL database To start Gitea in combination with a MySQL database, apply these changes to the diff --git a/routers/install/install.go b/routers/install/install.go index 4f5b00a31cac2..962dee8c8609a 100644 --- a/routers/install/install.go +++ b/routers/install/install.go @@ -113,7 +113,7 @@ func Install(ctx *context.Context) { } } if !isCurDBTypeSupported { - curDBType = setting.SupportedDatabaseTypes[0] + curDBType = "mysql" } ctx.Data["CurDbType"] = curDBType