editor.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  1. // Copyright 2016 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package repo
  5. import (
  6. "fmt"
  7. "net/http"
  8. "path"
  9. "path/filepath"
  10. "strings"
  11. log "unknwon.dev/clog/v2"
  12. "github.com/G-Node/gogs/internal/conf"
  13. "github.com/G-Node/gogs/internal/context"
  14. "github.com/G-Node/gogs/internal/db"
  15. "github.com/G-Node/gogs/internal/db/errors"
  16. "github.com/G-Node/gogs/internal/form"
  17. "github.com/G-Node/gogs/internal/gitutil"
  18. "github.com/G-Node/gogs/internal/markup"
  19. "github.com/G-Node/gogs/internal/pathutil"
  20. "github.com/G-Node/gogs/internal/template"
  21. "github.com/G-Node/gogs/internal/tool"
  22. )
  23. const (
  24. EDIT_FILE = "repo/editor/edit"
  25. EDIT_DIFF_PREVIEW = "repo/editor/diff_preview"
  26. DELETE_FILE = "repo/editor/delete"
  27. UPLOAD_FILE = "repo/editor/upload"
  28. )
  29. // getParentTreeFields returns list of parent tree names and corresponding tree paths
  30. // based on given tree path.
  31. func getParentTreeFields(treePath string) (treeNames []string, treePaths []string) {
  32. if len(treePath) == 0 {
  33. return treeNames, treePaths
  34. }
  35. treeNames = strings.Split(treePath, "/")
  36. treePaths = make([]string, len(treeNames))
  37. for i := range treeNames {
  38. treePaths[i] = strings.Join(treeNames[:i+1], "/")
  39. }
  40. return treeNames, treePaths
  41. }
  42. func editFile(c *context.Context, isNewFile bool) {
  43. c.PageIs("Edit")
  44. c.RequireHighlightJS()
  45. c.RequireSimpleMDE()
  46. c.Data["IsNewFile"] = isNewFile
  47. treeNames, treePaths := getParentTreeFields(c.Repo.TreePath)
  48. if !isNewFile {
  49. entry, err := c.Repo.Commit.TreeEntry(c.Repo.TreePath)
  50. if err != nil {
  51. c.NotFoundOrServerError("get tree entry", gitutil.IsErrRevisionNotExist, err)
  52. return
  53. }
  54. // No way to edit a directory online.
  55. if entry.IsTree() {
  56. c.NotFound()
  57. return
  58. }
  59. blob := entry.Blob()
  60. p, err := blob.Bytes()
  61. if err != nil {
  62. c.ServerError("blob.Data", err)
  63. return
  64. }
  65. c.Data["FileSize"] = blob.Size()
  66. c.Data["FileName"] = blob.Name()
  67. c.Data["IsJSON"] = markup.IsJSON(blob.Name())
  68. c.Data["IsYAML"] = markup.IsYAML(blob.Name())
  69. // Only text file are editable online.
  70. if !tool.IsTextFile(p) {
  71. c.NotFound()
  72. return
  73. }
  74. c.Data["IsODML"] = tool.IsODMLFile(p)
  75. if err, content := template.ToUTF8WithErr(p); err != nil {
  76. if err != nil {
  77. log.Error("Failed to convert encoding to UTF-8: %v", err)
  78. }
  79. c.Data["FileContent"] = string(p)
  80. } else {
  81. c.Data["FileContent"] = content
  82. }
  83. } else {
  84. treeNames = append(treeNames, "") // Append empty string to allow user name the new file.
  85. }
  86. c.Data["ParentTreePath"] = path.Dir(c.Repo.TreePath)
  87. c.Data["TreeNames"] = treeNames
  88. c.Data["TreePaths"] = treePaths
  89. c.Data["BranchLink"] = c.Repo.RepoLink + "/src/" + c.Repo.BranchName
  90. c.Data["commit_summary"] = ""
  91. c.Data["commit_message"] = ""
  92. c.Data["commit_choice"] = "direct"
  93. c.Data["new_branch_name"] = ""
  94. c.Data["last_commit"] = c.Repo.Commit.ID
  95. c.Data["MarkdownFileExts"] = strings.Join(conf.Markdown.FileExtensions, ",")
  96. c.Data["LineWrapExtensions"] = strings.Join(conf.Repository.Editor.LineWrapExtensions, ",")
  97. c.Data["PreviewableFileModes"] = strings.Join(conf.Repository.Editor.PreviewableFileModes, ",")
  98. c.Data["EditorconfigURLPrefix"] = fmt.Sprintf("%s/api/v1/repos/%s/editorconfig/", conf.Server.Subpath, c.Repo.Repository.FullName())
  99. c.Success(EDIT_FILE)
  100. }
  101. func EditFile(c *context.Context) {
  102. editFile(c, false)
  103. }
  104. func NewFile(c *context.Context) {
  105. editFile(c, true)
  106. }
  107. func editFilePost(c *context.Context, f form.EditRepoFile, isNewFile bool) {
  108. c.PageIs("Edit")
  109. c.RequireHighlightJS()
  110. c.RequireSimpleMDE()
  111. c.Data["IsNewFile"] = isNewFile
  112. oldBranchName := c.Repo.BranchName
  113. branchName := oldBranchName
  114. oldTreePath := c.Repo.TreePath
  115. lastCommit := f.LastCommit
  116. f.LastCommit = c.Repo.Commit.ID.String()
  117. if f.IsNewBrnach() {
  118. branchName = f.NewBranchName
  119. }
  120. f.TreePath = pathutil.Clean(f.TreePath)
  121. treeNames, treePaths := getParentTreeFields(f.TreePath)
  122. c.Data["ParentTreePath"] = path.Dir(c.Repo.TreePath)
  123. c.Data["TreePath"] = f.TreePath
  124. c.Data["TreeNames"] = treeNames
  125. c.Data["TreePaths"] = treePaths
  126. c.Data["BranchLink"] = c.Repo.RepoLink + "/src/" + branchName
  127. c.Data["FileContent"] = f.Content
  128. c.Data["commit_summary"] = f.CommitSummary
  129. c.Data["commit_message"] = f.CommitMessage
  130. c.Data["commit_choice"] = f.CommitChoice
  131. c.Data["new_branch_name"] = branchName
  132. c.Data["last_commit"] = f.LastCommit
  133. c.Data["MarkdownFileExts"] = strings.Join(conf.Markdown.FileExtensions, ",")
  134. c.Data["LineWrapExtensions"] = strings.Join(conf.Repository.Editor.LineWrapExtensions, ",")
  135. c.Data["PreviewableFileModes"] = strings.Join(conf.Repository.Editor.PreviewableFileModes, ",")
  136. if c.HasError() {
  137. c.Success(EDIT_FILE)
  138. return
  139. }
  140. if len(f.TreePath) == 0 {
  141. c.FormErr("TreePath")
  142. c.RenderWithErr(c.Tr("repo.editor.filename_cannot_be_empty"), EDIT_FILE, &f)
  143. return
  144. }
  145. if oldBranchName != branchName {
  146. if _, err := c.Repo.Repository.GetBranch(branchName); err == nil {
  147. c.FormErr("NewBranchName")
  148. c.RenderWithErr(c.Tr("repo.editor.branch_already_exists", branchName), EDIT_FILE, &f)
  149. return
  150. }
  151. }
  152. var newTreePath string
  153. for index, part := range treeNames {
  154. newTreePath = path.Join(newTreePath, part)
  155. entry, err := c.Repo.Commit.TreeEntry(newTreePath)
  156. if err != nil {
  157. if gitutil.IsErrRevisionNotExist(err) {
  158. // Means there is no item with that name, so we're good
  159. break
  160. }
  161. c.ServerError("Repo.Commit.GetTreeEntryByPath", err)
  162. return
  163. }
  164. if index != len(treeNames)-1 {
  165. if !entry.IsTree() {
  166. c.FormErr("TreePath")
  167. c.RenderWithErr(c.Tr("repo.editor.directory_is_a_file", part), EDIT_FILE, &f)
  168. return
  169. }
  170. } else {
  171. if entry.IsSymlink() {
  172. c.FormErr("TreePath")
  173. c.RenderWithErr(c.Tr("repo.editor.file_is_a_symlink", part), EDIT_FILE, &f)
  174. return
  175. } else if entry.IsTree() {
  176. c.FormErr("TreePath")
  177. c.RenderWithErr(c.Tr("repo.editor.filename_is_a_directory", part), EDIT_FILE, &f)
  178. return
  179. }
  180. }
  181. }
  182. if !isNewFile {
  183. _, err := c.Repo.Commit.TreeEntry(oldTreePath)
  184. if err != nil {
  185. if gitutil.IsErrRevisionNotExist(err) {
  186. c.FormErr("TreePath")
  187. c.RenderWithErr(c.Tr("repo.editor.file_editing_no_longer_exists", oldTreePath), EDIT_FILE, &f)
  188. } else {
  189. c.ServerError("GetTreeEntryByPath", err)
  190. }
  191. return
  192. }
  193. if lastCommit != c.Repo.CommitID {
  194. files, err := c.Repo.Commit.FilesChangedAfter(lastCommit)
  195. if err != nil {
  196. c.ServerError("GetFilesChangedSinceCommit", err)
  197. return
  198. }
  199. for _, file := range files {
  200. if file == f.TreePath {
  201. c.RenderWithErr(c.Tr("repo.editor.file_changed_while_editing", c.Repo.RepoLink+"/compare/"+lastCommit+"..."+c.Repo.CommitID), EDIT_FILE, &f)
  202. return
  203. }
  204. }
  205. }
  206. }
  207. if oldTreePath != f.TreePath {
  208. // We have a new filename (rename or completely new file) so we need to make sure it doesn't already exist, can't clobber.
  209. entry, err := c.Repo.Commit.TreeEntry(f.TreePath)
  210. if err != nil {
  211. if !gitutil.IsErrRevisionNotExist(err) {
  212. c.ServerError("GetTreeEntryByPath", err)
  213. return
  214. }
  215. }
  216. if entry != nil {
  217. c.FormErr("TreePath")
  218. c.RenderWithErr(c.Tr("repo.editor.file_already_exists", f.TreePath), EDIT_FILE, &f)
  219. return
  220. }
  221. }
  222. message := strings.TrimSpace(f.CommitSummary)
  223. if len(message) == 0 {
  224. if isNewFile {
  225. message = c.Tr("repo.editor.add", f.TreePath)
  226. } else {
  227. message = c.Tr("repo.editor.update", f.TreePath)
  228. }
  229. }
  230. f.CommitMessage = strings.TrimSpace(f.CommitMessage)
  231. if len(f.CommitMessage) > 0 {
  232. message += "\n\n" + f.CommitMessage
  233. }
  234. if err := c.Repo.Repository.UpdateRepoFile(c.User, db.UpdateRepoFileOptions{
  235. LastCommitID: lastCommit,
  236. OldBranch: oldBranchName,
  237. NewBranch: branchName,
  238. OldTreeName: oldTreePath,
  239. NewTreeName: f.TreePath,
  240. Message: message,
  241. Content: strings.Replace(f.Content, "\r", "", -1),
  242. IsNewFile: isNewFile,
  243. }); err != nil {
  244. log.Error("Failed to update repo file: %v", err)
  245. c.FormErr("TreePath")
  246. c.RenderWithErr(c.Tr("repo.editor.fail_to_update_file", f.TreePath, errors.InternalServerError), EDIT_FILE, &f)
  247. return
  248. }
  249. if f.IsNewBrnach() && c.Repo.PullRequest.Allowed {
  250. c.Redirect(c.Repo.PullRequestURL(oldBranchName, f.NewBranchName))
  251. } else {
  252. c.Redirect(c.Repo.RepoLink + "/src/" + branchName + "/" + f.TreePath)
  253. }
  254. }
  255. func EditFilePost(c *context.Context, f form.EditRepoFile) {
  256. editFilePost(c, f, false)
  257. }
  258. func NewFilePost(c *context.Context, f form.EditRepoFile) {
  259. editFilePost(c, f, true)
  260. }
  261. func DiffPreviewPost(c *context.Context, f form.EditPreviewDiff) {
  262. treePath := c.Repo.TreePath
  263. entry, err := c.Repo.Commit.TreeEntry(treePath)
  264. if err != nil {
  265. c.Error(500, "GetTreeEntryByPath: "+err.Error())
  266. return
  267. } else if entry.IsTree() {
  268. c.Error(422)
  269. return
  270. }
  271. diff, err := c.Repo.Repository.GetDiffPreview(c.Repo.BranchName, treePath, f.Content)
  272. if err != nil {
  273. c.Error(500, "GetDiffPreview: "+err.Error())
  274. return
  275. }
  276. if diff.NumFiles() == 0 {
  277. c.PlainText(200, []byte(c.Tr("repo.editor.no_changes_to_show")))
  278. return
  279. }
  280. c.Data["File"] = diff.Files[0]
  281. c.HTML(200, EDIT_DIFF_PREVIEW)
  282. }
  283. func DeleteFile(c *context.Context) {
  284. c.PageIs("Delete")
  285. c.Data["BranchLink"] = c.Repo.RepoLink + "/src/" + c.Repo.BranchName
  286. c.Data["TreePath"] = c.Repo.TreePath
  287. c.Data["commit_summary"] = ""
  288. c.Data["commit_message"] = ""
  289. c.Data["commit_choice"] = "direct"
  290. c.Data["new_branch_name"] = ""
  291. c.Success(DELETE_FILE)
  292. }
  293. func DeleteFilePost(c *context.Context, f form.DeleteRepoFile) {
  294. c.PageIs("Delete")
  295. c.Data["BranchLink"] = c.Repo.RepoLink + "/src/" + c.Repo.BranchName
  296. c.Repo.TreePath = pathutil.Clean(c.Repo.TreePath)
  297. c.Data["TreePath"] = c.Repo.TreePath
  298. oldBranchName := c.Repo.BranchName
  299. branchName := oldBranchName
  300. if f.IsNewBrnach() {
  301. branchName = f.NewBranchName
  302. }
  303. c.Data["commit_summary"] = f.CommitSummary
  304. c.Data["commit_message"] = f.CommitMessage
  305. c.Data["commit_choice"] = f.CommitChoice
  306. c.Data["new_branch_name"] = branchName
  307. if c.HasError() {
  308. c.Success(DELETE_FILE)
  309. return
  310. }
  311. if oldBranchName != branchName {
  312. if _, err := c.Repo.Repository.GetBranch(branchName); err == nil {
  313. c.FormErr("NewBranchName")
  314. c.RenderWithErr(c.Tr("repo.editor.branch_already_exists", branchName), DELETE_FILE, &f)
  315. return
  316. }
  317. }
  318. message := strings.TrimSpace(f.CommitSummary)
  319. if len(message) == 0 {
  320. message = c.Tr("repo.editor.delete", c.Repo.TreePath)
  321. }
  322. f.CommitMessage = strings.TrimSpace(f.CommitMessage)
  323. if len(f.CommitMessage) > 0 {
  324. message += "\n\n" + f.CommitMessage
  325. }
  326. if err := c.Repo.Repository.DeleteRepoFile(c.User, db.DeleteRepoFileOptions{
  327. LastCommitID: c.Repo.CommitID,
  328. OldBranch: oldBranchName,
  329. NewBranch: branchName,
  330. TreePath: c.Repo.TreePath,
  331. Message: message,
  332. }); err != nil {
  333. log.Error("Failed to delete repo file: %v", err)
  334. c.RenderWithErr(c.Tr("repo.editor.fail_to_delete_file", c.Repo.TreePath, errors.InternalServerError), DELETE_FILE, &f)
  335. return
  336. }
  337. if f.IsNewBrnach() && c.Repo.PullRequest.Allowed {
  338. c.Redirect(c.Repo.PullRequestURL(oldBranchName, f.NewBranchName))
  339. } else {
  340. c.Flash.Success(c.Tr("repo.editor.file_delete_success", c.Repo.TreePath))
  341. c.Redirect(c.Repo.RepoLink + "/src/" + branchName)
  342. }
  343. }
  344. func renderUploadSettings(c *context.Context) {
  345. c.RequireDropzone()
  346. c.Data["UploadAllowedTypes"] = strings.Join(conf.Repository.Upload.AllowedTypes, ",")
  347. c.Data["UploadMaxSize"] = conf.Repository.Upload.FileMaxSize
  348. c.Data["UploadMaxFiles"] = conf.Repository.Upload.MaxFiles
  349. }
  350. func UploadFile(c *context.Context) {
  351. c.PageIs("Upload")
  352. renderUploadSettings(c)
  353. treeNames, treePaths := getParentTreeFields(c.Repo.TreePath)
  354. if len(treeNames) == 0 {
  355. // We must at least have one element for user to input.
  356. treeNames = []string{""}
  357. }
  358. c.Data["TreeNames"] = treeNames
  359. c.Data["TreePaths"] = treePaths
  360. c.Data["BranchLink"] = c.Repo.RepoLink + "/src/" + c.Repo.BranchName
  361. c.Data["commit_summary"] = ""
  362. c.Data["commit_message"] = ""
  363. c.Data["commit_choice"] = "direct"
  364. c.Data["new_branch_name"] = ""
  365. c.Success(UPLOAD_FILE)
  366. }
  367. func UploadFilePost(c *context.Context, f form.UploadRepoFile) {
  368. c.PageIs("Upload")
  369. renderUploadSettings(c)
  370. oldBranchName := c.Repo.BranchName
  371. branchName := oldBranchName
  372. if f.IsNewBrnach() {
  373. branchName = f.NewBranchName
  374. }
  375. f.TreePath = pathutil.Clean(f.TreePath)
  376. treeNames, treePaths := getParentTreeFields(f.TreePath)
  377. if len(treeNames) == 0 {
  378. // We must at least have one element for user to input.
  379. treeNames = []string{""}
  380. }
  381. c.Data["TreePath"] = f.TreePath
  382. c.Data["TreeNames"] = treeNames
  383. c.Data["TreePaths"] = treePaths
  384. c.Data["BranchLink"] = c.Repo.RepoLink + "/src/" + branchName
  385. c.Data["commit_summary"] = f.CommitSummary
  386. c.Data["commit_message"] = f.CommitMessage
  387. c.Data["commit_choice"] = f.CommitChoice
  388. c.Data["new_branch_name"] = branchName
  389. if c.HasError() {
  390. c.Success(UPLOAD_FILE)
  391. return
  392. }
  393. if oldBranchName != branchName {
  394. if _, err := c.Repo.Repository.GetBranch(branchName); err == nil {
  395. c.FormErr("NewBranchName")
  396. c.RenderWithErr(c.Tr("repo.editor.branch_already_exists", branchName), UPLOAD_FILE, &f)
  397. return
  398. }
  399. }
  400. var newTreePath string
  401. for _, part := range treeNames {
  402. newTreePath = path.Join(newTreePath, part)
  403. entry, err := c.Repo.Commit.TreeEntry(newTreePath)
  404. if err != nil {
  405. if gitutil.IsErrRevisionNotExist(err) {
  406. // Means there is no item with that name, so we're good
  407. break
  408. }
  409. c.ServerError("GetTreeEntryByPath", err)
  410. return
  411. }
  412. // User can only upload files to a directory.
  413. if !entry.IsTree() {
  414. c.FormErr("TreePath")
  415. c.RenderWithErr(c.Tr("repo.editor.directory_is_a_file", part), UPLOAD_FILE, &f)
  416. return
  417. }
  418. }
  419. message := strings.TrimSpace(f.CommitSummary)
  420. if len(message) == 0 {
  421. message = c.Tr("repo.editor.upload_files_to_dir", f.TreePath)
  422. }
  423. f.CommitMessage = strings.TrimSpace(f.CommitMessage)
  424. if len(f.CommitMessage) > 0 {
  425. message += "\n\n" + f.CommitMessage
  426. }
  427. if err := c.Repo.Repository.UploadRepoFiles(c.User, db.UploadRepoFileOptions{
  428. LastCommitID: c.Repo.CommitID,
  429. OldBranch: oldBranchName,
  430. NewBranch: branchName,
  431. TreePath: f.TreePath,
  432. Message: message,
  433. Files: f.Files,
  434. }); err != nil {
  435. log.Error("Failed to upload files: %v", err)
  436. c.FormErr("TreePath")
  437. c.RenderWithErr(c.Tr("repo.editor.unable_to_upload_files", f.TreePath, errors.InternalServerError), UPLOAD_FILE, &f)
  438. return
  439. }
  440. if f.IsNewBrnach() && c.Repo.PullRequest.Allowed {
  441. c.Redirect(c.Repo.PullRequestURL(oldBranchName, f.NewBranchName))
  442. } else {
  443. c.Redirect(c.Repo.RepoLink + "/src/" + branchName + "/" + f.TreePath)
  444. }
  445. }
  446. func UploadFileToServer(c *context.Context) {
  447. file, header, err := c.Req.FormFile("file")
  448. fvalue := c.Req.Form
  449. fp := filepath.Dir(fvalue.Get("full_path"))
  450. log.Info("full_path: %s", fp)
  451. if err != nil {
  452. c.Error(http.StatusInternalServerError, fmt.Sprintf("FormFile: %v", err))
  453. return
  454. }
  455. defer file.Close()
  456. buf := make([]byte, 1024)
  457. n, _ := file.Read(buf)
  458. if n > 0 {
  459. buf = buf[:n]
  460. }
  461. fileType := http.DetectContentType(buf)
  462. if len(conf.Repository.Upload.AllowedTypes) > 0 {
  463. allowed := false
  464. for _, t := range conf.Repository.Upload.AllowedTypes {
  465. t := strings.Trim(t, " ")
  466. if t == "*/*" || t == fileType {
  467. allowed = true
  468. break
  469. }
  470. }
  471. if !allowed {
  472. c.Error(http.StatusBadRequest, ErrFileTypeForbidden.Error())
  473. return
  474. }
  475. }
  476. upload, err := db.NewUpload(filepath.Join(fp, header.Filename), buf, file)
  477. if err != nil {
  478. c.Error(http.StatusInternalServerError, fmt.Sprintf("NewUpload: %v", err))
  479. return
  480. }
  481. log.Trace("New file uploaded by user[%d]: %s", c.UserID(), upload.UUID)
  482. c.JSONSuccess(map[string]string{
  483. "uuid": upload.UUID,
  484. })
  485. }
  486. func RemoveUploadFileFromServer(c *context.Context, f form.RemoveUploadFile) {
  487. if len(f.File) == 0 {
  488. c.Status(204)
  489. return
  490. }
  491. if err := db.DeleteUploadByUUID(f.File); err != nil {
  492. c.Error(500, fmt.Sprintf("DeleteUploadByUUID: %v", err))
  493. return
  494. }
  495. log.Trace("Upload file removed: %s", f.File)
  496. c.Status(204)
  497. }
  498. func CreateDatacite(c *context.Context) {
  499. dcname := path.Join("conf/datacite/datacite.yml")
  500. treeNames, treePaths := getParentTreeFields(c.Repo.TreePath)
  501. c.PageIs("Edit")
  502. c.RequireHighlightJS()
  503. c.RequireSimpleMDE()
  504. c.Data["IsYAML"] = true
  505. // safe to ignore error since we check for the asset at startup
  506. data, _ := conf.Asset(dcname)
  507. c.Data["FileContent"] = string(data)
  508. c.Data["ParentTreePath"] = path.Dir(c.Repo.TreePath)
  509. c.Data["TreeNames"] = treeNames
  510. c.Data["TreePaths"] = treePaths
  511. c.Data["BranchLink"] = c.Repo.RepoLink + "/src/" + c.Repo.BranchName
  512. c.Data["commit_summary"] = "Add information for publishing with DataCite"
  513. c.Data["commit_message"] = ""
  514. c.Data["commit_choice"] = "direct"
  515. c.Data["new_branch_name"] = ""
  516. c.Data["last_commit"] = c.Repo.Commit.ID
  517. c.Data["MarkdownFileExts"] = strings.Join(conf.Markdown.FileExtensions, ",")
  518. c.Data["LineWrapExtensions"] = strings.Join(conf.Repository.Editor.LineWrapExtensions, ",")
  519. c.Data["PreviewableFileModes"] = strings.Join(conf.Repository.Editor.PreviewableFileModes, ",")
  520. c.Data["EditorconfigURLPrefix"] = fmt.Sprintf("%s/api/v1/repos/%s/editorconfig/", conf.Server.Subpath, c.Repo.Repository.FullName())
  521. c.Success(EDIT_FILE)
  522. }