mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-31 18:12:20 +01:00 
			
		
		
		
	
							parent
							
								
									369972b116
								
							
						
					
					
						commit
						f8c2903484
					
				| @ -89,7 +89,7 @@ func discardLocalWikiChanges(localPath string) error { | ||||
| } | ||||
| 
 | ||||
| // 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)) | ||||
| 	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) | ||||
| 	} | ||||
| 
 | ||||
| 	title = ToWikiPageName(title) | ||||
| 	filename := path.Join(localPath, title+".md") | ||||
| 	title := ToWikiPageName(wikiPath) | ||||
| 	filename := path.Join(localPath, wikiPath+".md") | ||||
| 
 | ||||
| 	// If not a new file, show perform update not create. | ||||
| 	if isNew { | ||||
| @ -113,7 +113,7 @@ func (repo *Repository) updateWikiPage(doer *User, oldTitle, title, content, mes | ||||
| 			return ErrWikiAlreadyExist{filename} | ||||
| 		} | ||||
| 	} else { | ||||
| 		file := path.Join(localPath, oldTitle+".md") | ||||
| 		file := path.Join(localPath, oldWikiPath+".md") | ||||
| 
 | ||||
| 		if err := os.Remove(file); err != nil { | ||||
| 			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 | ||||
| } | ||||
| 
 | ||||
| // AddWikiPage adds a new wiki page with a given title. | ||||
| func (repo *Repository) AddWikiPage(doer *User, title, content, message string) error { | ||||
| 	return repo.updateWikiPage(doer, "", title, content, message, true) | ||||
| // AddWikiPage adds a new wiki page with a given wikiPath. | ||||
| func (repo *Repository) AddWikiPage(doer *User, wikiPath, content, message string) error { | ||||
| 	return repo.updateWikiPage(doer, "", wikiPath, content, message, true) | ||||
| } | ||||
| 
 | ||||
| // EditWikiPage updates a wiki page identified by its title, | ||||
| // optionally also changing title. | ||||
| func (repo *Repository) EditWikiPage(doer *User, oldTitle, title, content, message string) error { | ||||
| 	return repo.updateWikiPage(doer, oldTitle, title, content, message, false) | ||||
| // EditWikiPage updates a wiki page identified by its wikiPath, | ||||
| // optionally also changing wikiPath. | ||||
| func (repo *Repository) EditWikiPage(doer *User, oldWikiPath, wikiPath, content, message string) error { | ||||
| 	return repo.updateWikiPage(doer, oldWikiPath, wikiPath, content, message, false) | ||||
| } | ||||
| 
 | ||||
| // DeleteWikiPage deletes a wiki page identified by its title. | ||||
| func (repo *Repository) DeleteWikiPage(doer *User, title string) (err error) { | ||||
| // DeleteWikiPage deletes a wiki page identified by its wikiPath. | ||||
| func (repo *Repository) DeleteWikiPage(doer *User, wikiPath string) (err error) { | ||||
| 	wikiWorkingPool.CheckIn(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) | ||||
| 	} | ||||
| 
 | ||||
| 	title = ToWikiPageName(title) | ||||
| 	filename := path.Join(localPath, title+".md") | ||||
| 	filename := path.Join(localPath, wikiPath+".md") | ||||
| 
 | ||||
| 	if err := os.Remove(filename); err != nil { | ||||
| 		return fmt.Errorf("Fail to remove %s: %v", filename, err) | ||||
| 	} | ||||
| 
 | ||||
| 	title := ToWikiPageName(wikiPath) | ||||
| 	message := "Delete page '" + title + "'" | ||||
| 
 | ||||
| 	if err = git.AddChanges(localPath, true); err != nil { | ||||
|  | ||||
| @ -89,7 +89,7 @@ func renderWikiPage(ctx *context.Context, isViewPage bool) (*git.Repository, str | ||||
| 	ctx.Data["title"] = pageName | ||||
| 	ctx.Data["RequireHighlightJS"] = true | ||||
| 
 | ||||
| 	blob, err := commit.GetBlobByPath(pageName + ".md") | ||||
| 	blob, err := commit.GetBlobByPath(pageURL + ".md") | ||||
| 	if err != nil { | ||||
| 		if git.IsErrNotExist(err) { | ||||
| 			ctx.Redirect(ctx.Repo.RepoLink + "/wiki/_pages") | ||||
| @ -114,7 +114,7 @@ func renderWikiPage(ctx *context.Context, isViewPage bool) (*git.Repository, str | ||||
| 		ctx.Data["content"] = string(data) | ||||
| 	} | ||||
| 
 | ||||
| 	return wikiRepo, pageName | ||||
| 	return wikiRepo, pageURL | ||||
| } | ||||
| 
 | ||||
| // Wiki render wiki page | ||||
| @ -127,13 +127,13 @@ func Wiki(ctx *context.Context) { | ||||
| 		return | ||||
| 	} | ||||
| 
 | ||||
| 	wikiRepo, pageName := renderWikiPage(ctx, true) | ||||
| 	wikiRepo, pagePath := renderWikiPage(ctx, true) | ||||
| 	if ctx.Written() { | ||||
| 		return | ||||
| 	} | ||||
| 
 | ||||
| 	// Get last change information. | ||||
| 	lastCommit, err := wikiRepo.GetCommitByPath(pageName + ".md") | ||||
| 	lastCommit, err := wikiRepo.GetCommitByPath(pagePath + ".md") | ||||
| 	if err != nil { | ||||
| 		ctx.Handle(500, "GetCommitByPath", err) | ||||
| 		return | ||||
| @ -214,7 +214,9 @@ func NewWikiPost(ctx *context.Context, form auth.NewWikiForm) { | ||||
| 		return | ||||
| 	} | ||||
| 
 | ||||
| 	if err := ctx.Repo.Repository.AddWikiPage(ctx.User, form.Title, form.Content, form.Message); err != nil { | ||||
| 	wikiPath := models.ToWikiPageURL(form.Title) | ||||
| 
 | ||||
| 	if err := ctx.Repo.Repository.AddWikiPage(ctx.User, wikiPath, form.Content, form.Message); err != nil { | ||||
| 		if models.IsErrWikiAlreadyExist(err) { | ||||
| 			ctx.Data["Err_Title"] = true | ||||
| 			ctx.RenderWithErr(ctx.Tr("repo.wiki.page_already_exists"), tplWikiNew, &form) | ||||
| @ -224,7 +226,7 @@ func NewWikiPost(ctx *context.Context, form auth.NewWikiForm) { | ||||
| 		return | ||||
| 	} | ||||
| 
 | ||||
| 	ctx.Redirect(ctx.Repo.RepoLink + "/wiki/" + models.ToWikiPageURL(form.Title)) | ||||
| 	ctx.Redirect(ctx.Repo.RepoLink + "/wiki/" + wikiPath) | ||||
| } | ||||
| 
 | ||||
| // EditWiki render wiki modify page | ||||
| @ -257,12 +259,15 @@ func EditWikiPost(ctx *context.Context, form auth.NewWikiForm) { | ||||
| 		return | ||||
| 	} | ||||
| 
 | ||||
| 	if err := ctx.Repo.Repository.EditWikiPage(ctx.User, form.OldTitle, form.Title, form.Content, form.Message); err != nil { | ||||
| 	oldWikiPath := ctx.Params(":page") | ||||
| 	newWikiPath := models.ToWikiPageURL(form.Title) | ||||
| 
 | ||||
| 	if err := ctx.Repo.Repository.EditWikiPage(ctx.User, oldWikiPath, newWikiPath, form.Content, form.Message); err != nil { | ||||
| 		ctx.Handle(500, "EditWikiPage", err) | ||||
| 		return | ||||
| 	} | ||||
| 
 | ||||
| 	ctx.Redirect(ctx.Repo.RepoLink + "/wiki/" + models.ToWikiPageURL(form.Title)) | ||||
| 	ctx.Redirect(ctx.Repo.RepoLink + "/wiki/" + newWikiPath) | ||||
| } | ||||
| 
 | ||||
| // DeleteWikiPagePost delete wiki page | ||||
| @ -272,8 +277,7 @@ func DeleteWikiPagePost(ctx *context.Context) { | ||||
| 		pageURL = "Home" | ||||
| 	} | ||||
| 
 | ||||
| 	pageName := models.ToWikiPageName(pageURL) | ||||
| 	if err := ctx.Repo.Repository.DeleteWikiPage(ctx.User, pageName); err != nil { | ||||
| 	if err := ctx.Repo.Repository.DeleteWikiPage(ctx.User, pageURL); err != nil { | ||||
| 		ctx.Handle(500, "DeleteWikiPage", err) | ||||
| 		return | ||||
| 	} | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user