|
|
@ -89,7 +89,7 @@ func discardLocalWikiChanges(localPath string) error { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// updateWikiPage adds new page to repository wiki.
|
|
|
|
// updateWikiPage adds new page to repository wiki.
|
|
|
|
func (repo *Repository) updateWikiPage(doer *User, oldTitle, title, content, message string, isNew bool) (err error) { |
|
|
|
func (repo *Repository) updateWikiPage(doer *User, oldWikiPath, wikiPath, content, message string, isNew bool) (err error) { |
|
|
|
wikiWorkingPool.CheckIn(com.ToStr(repo.ID)) |
|
|
|
wikiWorkingPool.CheckIn(com.ToStr(repo.ID)) |
|
|
|
defer wikiWorkingPool.CheckOut(com.ToStr(repo.ID)) |
|
|
|
defer wikiWorkingPool.CheckOut(com.ToStr(repo.ID)) |
|
|
|
|
|
|
|
|
|
|
@ -104,8 +104,8 @@ func (repo *Repository) updateWikiPage(doer *User, oldTitle, title, content, mes |
|
|
|
return fmt.Errorf("UpdateLocalWiki: %v", err) |
|
|
|
return fmt.Errorf("UpdateLocalWiki: %v", err) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
title = ToWikiPageName(title) |
|
|
|
title := ToWikiPageName(wikiPath) |
|
|
|
filename := path.Join(localPath, title+".md") |
|
|
|
filename := path.Join(localPath, wikiPath+".md") |
|
|
|
|
|
|
|
|
|
|
|
// If not a new file, show perform update not create.
|
|
|
|
// If not a new file, show perform update not create.
|
|
|
|
if isNew { |
|
|
|
if isNew { |
|
|
@ -113,7 +113,7 @@ func (repo *Repository) updateWikiPage(doer *User, oldTitle, title, content, mes |
|
|
|
return ErrWikiAlreadyExist{filename} |
|
|
|
return ErrWikiAlreadyExist{filename} |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
file := path.Join(localPath, oldTitle+".md") |
|
|
|
file := path.Join(localPath, oldWikiPath+".md") |
|
|
|
|
|
|
|
|
|
|
|
if err := os.Remove(file); err != nil { |
|
|
|
if err := os.Remove(file); err != nil { |
|
|
|
return fmt.Errorf("Fail to remove %s: %v", file, err) |
|
|
|
return fmt.Errorf("Fail to remove %s: %v", file, err) |
|
|
@ -149,19 +149,19 @@ func (repo *Repository) updateWikiPage(doer *User, oldTitle, title, content, mes |
|
|
|
return nil |
|
|
|
return nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// AddWikiPage adds a new wiki page with a given title.
|
|
|
|
// AddWikiPage adds a new wiki page with a given wikiPath.
|
|
|
|
func (repo *Repository) AddWikiPage(doer *User, title, content, message string) error { |
|
|
|
func (repo *Repository) AddWikiPage(doer *User, wikiPath, content, message string) error { |
|
|
|
return repo.updateWikiPage(doer, "", title, content, message, true) |
|
|
|
return repo.updateWikiPage(doer, "", wikiPath, content, message, true) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// EditWikiPage updates a wiki page identified by its title,
|
|
|
|
// EditWikiPage updates a wiki page identified by its wikiPath,
|
|
|
|
// optionally also changing title.
|
|
|
|
// optionally also changing wikiPath.
|
|
|
|
func (repo *Repository) EditWikiPage(doer *User, oldTitle, title, content, message string) error { |
|
|
|
func (repo *Repository) EditWikiPage(doer *User, oldWikiPath, wikiPath, content, message string) error { |
|
|
|
return repo.updateWikiPage(doer, oldTitle, title, content, message, false) |
|
|
|
return repo.updateWikiPage(doer, oldWikiPath, wikiPath, content, message, false) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// DeleteWikiPage deletes a wiki page identified by its title.
|
|
|
|
// DeleteWikiPage deletes a wiki page identified by its wikiPath.
|
|
|
|
func (repo *Repository) DeleteWikiPage(doer *User, title string) (err error) { |
|
|
|
func (repo *Repository) DeleteWikiPage(doer *User, wikiPath string) (err error) { |
|
|
|
wikiWorkingPool.CheckIn(com.ToStr(repo.ID)) |
|
|
|
wikiWorkingPool.CheckIn(com.ToStr(repo.ID)) |
|
|
|
defer wikiWorkingPool.CheckOut(com.ToStr(repo.ID)) |
|
|
|
defer wikiWorkingPool.CheckOut(com.ToStr(repo.ID)) |
|
|
|
|
|
|
|
|
|
|
@ -172,13 +172,13 @@ func (repo *Repository) DeleteWikiPage(doer *User, title string) (err error) { |
|
|
|
return fmt.Errorf("UpdateLocalWiki: %v", err) |
|
|
|
return fmt.Errorf("UpdateLocalWiki: %v", err) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
title = ToWikiPageName(title) |
|
|
|
filename := path.Join(localPath, wikiPath+".md") |
|
|
|
filename := path.Join(localPath, title+".md") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err := os.Remove(filename); err != nil { |
|
|
|
if err := os.Remove(filename); err != nil { |
|
|
|
return fmt.Errorf("Fail to remove %s: %v", filename, err) |
|
|
|
return fmt.Errorf("Fail to remove %s: %v", filename, err) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
title := ToWikiPageName(wikiPath) |
|
|
|
message := "Delete page '" + title + "'" |
|
|
|
message := "Delete page '" + title + "'" |
|
|
|
|
|
|
|
|
|
|
|
if err = git.AddChanges(localPath, true); err != nil { |
|
|
|
if err = git.AddChanges(localPath, true); err != nil { |
|
|
|