Show More
@@ -118,26 +118,11 b' class hgweb(object):' | |||||
118 | return req |
|
118 | return req | |
119 |
|
119 | |||
120 | def run_wsgi(self, req): |
|
120 | def run_wsgi(self, req): | |
121 | def header(**map): |
|
121 | ||
122 | header_file = cStringIO.StringIO( |
|
122 | self.refresh() | |
123 | ''.join(self.t("header", encoding=self.encoding, **map))) |
|
|||
124 | msg = mimetools.Message(header_file, 0) |
|
|||
125 | req.header(msg.items()) |
|
|||
126 | yield header_file.read() |
|
|||
127 |
|
123 | |||
128 | def rawfileheader(**map): |
|
124 | # expand form shortcuts | |
129 | req.header([('Content-type', map['mimetype']), |
|
|||
130 | ('Content-disposition', 'filename=%s' % map['file']), |
|
|||
131 | ('Content-length', str(len(map['raw'])))]) |
|
|||
132 | yield '' |
|
|||
133 |
|
125 | |||
134 | def footer(**map): |
|
|||
135 | yield self.t("footer", **map) |
|
|||
136 |
|
||||
137 | def motd(**map): |
|
|||
138 | yield self.config("web", "motd", "") |
|
|||
139 |
|
||||
140 | def expand_form(form): |
|
|||
141 |
|
|
126 | shortcuts = { | |
142 |
|
|
127 | 'cl': [('cmd', ['changelog']), ('rev', None)], | |
143 |
|
|
128 | 'sl': [('cmd', ['shortlog']), ('rev', None)], | |
@@ -154,15 +139,15 b' class hgweb(object):' | |||||
154 |
|
|
139 | } | |
155 |
|
140 | |||
156 |
|
|
141 | for k in shortcuts.iterkeys(): | |
157 |
|
|
142 | if k in req.form: | |
158 |
|
|
143 | for name, value in shortcuts[k]: | |
159 |
|
|
144 | if value is None: | |
160 |
|
|
145 | value = req.form[k] | |
161 |
|
|
146 | req.form[name] = value | |
162 |
|
|
147 | del req.form[k] | |
163 |
|
148 | |||
164 | def rewrite_request(req): |
|
149 | # work with CGI variables to create coherent structure | |
165 | '''translate new web interface to traditional format''' |
|
150 | # use SCRIPT_NAME, PATH_INFO and QUERY_STRING as well as our REPO_NAME | |
166 |
|
151 | |||
167 |
|
|
152 | req.url = req.env['SCRIPT_NAME'] | |
168 |
|
|
153 | if not req.url.endswith('/'): | |
@@ -180,19 +165,17 b' class hgweb(object):' | |||||
180 |
|
|
165 | query = req.env['QUERY_STRING'].split('&', 1)[0] | |
181 |
|
|
166 | query = query.split(';', 1)[0] | |
182 |
|
167 | |||
183 | if req.form.has_key('cmd'): |
|
168 | # translate user-visible url structure to internal structure | |
184 | # old style |
|
|||
185 | return |
|
|||
186 |
|
169 | |||
187 |
|
|
170 | args = query.split('/', 2) | |
188 |
|
|
171 | if 'cmd' not in req.form and args and args[0]: | |
189 | return |
|
|||
190 |
|
172 | |||
191 | cmd = args.pop(0) |
|
173 | cmd = args.pop(0) | |
192 | style = cmd.rfind('-') |
|
174 | style = cmd.rfind('-') | |
193 | if style != -1: |
|
175 | if style != -1: | |
194 | req.form['style'] = [cmd[:style]] |
|
176 | req.form['style'] = [cmd[:style]] | |
195 | cmd = cmd[style+1:] |
|
177 | cmd = cmd[style+1:] | |
|
178 | ||||
196 | # avoid accepting e.g. style parameter as command |
|
179 | # avoid accepting e.g. style parameter as command | |
197 | if hasattr(webcommands, cmd): |
|
180 | if hasattr(webcommands, cmd): | |
198 | req.form['cmd'] = [cmd] |
|
181 | req.form['cmd'] = [cmd] | |
@@ -213,27 +196,8 b' class hgweb(object):' | |||||
213 | req.form['node'] = [fn[:-len(ext)]] |
|
196 | req.form['node'] = [fn[:-len(ext)]] | |
214 | req.form['type'] = [type_] |
|
197 | req.form['type'] = [type_] | |
215 |
|
198 | |||
216 | def sessionvars(**map): |
|
199 | # determine scheme, port and server name | |
217 | fields = [] |
|
200 | # this is needed to create absolute urls | |
218 | if req.form.has_key('style'): |
|
|||
219 | style = req.form['style'][0] |
|
|||
220 | if style != self.config('web', 'style', ''): |
|
|||
221 | fields.append(('style', style)) |
|
|||
222 |
|
||||
223 | separator = req.url[-1] == '?' and ';' or '?' |
|
|||
224 | for name, value in fields: |
|
|||
225 | yield dict(name=name, value=value, separator=separator) |
|
|||
226 | separator = ';' |
|
|||
227 |
|
||||
228 | self.refresh() |
|
|||
229 |
|
||||
230 | expand_form(req.form) |
|
|||
231 | rewrite_request(req) |
|
|||
232 |
|
||||
233 | style = self.config("web", "style", "") |
|
|||
234 | if req.form.has_key('style'): |
|
|||
235 | style = req.form['style'][0] |
|
|||
236 | mapfile = style_map(self.templatepath, style) |
|
|||
237 |
|
201 | |||
238 | proto = req.env.get('wsgi.url_scheme') |
|
202 | proto = req.env.get('wsgi.url_scheme') | |
239 | if proto == 'https': |
|
203 | if proto == 'https': | |
@@ -250,6 +214,44 b' class hgweb(object):' | |||||
250 | if not staticurl.endswith('/'): |
|
214 | if not staticurl.endswith('/'): | |
251 | staticurl += '/' |
|
215 | staticurl += '/' | |
252 |
|
216 | |||
|
217 | # some functions for the templater | |||
|
218 | ||||
|
219 | def header(**map): | |||
|
220 | header_file = cStringIO.StringIO( | |||
|
221 | ''.join(self.t("header", encoding=self.encoding, **map))) | |||
|
222 | msg = mimetools.Message(header_file, 0) | |||
|
223 | req.header(msg.items()) | |||
|
224 | yield header_file.read() | |||
|
225 | ||||
|
226 | def rawfileheader(**map): | |||
|
227 | req.header([('Content-type', map['mimetype']), | |||
|
228 | ('Content-disposition', 'filename=%s' % map['file']), | |||
|
229 | ('Content-length', str(len(map['raw'])))]) | |||
|
230 | yield '' | |||
|
231 | ||||
|
232 | def footer(**map): | |||
|
233 | yield self.t("footer", **map) | |||
|
234 | ||||
|
235 | def motd(**map): | |||
|
236 | yield self.config("web", "motd", "") | |||
|
237 | ||||
|
238 | def sessionvars(**map): | |||
|
239 | fields = [] | |||
|
240 | if req.form.has_key('style'): | |||
|
241 | style = req.form['style'][0] | |||
|
242 | if style != self.config('web', 'style', ''): | |||
|
243 | fields.append(('style', style)) | |||
|
244 | ||||
|
245 | separator = req.url[-1] == '?' and ';' or '?' | |||
|
246 | for name, value in fields: | |||
|
247 | yield dict(name=name, value=value, separator=separator) | |||
|
248 | separator = ';' | |||
|
249 | ||||
|
250 | style = self.config("web", "style", "") | |||
|
251 | if req.form.has_key('style'): | |||
|
252 | style = req.form['style'][0] | |||
|
253 | mapfile = style_map(self.templatepath, style) | |||
|
254 | ||||
253 | if not self.reponame: |
|
255 | if not self.reponame: | |
254 | self.reponame = (self.config("web", "name") |
|
256 | self.reponame = (self.config("web", "name") | |
255 | or req.env.get('REPO_NAME') |
|
257 | or req.env.get('REPO_NAME') |
General Comments 0
You need to be logged in to leave comments.
Login now