Show More
@@ -135,6 +135,74 b' class requestcontext(object):' | |||
|
135 | 135 | if typ in allowed or self.configbool('web', 'allow%s' % typ): |
|
136 | 136 | yield {'type': typ, 'extension': spec[2], 'node': nodeid} |
|
137 | 137 | |
|
138 | def templater(self, req): | |
|
139 | # determine scheme, port and server name | |
|
140 | # this is needed to create absolute urls | |
|
141 | ||
|
142 | proto = req.env.get('wsgi.url_scheme') | |
|
143 | if proto == 'https': | |
|
144 | proto = 'https' | |
|
145 | default_port = '443' | |
|
146 | else: | |
|
147 | proto = 'http' | |
|
148 | default_port = '80' | |
|
149 | ||
|
150 | port = req.env['SERVER_PORT'] | |
|
151 | port = port != default_port and (':' + port) or '' | |
|
152 | urlbase = '%s://%s%s' % (proto, req.env['SERVER_NAME'], port) | |
|
153 | logourl = self.config('web', 'logourl', 'http://mercurial.selenic.com/') | |
|
154 | logoimg = self.config('web', 'logoimg', 'hglogo.png') | |
|
155 | staticurl = self.config('web', 'staticurl') or req.url + 'static/' | |
|
156 | if not staticurl.endswith('/'): | |
|
157 | staticurl += '/' | |
|
158 | ||
|
159 | # some functions for the templater | |
|
160 | ||
|
161 | def motd(**map): | |
|
162 | yield self.config('web', 'motd', '') | |
|
163 | ||
|
164 | # figure out which style to use | |
|
165 | ||
|
166 | vars = {} | |
|
167 | styles = ( | |
|
168 | req.form.get('style', [None])[0], | |
|
169 | self.config('web', 'style'), | |
|
170 | 'paper', | |
|
171 | ) | |
|
172 | style, mapfile = templater.stylemap(styles, self.templatepath) | |
|
173 | if style == styles[0]: | |
|
174 | vars['style'] = style | |
|
175 | ||
|
176 | start = req.url[-1] == '?' and '&' or '?' | |
|
177 | sessionvars = webutil.sessionvars(vars, start) | |
|
178 | ||
|
179 | if not self.reponame: | |
|
180 | self.reponame = (self.config('web', 'name') | |
|
181 | or req.env.get('REPO_NAME') | |
|
182 | or req.url.strip('/') or self.repo.root) | |
|
183 | ||
|
184 | def websubfilter(text): | |
|
185 | return websub(text, self.websubtable) | |
|
186 | ||
|
187 | # create the templater | |
|
188 | ||
|
189 | tmpl = templater.templater(mapfile, | |
|
190 | filters={'websub': websubfilter}, | |
|
191 | defaults={'url': req.url, | |
|
192 | 'logourl': logourl, | |
|
193 | 'logoimg': logoimg, | |
|
194 | 'staticurl': staticurl, | |
|
195 | 'urlbase': urlbase, | |
|
196 | 'repo': self.reponame, | |
|
197 | 'encoding': encoding.encoding, | |
|
198 | 'motd': motd, | |
|
199 | 'sessionvars': sessionvars, | |
|
200 | 'pathdef': makebreadcrumb(req.url), | |
|
201 | 'style': style, | |
|
202 | }) | |
|
203 | return tmpl | |
|
204 | ||
|
205 | ||
|
138 | 206 | class hgweb(object): |
|
139 | 207 | """HTTP server for individual repositories. |
|
140 | 208 | |
@@ -173,12 +241,6 b' class hgweb(object):' | |||
|
173 | 241 | self.reponame = name |
|
174 | 242 | self.websubtable = webutil.getwebsubs(r) |
|
175 | 243 | |
|
176 | # The CGI scripts are often run by a user different from the repo owner. | |
|
177 | # Trust the settings from the .hg/hgrc files by default. | |
|
178 | def config(self, section, name, default=None, untrusted=True): | |
|
179 | return self.repo.ui.config(section, name, default, | |
|
180 | untrusted=untrusted) | |
|
181 | ||
|
182 | 244 | def _getview(self, repo): |
|
183 | 245 | """The 'web.view' config controls changeset filter to hgweb. Possible |
|
184 | 246 | values are ``served``, ``visible`` and ``all``. Default is ``served``. |
@@ -336,7 +398,7 b' class hgweb(object):' | |||
|
336 | 398 | # process the web interface request |
|
337 | 399 | |
|
338 | 400 | try: |
|
339 |
tmpl = |
|
|
401 | tmpl = rctx.templater(req) | |
|
340 | 402 | ctype = tmpl('mimetype', encoding=encoding.encoding) |
|
341 | 403 | ctype = templater.stringify(ctype) |
|
342 | 404 | |
@@ -379,74 +441,6 b' class hgweb(object):' | |||
|
379 | 441 | return [''] |
|
380 | 442 | return tmpl('error', error=inst.message) |
|
381 | 443 | |
|
382 | def templater(self, req): | |
|
383 | ||
|
384 | # determine scheme, port and server name | |
|
385 | # this is needed to create absolute urls | |
|
386 | ||
|
387 | proto = req.env.get('wsgi.url_scheme') | |
|
388 | if proto == 'https': | |
|
389 | proto = 'https' | |
|
390 | default_port = "443" | |
|
391 | else: | |
|
392 | proto = 'http' | |
|
393 | default_port = "80" | |
|
394 | ||
|
395 | port = req.env["SERVER_PORT"] | |
|
396 | port = port != default_port and (":" + port) or "" | |
|
397 | urlbase = '%s://%s%s' % (proto, req.env['SERVER_NAME'], port) | |
|
398 | logourl = self.config("web", "logourl", "http://mercurial.selenic.com/") | |
|
399 | logoimg = self.config("web", "logoimg", "hglogo.png") | |
|
400 | staticurl = self.config("web", "staticurl") or req.url + 'static/' | |
|
401 | if not staticurl.endswith('/'): | |
|
402 | staticurl += '/' | |
|
403 | ||
|
404 | # some functions for the templater | |
|
405 | ||
|
406 | def motd(**map): | |
|
407 | yield self.config("web", "motd", "") | |
|
408 | ||
|
409 | # figure out which style to use | |
|
410 | ||
|
411 | vars = {} | |
|
412 | styles = ( | |
|
413 | req.form.get('style', [None])[0], | |
|
414 | self.config('web', 'style'), | |
|
415 | 'paper', | |
|
416 | ) | |
|
417 | style, mapfile = templater.stylemap(styles, self.templatepath) | |
|
418 | if style == styles[0]: | |
|
419 | vars['style'] = style | |
|
420 | ||
|
421 | start = req.url[-1] == '?' and '&' or '?' | |
|
422 | sessionvars = webutil.sessionvars(vars, start) | |
|
423 | ||
|
424 | if not self.reponame: | |
|
425 | self.reponame = (self.config("web", "name") | |
|
426 | or req.env.get('REPO_NAME') | |
|
427 | or req.url.strip('/') or self.repo.root) | |
|
428 | ||
|
429 | def websubfilter(text): | |
|
430 | return websub(text, self.websubtable) | |
|
431 | ||
|
432 | # create the templater | |
|
433 | ||
|
434 | tmpl = templater.templater(mapfile, | |
|
435 | filters={"websub": websubfilter}, | |
|
436 | defaults={"url": req.url, | |
|
437 | "logourl": logourl, | |
|
438 | "logoimg": logoimg, | |
|
439 | "staticurl": staticurl, | |
|
440 | "urlbase": urlbase, | |
|
441 | "repo": self.reponame, | |
|
442 | "encoding": encoding.encoding, | |
|
443 | "motd": motd, | |
|
444 | "sessionvars": sessionvars, | |
|
445 | "pathdef": makebreadcrumb(req.url), | |
|
446 | "style": style, | |
|
447 | }) | |
|
448 | return tmpl | |
|
449 | ||
|
450 | 444 | def check_perm(self, rctx, req, op): |
|
451 | 445 | for permhook in permhooks: |
|
452 | 446 | permhook(rctx, req, op) |
General Comments 0
You need to be logged in to leave comments.
Login now