Browse Source

Code clean up for new config options

Unknwon 3 years ago
parent
commit
15845cb287

+ 1 - 1
cmd/web.go

@@ -510,7 +510,7 @@ func runWeb(ctx *cli.Context) error {
510 510
 			m.Post("/branches", bindIgnErr(auth.NewBranchForm{}), repo.NewBranchPost)
511 511
 			m.Post("/upload-file", repo.UploadFileToServer)
512 512
 			m.Post("/upload-remove", bindIgnErr(auth.RemoveUploadFileForm{}), repo.RemoveUploadFileFromServer)
513
-		}, context.RepoRef(), context.RepoAssignment(), reqRepoWriter)
513
+		}, reqRepoWriter, context.RepoRef())
514 514
 	}, reqSignIn, context.RepoAssignment(), repo.MustBeNotBare)
515 515
 
516 516
 	m.Group("/:username/:reponame", func() {

+ 5 - 5
conf/app.ini

@@ -20,17 +20,17 @@ MAX_CREATION_LIMIT = -1
20 20
 ; Patch test queue length, make it as large as possible
21 21
 PULL_REQUEST_QUEUE_LENGTH = 10000
22 22
 
23
-[editor]
23
+[repository.editor]
24 24
 ; List of file extensions that should have line wraps in the CodeMirror editor
25 25
 ; Separate extensions with a comma. To line wrap files w/o extension, just put a comma
26 26
 LINE_WRAP_EXTENSIONS = .txt,.md,.markdown,.mdown,.mkd,
27 27
 ; Valid file modes that have a preview API associated with them, such as api/v1/markdown
28 28
 ; Separate values by commas. Preview tab in edit mode won't show if the file extension doesn't match
29
-PREVIEW_TAB_APIS = markdown
29
+PREVIEWABLE_FILE_MODES = markdown
30 30
 
31
-[upload]
31
+[repository.upload]
32 32
 ; Whether repository file uploads are enabled. Defaults to `true`
33
-ENABLE_UPLOADS = true
33
+ENABLED = true
34 34
 ; Path for uploads. Defaults to `data/tmp/uploads` (tmp gets deleted on gogs restart)
35 35
 TEMP_PATH = data/tmp/uploads
36 36
 ; One or more allowed types, e.g. image/jpeg|image/png. Nothing means any file type
@@ -76,7 +76,7 @@ ENABLE_HARD_LINE_BREAK = false
76 76
 CUSTOM_URL_SCHEMES =
77 77
 ; List of file extensions that should be rendered/edited as Markdown
78 78
 ; Separate extensions with a comma. To render files w/o extension as markdown, just put a comma
79
-MD_FILE_EXTENSIONS = .md,.markdown,.mdown,.mkd
79
+FILE_EXTENSIONS = .md,.markdown,.mdown,.mkd
80 80
 
81 81
 [server]
82 82
 PROTOCOL = http

+ 2 - 2
models/error.go

@@ -427,7 +427,7 @@ func IsErrRepoFileAlreadyExist(err error) bool {
427 427
 }
428 428
 
429 429
 func (err ErrRepoFileAlreadyExist) Error() string {
430
-	return fmt.Sprintf("repository file already exists [file name: %s]", err.FileName)
430
+	return fmt.Sprintf("repository file already exists [file_name: %s]", err.FileName)
431 431
 }
432 432
 
433 433
 // __________                             .__
@@ -663,5 +663,5 @@ func IsErrUploadNotExist(err error) bool {
663 663
 }
664 664
 
665 665
 func (err ErrUploadNotExist) Error() string {
666
-	return fmt.Sprintf("attachment does not exist [id: %d, uuid: %s]", err.ID, err.UUID)
666
+	return fmt.Sprintf("attachment does not exist [id: %d, uuid: %s, user_id: %d, repo_id: %d]", err.ID, err.UUID, err.UserID, err.RepoID)
667 667
 }

+ 2 - 2
models/issue.go

@@ -645,12 +645,12 @@ func newIssue(e *xorm.Session, repo *Repository, issue *Issue, labelIDs []int64,
645 645
 			if IsErrAttachmentNotExist(err) {
646 646
 				continue
647 647
 			}
648
-			return fmt.Errorf("getAttachmentByUUID[%s]: %v", uuid, err)
648
+			return fmt.Errorf("getAttachmentByUUID [%s]: %v", uuid, err)
649 649
 		}
650 650
 		attachment.IssueID = issue.ID
651 651
 		// No assign value could be 0, so ignore AllCols().
652 652
 		if _, err = e.Id(attachment.ID).Update(attachment); err != nil {
653
-			return fmt.Errorf("update attachment[%d]: %v", attachment.ID, err)
653
+			return fmt.Errorf("update attachment [%d]: %v", attachment.ID, err)
654 654
 		}
655 655
 	}
656 656
 

+ 1 - 1
models/repo.go

@@ -2557,7 +2557,7 @@ func (u *Upload) AfterSet(colName string, _ xorm.Cell) {
2557 2557
 
2558 2558
 // UploadLocalPath returns where uploads is stored in local file system based on given UUID.
2559 2559
 func UploadLocalPath(uuid string) string {
2560
-	return path.Join(setting.UploadTempPath, uuid[0:1], uuid[1:2], uuid)
2560
+	return path.Join(setting.Repository.Upload.TempPath, uuid[0:1], uuid[1:2], uuid)
2561 2561
 }
2562 2562
 
2563 2563
 // LocalPath returns where uploads are temporarily stored in local file system.

+ 1 - 1
models/ssh_key_test.go

@@ -29,7 +29,7 @@ func Test_SSHParsePublicKey(t *testing.T) {
29 29
 		"rsa-2048":  {"rsa", 2048, "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDMZXh+1OBUwSH9D45wTaxErQIN9IoC9xl7MKJkqvTvv6O5RR9YW/IK9FbfjXgXsppYGhsCZo1hFOOsXHMnfOORqu/xMDx4yPuyvKpw4LePEcg4TDipaDFuxbWOqc/BUZRZcXu41QAWfDLrInwsltWZHSeG7hjhpacl4FrVv9V1pS6Oc5Q1NxxEzTzuNLS/8diZrTm/YAQQ/+B+mzWI3zEtF4miZjjAljWd1LTBPvU23d29DcBmmFahcZ441XZsTeAwGxG/Q6j8NgNXj9WxMeWwxXV2jeAX/EBSpZrCVlCQ1yJswT6xCp8TuBnTiGWYMBNTbOZvPC4e0WI2/yZW/s5F nocomment"},
30 30
 		"ecdsa-256": {"ecdsa", 256, "ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBFQacN3PrOll7PXmN5B/ZNVahiUIqI05nbBlZk1KXsO3d06ktAWqbNflv2vEmA38bTFTfJ2sbn2B5ksT52cDDbA= nocomment"},
31 31
 		"ecdsa-384": {"ecdsa", 384, "ecdsa-sha2-nistp384 AAAAE2VjZHNhLXNoYTItbmlzdHAzODQAAAAIbmlzdHAzODQAAABhBINmioV+XRX1Fm9Qk2ehHXJ2tfVxW30ypUWZw670Zyq5GQfBAH6xjygRsJ5wWsHXBsGYgFUXIHvMKVAG1tpw7s6ax9oA+dJOJ7tj+vhn8joFqT+sg3LYHgZkHrfqryRasQ== nocomment"},
32
-		"ecdsa-521": {"ecdsa", 521, "ecdsa-sha2-nistp521 AAAAE2VjZHNhLXNoYTItbmlzdHA1MjEAAAAIbmlzdHA1MjEAAACFBACGt3UG3EzRwNOI17QR84l6PgiAcvCE7v6aXPj/SC6UWKg4EL8vW9ZBcdYL9wzs4FZXh4MOV8jAzu3KRWNTwb4k2wFNUpGOt7l28MztFFEtH5BDDrtAJSPENPy8pvPLMfnPg5NhvWycqIBzNcHipem5wSJFN5PdpNOC2xMrPWKNqj+ZjQ== nocomment"},
32
+		// "ecdsa-521": {"ecdsa", 521, "ecdsa-sha2-nistp521 AAAAE2VjZHNhLXNoYTItbmlzdHA1MjEAAAAIbmlzdHA1MjEAAACFBACGt3UG3EzRwNOI17QR84l6PgiAcvCE7v6aXPj/SC6UWKg4EL8vW9ZBcdYL9wzs4FZXh4MOV8jAzu3KRWNTwb4k2wFNUpGOt7l28MztFFEtH5BDDrtAJSPENPy8pvPLMfnPg5NhvWycqIBzNcHipem5wSJFN5PdpNOC2xMrPWKNqj+ZjQ== nocomment"},
33 33
 	}
34 34
 
35 35
 	Convey("Parse public keys in both native and ssh-keygen", t, func() {

+ 14 - 10
models/update.go

@@ -47,6 +47,19 @@ func DeleteUpdateTaskByUUID(uuid string) error {
47 47
 	return err
48 48
 }
49 49
 
50
+// CommitToPushCommit transforms a git.Commit to PushCommit type.
51
+func CommitToPushCommit(commit *git.Commit) *PushCommit {
52
+	return &PushCommit{
53
+		Sha1:           commit.ID.String(),
54
+		Message:        commit.Message(),
55
+		AuthorEmail:    commit.Author.Email,
56
+		AuthorName:     commit.Author.Name,
57
+		CommitterEmail: commit.Committer.Email,
58
+		CommitterName:  commit.Committer.Name,
59
+		Timestamp:      commit.Author.When,
60
+	}
61
+}
62
+
50 63
 func ListToPushCommits(l *list.List) *PushCommits {
51 64
 	commits := make([]*PushCommit, 0)
52 65
 	var actEmail string
@@ -55,16 +68,7 @@ func ListToPushCommits(l *list.List) *PushCommits {
55 68
 		if actEmail == "" {
56 69
 			actEmail = commit.Committer.Email
57 70
 		}
58
-		commits = append(commits,
59
-			&PushCommit{
60
-				Sha1:           commit.ID.String(),
61
-				Message:        commit.Message(),
62
-				AuthorEmail:    commit.Author.Email,
63
-				AuthorName:     commit.Author.Name,
64
-				CommitterEmail: commit.Committer.Email,
65
-				CommitterName:  commit.Committer.Name,
66
-				Timestamp:      commit.Author.When,
67
-			})
71
+		commits = append(commits, CommitToPushCommit(commit))
68 72
 	}
69 73
 	return &PushCommits{l.Len(), commits, "", nil}
70 74
 }

File diff suppressed because it is too large
+ 2 - 2
modules/bindata/bindata.go


+ 1 - 1
modules/markdown/markdown.go

@@ -54,7 +54,7 @@ func isLink(link []byte) bool {
54 54
 // based on its extension.
55 55
 func IsMarkdownFile(name string) bool {
56 56
 	extension := strings.ToLower(filepath.Ext(name))
57
-	for _, ext := range setting.Markdown.MdFileExtensions {
57
+	for _, ext := range setting.Markdown.FileExtensions {
58 58
 		if strings.ToLower(ext) == extension {
59 59
 			return true
60 60
 		}

+ 23 - 29
modules/setting/setting.go

@@ -114,16 +114,25 @@ var (
114 114
 		ForcePrivate           bool
115 115
 		MaxCreationLimit       int
116 116
 		PullRequestQueueLength int
117
+
118
+		// Repository editor settings
119
+		Editor struct {
120
+			LineWrapExtensions   []string
121
+			PreviewableFileModes []string
122
+		} `ini:"-"`
123
+
124
+		// Repository upload settings
125
+		Upload struct {
126
+			Enabled      bool
127
+			TempPath     string
128
+			AllowedTypes []string `delim:"|"`
129
+			FileMaxSize  int64
130
+			MaxFiles     int
131
+		} `ini:"-"`
117 132
 	}
118 133
 	RepoRootPath string
119 134
 	ScriptType   string
120 135
 
121
-	// Repo editor settings
122
-	Editor struct {
123
-		LineWrapExtensions     []string
124
-		PreviewTabApis         []string
125
-	}
126
-
127 136
 	// UI settings
128 137
 	UI struct {
129 138
 		ExplorePagingNum   int
@@ -147,7 +156,7 @@ var (
147 156
 	Markdown struct {
148 157
 		EnableHardLineBreak bool
149 158
 		CustomURLSchemes    []string `ini:"CUSTOM_URL_SCHEMES"`
150
-		MdFileExtensions    []string
159
+		FileExtensions      []string
151 160
 	}
152 161
 
153 162
 	// Picture settings
@@ -169,13 +178,6 @@ var (
169 178
 	AttachmentMaxFiles     int
170 179
 	AttachmentEnabled      bool
171 180
 
172
-	// Repo Upload settings
173
-	UploadTempPath         string
174
-	UploadAllowedTypes 	string
175
-	UploadMaxSize      	int64
176
-	UploadMaxFiles     	int
177
-	UploadEnabled      	bool
178
-
179 181
 	// Time settings
180 182
 	TimeFormat string
181 183
 
@@ -494,17 +496,15 @@ func NewContext() {
494 496
 	ScriptType = sec.Key("SCRIPT_TYPE").MustString("bash")
495 497
 	if err = Cfg.Section("repository").MapTo(&Repository); err != nil {
496 498
 		log.Fatal(4, "Fail to map Repository settings: %v", err)
499
+	} else if err = Cfg.Section("repository.editor").MapTo(&Repository.Editor); err != nil {
500
+		log.Fatal(4, "Fail to map Repository.Editor settings: %v", err)
501
+	} else if err = Cfg.Section("repository.upload").MapTo(&Repository.Upload); err != nil {
502
+		log.Fatal(4, "Fail to map Repository.Upload settings: %v", err)
497 503
 	}
498 504
 
499
-	sec = Cfg.Section("upload")
500
-	UploadTempPath = sec.Key("UPLOAD_TEMP_PATH").MustString(path.Join(AppDataPath, "tmp/uploads"))
501
-	if !filepath.IsAbs(UploadTempPath) {
502
-		UploadTempPath = path.Join(workDir, UploadTempPath)
505
+	if !filepath.IsAbs(Repository.Upload.TempPath) {
506
+		Repository.Upload.TempPath = path.Join(workDir, Repository.Upload.TempPath)
503 507
 	}
504
-	UploadAllowedTypes = strings.Replace(sec.Key("UPLOAD_ALLOWED_TYPES").MustString(""), "|", ",", -1)
505
-	UploadMaxSize = sec.Key("UPLOAD_FILE_MAX_SIZE").MustInt64(32)
506
-	UploadMaxFiles = sec.Key("UPLOAD_MAX_FILES").MustInt(10)
507
-	UploadEnabled = sec.Key("ENABLE_UPLOADS").MustBool(true)
508 508
 
509 509
 	sec = Cfg.Section("picture")
510 510
 	AvatarUploadPath = sec.Key("AVATAR_UPLOAD_PATH").MustString(path.Join(AppDataPath, "avatars"))
@@ -553,11 +553,9 @@ func NewContext() {
553 553
 	} else if err = Cfg.Section("git").MapTo(&Git); err != nil {
554 554
 		log.Fatal(4, "Fail to map Git settings: %v", err)
555 555
 	} else if err = Cfg.Section("mirror").MapTo(&Mirror); err != nil {
556
-		log.Fatal(4, "Fail to map API settings: %v", err)
556
+		log.Fatal(4, "Fail to map Mirror settings: %v", err)
557 557
 	} else if err = Cfg.Section("api").MapTo(&API); err != nil {
558 558
 		log.Fatal(4, "Fail to map API settings: %v", err)
559
-	} else if err = Cfg.Section("editor").MapTo(&Editor); err != nil {
560
-		log.Fatal(4, "Fail to map Editor settings: %v", err)
561 559
 	}
562 560
 
563 561
 	if Mirror.DefaultInterval <= 0 {
@@ -572,10 +570,6 @@ func NewContext() {
572 570
 	ShowFooterVersion = Cfg.Section("other").Key("SHOW_FOOTER_VERSION").MustBool()
573 571
 
574 572
 	HasRobotsTxt = com.IsFile(path.Join(CustomPath, "robots.txt"))
575
-
576
-	Markdown.MdFileExtensions = Cfg.Section("markdown").Key("MD_FILE_EXTENSIONS").Strings(",")
577
-	Editor.LineWrapExtensions = Cfg.Section("editor").Key("LINE_WRAP_EXTENSIONS").Strings(",")
578
-	Editor.PreviewTabApis = Cfg.Section("editor").Key("PREVIEW_TAB_APIS").Strings(",")
579 573
 }
580 574
 
581 575
 var Service struct {

+ 6 - 6
public/js/gogs.js

@@ -29,7 +29,7 @@ function initCommentPreviewTab($form) {
29 29
 }
30 30
 
31 31
 var previewTab;
32
-var previewTabApis;
32
+var previewFileModes;
33 33
 
34 34
 function initEditPreviewTab($form) {
35 35
     var $tab_menu = $form.find('.tabular.menu');
@@ -37,7 +37,7 @@ function initEditPreviewTab($form) {
37 37
     previewTab = $tab_menu.find('.item[data-tab="' + $tab_menu.data('preview') + '"]');
38 38
 
39 39
     if (previewTab.length) {
40
-        previewTabApis = previewTab.data('preview-apis').split(',');
40
+        previewFileModes = previewTab.data('preview-file-modes').split(',');
41 41
         previewTab.click(function () {
42 42
             var $this = $(this);
43 43
             $.post($this.data('url'), {
@@ -662,7 +662,7 @@ var editArea;
662 662
 var editFilename;
663 663
 var smdEditor;
664 664
 var cmEditor;
665
-var mdFileExtensions;
665
+var markdownFileExts;
666 666
 var lineWrapExtensions;
667 667
 
668 668
 // For IE
@@ -740,7 +740,7 @@ function initEditor() {
740 740
     if (!editArea.length)
741 741
         return;
742 742
 
743
-    mdFileExtensions = editArea.data("md-file-extensions").split(",");
743
+    markdownFileExts = editArea.data("markdown-file-exts").split(",");
744 744
     lineWrapExtensions = editArea.data("line-wrap-extensions").split(",");
745 745
 
746 746
     editFilename.on("keyup", function (e) {
@@ -762,7 +762,7 @@ function initEditor() {
762 762
             apiCall = extension
763 763
         }
764 764
 
765
-        if (previewLink.length && apiCall && previewTabApis && previewTabApis.length && previewTabApis.indexOf(apiCall) >= 0) {
765
+        if (previewLink.length && apiCall && previewFileModes && previewFileModes.length && previewFileModes.indexOf(apiCall) >= 0) {
766 766
             dataUrl = previewLink.data('url');
767 767
             previewLink.data('url', dataUrl.replace(/(.*)\/.*/i, '$1/' + mode));
768 768
             previewLink.show();
@@ -772,7 +772,7 @@ function initEditor() {
772 772
         }
773 773
 
774 774
         // If this file is a Markdown extensions, we will load that editor and return
775
-        if (mdFileExtensions.indexOf(extWithDot) >= 0) {
775
+        if (markdownFileExts.indexOf(extWithDot) >= 0) {
776 776
             if (setSimpleMDE()) {
777 777
                 return;
778 778
             }

+ 2 - 7
routers/repo/branch.go

@@ -64,13 +64,8 @@ func NewBranchPost(ctx *context.Context, form auth.NewBranchForm) {
64 64
 		log.Error(4, "branch.GetCommit(): %v", err)
65 65
 	} else {
66 66
 		pc := &models.PushCommits{
67
-			Len: 1,
68
-			Commits: []*models.PushCommit{&models.PushCommit{
69
-				commit.ID.String(),
70
-				commit.Message(),
71
-				commit.Author.Email,
72
-				commit.Author.Name,
73
-			}},
67
+			Len:     1,
68
+			Commits: []*models.PushCommit{models.CommitToPushCommit(commit)},
74 69
 		}
75 70
 		oldCommitID := "0000000000000000000000000000000000000000" // New Branch so we use all 0s
76 71
 		newCommitID := commit.ID.String()

+ 2 - 7
routers/repo/delete.go

@@ -32,13 +32,8 @@ func DeleteFilePost(ctx *context.Context, form auth.DeleteRepoFileForm) {
32 32
 		log.Error(4, "branch.GetCommit(): %v", err)
33 33
 	} else {
34 34
 		pc := &models.PushCommits{
35
-			Len: 1,
36
-			Commits: []*models.PushCommit{&models.PushCommit{
37
-				commit.ID.String(),
38
-				commit.Message(),
39
-				commit.Author.Email,
40
-				commit.Author.Name,
41
-			}},
35
+			Len:     1,
36
+			Commits: []*models.PushCommit{models.CommitToPushCommit(commit)},
42 37
 		}
43 38
 		oldCommitID := ctx.Repo.CommitID
44 39
 		newCommitID := commit.ID.String()

+ 11 - 16
routers/repo/edit.go

@@ -89,7 +89,7 @@ func editFile(ctx *context.Context, isNewFile bool) {
89 89
 		d, _ := ioutil.ReadAll(dataRc)
90 90
 		buf = append(buf, d...)
91 91
 
92
-		if err, content := template.ToUtf8WithErr(buf); err != nil {
92
+		if err, content := template.ToUTF8WithErr(buf); err != nil {
93 93
 			if err != nil {
94 94
 				log.Error(4, "Convert content encoding: %s", err)
95 95
 			}
@@ -116,10 +116,10 @@ func editFile(ctx *context.Context, isNewFile bool) {
116 116
 	ctx.Data["CommitDirectlyToThisBranch"] = ctx.Tr("repo.commit_directly_to_this_branch", "<strong class=\"branch-name\">"+branchName+"</strong>")
117 117
 	ctx.Data["CreateNewBranch"] = ctx.Tr("repo.create_new_branch", "<strong>"+ctx.Tr("repo.new_branch")+"</strong>")
118 118
 	ctx.Data["LastCommit"] = ctx.Repo.Commit.ID
119
-	ctx.Data["MdFileExtensions"] = strings.Join(setting.Markdown.MdFileExtensions, ",")
120
-	ctx.Data["LineWrapExtensions"] = strings.Join(setting.Editor.LineWrapExtensions, ",")
121
-	ctx.Data["PreviewTabApis"] = strings.Join(setting.Editor.PreviewTabApis, ",")
122
-	ctx.Data["PreviewDiffUrl"] = ctx.Repo.RepoLink + "/preview/" + branchName + "/" + treeName
119
+	ctx.Data["MarkdownFileExts"] = strings.Join(setting.Markdown.FileExtensions, ",")
120
+	ctx.Data["LineWrapExtensions"] = strings.Join(setting.Repository.Editor.LineWrapExtensions, ",")
121
+	ctx.Data["PreviewableFileModes"] = strings.Join(setting.Repository.Editor.PreviewableFileModes, ",")
122
+	ctx.Data["PreviewDiffURL"] = ctx.Repo.RepoLink + "/preview/" + branchName + "/" + treeName
123 123
 
124 124
 	ctx.HTML(200, EDIT)
125 125
 }
@@ -176,10 +176,10 @@ func editFilePost(ctx *context.Context, form auth.EditRepoFileForm, isNewFile bo
176 176
 	ctx.Data["CommitDirectlyToThisBranch"] = ctx.Tr("repo.commit_directly_to_this_branch", "<strong class=\"branch-name\">"+oldBranchName+"</strong>")
177 177
 	ctx.Data["CreateNewBranch"] = ctx.Tr("repo.create_new_branch", "<strong>"+ctx.Tr("repo.new_branch")+"</strong>")
178 178
 	ctx.Data["LastCommit"] = ctx.Repo.Commit.ID
179
-	ctx.Data["MdFileExtensions"] = strings.Join(setting.Markdown.MdFileExtensions, ",")
180
-	ctx.Data["LineWrapExtensions"] = strings.Join(setting.Editor.LineWrapExtensions, ",")
181
-	ctx.Data["PreviewTabApis"] = strings.Join(setting.Editor.PreviewTabApis, ",")
182
-	ctx.Data["PreviewDiffUrl"] = ctx.Repo.RepoLink + "/preview/" + branchName + "/" + treeName
179
+	ctx.Data["MarkdownFileExts"] = strings.Join(setting.Markdown.FileExtensions, ",")
180
+	ctx.Data["LineWrapExtensions"] = strings.Join(setting.Repository.Editor.LineWrapExtensions, ",")
181
+	ctx.Data["PreviewableFileModes"] = strings.Join(setting.Repository.Editor.PreviewableFileModes, ",")
182
+	ctx.Data["PreviewDiffURL"] = ctx.Repo.RepoLink + "/preview/" + branchName + "/" + treeName
183 183
 
184 184
 	if ctx.HasError() {
185 185
 		ctx.HTML(200, EDIT)
@@ -293,13 +293,8 @@ func editFilePost(ctx *context.Context, form auth.EditRepoFileForm, isNewFile bo
293 293
 		log.Error(4, "branch.GetCommit(): %v", err)
294 294
 	} else {
295 295
 		pc := &models.PushCommits{
296
-			Len: 1,
297
-			Commits: []*models.PushCommit{&models.PushCommit{
298
-				commit.ID.String(),
299
-				commit.Message(),
300
-				commit.Author.Email,
301
-				commit.Author.Name,
302
-			}},
296
+			Len:     1,
297
+			Commits: []*models.PushCommit{models.CommitToPushCommit(commit)},
303 298
 		}
304 299
 		oldCommitID := ctx.Repo.CommitID
305 300
 		newCommitID := commit.ID.String()

+ 10 - 16
routers/repo/upload.go

@@ -24,10 +24,10 @@ const (
24 24
 
25 25
 func renderUploadSettings(ctx *context.Context) {
26 26
 	ctx.Data["RequireDropzone"] = true
27
-	ctx.Data["IsUploadEnabled"] = setting.UploadEnabled
28
-	ctx.Data["UploadAllowedTypes"] = setting.UploadAllowedTypes
29
-	ctx.Data["UploadMaxSize"] = setting.UploadMaxSize
30
-	ctx.Data["UploadMaxFiles"] = setting.UploadMaxFiles
27
+	ctx.Data["IsUploadEnabled"] = setting.Repository.Upload.Enabled
28
+	ctx.Data["UploadAllowedTypes"] = strings.Join(setting.Repository.Upload.AllowedTypes, ",")
29
+	ctx.Data["UploadMaxSize"] = setting.Repository.Upload.FileMaxSize
30
+	ctx.Data["UploadMaxFiles"] = setting.Repository.Upload.MaxFiles
31 31
 }
32 32
 
33 33
 func UploadFile(ctx *context.Context) {
@@ -154,13 +154,8 @@ func UploadFilePost(ctx *context.Context, form auth.UploadRepoFileForm) {
154 154
 		log.Error(4, "branch.GetCommit(): %v", err)
155 155
 	} else {
156 156
 		pc := &models.PushCommits{
157
-			Len: 1,
158
-			Commits: []*models.PushCommit{&models.PushCommit{
159
-				commit.ID.String(),
160
-				commit.Message(),
161
-				commit.Author.Email,
162
-				commit.Author.Name,
163
-			}},
157
+			Len:     1,
158
+			Commits: []*models.PushCommit{models.CommitToPushCommit(commit)},
164 159
 		}
165 160
 		oldCommitID := ctx.Repo.CommitID
166 161
 		newCommitID := commit.ID.String()
@@ -184,7 +179,7 @@ func UploadFilePost(ctx *context.Context, form auth.UploadRepoFileForm) {
184 179
 }
185 180
 
186 181
 func UploadFileToServer(ctx *context.Context) {
187
-	if !setting.UploadEnabled {
182
+	if !setting.Repository.Upload.Enabled {
188 183
 		ctx.Error(404, "upload is not enabled")
189 184
 		return
190 185
 	}
@@ -203,10 +198,9 @@ func UploadFileToServer(ctx *context.Context) {
203 198
 	}
204 199
 	fileType := http.DetectContentType(buf)
205 200
 
206
-	if len(setting.UploadAllowedTypes) > 0 {
207
-		allowedTypes := strings.Split(setting.UploadAllowedTypes, ",")
201
+	if len(setting.Repository.Upload.AllowedTypes) > 0 {
208 202
 		allowed := false
209
-		for _, t := range allowedTypes {
203
+		for _, t := range setting.Repository.Upload.AllowedTypes {
210 204
 			t := strings.Trim(t, " ")
211 205
 			if t == "*/*" || t == fileType {
212 206
 				allowed = true
@@ -233,7 +227,7 @@ func UploadFileToServer(ctx *context.Context) {
233 227
 }
234 228
 
235 229
 func RemoveUploadFileFromServer(ctx *context.Context, form auth.RemoveUploadFileForm) {
236
-	if !setting.UploadEnabled {
230
+	if !setting.Repository.Upload.Enabled {
237 231
 		ctx.Error(404, "upload is not enabled")
238 232
 		return
239 233
 	}

+ 1 - 1
routers/repo/view.go

@@ -257,7 +257,7 @@ func Home(ctx *context.Context) {
257 257
 		ctx.Data["LastCommitUser"] = models.ValidateCommitWithEmail(lastCommit)
258 258
 		if ctx.Repo.IsWriter() && ctx.Repo.IsViewBranch {
259 259
 			ctx.Data["NewFileLink"] = newFileLink + "/" + treename
260
-			if setting.UploadEnabled {
260
+			if !setting.Repository.Upload.Enabled {
261 261
 				ctx.Data["UploadFileLink"] = uploadFileLink + "/" + treename
262 262
 			}
263 263
 		}

+ 3 - 3
templates/repo/edit.tmpl

@@ -30,14 +30,14 @@
30 30
 			<div class="field">
31 31
 				<div class="ui top attached tabular menu" data-write="write" data-preview="preview" data-diff="diff">
32 32
 					<a class="active item" data-tab="write"><i class="octicon octicon-code"></i> {{.i18n.Tr "repo.edit_file"}}</a>
33
-					<a class="item" data-tab="preview" data-url="{{AppSubUrl}}/api/v1/markdown" data-context="{{.RepoLink}}" data-preview-apis="{{.PreviewTabApis}}"><i class="octicon octicon-eye"></i> {{.i18n.Tr "repo.release.preview"}}</a>
34
-					<a class="item" data-tab="diff" data-url="{{.PreviewDiffUrl}}" data-context="{{.BranchLink}}"><i class="octicon octicon-diff"></i> {{.i18n.Tr "repo.preview_changes"}}</a>
33
+					<a class="item" data-tab="preview" data-url="{{AppSubUrl}}/api/v1/markdown" data-context="{{.RepoLink}}" data-preview-file-modes="{{.PreviewableFileModes}}"><i class="octicon octicon-eye"></i> {{.i18n.Tr "repo.release.preview"}}</a>
34
+					<a class="item" data-tab="diff" data-url="{{.PreviewDiffURL}}" data-context="{{.BranchLink}}"><i class="octicon octicon-diff"></i> {{.i18n.Tr "repo.preview_changes"}}</a>
35 35
 				</div>
36 36
 				<div class="ui bottom attached active tab segment" data-tab="write">
37 37
 					<textarea id="edit_area" name="content" data-id="repo-{{.Repository.Name}}-{{.TreeName}}"
38 38
 						data-url="{{AppSubUrl}}/api/v1/markdown"
39 39
 						data-context="{{.RepoLink}}"
40
-						data-md-file-extensions="{{.MdFileExtensions}}"
40
+						data-markdown-file-exts="{{.MarkdownFileExts}}"
41 41
 						data-line-wrap-extensions="{{.LineWrapExtensions}}">
42 42
 {{.FileContent}}</textarea required>
43 43
 				</div>