Attachment 'HttpLink-1.1.py'
Download 1 # -*- coding: iso-8859-1 -*-
2 """
3 MoinMoin - HttpLink macro Version 1.1, 07.03.2015
4
5 Inserts a local wiki page link as an external link, for stituations where
6 it would be helpful to show the full URL, such as pages intended to be
7 printed or saved in PDF formated.
8
9 Syntax:
10 <<HttpLink>>; <<HttpLink()>>
11 <<HttpLink(page)>>
12
13 Version 1.1 - 07.03.2015: import get_host from version 1.9.8
14
15 Version 1.0 - 24.06.2014: initial version.
16
17 @copyright: 2014-2015 Ian Riley <ian@riley.asia>
18 license: GNU GPL, see COPYING for details.
19
20 """
21
22 from MoinMoin import wikiutil
23 from MoinMoin.Page import Page
24 try:
25 from werkzeug.utils import get_host # moinmoin 1.9.2
26 except:
27 from werkzeug.wsgi import get_host # moinmoin 1.9.8
28
29 def execute(macro, args):
30 request = macro.request
31 page_name = macro.formatter.page.page_name
32 result = []
33
34 url_page = page_name
35 if args:
36 url_page = args
37
38 if Page(request, url_page).exists():
39 url_page = wikiutil.AbsPageName(page_name, url_page)
40 url_page = url_page.replace(' ','_')
41
42 url_base = get_host(request.environ) + '/'
43 if request.script_root:
44 url_base += request.script_root + '/'
45
46 target = 'http://' + (url_base + url_page).replace('//','/')
47
48 result.extend([
49 '\n',
50 macro.formatter.url(1, target, css='http') +
51 macro.formatter.text(target) +
52 macro.formatter.url(0)
53 ])
54
55 return ''.join(result)
You are not allowed to attach a file to this page.