Skip to content

Commit 1206b6d

Browse files
committed
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: Polyfill SubmitEvent for PaleMoon (go-gitea#28441) Fix Chinese translation of config cheat sheet[API] (go-gitea#28472) Add combined index for issue_user.uid and issue_id (go-gitea#28080) Fix documents for "custom/public/assets/" (go-gitea#28465) Only use SHA256 feature when git >= 2.42 (go-gitea#28466)
2 parents feea278 + 6632d14 commit 1206b6d

File tree

22 files changed

+155
-33
lines changed

22 files changed

+155
-33
lines changed

docs/content/administration/adding-legal-pages.en-us.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ Some jurisdictions (such as EU), requires certain legal pages (e.g. Privacy Poli
1919

2020
## Getting Pages
2121

22-
Gitea source code ships with sample pages, available in `contrib/legal` directory. Copy them to `custom/public/`. For example, to add Privacy Policy:
22+
Gitea source code ships with sample pages, available in `contrib/legal` directory. Copy them to `custom/public/assets/`. For example, to add Privacy Policy:
2323

2424
```
25-
wget -O /path/to/custom/public/privacy.html https://raw.githubusercontent.com/go-gitea/gitea/main/contrib/legal/privacy.html.sample
25+
wget -O /path/to/custom/public/assets/privacy.html https://raw.githubusercontent.com/go-gitea/gitea/main/contrib/legal/privacy.html.sample
2626
```
2727

2828
Now you need to edit the page to meet your requirements. In particular you must change the email addresses, web addresses and references to "Your Gitea Instance" to match your situation.

docs/content/administration/adding-legal-pages.zh-cn.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ menu:
1919

2020
## 获取页面
2121

22-
Gitea 源代码附带了示例页面,位于 `contrib/legal` 目录中。将它们复制到 `custom/public/` 目录下。例如,如果要添加隐私政策:
22+
Gitea 源代码附带了示例页面,位于 `contrib/legal` 目录中。将它们复制到 `custom/public/assets/` 目录下。例如,如果要添加隐私政策:
2323

2424
```
25-
wget -O /path/to/custom/public/privacy.html https://raw.githubusercontent.com/go-gitea/gitea/main/contrib/legal/privacy.html.sample
25+
wget -O /path/to/custom/public/assets/privacy.html https://raw.githubusercontent.com/go-gitea/gitea/main/contrib/legal/privacy.html.sample
2626
```
2727

2828
现在,你需要编辑该页面以满足你的需求。特别是,你必须更改电子邮件地址、网址以及与 "Your Gitea Instance" 相关的引用,以匹配你的情况。

docs/content/administration/config-cheat-sheet.zh-cn.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,10 +1039,11 @@ Gitea 创建以下非唯一队列:
10391039

10401040
## API (`api`)
10411041

1042-
- `ENABLE_SWAGGER`: **true**: 是否启用swagger路由 (`/api/swagger`, `/api/v1/swagger`, …)。
1043-
- `MAX_RESPONSE_ITEMS`: **50**: 单个页面的最大 Feed.
1044-
- `ENABLE_OPENID_SIGNIN`: **false**: 允许使用OpenID登录,当设置为`true`时可以通过 `/user/login` 页面进行OpenID登录。
1045-
- `DISABLE_REGISTRATION`: **false**: 关闭用户注册。
1042+
- `ENABLE_SWAGGER`: **true**: 启用API文档接口 (`/api/swagger`, `/api/v1/swagger`, …). True or false。
1043+
- `MAX_RESPONSE_ITEMS`: **50**: API分页的最大单页项目数。
1044+
- `DEFAULT_PAGING_NUM`: **30**: API分页的默认分页数。
1045+
- `DEFAULT_GIT_TREES_PER_PAGE`: **1000**: Git trees API的默认单页项目数。
1046+
- `DEFAULT_MAX_BLOB_SIZE`: **10485760** (10MiB): blobs API的默认最大文件大小。
10461047

10471048
## OAuth2 (`oauth2`)
10481049

docs/content/administration/customizing-gitea.zh-cn.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ Gitea 引用 `custom` 目录中的自定义配置文件来覆盖配置、模板
4242

4343
将自定义的公共文件(比如页面和图片)作为 webroot 放在 `custom/public/` 中来让 Gitea 提供这些自定义内容(符号链接将被追踪)。
4444

45-
举例说明:`image.png` 存放在 `custom/public/`中,那么它可以通过链接 http://gitea.domain.tld/assets/image.png 访问。
45+
举例说明:`image.png` 存放在 `custom/public/assets/`中,那么它可以通过链接 http://gitea.domain.tld/assets/image.png 访问。
4646

4747
## 修改默认头像
4848

49-
替换以下目录中的 png 图片: `custom/public/img/avatar\_default.png`
49+
替换以下目录中的 png 图片: `custom/public/assets/img/avatar\_default.png`
5050

5151
## 自定义 Gitea 页面
5252

docs/content/administration/external-renderers.zh-cn.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ ALLOW_DATA_URI_IMAGES = true
194194
}
195195
```
196196

197-
将您的样式表添加到自定义目录中,例如 `custom/public/css/my-style-XXXXX.css`,并使用自定义的头文件 `custom/templates/custom/header.tmpl` 进行导入:
197+
将您的样式表添加到自定义目录中,例如 `custom/public/assets/css/my-style-XXXXX.css`,并使用自定义的头文件 `custom/templates/custom/header.tmpl` 进行导入:
198198

199199
```html
200200
<link rel="stylesheet" href="{{AppSubUrl}}/assets/css/my-style-XXXXX.css" />

docs/content/help/faq.zh-cn.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ Gitea 目前支持三个官方主题,分别是 `gitea-light`、`gitea-dark`
189189

190190
假设我们的主题是 `arc-blue`(这是一个真实的主题,可以在[此问题](https://github.com/go-gitea/gitea/issues/6011)中找到)
191191

192-
`.css`文件命名为`theme-arc-blue.css`并将其添加到`custom/public/css`文件夹中
192+
`.css`文件命名为`theme-arc-blue.css`并将其添加到`custom/public/assets/css`文件夹中
193193

194194
通过将`arc-blue`添加到`app.ini`中的`THEMES`列表中,允许用户使用该主题
195195

models/issues/issue_user.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import (
1414
// IssueUser represents an issue-user relation.
1515
type IssueUser struct {
1616
ID int64 `xorm:"pk autoincr"`
17-
UID int64 `xorm:"INDEX"` // User ID.
18-
IssueID int64 `xorm:"INDEX"`
17+
UID int64 `xorm:"INDEX unique(uid_to_issue)"` // User ID.
18+
IssueID int64 `xorm:"INDEX unique(uid_to_issue)"`
1919
IsRead bool
2020
IsMentioned bool
2121
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
-
2+
id: 1
3+
uid: 1
4+
issue_id: 1
5+
is_read: true
6+
is_mentioned: false
7+
8+
-
9+
id: 2
10+
uid: 2
11+
issue_id: 1
12+
is_read: true
13+
is_mentioned: false
14+
15+
-
16+
id: 3
17+
uid: 2
18+
issue_id: 1 # duplicated with id 2
19+
is_read: false
20+
is_mentioned: true

models/migrations/migrations.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,8 @@ var migrations = []Migration{
550550
NewMigration("Add auth_token table", v1_22.CreateAuthTokenTable),
551551
// v282 -> v283
552552
NewMigration("Add Index to pull_auto_merge.doer_id", v1_22.AddIndexToPullAutoMergeDoerID),
553+
// v283 -> v284
554+
NewMigration("Add combined Index to issue_user.uid and issue_id", v1_22.AddCombinedIndexToIssueUser),
553555
}
554556

555557
// GetCurrentDBVersion returns the current db version

models/migrations/v1_22/main_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2023 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package v1_22 //nolint
5+
6+
import (
7+
"testing"
8+
9+
"code.gitea.io/gitea/models/migrations/base"
10+
)
11+
12+
func TestMain(m *testing.M) {
13+
base.MainTest(m)
14+
}

models/migrations/v1_22/v283.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 2023 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package v1_22 //nolint
5+
6+
import (
7+
"xorm.io/xorm"
8+
)
9+
10+
func AddCombinedIndexToIssueUser(x *xorm.Engine) error {
11+
type OldIssueUser struct {
12+
IssueID int64
13+
UID int64
14+
Cnt int64
15+
}
16+
17+
var duplicatedIssueUsers []OldIssueUser
18+
if err := x.SQL("select * from (select issue_id, uid, count(1) as cnt from issue_user group by issue_id, uid) a where a.cnt > 1").
19+
Find(&duplicatedIssueUsers); err != nil {
20+
return err
21+
}
22+
for _, issueUser := range duplicatedIssueUsers {
23+
if _, err := x.Exec("delete from issue_user where id in (SELECT id FROM issue_user WHERE issue_id = ? and uid = ? limit ?)", issueUser.IssueID, issueUser.UID, issueUser.Cnt-1); err != nil {
24+
return err
25+
}
26+
}
27+
28+
type IssueUser struct {
29+
UID int64 `xorm:"INDEX unique(uid_to_issue)"` // User ID.
30+
IssueID int64 `xorm:"INDEX unique(uid_to_issue)"`
31+
}
32+
33+
return x.Sync(&IssueUser{})
34+
}

models/migrations/v1_22/v283_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2023 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package v1_22 //nolint
5+
6+
import (
7+
"testing"
8+
9+
"code.gitea.io/gitea/models/migrations/base"
10+
)
11+
12+
func Test_AddCombinedIndexToIssueUser(t *testing.T) {
13+
type IssueUser struct {
14+
UID int64 `xorm:"INDEX unique(uid_to_issue)"` // User ID.
15+
IssueID int64 `xorm:"INDEX unique(uid_to_issue)"`
16+
}
17+
18+
// Prepare and load the testing database
19+
x, deferable := base.PrepareTestEnv(t, 0, new(IssueUser))
20+
defer deferable()
21+
if x == nil || t.Failed() {
22+
return
23+
}
24+
25+
if err := AddCombinedIndexToIssueUser(x); err != nil {
26+
t.Fatal(err)
27+
}
28+
}

modules/git/git.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ var (
3333
// DefaultContext is the default context to run git commands in, must be initialized by git.InitXxx
3434
DefaultContext context.Context
3535

36-
// SupportProcReceive version >= 2.29.0
37-
SupportProcReceive bool
36+
SupportProcReceive bool // >= 2.29
37+
SupportHashSha256 bool // >= 2.42, SHA-256 repositories no longer an ‘experimental curiosity’
3838

3939
gitVersion *version.Version
4040
)
@@ -189,7 +189,7 @@ func InitFull(ctx context.Context) (err error) {
189189
globalCommandArgs = append(globalCommandArgs, "-c", "credential.helper=")
190190
}
191191
SupportProcReceive = CheckGitVersionAtLeast("2.29") == nil
192-
192+
SupportHashSha256 = CheckGitVersionAtLeast("2.42") == nil
193193
if setting.LFS.StartServer {
194194
if CheckGitVersionAtLeast("2.1.2") != nil {
195195
return errors.New("LFS server support requires Git >= 2.1.2")

modules/git/object_format.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ type ObjectFormat interface {
4040
NewHasher() HasherInterface
4141
}
4242

43-
/* SHA1 Type */
4443
type Sha1ObjectFormat struct{}
4544

4645
func (*Sha1ObjectFormat) ID() ObjectFormatID { return Sha1 }
@@ -83,7 +82,6 @@ func (h *Sha1ObjectFormat) NewHasher() HasherInterface {
8382
return &Sha1Hasher{sha1.New()}
8483
}
8584

86-
// utils
8785
func ObjectFormatFromID(id ObjectFormatID) ObjectFormat {
8886
switch id {
8987
case Sha1:

modules/git/object_id.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ type ObjectID interface {
2020
Type() ObjectFormat
2121
}
2222

23-
/* SHA1 */
2423
type Sha1Hash [20]byte
2524

2625
func (h *Sha1Hash) String() string {
@@ -38,7 +37,7 @@ func NewSha1() *Sha1Hash {
3837
return &Sha1Hash{}
3938
}
4039

41-
// generic implementations
40+
// NewHash is for generic implementations
4241
func NewHash(hash string) (ObjectID, error) {
4342
hash = strings.ToLower(hash)
4443
switch hash {
@@ -73,7 +72,6 @@ func genericIDFromString(h ObjectFormat, s string) (ObjectID, error) {
7372
return h.NewID(b)
7473
}
7574

76-
// utils
7775
func IDFromString(hexHash string) (ObjectID, error) {
7876
switch len(hexHash) {
7977
case 40:
@@ -101,7 +99,7 @@ func IsEmptyCommitID(commitID string) bool {
10199
return id.IsZero()
102100
}
103101

104-
// HashInterface is a struct that will generate a Hash
102+
// HasherInterface is a struct that will generate a Hash
105103
type HasherInterface interface {
106104
hash.Hash
107105

@@ -127,7 +125,7 @@ func ComputeHash(hashType ObjectFormat, t ObjectType, content []byte) ObjectID {
127125
return h.HashSum()
128126
}
129127

130-
// Sum generates a SHA1 for the provided hash
128+
// HashSum generates a SHA1 for the provided hash
131129
func (h *Sha1Hasher) HashSum() ObjectID {
132130
var sha1 Sha1Hash
133131
copy(sha1[:], h.Hash.Sum(nil))

modules/git/repo.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func IsRepoURLAccessible(ctx context.Context, url string) bool {
6363
return err == nil
6464
}
6565

66-
// GetObjectFormatOfRepo returns the hash type of a repository at a given path
66+
// GetObjectFormatOfRepo returns the hash type of repository at a given path
6767
func GetObjectFormatOfRepo(ctx context.Context, repoPath string) (ObjectFormat, error) {
6868
var stdout, stderr strings.Builder
6969

@@ -96,7 +96,10 @@ func InitRepository(ctx context.Context, repoPath string, bare bool, objectForma
9696
return err
9797
}
9898

99-
cmd := NewCommand(ctx, "init", "--object-format").AddDynamicArguments(objectFormat.String())
99+
cmd := NewCommand(ctx, "init")
100+
if SupportHashSha256 {
101+
cmd.AddOptionValues("--object-format", objectFormat.String())
102+
}
100103
if bare {
101104
cmd.AddArguments("--bare")
102105
}

web_src/js/features/common-global.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {initCompColorPicker} from './comp/ColorPicker.js';
66
import {showGlobalErrorMessage} from '../bootstrap.js';
77
import {handleGlobalEnterQuickSubmit} from './comp/QuickSubmit.js';
88
import {svg} from '../svg.js';
9-
import {hideElem, showElem, toggleElem} from '../utils/dom.js';
9+
import {hideElem, showElem, toggleElem, initSubmitEventPolyfill, submitEventSubmitter} from '../utils/dom.js';
1010
import {htmlEscape} from 'escape-goat';
1111
import {showTemporaryTooltip} from '../modules/tippy.js';
1212
import {confirmModal} from './comp/ConfirmModal.js';
@@ -121,7 +121,8 @@ async function formFetchAction(e) {
121121
const formMethod = formEl.getAttribute('method') || 'get';
122122
const formActionUrl = formEl.getAttribute('action');
123123
const formData = new FormData(formEl);
124-
const [submitterName, submitterValue] = [e.submitter?.getAttribute('name'), e.submitter?.getAttribute('value')];
124+
const formSubmitter = submitEventSubmitter(e);
125+
const [submitterName, submitterValue] = [formSubmitter?.getAttribute('name'), formSubmitter?.getAttribute('value')];
125126
if (submitterName) {
126127
formData.append(submitterName, submitterValue || '');
127128
}
@@ -192,6 +193,7 @@ export function initGlobalCommon() {
192193

193194
$('.tabular.menu .item').tab();
194195

196+
initSubmitEventPolyfill();
195197
document.addEventListener('submit', formFetchAction);
196198
document.addEventListener('click', linkAction);
197199
}

web_src/js/features/common-issue-list.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import $ from 'jquery';
2-
import {isElemHidden, onInputDebounce, toggleElem} from '../utils/dom.js';
2+
import {isElemHidden, onInputDebounce, submitEventSubmitter, toggleElem} from '../utils/dom.js';
33
import {GET} from '../modules/fetch.js';
44

55
const {appSubUrl} = window.config;
@@ -40,7 +40,7 @@ export function initCommonIssueListQuickGoto() {
4040
$form.on('submit', (e) => {
4141
// if there is no goto button, or the form is submitted by non-quick-goto elements, submit the form directly
4242
let doQuickGoto = !isElemHidden($goto);
43-
const submitter = e.originalEvent.submitter;
43+
const submitter = submitEventSubmitter(e.originalEvent);
4444
if (submitter !== $form[0] && submitter !== $input[0] && submitter !== $goto[0]) doQuickGoto = false;
4545
if (!doQuickGoto) return;
4646

web_src/js/features/repo-diff.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {validateTextareaNonEmpty} from './comp/ComboMarkdownEditor.js';
77
import {initViewedCheckboxListenerFor, countAndUpdateViewedFiles, initExpandAndCollapseFilesButton} from './pull-view-file.js';
88
import {initImageDiff} from './imagediff.js';
99
import {showErrorToast} from '../modules/toast.js';
10+
import {submitEventSubmitter} from '../utils/dom.js';
1011

1112
const {csrfToken, pageData, i18n} = window.config;
1213

@@ -57,7 +58,7 @@ function initRepoDiffConversationForm() {
5758
const formData = new FormData($form[0]);
5859

5960
// if the form is submitted by a button, append the button's name and value to the form data
60-
const submitter = e.originalEvent?.submitter;
61+
const submitter = submitEventSubmitter(e.originalEvent);
6162
const isSubmittedByButton = (submitter?.nodeName === 'BUTTON') || (submitter?.nodeName === 'INPUT' && submitter.type === 'submit');
6263
if (isSubmittedByButton && submitter.name) {
6364
formData.append(submitter.name, submitter.value);

web_src/js/modules/tippy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ function switchTitleToTooltip(target) {
106106
/**
107107
* Creating tooltip tippy instance is expensive, so we only create it when the user hovers over the element
108108
* According to https://www.w3.org/TR/DOM-Level-3-Events/#events-mouseevent-event-order , mouseover event is fired before mouseenter event
109-
* Some old browsers like Pale Moon doesn't support "mouseenter(capture)"
109+
* Some browsers like PaleMoon don't support "addEventListener('mouseenter', capture)"
110110
* The tippy by default uses "mouseenter" event to show, so we use "mouseover" event to switch to tippy
111111
* @param e {Event}
112112
*/

web_src/js/utils/dom.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,3 +194,24 @@ export function loadElem(el, src) {
194194
el.src = src;
195195
});
196196
}
197+
198+
// some browsers like PaleMoon don't have "SubmitEvent" support, so polyfill it by a tricky method: use the last clicked button as submitter
199+
// it can't use other transparent polyfill patches because PaleMoon also doesn't support "addEventListener(capture)"
200+
const needSubmitEventPolyfill = typeof SubmitEvent === 'undefined';
201+
202+
export function submitEventSubmitter(e) {
203+
return needSubmitEventPolyfill ? (e.target._submitter || null) : e.submitter;
204+
}
205+
206+
function submitEventPolyfillListener(e) {
207+
const form = e.target.closest('form');
208+
if (!form) return;
209+
form._submitter = e.target.closest('button:not([type]), button[type="submit"], input[type="submit"]');
210+
}
211+
212+
export function initSubmitEventPolyfill() {
213+
if (!needSubmitEventPolyfill) return;
214+
console.warn(`This browser doesn't have "SubmitEvent" support, use a tricky method to polyfill`);
215+
document.body.addEventListener('click', submitEventPolyfillListener);
216+
document.body.addEventListener('focus', submitEventPolyfillListener);
217+
}

web_src/js/webcomponents/webcomponents.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import '@webcomponents/custom-elements'; // polyfill for some browsers like Pale Moon
1+
import '@webcomponents/custom-elements'; // polyfill for some browsers like PaleMoon
22
import './polyfill.js';
33

44
import '@github/relative-time-element';

0 commit comments

Comments
 (0)