editor.go 17 KB

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