summaryrefslogtreecommitdiffstats
path: root/models/wiki.go
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2015-11-27 01:50:38 -0500
committerUnknwon <u@gogs.io>2015-11-27 01:50:38 -0500
commite42fcb033d4a7ee44fe397be3e933d7031b7d8f7 (patch)
treea203fff39c92f947c4585a746e2345b3ebc67b3c /models/wiki.go
parent392f3ee21016476fb9794f78882d6c447acb8449 (diff)
downloadgitea-e42fcb033d4a7ee44fe397be3e933d7031b7d8f7.tar.gz
gitea-e42fcb033d4a7ee44fe397be3e933d7031b7d8f7.zip
wiki: finish edit
Diffstat (limited to 'models/wiki.go')
-rw-r--r--models/wiki.go25
1 files changed, 22 insertions, 3 deletions
diff --git a/models/wiki.go b/models/wiki.go
index d78c51a88d..fd84ce4457 100644
--- a/models/wiki.go
+++ b/models/wiki.go
@@ -7,6 +7,7 @@ package models
import (
"fmt"
"io/ioutil"
+ "os"
"path"
"path/filepath"
"strings"
@@ -108,8 +109,8 @@ func (repo *Repository) UpdateLocalWiki() error {
return updateLocalCopy(repo.WikiPath(), repo.LocalWikiPath())
}
-// AddWikiPage adds new page to repository wiki.
-func (repo *Repository) AddWikiPage(doer *User, title, content, message string) (err error) {
+// updateWikiPage adds new page to repository wiki.
+func (repo *Repository) updateWikiPage(doer *User, oldTitle, title, content, message string, isNew bool) (err error) {
wikiWorkingPool.CheckIn(com.ToStr(repo.ID))
defer wikiWorkingPool.CheckOut(com.ToStr(repo.ID))
@@ -133,8 +134,18 @@ func (repo *Repository) AddWikiPage(doer *User, title, content, message string)
return fmt.Errorf("UpdateLocalWiki: %v", err)
}
- title = strings.Replace(title, "/", " ", -1)
+ title = ToWikiPageName(strings.Replace(title, "/", " ", -1))
filename := path.Join(localPath, title+".md")
+
+ // If not a new file, show perform update not create.
+ if isNew {
+ if com.IsExist(filename) {
+ return ErrWikiAlreadyExist{filename}
+ }
+ } else {
+ os.Remove(path.Join(localPath, oldTitle+".md"))
+ }
+
if err = ioutil.WriteFile(filename, []byte(content), 0666); err != nil {
return fmt.Errorf("WriteFile: %v", err)
}
@@ -152,3 +163,11 @@ func (repo *Repository) AddWikiPage(doer *User, title, content, message string)
return nil
}
+
+func (repo *Repository) AddWikiPage(doer *User, title, content, message string) error {
+ return repo.updateWikiPage(doer, "", title, content, message, true)
+}
+
+func (repo *Repository) EditWikiPage(doer *User, oldTitle, title, content, message string) error {
+ return repo.updateWikiPage(doer, oldTitle, title, content, message, false)
+}