diff options
author | Unknwon <u@gogs.io> | 2015-11-26 17:33:45 -0500 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2015-11-26 17:33:45 -0500 |
commit | c50a3503e6e8ece0dabd109932a72fe093c3cab3 (patch) | |
tree | d9918c4b9c5d5efc94771cae22231fdcc0796102 /models/wiki.go | |
parent | 2b10fdc4dcb987b347b031f460cf4f02fd48a31a (diff) | |
download | gitea-c50a3503e6e8ece0dabd109932a72fe093c3cab3.tar.gz gitea-c50a3503e6e8ece0dabd109932a72fe093c3cab3.zip |
introduce git-shell
Diffstat (limited to 'models/wiki.go')
-rw-r--r-- | models/wiki.go | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/models/wiki.go b/models/wiki.go new file mode 100644 index 0000000000..e08505d2bb --- /dev/null +++ b/models/wiki.go @@ -0,0 +1,56 @@ +// Copyright 2015 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package models + +import ( + "fmt" + "path/filepath" + "strings" + + "github.com/Unknwon/com" + + "github.com/gogits/git-shell" +) + +// ToWikiPageName formats a string to corresponding wiki URL name. +func ToWikiPageName(name string) string { + return strings.Replace(name, " ", "-", -1) +} + +// WikiPath returns wiki data path by given user and repository name. +func WikiPath(userName, repoName string) string { + return filepath.Join(UserPath(userName), strings.ToLower(repoName)+".wiki.git") +} + +func (repo *Repository) WikiPath() string { + return WikiPath(repo.MustOwner().Name, repo.Name) +} + +// HasWiki returns true if repository has wiki. +func (repo *Repository) HasWiki() bool { + return com.IsDir(repo.WikiPath()) +} + +// InitWiki initializes a wiki for repository, +// it does nothing when repository already has wiki. +func (repo *Repository) InitWiki() error { + if repo.HasWiki() { + return nil + } + + if err := git.InitRepository(repo.WikiPath(), true); err != nil { + return fmt.Errorf("InitRepository: %v", err) + } + return nil +} + +// AddWikiPage adds new page to repository wiki. +func (repo *Repository) AddWikiPage(title, content, message string) (err error) { + if err = repo.InitWiki(); err != nil { + return fmt.Errorf("InitWiki: %v", err) + } + + return nil +} |