Rename ctx.Form() to ctx.FormString() and move code into own file (#16571)

Followup from #16562 prepare for #16567

* Rename ctx.Form() to ctx.FormString()
* Reimplement FormX func to need less code and cpu cycles
* Move code into own file
This commit is contained in:
6543
2021-08-11 02:31:13 +02:00
committed by GitHub
parent 2eeae4edb6
commit c4d70a0325
64 changed files with 236 additions and 449 deletions
-36
View File
@@ -28,7 +28,6 @@ import (
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/templates"
"code.gitea.io/gitea/modules/translation"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/modules/web/middleware"
"code.gitea.io/gitea/services/auth"
@@ -287,41 +286,6 @@ func (ctx *Context) Header() http.Header {
return ctx.Resp.Header()
}
// Form returns request form as string with default
func (ctx *Context) Form(key string, defaults ...string) string {
return (*Forms)(ctx.Req).MustString(key, defaults...)
}
// FormTrim returns request form as string with default and trimmed spaces
func (ctx *Context) FormTrim(key string, defaults ...string) string {
return (*Forms)(ctx.Req).MustTrimmed(key, defaults...)
}
// FormStrings returns request form as strings with default
func (ctx *Context) FormStrings(key string, defaults ...[]string) []string {
return (*Forms)(ctx.Req).MustStrings(key, defaults...)
}
// FormInt returns request form as int with default
func (ctx *Context) FormInt(key string, defaults ...int) int {
return (*Forms)(ctx.Req).MustInt(key, defaults...)
}
// FormInt64 returns request form as int64 with default
func (ctx *Context) FormInt64(key string, defaults ...int64) int64 {
return (*Forms)(ctx.Req).MustInt64(key, defaults...)
}
// FormBool returns request form as bool with default
func (ctx *Context) FormBool(key string, defaults ...bool) bool {
return (*Forms)(ctx.Req).MustBool(key, defaults...)
}
// FormOptionalBool returns request form as OptionalBool with default
func (ctx *Context) FormOptionalBool(key string, defaults ...util.OptionalBool) util.OptionalBool {
return (*Forms)(ctx.Req).MustOptionalBool(key, defaults...)
}
// HandleText handles HTTP status code
func (ctx *Context) HandleText(status int, title string) {
if (status/100 == 4) || (status/100 == 5) {
+27 -204
View File
@@ -5,237 +5,60 @@
package context
import (
"errors"
"net/http"
"net/url"
"strconv"
"strings"
"text/template"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/util"
)
// Forms a new enhancement of http.Request
type Forms http.Request
// Values returns http.Request values
func (f *Forms) Values() url.Values {
return (*http.Request)(f).Form
// FormString returns the first value matching the provided key in the form as a string
func (ctx *Context) FormString(key string) string {
return ctx.Req.FormValue(key)
}
// String returns request form as string
func (f *Forms) String(key string) (string, error) {
return (*http.Request)(f).FormValue(key), nil
}
// Trimmed returns request form as string with trimed spaces left and right
func (f *Forms) Trimmed(key string) (string, error) {
return strings.TrimSpace((*http.Request)(f).FormValue(key)), nil
}
// Strings returns request form as strings
func (f *Forms) Strings(key string) ([]string, error) {
if (*http.Request)(f).Form == nil {
if err := (*http.Request)(f).ParseMultipartForm(32 << 20); err != nil {
return nil, err
// FormStrings returns a string slice for the provided key from the form
func (ctx *Context) FormStrings(key string) []string {
if ctx.Req.Form == nil {
if err := ctx.Req.ParseMultipartForm(32 << 20); err != nil {
return nil
}
}
if v, ok := (*http.Request)(f).Form[key]; ok {
return v, nil
}
return nil, errors.New("not exist")
}
// Escape returns request form as escaped string
func (f *Forms) Escape(key string) (string, error) {
return template.HTMLEscapeString((*http.Request)(f).FormValue(key)), nil
}
// Int returns request form as int
func (f *Forms) Int(key string) (int, error) {
return strconv.Atoi((*http.Request)(f).FormValue(key))
}
// Int32 returns request form as int32
func (f *Forms) Int32(key string) (int32, error) {
v, err := strconv.ParseInt((*http.Request)(f).FormValue(key), 10, 32)
return int32(v), err
}
// Int64 returns request form as int64
func (f *Forms) Int64(key string) (int64, error) {
return strconv.ParseInt((*http.Request)(f).FormValue(key), 10, 64)
}
// Uint returns request form as uint
func (f *Forms) Uint(key string) (uint, error) {
v, err := strconv.ParseUint((*http.Request)(f).FormValue(key), 10, 64)
return uint(v), err
}
// Uint32 returns request form as uint32
func (f *Forms) Uint32(key string) (uint32, error) {
v, err := strconv.ParseUint((*http.Request)(f).FormValue(key), 10, 32)
return uint32(v), err
}
// Uint64 returns request form as uint64
func (f *Forms) Uint64(key string) (uint64, error) {
return strconv.ParseUint((*http.Request)(f).FormValue(key), 10, 64)
}
// Bool returns request form as bool
func (f *Forms) Bool(key string) (bool, error) {
return strconv.ParseBool((*http.Request)(f).FormValue(key))
}
// Float32 returns request form as float32
func (f *Forms) Float32(key string) (float32, error) {
v, err := strconv.ParseFloat((*http.Request)(f).FormValue(key), 64)
return float32(v), err
}
// Float64 returns request form as float64
func (f *Forms) Float64(key string) (float64, error) {
return strconv.ParseFloat((*http.Request)(f).FormValue(key), 64)
}
// MustString returns request form as string with default
func (f *Forms) MustString(key string, defaults ...string) string {
if v := (*http.Request)(f).FormValue(key); len(v) > 0 {
if v, ok := ctx.Req.Form[key]; ok {
return v
}
if len(defaults) > 0 {
return defaults[0]
}
return ""
return nil
}
// MustTrimmed returns request form as string with default
func (f *Forms) MustTrimmed(key string, defaults ...string) string {
return strings.TrimSpace(f.MustString(key, defaults...))
// FormTrim returns the first value for the provided key in the form as a space trimmed string
func (ctx *Context) FormTrim(key string) string {
return strings.TrimSpace(ctx.Req.FormValue(key))
}
// MustStrings returns request form as strings with default
func (f *Forms) MustStrings(key string, defaults ...[]string) []string {
if (*http.Request)(f).Form == nil {
if err := (*http.Request)(f).ParseMultipartForm(32 << 20); err != nil {
log.Error("ParseMultipartForm: %v", err)
return []string{}
}
}
if v, ok := (*http.Request)(f).Form[key]; ok {
return v
}
if len(defaults) > 0 {
return defaults[0]
}
return []string{}
}
// MustEscape returns request form as escaped string with default
func (f *Forms) MustEscape(key string, defaults ...string) string {
if v := (*http.Request)(f).FormValue(key); len(v) > 0 {
return template.HTMLEscapeString(v)
}
if len(defaults) > 0 {
return defaults[0]
}
return ""
}
// MustInt returns request form as int with default
func (f *Forms) MustInt(key string, defaults ...int) int {
v, err := strconv.Atoi((*http.Request)(f).FormValue(key))
if len(defaults) > 0 && err != nil {
return defaults[0]
}
// FormInt returns the first value for the provided key in the form as an int
func (ctx *Context) FormInt(key string) int {
v, _ := strconv.Atoi(ctx.Req.FormValue(key))
return v
}
// MustInt32 returns request form as int32 with default
func (f *Forms) MustInt32(key string, defaults ...int32) int32 {
v, err := strconv.ParseInt((*http.Request)(f).FormValue(key), 10, 32)
if len(defaults) > 0 && err != nil {
return defaults[0]
}
return int32(v)
}
// MustInt64 returns request form as int64 with default
func (f *Forms) MustInt64(key string, defaults ...int64) int64 {
v, err := strconv.ParseInt((*http.Request)(f).FormValue(key), 10, 64)
if len(defaults) > 0 && err != nil {
return defaults[0]
}
// FormInt64 returns the first value for the provided key in the form as an int64
func (ctx *Context) FormInt64(key string) int64 {
v, _ := strconv.ParseInt(ctx.Req.FormValue(key), 10, 64)
return v
}
// MustUint returns request form as uint with default
func (f *Forms) MustUint(key string, defaults ...uint) uint {
v, err := strconv.ParseUint((*http.Request)(f).FormValue(key), 10, 64)
if len(defaults) > 0 && err != nil {
return defaults[0]
}
return uint(v)
}
// MustUint32 returns request form as uint32 with default
func (f *Forms) MustUint32(key string, defaults ...uint32) uint32 {
v, err := strconv.ParseUint((*http.Request)(f).FormValue(key), 10, 32)
if len(defaults) > 0 && err != nil {
return defaults[0]
}
return uint32(v)
}
// MustUint64 returns request form as uint64 with default
func (f *Forms) MustUint64(key string, defaults ...uint64) uint64 {
v, err := strconv.ParseUint((*http.Request)(f).FormValue(key), 10, 64)
if len(defaults) > 0 && err != nil {
return defaults[0]
}
// FormBool returns true if the value for the provided key in the form is "1" or "true"
func (ctx *Context) FormBool(key string) bool {
v, _ := strconv.ParseBool(ctx.Req.FormValue(key))
return v
}
// MustFloat32 returns request form as float32 with default
func (f *Forms) MustFloat32(key string, defaults ...float32) float32 {
v, err := strconv.ParseFloat((*http.Request)(f).FormValue(key), 32)
if len(defaults) > 0 && err != nil {
return defaults[0]
}
return float32(v)
}
// MustFloat64 returns request form as float64 with default
func (f *Forms) MustFloat64(key string, defaults ...float64) float64 {
v, err := strconv.ParseFloat((*http.Request)(f).FormValue(key), 64)
if len(defaults) > 0 && err != nil {
return defaults[0]
}
return v
}
// MustBool returns request form as bool with default
func (f *Forms) MustBool(key string, defaults ...bool) bool {
v, err := strconv.ParseBool((*http.Request)(f).FormValue(key))
if len(defaults) > 0 && err != nil {
return defaults[0]
}
return v
}
// MustOptionalBool returns request form as OptionalBool with default
func (f *Forms) MustOptionalBool(key string, defaults ...util.OptionalBool) util.OptionalBool {
value := (*http.Request)(f).FormValue(key)
// FormOptionalBool returns an OptionalBoolTrue or OptionalBoolFalse if the value
// for the provided key exists in the form else it returns OptionalBoolNone
func (ctx *Context) FormOptionalBool(key string) util.OptionalBool {
value := ctx.Req.FormValue(key)
if len(value) == 0 {
return util.OptionalBoolNone
}
v, err := strconv.ParseBool((*http.Request)(f).FormValue(key))
if len(defaults) > 0 && err != nil {
return defaults[0]
}
v, _ := strconv.ParseBool(ctx.Req.FormValue(key))
return util.OptionalBoolOf(v)
}
+4 -4
View File
@@ -346,7 +346,7 @@ func repoAssignment(ctx *Context, repo *models.Repository) {
// Check access.
if ctx.Repo.Permission.AccessMode == models.AccessModeNone {
if ctx.Form("go-get") == "1" {
if ctx.FormString("go-get") == "1" {
EarlyResponseForGoGetMeta(ctx)
return
}
@@ -415,7 +415,7 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
owner, err = models.GetUserByName(userName)
if err != nil {
if models.IsErrUserNotExist(err) {
if ctx.Form("go-get") == "1" {
if ctx.FormString("go-get") == "1" {
EarlyResponseForGoGetMeta(ctx)
return
}
@@ -437,7 +437,7 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
if err == nil {
RedirectToRepo(ctx, redirectRepoID)
} else if models.IsErrRepoRedirectNotExist(err) {
if ctx.Form("go-get") == "1" {
if ctx.FormString("go-get") == "1" {
EarlyResponseForGoGetMeta(ctx)
return
}
@@ -618,7 +618,7 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
}
}
if ctx.Form("go-get") == "1" {
if ctx.FormString("go-get") == "1" {
ctx.Data["GoGetImport"] = ComposeGoGetImport(owner.Name, repo.Name)
prefix := setting.AppURL + path.Join(owner.Name, repo.Name, "src", "branch", ctx.Repo.BranchName)
ctx.Data["GoDocDirectory"] = prefix + "{/dir}"
+1 -1
View File
@@ -42,7 +42,7 @@ func ListUnadoptedRepositories(ctx *context.APIContext) {
// "$ref": "#/responses/forbidden"
listOptions := utils.GetListOptions(ctx)
repoNames, count, err := repository.ListUnadoptedRepositories(ctx.Form("query"), &listOptions)
repoNames, count, err := repository.ListUnadoptedRepositories(ctx.FormString("query"), &listOptions)
if err != nil {
ctx.InternalServerError(err)
}
+1 -1
View File
@@ -93,7 +93,7 @@ import (
func sudo() func(ctx *context.APIContext) {
return func(ctx *context.APIContext) {
sudo := ctx.Form("sudo")
sudo := ctx.FormString("sudo")
if len(sudo) == 0 {
sudo = ctx.Req.Header.Get("Sudo")
}
+2 -2
View File
@@ -171,7 +171,7 @@ func ReadRepoNotifications(ctx *context.APIContext) {
// "$ref": "#/responses/empty"
lastRead := int64(0)
qLastRead := strings.Trim(ctx.Form("last_read_at"), " ")
qLastRead := strings.Trim(ctx.FormString("last_read_at"), " ")
if len(qLastRead) > 0 {
tmpLastRead, err := time.Parse(time.RFC3339, qLastRead)
if err != nil {
@@ -200,7 +200,7 @@ func ReadRepoNotifications(ctx *context.APIContext) {
return
}
targetStatus := statusStringToNotificationStatus(ctx.Form("to-status"))
targetStatus := statusStringToNotificationStatus(ctx.FormString("to-status"))
if targetStatus == 0 {
targetStatus = models.NotificationStatusRead
}
+1 -1
View File
@@ -82,7 +82,7 @@ func ReadThread(ctx *context.APIContext) {
return
}
targetStatus := statusStringToNotificationStatus(ctx.Form("to-status"))
targetStatus := statusStringToNotificationStatus(ctx.FormString("to-status"))
if targetStatus == 0 {
targetStatus = models.NotificationStatusRead
}
+2 -2
View File
@@ -122,7 +122,7 @@ func ReadNotifications(ctx *context.APIContext) {
// "$ref": "#/responses/empty"
lastRead := int64(0)
qLastRead := strings.Trim(ctx.Form("last_read_at"), " ")
qLastRead := strings.Trim(ctx.FormString("last_read_at"), " ")
if len(qLastRead) > 0 {
tmpLastRead, err := time.Parse(time.RFC3339, qLastRead)
if err != nil {
@@ -147,7 +147,7 @@ func ReadNotifications(ctx *context.APIContext) {
return
}
targetStatus := statusStringToNotificationStatus(ctx.Form("to-status"))
targetStatus := statusStringToNotificationStatus(ctx.FormString("to-status"))
if targetStatus == 0 {
targetStatus = models.NotificationStatusRead
}
+1 -1
View File
@@ -43,7 +43,7 @@ func ListLabels(ctx *context.APIContext) {
// "200":
// "$ref": "#/responses/LabelList"
labels, err := models.GetLabelsByOrgID(ctx.Org.Organization.ID, ctx.Form("sort"), utils.GetListOptions(ctx))
labels, err := models.GetLabelsByOrgID(ctx.Org.Organization.ID, ctx.FormString("sort"), utils.GetListOptions(ctx))
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetLabelsByOrgID", err)
return
+2 -2
View File
@@ -658,9 +658,9 @@ func SearchTeam(ctx *context.APIContext) {
opts := &models.SearchTeamOptions{
UserID: ctx.User.ID,
Keyword: strings.TrimSpace(ctx.Form("q")),
Keyword: strings.TrimSpace(ctx.FormString("q")),
OrgID: ctx.Org.Organization.ID,
IncludeDesc: ctx.Form("include_desc") == "" || ctx.FormBool("include_desc"),
IncludeDesc: ctx.FormString("include_desc") == "" || ctx.FormBool("include_desc"),
ListOptions: listOptions,
}
+1 -1
View File
@@ -147,7 +147,7 @@ func GetAllCommits(ctx *context.APIContext) {
listOptions.PageSize = setting.Git.CommitsRangeSize
}
sha := ctx.Form("sha")
sha := ctx.FormString("sha")
var baseCommit *git.Commit
if len(sha) == 0 {
+11 -11
View File
@@ -106,7 +106,7 @@ func SearchIssues(ctx *context.APIContext) {
}
var isClosed util.OptionalBool
switch ctx.Form("state") {
switch ctx.FormString("state") {
case "closed":
isClosed = util.OptionalBoolTrue
case "all":
@@ -140,7 +140,7 @@ func SearchIssues(ctx *context.APIContext) {
var issues []*models.Issue
var filteredCount int64
keyword := strings.Trim(ctx.Form("q"), " ")
keyword := strings.Trim(ctx.FormString("q"), " ")
if strings.IndexByte(keyword, 0) >= 0 {
keyword = ""
}
@@ -153,7 +153,7 @@ func SearchIssues(ctx *context.APIContext) {
}
var isPull util.OptionalBool
switch ctx.Form("type") {
switch ctx.FormString("type") {
case "pulls":
isPull = util.OptionalBoolTrue
case "issues":
@@ -162,13 +162,13 @@ func SearchIssues(ctx *context.APIContext) {
isPull = util.OptionalBoolNone
}
labels := strings.TrimSpace(ctx.Form("labels"))
labels := strings.TrimSpace(ctx.FormString("labels"))
var includedLabelNames []string
if len(labels) > 0 {
includedLabelNames = strings.Split(labels, ",")
}
milestones := strings.TrimSpace(ctx.Form("milestones"))
milestones := strings.TrimSpace(ctx.FormString("milestones"))
var includedMilestones []string
if len(milestones) > 0 {
includedMilestones = strings.Split(milestones, ",")
@@ -319,7 +319,7 @@ func ListIssues(ctx *context.APIContext) {
}
var isClosed util.OptionalBool
switch ctx.Form("state") {
switch ctx.FormString("state") {
case "closed":
isClosed = util.OptionalBoolTrue
case "all":
@@ -331,7 +331,7 @@ func ListIssues(ctx *context.APIContext) {
var issues []*models.Issue
var filteredCount int64
keyword := strings.Trim(ctx.Form("q"), " ")
keyword := strings.Trim(ctx.FormString("q"), " ")
if strings.IndexByte(keyword, 0) >= 0 {
keyword = ""
}
@@ -345,7 +345,7 @@ func ListIssues(ctx *context.APIContext) {
}
}
if splitted := strings.Split(ctx.Form("labels"), ","); len(splitted) > 0 {
if splitted := strings.Split(ctx.FormString("labels"), ","); len(splitted) > 0 {
labelIDs, err = models.GetLabelIDsInRepoByNames(ctx.Repo.Repository.ID, splitted)
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetLabelIDsInRepoByNames", err)
@@ -354,7 +354,7 @@ func ListIssues(ctx *context.APIContext) {
}
var mileIDs []int64
if part := strings.Split(ctx.Form("milestones"), ","); len(part) > 0 {
if part := strings.Split(ctx.FormString("milestones"), ","); len(part) > 0 {
for i := range part {
// uses names and fall back to ids
// non existent milestones are discarded
@@ -386,7 +386,7 @@ func ListIssues(ctx *context.APIContext) {
listOptions := utils.GetListOptions(ctx)
var isPull util.OptionalBool
switch ctx.Form("type") {
switch ctx.FormString("type") {
case "pulls":
isPull = util.OptionalBoolTrue
case "issues":
@@ -448,7 +448,7 @@ func ListIssues(ctx *context.APIContext) {
}
func getUserIDForFilter(ctx *context.APIContext, queryName string) int64 {
userName := ctx.Form(queryName)
userName := ctx.FormString(queryName)
if len(userName) == 0 {
return 0
}
+2 -2
View File
@@ -90,7 +90,7 @@ func ListTrackedTimes(ctx *context.APIContext) {
IssueID: issue.ID,
}
qUser := strings.Trim(ctx.Form("user"), " ")
qUser := strings.Trim(ctx.FormString("user"), " ")
if qUser != "" {
user, err := models.GetUserByName(qUser)
if models.IsErrUserNotExist(err) {
@@ -500,7 +500,7 @@ func ListTrackedTimesByRepository(ctx *context.APIContext) {
}
// Filters
qUser := strings.Trim(ctx.Form("user"), " ")
qUser := strings.Trim(ctx.FormString("user"), " ")
if qUser != "" {
user, err := models.GetUserByName(qUser)
if models.IsErrUserNotExist(err) {
+1 -1
View File
@@ -78,7 +78,7 @@ func ListDeployKeys(ctx *context.APIContext) {
var keys []*models.DeployKey
var err error
fingerprint := ctx.Form("fingerprint")
fingerprint := ctx.FormString("fingerprint")
keyID := ctx.FormInt64("key_id")
if fingerprint != "" || keyID != 0 {
keys, err = models.SearchDeployKeys(ctx.Repo.Repository.ID, keyID, fingerprint)
+1 -1
View File
@@ -49,7 +49,7 @@ func ListLabels(ctx *context.APIContext) {
// "200":
// "$ref": "#/responses/LabelList"
labels, err := models.GetLabelsByRepoID(ctx.Repo.Repository.ID, ctx.Form("sort"), utils.GetListOptions(ctx))
labels, err := models.GetLabelsByRepoID(ctx.Repo.Repository.ID, ctx.FormString("sort"), utils.GetListOptions(ctx))
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetLabelsByRepoID", err)
return
+2 -2
View File
@@ -60,8 +60,8 @@ func ListMilestones(ctx *context.APIContext) {
milestones, err := models.GetMilestones(models.GetMilestonesOption{
ListOptions: utils.GetListOptions(ctx),
RepoID: ctx.Repo.Repository.ID,
State: api.StateType(ctx.Form("state")),
Name: ctx.Form("name"),
State: api.StateType(ctx.FormString("state")),
Name: ctx.FormString("name"),
})
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetMilestones", err)
+1 -1
View File
@@ -190,7 +190,7 @@ func CreateReleaseAttachment(ctx *context.APIContext) {
}
var filename = header.Filename
if query := ctx.Form("name"); query != "" {
if query := ctx.FormString("name"); query != "" {
filename = query
}
+8 -8
View File
@@ -135,19 +135,19 @@ func Search(ctx *context.APIContext) {
opts := &models.SearchRepoOptions{
ListOptions: utils.GetListOptions(ctx),
Actor: ctx.User,
Keyword: strings.Trim(ctx.Form("q"), " "),
Keyword: strings.Trim(ctx.FormString("q"), " "),
OwnerID: ctx.FormInt64("uid"),
PriorityOwnerID: ctx.FormInt64("priority_owner_id"),
TeamID: ctx.FormInt64("team_id"),
TopicOnly: ctx.FormBool("topic"),
Collaborate: util.OptionalBoolNone,
Private: ctx.IsSigned && (ctx.Form("private") == "" || ctx.FormBool("private")),
Private: ctx.IsSigned && (ctx.FormString("private") == "" || ctx.FormBool("private")),
Template: util.OptionalBoolNone,
StarredByID: ctx.FormInt64("starredBy"),
IncludeDescription: ctx.FormBool("includeDesc"),
}
if ctx.Form("template") != "" {
if ctx.FormString("template") != "" {
opts.Template = util.OptionalBoolOf(ctx.FormBool("template"))
}
@@ -155,7 +155,7 @@ func Search(ctx *context.APIContext) {
opts.Collaborate = util.OptionalBoolFalse
}
var mode = ctx.Form("mode")
var mode = ctx.FormString("mode")
switch mode {
case "source":
opts.Fork = util.OptionalBoolFalse
@@ -173,17 +173,17 @@ func Search(ctx *context.APIContext) {
return
}
if ctx.Form("archived") != "" {
if ctx.FormString("archived") != "" {
opts.Archived = util.OptionalBoolOf(ctx.FormBool("archived"))
}
if ctx.Form("is_private") != "" {
if ctx.FormString("is_private") != "" {
opts.IsPrivate = util.OptionalBoolOf(ctx.FormBool("is_private"))
}
var sortMode = ctx.Form("sort")
var sortMode = ctx.FormString("sort")
if len(sortMode) > 0 {
var sortOrder = ctx.Form("order")
var sortOrder = ctx.FormString("order")
if len(sortOrder) == 0 {
sortOrder = "asc"
}
+1 -1
View File
@@ -274,7 +274,7 @@ func TopicSearch(ctx *context.APIContext) {
return
}
kw := ctx.Form("q")
kw := ctx.FormString("q")
listOptions := utils.GetListOptions(ctx)
+1 -1
View File
@@ -48,7 +48,7 @@ func listPublicKeys(ctx *context.APIContext, user *models.User) {
var keys []*models.PublicKey
var err error
fingerprint := ctx.Form("fingerprint")
fingerprint := ctx.FormString("fingerprint")
username := ctx.Params("username")
if fingerprint != "" {
+1 -1
View File
@@ -58,7 +58,7 @@ func Search(ctx *context.APIContext) {
opts := &models.SearchUserOptions{
Actor: ctx.User,
Keyword: strings.Trim(ctx.Form("q"), " "),
Keyword: strings.Trim(ctx.FormString("q"), " "),
UID: ctx.FormInt64("uid"),
Type: models.UserTypeIndividual,
ListOptions: listOptions,
+1 -1
View File
@@ -54,7 +54,7 @@ func parseTime(value string) (int64, error) {
// prepareQueryArg unescape and trim a query arg
func prepareQueryArg(ctx *context.APIContext, name string) (value string, err error) {
value, err = url.PathUnescape(ctx.Form(name))
value, err = url.PathUnescape(ctx.FormString(name))
value = strings.TrimSpace(value)
return
}
+1 -1
View File
@@ -50,7 +50,7 @@ func UpdatePublicKeyInRepo(ctx *context.PrivateContext) {
// AuthorizedPublicKeyByContent searches content as prefix (leak e-mail part)
// and returns public key found.
func AuthorizedPublicKeyByContent(ctx *context.PrivateContext) {
content := ctx.Form("content")
content := ctx.FormString("content")
publicKey, err := models.SearchPublicKeyByContent(content)
if err != nil {
+6 -6
View File
@@ -161,7 +161,7 @@ func DashboardPost(ctx *context.Context) {
// SendTestMail send test mail to confirm mail service is OK
func SendTestMail(ctx *context.Context) {
email := ctx.Form("email")
email := ctx.FormString("email")
// Send a test email to the user's email address and redirect back to Config
if err := mailer.SendTestMail(email); err != nil {
ctx.Flash.Error(ctx.Tr("admin.config.test_mail_failed", email, err))
@@ -377,7 +377,7 @@ func Flush(ctx *context.Context) {
ctx.Status(404)
return
}
timeout, err := time.ParseDuration(ctx.Form("timeout"))
timeout, err := time.ParseDuration(ctx.FormString("timeout"))
if err != nil {
timeout = -1
}
@@ -405,7 +405,7 @@ func AddWorkers(ctx *context.Context) {
ctx.Redirect(setting.AppSubURL + "/admin/monitor/queue/" + strconv.FormatInt(qid, 10))
return
}
timeout, err := time.ParseDuration(ctx.Form("timeout"))
timeout, err := time.ParseDuration(ctx.FormString("timeout"))
if err != nil {
ctx.Flash.Error(ctx.Tr("admin.monitor.queue.pool.addworkers.musttimeoutduration"))
ctx.Redirect(setting.AppSubURL + "/admin/monitor/queue/" + strconv.FormatInt(qid, 10))
@@ -435,9 +435,9 @@ func SetQueueSettings(ctx *context.Context) {
return
}
maxNumberStr := ctx.Form("max-number")
numberStr := ctx.Form("number")
timeoutStr := ctx.Form("timeout")
maxNumberStr := ctx.FormString("max-number")
numberStr := ctx.FormString("number")
timeoutStr := ctx.FormString("timeout")
var err error
var maxNumber, number int
+7 -7
View File
@@ -51,8 +51,8 @@ func Emails(ctx *context.Context) {
orderBy models.SearchEmailOrderBy
)
ctx.Data["SortType"] = ctx.Form("sort")
switch ctx.Form("sort") {
ctx.Data["SortType"] = ctx.FormString("sort")
switch ctx.FormString("sort") {
case "email":
orderBy = models.SearchEmailOrderByEmail
case "reverseemail":
@@ -68,10 +68,10 @@ func Emails(ctx *context.Context) {
opts.Keyword = ctx.FormTrim("q")
opts.SortType = orderBy
if len(ctx.Form("is_activated")) != 0 {
if len(ctx.FormString("is_activated")) != 0 {
opts.IsActivated = util.OptionalBoolOf(ctx.FormBool("activated"))
}
if len(ctx.Form("is_primary")) != 0 {
if len(ctx.FormString("is_primary")) != 0 {
opts.IsPrimary = util.OptionalBoolOf(ctx.FormBool("primary"))
}
@@ -114,9 +114,9 @@ func ActivateEmail(ctx *context.Context) {
truefalse := map[string]bool{"1": true, "0": false}
uid := ctx.FormInt64("uid")
email := ctx.Form("email")
primary, okp := truefalse[ctx.Form("primary")]
activate, oka := truefalse[ctx.Form("activate")]
email := ctx.FormString("email")
primary, okp := truefalse[ctx.FormString("primary")]
activate, oka := truefalse[ctx.FormString("activate")]
if uid == 0 || len(email) == 0 || !okp || !oka {
ctx.Error(http.StatusBadRequest)
+5 -5
View File
@@ -59,7 +59,7 @@ func DeleteRepo(ctx *context.Context) {
ctx.Flash.Success(ctx.Tr("repo.settings.deletion_success"))
ctx.JSON(http.StatusOK, map[string]interface{}{
"redirect": setting.AppSubURL + "/admin/repos?page=" + ctx.Form("page") + "&sort=" + ctx.Form("sort"),
"redirect": setting.AppSubURL + "/admin/repos?page=" + ctx.FormString("page") + "&sort=" + ctx.FormString("sort"),
})
}
@@ -83,7 +83,7 @@ func UnadoptedRepos(ctx *context.Context) {
doSearch := ctx.FormBool("search")
ctx.Data["search"] = doSearch
q := ctx.Form("q")
q := ctx.FormString("q")
if !doSearch {
pager := context.NewPagination(0, opts.PageSize, opts.Page, 5)
@@ -109,10 +109,10 @@ func UnadoptedRepos(ctx *context.Context) {
// AdoptOrDeleteRepository adopts or deletes a repository
func AdoptOrDeleteRepository(ctx *context.Context) {
dir := ctx.Form("id")
action := ctx.Form("action")
dir := ctx.FormString("id")
action := ctx.FormString("action")
page := ctx.FormInt("page")
q := ctx.Form("q")
q := ctx.FormString("q")
dirSplit := strings.SplitN(dir, "/", 2)
if len(dirSplit) != 2 {
+3 -3
View File
@@ -33,14 +33,14 @@ func Code(ctx *context.Context) {
ctx.Data["PageIsExplore"] = true
ctx.Data["PageIsExploreCode"] = true
language := strings.TrimSpace(ctx.Form("l"))
keyword := strings.TrimSpace(ctx.Form("q"))
language := strings.TrimSpace(ctx.FormString("l"))
keyword := strings.TrimSpace(ctx.FormString("q"))
page := ctx.FormInt("page")
if page <= 0 {
page = 1
}
queryType := strings.TrimSpace(ctx.Form("t"))
queryType := strings.TrimSpace(ctx.FormString("t"))
isMatch := queryType == "match"
var (
+3 -3
View File
@@ -42,8 +42,8 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
orderBy models.SearchOrderBy
)
ctx.Data["SortType"] = ctx.Form("sort")
switch ctx.Form("sort") {
ctx.Data["SortType"] = ctx.FormString("sort")
switch ctx.FormString("sort") {
case "newest":
orderBy = models.SearchOrderByNewest
case "oldest":
@@ -73,7 +73,7 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
orderBy = models.SearchOrderByRecentUpdated
}
keyword := strings.Trim(ctx.Form("q"), " ")
keyword := strings.Trim(ctx.FormString("q"), " ")
topicOnly := ctx.FormBool("topic")
ctx.Data["TopicOnly"] = topicOnly
+3 -3
View File
@@ -44,8 +44,8 @@ func RenderUserSearch(ctx *context.Context, opts *models.SearchUserOptions, tplN
orderBy models.SearchOrderBy
)
ctx.Data["SortType"] = ctx.Form("sort")
switch ctx.Form("sort") {
ctx.Data["SortType"] = ctx.FormString("sort")
switch ctx.FormString("sort") {
case "newest":
orderBy = models.SearchOrderByIDReverse
case "oldest":
@@ -63,7 +63,7 @@ func RenderUserSearch(ctx *context.Context, opts *models.SearchUserOptions, tplN
orderBy = models.SearchOrderByAlphabetically
}
opts.Keyword = strings.Trim(ctx.Form("q"), " ")
opts.Keyword = strings.Trim(ctx.FormString("q"), " ")
opts.OrderBy = orderBy
if len(opts.Keyword) == 0 || isKeywordValid(opts.Keyword) {
users, count, err = models.SearchUsers(opts)
+1 -1
View File
@@ -18,7 +18,7 @@ import (
)
func goGet(ctx *context.Context) {
if ctx.Req.Method != "GET" || ctx.Form("go-get") != "1" || len(ctx.Req.URL.Query()) > 1 {
if ctx.Req.Method != "GET" || ctx.FormString("go-get") != "1" || len(ctx.Req.URL.Query()) > 1 {
return
}

Some files were not shown because too many files have changed in this diff Show More