##// END OF EJS Templates
hgweb: perform all parameter lookup via qsparams...
Gregory Szorc -
r36881:3d60a22e default
parent child Browse files
Show More
@@ -332,7 +332,7 b' class hgweb(object):'
332 332 # translate user-visible url structure to internal structure
333 333
334 334 args = query.split('/', 2)
335 if 'cmd' not in wsgireq.form and args and args[0]:
335 if 'cmd' not in req.qsparams and args and args[0]:
336 336 cmd = args.pop(0)
337 337 style = cmd.rfind('-')
338 338 if style != -1:
@@ -364,16 +364,16 b' class hgweb(object):'
364 364 req.qsparams['style'] = 'raw'
365 365
366 366 if cmd == 'archive':
367 fn = wsgireq.form['node'][0]
367 fn = req.qsparams['node']
368 368 for type_, spec in rctx.archivespecs.iteritems():
369 369 ext = spec[2]
370 370 if fn.endswith(ext):
371 371 wsgireq.form['node'] = [fn[:-len(ext)]]
372 req.qsparams['node'] = fn[:-len(next)]
372 req.qsparams['node'] = fn[:-len(ext)]
373 373 wsgireq.form['type'] = [type_]
374 374 req.qsparams['type'] = type_
375 375 else:
376 cmd = wsgireq.form.get('cmd', [''])[0]
376 cmd = req.qsparams.get('cmd', '')
377 377
378 378 # process the web interface request
379 379
@@ -389,7 +389,7 b' class hgweb(object):'
389 389 if cmd == '':
390 390 wsgireq.form['cmd'] = [tmpl.cache['default']]
391 391 req.qsparams['cmd'] = tmpl.cache['default']
392 cmd = wsgireq.form['cmd'][0]
392 cmd = req.qsparams['cmd']
393 393
394 394 # Don't enable caching if using a CSP nonce because then it wouldn't
395 395 # be a nonce.
@@ -229,6 +229,8 b' class hgwebdir(object):'
229 229 yield r
230 230
231 231 def _runwsgi(self, wsgireq):
232 req = wsgireq.req
233
232 234 try:
233 235 self.refresh()
234 236
@@ -242,11 +244,11 b' class hgwebdir(object):'
242 244 ctype = templater.stringify(ctype)
243 245
244 246 # a static file
245 if virtual.startswith('static/') or 'static' in wsgireq.form:
247 if virtual.startswith('static/') or 'static' in req.qsparams:
246 248 if virtual.startswith('static/'):
247 249 fname = virtual[7:]
248 250 else:
249 fname = wsgireq.form['static'][0]
251 fname = req.qsparams['static']
250 252 static = self.ui.config("web", "static", None,
251 253 untrusted=False)
252 254 if not static:
@@ -471,8 +473,8 b' class hgwebdir(object):'
471 473 self.refresh()
472 474 sortable = ["name", "description", "contact", "lastchange"]
473 475 sortcolumn, descending = sortdefault
474 if 'sort' in wsgireq.form:
475 sortcolumn = wsgireq.form['sort'][0]
476 if 'sort' in wsgireq.req.qsparams:
477 sortcolum = wsgireq.req.qsparams['sort']
476 478 descending = sortcolumn.startswith('-')
477 479 if descending:
478 480 sortcolumn = sortcolumn[1:]
@@ -85,7 +85,7 b' def log(web, req, tmpl):'
85 85 file will be shown. This form is equivalent to the ``filelog`` handler.
86 86 """
87 87
88 if 'file' in req.form and req.form['file'][0]:
88 if req.req.qsparams.get('file'):
89 89 return filelog(web, req, tmpl)
90 90 else:
91 91 return changelog(web, req, tmpl)
@@ -94,7 +94,7 b' def log(web, req, tmpl):'
94 94 def rawfile(web, req, tmpl):
95 95 guessmime = web.configbool('web', 'guessmime')
96 96
97 path = webutil.cleanpath(web.repo, req.form.get('file', [''])[0])
97 path = webutil.cleanpath(web.repo, req.req.qsparams.get('file', ''))
98 98 if not path:
99 99 content = manifest(web, req, tmpl)
100 100 req.respond(HTTP_OK, web.ctype)
@@ -173,7 +173,7 b' def file(web, req, tmpl):'
173 173 If ``path`` is not defined, information about the root directory will
174 174 be rendered.
175 175 """
176 path = webutil.cleanpath(web.repo, req.form.get('file', [''])[0])
176 path = webutil.cleanpath(web.repo, req.req.qsparams.get('file', ''))
177 177 if not path:
178 178 return manifest(web, req, tmpl)
179 179 try:
@@ -289,11 +289,11 b' def _search(web, req, tmpl):'
289 289 if count >= revcount:
290 290 break
291 291
292 query = req.form['rev'][0]
292 query = req.req.qsparams['rev']
293 293 revcount = web.maxchanges
294 if 'revcount' in req.form:
294 if 'revcount' in req.req.qsparams:
295 295 try:
296 revcount = int(req.form.get('revcount', [revcount])[0])
296 revcount = int(req.req.qsparams.get('revcount', revcount))
297 297 revcount = max(revcount, 1)
298 298 tmpl.defaults['sessionvars']['revcount'] = revcount
299 299 except ValueError:
@@ -308,7 +308,7 b' def _search(web, req, tmpl):'
308 308
309 309 mode, funcarg = getsearchmode(query)
310 310
311 if 'forcekw' in req.form:
311 if 'forcekw' in req.req.qsparams:
312 312 showforcekw = ''
313 313 showunforcekw = searchfuncs[mode][1]
314 314 mode = MODE_KEYWORD
@@ -358,10 +358,10 b' def changelog(web, req, tmpl, shortlog=F'
358 358 """
359 359
360 360 query = ''
361 if 'node' in req.form:
361 if 'node' in req.req.qsparams:
362 362 ctx = webutil.changectx(web.repo, req)
363 363 symrev = webutil.symrevorshortnode(req, ctx)
364 elif 'rev' in req.form:
364 elif 'rev' in req.req.qsparams:
365 365 return _search(web, req, tmpl)
366 366 else:
367 367 ctx = web.repo['tip']
@@ -386,9 +386,9 b' def changelog(web, req, tmpl, shortlog=F'
386 386 else:
387 387 revcount = web.maxchanges
388 388
389 if 'revcount' in req.form:
389 if 'revcount' in req.req.qsparams:
390 390 try:
391 revcount = int(req.form.get('revcount', [revcount])[0])
391 revcount = int(req.req.qsparams.get('revcount', revcount))
392 392 revcount = max(revcount, 1)
393 393 tmpl.defaults['sessionvars']['revcount'] = revcount
394 394 except ValueError:
@@ -481,13 +481,13 b' def manifest(web, req, tmpl):'
481 481
482 482 The ``manifest`` template will be rendered for this handler.
483 483 """
484 if 'node' in req.form:
484 if 'node' in req.req.qsparams:
485 485 ctx = webutil.changectx(web.repo, req)
486 486 symrev = webutil.symrevorshortnode(req, ctx)
487 487 else:
488 488 ctx = web.repo['tip']
489 489 symrev = 'tip'
490 path = webutil.cleanpath(web.repo, req.form.get('file', [''])[0])
490 path = webutil.cleanpath(web.repo, req.req.qsparams.get('file', ''))
491 491 mf = ctx.manifest()
492 492 node = ctx.node()
493 493
@@ -752,7 +752,7 b' def filediff(web, req, tmpl):'
752 752 fctx = webutil.filectx(web.repo, req)
753 753 except LookupError:
754 754 ctx = webutil.changectx(web.repo, req)
755 path = webutil.cleanpath(web.repo, req.form['file'][0])
755 path = webutil.cleanpath(web.repo, req.req.qsparams['file'])
756 756 if path not in ctx.files():
757 757 raise
758 758
@@ -799,13 +799,13 b' def comparison(web, req, tmpl):'
799 799 The ``filecomparison`` template is rendered.
800 800 """
801 801 ctx = webutil.changectx(web.repo, req)
802 if 'file' not in req.form:
802 if 'file' not in req.req.qsparams:
803 803 raise ErrorResponse(HTTP_NOT_FOUND, 'file not given')
804 path = webutil.cleanpath(web.repo, req.form['file'][0])
804 path = webutil.cleanpath(web.repo, req.req.qsparams['file'])
805 805
806 806 parsecontext = lambda v: v == 'full' and -1 or int(v)
807 if 'context' in req.form:
808 context = parsecontext(req.form['context'][0])
807 if 'context' in req.req.qsparams:
808 context = parsecontext(req.req.qsparams['context'])
809 809 else:
810 810 context = parsecontext(web.config('web', 'comparisoncontext', '5'))
811 811
@@ -964,7 +964,7 b' def filelog(web, req, tmpl):'
964 964 f = fctx.path()
965 965 fl = fctx.filelog()
966 966 except error.LookupError:
967 f = webutil.cleanpath(web.repo, req.form['file'][0])
967 f = webutil.cleanpath(web.repo, req.req.qsparams['file'])
968 968 fl = web.repo.file(f)
969 969 numrevs = len(fl)
970 970 if not numrevs: # file doesn't exist at all
@@ -979,9 +979,9 b' def filelog(web, req, tmpl):'
979 979 fctx = web.repo.filectx(f, fl.linkrev(frev))
980 980
981 981 revcount = web.maxshortchanges
982 if 'revcount' in req.form:
982 if 'revcount' in req.req.qsparams:
983 983 try:
984 revcount = int(req.form.get('revcount', [revcount])[0])
984 revcount = int(req.req.qsparams.get('revcount', revcount))
985 985 revcount = max(revcount, 1)
986 986 tmpl.defaults['sessionvars']['revcount'] = revcount
987 987 except ValueError:
@@ -994,12 +994,12 b' def filelog(web, req, tmpl):'
994 994 morevars = copy.copy(tmpl.defaults['sessionvars'])
995 995 morevars['revcount'] = revcount * 2
996 996
997 patch = 'patch' in req.form
997 patch = 'patch' in req.req.qsparams
998 998 if patch:
999 lessvars['patch'] = morevars['patch'] = req.form['patch'][0]
1000 descend = 'descend' in req.form
999 lessvars['patch'] = morevars['patch'] = req.req.qsparams['patch']
1000 descend = 'descend' in req.req.qsparams
1001 1001 if descend:
1002 lessvars['descend'] = morevars['descend'] = req.form['descend'][0]
1002 lessvars['descend'] = morevars['descend'] = req.req.qsparams['descend']
1003 1003
1004 1004 count = fctx.filerev() + 1
1005 1005 start = max(0, count - revcount) # first rev on this page
@@ -1103,9 +1103,9 b' def archive(web, req, tmpl):'
1103 1103 No template is used for this handler. Raw, binary content is generated.
1104 1104 """
1105 1105
1106 type_ = req.form.get('type', [None])[0]
1106 type_ = req.req.qsparams.get('type')
1107 1107 allowed = web.configlist("web", "allow_archive")
1108 key = req.form['node'][0]
1108 key = req.req.qsparams['node']
1109 1109
1110 1110 if type_ not in web.archivespecs:
1111 1111 msg = 'Unsupported archive type: %s' % type_
@@ -1126,15 +1126,15 b' def archive(web, req, tmpl):'
1126 1126 ctx = webutil.changectx(web.repo, req)
1127 1127 pats = []
1128 1128 match = scmutil.match(ctx, [])
1129 file = req.form.get('file', None)
1129 file = req.req.qsparams.get('file')
1130 1130 if file:
1131 pats = ['path:' + file[0]]
1131 pats = ['path:' + file]
1132 1132 match = scmutil.match(ctx, pats, default='path')
1133 1133 if pats:
1134 1134 files = [f for f in ctx.manifest().keys() if match(f)]
1135 1135 if not files:
1136 1136 raise ErrorResponse(HTTP_NOT_FOUND,
1137 'file(s) not found: %s' % file[0])
1137 'file(s) not found: %s' % file)
1138 1138
1139 1139 mimetype, artype, extension, encoding = web.archivespecs[type_]
1140 1140 headers = [
@@ -1153,7 +1153,7 b' def archive(web, req, tmpl):'
1153 1153
1154 1154 @webcommand('static')
1155 1155 def static(web, req, tmpl):
1156 fname = req.form['file'][0]
1156 fname = req.req.qsparams['file']
1157 1157 # a repo owner may set web.static in .hg/hgrc to get any file
1158 1158 # readable by the user running the CGI script
1159 1159 static = web.config("web", "static", None, untrusted=False)
@@ -1189,7 +1189,7 b' def graph(web, req, tmpl):'
1189 1189 This handler will render the ``graph`` template.
1190 1190 """
1191 1191
1192 if 'node' in req.form:
1192 if 'node' in req.req.qsparams:
1193 1193 ctx = webutil.changectx(web.repo, req)
1194 1194 symrev = webutil.symrevorshortnode(req, ctx)
1195 1195 else:
@@ -1199,9 +1199,9 b' def graph(web, req, tmpl):'
1199 1199
1200 1200 bg_height = 39
1201 1201 revcount = web.maxshortchanges
1202 if 'revcount' in req.form:
1202 if 'revcount' in req.req.qsparams:
1203 1203 try:
1204 revcount = int(req.form.get('revcount', [revcount])[0])
1204 revcount = int(req.req.qsparams.get('revcount', revcount))
1205 1205 revcount = max(revcount, 1)
1206 1206 tmpl.defaults['sessionvars']['revcount'] = revcount
1207 1207 except ValueError:
@@ -1212,7 +1212,7 b' def graph(web, req, tmpl):'
1212 1212 morevars = copy.copy(tmpl.defaults['sessionvars'])
1213 1213 morevars['revcount'] = revcount * 2
1214 1214
1215 graphtop = req.form.get('graphtop', [ctx.hex()])[0]
1215 graphtop = req.req.qsparams.get('graphtop', ctx.hex())
1216 1216 graphvars = copy.copy(tmpl.defaults['sessionvars'])
1217 1217 graphvars['graphtop'] = graphtop
1218 1218
@@ -1342,7 +1342,7 b' def help(web, req, tmpl):'
1342 1342 """
1343 1343 from .. import commands, help as helpmod # avoid cycle
1344 1344
1345 topicname = req.form.get('node', [None])[0]
1345 topicname = req.req.qsparams.get('node')
1346 1346 if not topicname:
1347 1347 def topics(**map):
1348 1348 for entries, summary, _doc in helpmod.helptable:
@@ -177,7 +177,7 b' def difffeatureopts(req, ui, section):'
177 177 section=section, whitespace=True)
178 178
179 179 for k in ('ignorews', 'ignorewsamount', 'ignorewseol', 'ignoreblanklines'):
180 v = req.form.get(k, [None])[0]
180 v = req.req.qsparams.get(k)
181 181 if v is not None:
182 182 v = util.parsebool(v)
183 183 setattr(diffopts, k, v if v is not None else True)
@@ -295,19 +295,19 b' def changeidctx(repo, changeid):'
295 295
296 296 def changectx(repo, req):
297 297 changeid = "tip"
298 if 'node' in req.form:
299 changeid = req.form['node'][0]
298 if 'node' in req.req.qsparams:
299 changeid = req.req.qsparams['node']
300 300 ipos = changeid.find(':')
301 301 if ipos != -1:
302 302 changeid = changeid[(ipos + 1):]
303 elif 'manifest' in req.form:
304 changeid = req.form['manifest'][0]
303 elif 'manifest' in req.req.qsparams:
304 changeid = req.req.qsparams['manifest']
305 305
306 306 return changeidctx(repo, changeid)
307 307
308 308 def basechangectx(repo, req):
309 if 'node' in req.form:
310 changeid = req.form['node'][0]
309 if 'node' in req.req.qsparams:
310 changeid = req.req.qsparams['node']
311 311 ipos = changeid.find(':')
312 312 if ipos != -1:
313 313 changeid = changeid[:ipos]
@@ -316,13 +316,13 b' def basechangectx(repo, req):'
316 316 return None
317 317
318 318 def filectx(repo, req):
319 if 'file' not in req.form:
319 if 'file' not in req.req.qsparams:
320 320 raise ErrorResponse(HTTP_NOT_FOUND, 'file not given')
321 path = cleanpath(repo, req.form['file'][0])
322 if 'node' in req.form:
323 changeid = req.form['node'][0]
324 elif 'filenode' in req.form:
325 changeid = req.form['filenode'][0]
321 path = cleanpath(repo, req.req.qsparams['file'])
322 if 'node' in req.req.qsparams:
323 changeid = req.req.qsparams['node']
324 elif 'filenode' in req.req.qsparams:
325 changeid = req.req.qsparams['filenode']
326 326 else:
327 327 raise ErrorResponse(HTTP_NOT_FOUND, 'node or filenode not given')
328 328 try:
@@ -333,8 +333,8 b' def filectx(repo, req):'
333 333 return fctx
334 334
335 335 def linerange(req):
336 linerange = req.form.get('linerange')
337 if linerange is None:
336 linerange = req.req.qsparams.getall('linerange')
337 if not linerange:
338 338 return None
339 339 if len(linerange) > 1:
340 340 raise ErrorResponse(HTTP_BAD_REQUEST,
@@ -412,8 +412,8 b' def changelistentry(web, ctx, tmpl):'
412 412 return entry
413 413
414 414 def symrevorshortnode(req, ctx):
415 if 'node' in req.form:
416 return templatefilters.revescape(req.form['node'][0])
415 if 'node' in req.req.qsparams:
416 return templatefilters.revescape(req.req.qsparams['node'])
417 417 else:
418 418 return short(ctx.node())
419 419
@@ -10,7 +10,7 b' def raiseerror(web, req, tmpl):'
10 10 '''Dummy web command that raises an uncaught Exception.'''
11 11
12 12 # Simulate an error after partial response.
13 if 'partialresponse' in req.form:
13 if 'partialresponse' in req.req.qsparams:
14 14 req.respond(200, 'text/plain')
15 15 req.write('partial content\n')
16 16
General Comments 0
You need to be logged in to leave comments. Login now