Attachment 'EmbedWikiPage-1.2.3-3.py'
Download 1 """
2 MoinMoin - EmbedWikiPage a macro to embed a wiki page from a different wiki
3 @license: GNU GPL, see COPYING for details.
4
5 PURPOSE:
6 This macro is used to embed a wiki page into the current wikipage.
7 It is possible to embed local pages as well as external wiki pages.
8
9 if a WikiName is detected the name is translated into a link to the original page.
10 On some circumstances a WikiName is not detected, see RESTRICTIONS.
11
12 The page is embedded temporary and you get at the end a link to edit the original page.
13
14 At this stage it could be used to embed single pages e.g. macro explanaitions from moinmoin
15
16 CALLING SEQUENCE:
17 [[EmbedWikiPage(site,name)]]
18
19
20 INPUTS:
21 site: the URL of the wiki where the page is on
22 name: the wikiname of the page
23
24 EXAMPLE:
25 [[EmbedWikiPage(http://moinmoin.wikiwikiweb.de:8000/,ProcessorMarket/sctable)]]
26
27 PROCEDURE:
28 * Editing of an embedded page is always editing the original page.
29 * wiki:, wiki:/ or [" "] page and normal !WikiName links are followed to their original locations
30 * attachments are embedded
31
32 Please remove the version number from the routine name!
33
34 RESTRICTIONS:
35 * at the moment it follows nearly all wiki links
36
37 I have a simple mechanism to detect wiki:, wiki:/ or ["HOWTO"] and normal !WikiName pagelinks
38
39 At the moment I don't find !WikiName which are inserted into tabulars and macros.
40
41 Later on it would be fine to use the icon of the page (favicon)
42 to show where are the links from.
43
44 MODIFICATION:
45 @copyright: 2004-09-26 by Reimar Bauer (R.Bauer@fz-juelich.de) EmbedWikiPage-1.2.3-1
46 2004-09-28: RB 1.2.3-2 !WikiName is now supported (some cases are missing)
47 2004-09-28: RB 1.2.3-3 !WikiName rules extended
48 DISCUSSION:
49 * NEED HELP to find WikiName in some cases
50
51
52
53 """
54 import string
55 import os
56 import urllib
57 from MoinMoin.parser import wiki
58 from MoinMoin import wikiutil
59
60 def fetchfile(urlopener, url):
61 #Copyright (c) 2002-2003 Gustavo Niemeyer <niemeyer@conectiva.com>
62 # adopted by Reimar Bauer
63 geturl = url+"?action=raw"
64 filename, headers = urlopener.retrieve(geturl)
65 return filename
66
67 def get_urlopener(moinurl):
68 #Copyright (c) 2002-2003 Gustavo Niemeyer <niemeyer@conectiva.com>
69 # adopted by Reimar Bauer
70 urlopener = urllib.URLopener()
71 proxy = os.environ.get("http_proxy")
72 if proxy:
73 urlopener.proxies.update({"http": proxy})
74 return urlopener
75
76
77 def execute(macro, text):
78
79 request=macro.request
80 formatter=macro.formatter
81
82 if text:
83 args=text.split(',')
84 else:
85 args=[]
86 number_args=len(args)
87 if number_args < 2:
88 return macro.formatter.sysmsg('Not enough arguments to EmbedWikiPage macro')
89
90
91 site=wikiutil.escape(string.join(args[0],''), quote=1)
92 name=wikiutil.escape(string.join(args[1],''), quote=1)
93
94 url="%(site)s%(name)s" %{
95 "site": site,
96 "name": name
97 }
98
99 urlopener = get_urlopener(url)
100
101 moinfile = fetchfile(urlopener, url)
102
103 id = open(moinfile, "r")
104 txt=id.readlines()
105 id.close()
106
107 # simple but not finished
108
109 # I need this routine already to show the macro help pages which are on moinmoin.
110
111 i=0
112 for line in txt:
113
114 test=line.lstrip()
115
116 if ((test.find('=') == -1 ) and (test.find('#!') == -1 ) and (test.find('{{{') == -1 )and (test.find('}}}') == -1 )):
117
118
119 line=string.replace(line,"attachment:",site+name+'?action=AttachFile&do=get&target=')
120 txt[i]=line
121 words=line.split()
122
123 for w in words:
124
125 if (w.find('.') > -1):
126 w=string.replace(w,'.','')
127 if (w.find(',') > -1):
128 w=string.replace(w,',','')
129 if (w.find('!') > 0):
130 w=string.replace(w,'!','')
131 if (w.find(';') > -1):
132 w=string.replace(w,';','')
133 if (w.find('/') == 0):
134 line=string.replace(line,w,' ['+site+name+w+' '+w+']')
135
136 if (w.find('wiki:/') > -1):
137 s=string.replace(w,'_','_5f')
138 line=string.replace(line,w,s)
139 line=string.replace(line,"wiki:/",site+name+'/')
140
141
142 if (w.find('wiki:') > -1):
143 s=string.replace(w,'_','_5f')
144 line=string.replace(line,w,s)
145 line=string.replace(line,"wiki:",site)
146
147 if (string.join(w[0]) == '['):
148 if (string.join(w[1]) == '"'):
149 word=w[2:]
150 pos=word.find('"')
151 word=word[0:pos]
152 pos=w.find(']')
153 w=w[0:pos]
154 line=string.replace(line,w,' ['+site+word+' '+word)
155
156
157
158 if wikiutil.isStrictWikiname(w):
159 if (w.find('_') > -1):
160 w=string.replace(w,'_','_5f')
161 line=string.replace(line,w,' ['+site+w+' '+w+']')
162
163 if (test.find('#!EmbedWikiPage') > -1):
164 line=string.replace(line,'#!EmbedWikiPage','#!EmbedWikiPage-1.2.3-3') # it's only if its used to call itselfs, till I know how to test if a site exists
165 txt[i]=line
166 i=i+1
167
168 wikiizer = wiki.Parser(string.join(txt,""),request)
169 wikiizer.format(formatter)
170
171 edit_url=url+'?action=edit'
172
173 edit_icon=request.theme.make_icon("edit")
174
175 request.write('<HR>')
176 cmd="<a title=%(edit_url)s href=%(edit_url)s > %(edit_icon)s %(txt)s</a>" % {
177 "edit_url":'"'+edit_url+'"',
178 "edit_icon":edit_icon,
179 "txt":'Edit embeded page '+name+' on '+site
180 }
181
182
183 request.write(cmd)
184 return ""
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.