Attachment 'HelpOn-1.3.5-4.py'
Download 1 # -*- coding: iso-8859-1 -*-
2 """
3 MoinMoin - HelpOn Action Macro
4
5 PURPOSE:
6 This action macro is used to get help on an other extensions
7
8 CALLING SEQUENCE:
9 http://WikiServer/WikiName?action=HelpOn
10
11 PROCEDURE:
12 You get a pull down list of available extensions and after selection
13 the help from inside of the routine is shown
14
15 The extensions below the MoinMoin path are indicated by the prefix MM-
16 While the others are indicated by a W- in the list
17
18 Please remove the version number from the filename.
19
20 MODIFICATION HISTORY:
21 @copyright: 2005 by Reimar Bauer (R.Bauer@fz-juelich.de)
22 @license: GNU GPL, see COPYING for details.
23 Version: 1.3.5-1
24
25 1.3.5-2 bug fix if no routine desription is defined
26 minor change from table output to preformatted text
27
28 1.3.5-3 code refactored
29 1.3.5-4 PRE does not need an additional line break
30
31 """
32
33 import string, codecs, os
34 from MoinMoin import config, wikiutil, wikiaction, user, macro, action, parser
35 from MoinMoin.Page import Page
36 from MoinMoin.formatter.text_html import Formatter
37
38 def HelpOn_Extract_Help(module_path_name,module_name):
39 file = codecs.open(module_path_name, 'r')
40 lines = file.readlines()
41 file.close()
42
43 index=[]
44 i = 0
45 for line in lines:
46 if line.strip() == '"""' :
47 index.append(i)
48 i+=1
49
50 if len(index) >= 2 :
51 txt = lines[(index[0])+1:index[1]]
52 else :
53 txt = ["no help available for %(name)s" % {"name": module_name}]
54
55 return (txt)
56
57 def HelpOn(request,pagename,module):
58
59 request.formatter = Formatter(request)
60
61 mod = module.split(':')
62 module_type = mod[0]
63
64 this_type= module_type.split('-')
65
66 module_type = this_type[1]
67 module_name = mod[1]
68
69 if this_type[0] == 'MM' :
70
71 module_path_name = "%(path)s/%(module_type)s/%(name)s.py" % {
72 "module_type": module_type,
73 "path" : request.cfg.moinmoin_dir,
74 "name" : module_name }
75
76 if this_type[0] == 'W' :
77 module_path_name = "%(path)s/plugin/%(module_type)s/%(name)s.py" % {
78 "module_type": module_type,
79 "path" : request.cfg.data_dir,
80 "name" : module_name }
81
82 info = HelpOn_Extract_Help(module_path_name,module)
83 html = "<PRE>%(txt)s</PRE>" % {
84 "txt" : string.join(info)}
85
86 request.http_headers()
87 request.setContentLanguage(request.lang)
88 wikiutil.send_title(request, pagename,
89 pagename=pagename)
90 request.write(request.formatter.startContent("content"))
91
92 request.write(html)
93 request.write(request.formatter.endContent())
94 wikiutil.send_footer(request, pagename)
95 msg = None
96
97 if msg:
98 AttachFile.error_msg(pagename, request, msg)
99
100 return()
101
102
103 def execute(pagename, request):
104
105 _ = request.getText
106 actname = __name__.split('.')[-1]
107
108 thispage = Page(request,pagename)
109
110 if request.form.has_key('button') and request.form.has_key('ticket'):
111 # check whether this is a valid ticket request (make outside
112 # attacks harder by requiring two full HTTP transactions)
113 if not wikiutil.checkTicket(request.form['ticket'][0]) :
114 return thispage.send_page(request,
115 msg = _('Please use the interactive user interface for HelpOn extensions!'))
116
117 module = request.form.get('helpon', [u''])[0]
118
119 return (HelpOn(request,pagename,module))
120
121
122 html = []
123 for name in action.extension_actions :
124 if not name in request.cfg.excluded_actions:
125 html.append("<OPTION>MM-action:%(name)s</OPTION>" % { "name":name})
126 for name in wikiaction.getPlugins(request)[1]:
127 html.append("<OPTION>W-action:%(name)s</OPTION>" % { "name":name})
128
129 for name in macro.extension_macros :
130 html.append("<OPTION>MM-macro:%(name)s</OPTION>" % { "name":name})
131
132 for name in wikiutil.wikiPlugins('macro', request.cfg):
133 html.append("<OPTION>W-macro:%(name)s</OPTION>" % { "name":name})
134
135 for name in parser.modules :
136 html.append("<OPTION>MM-parser:%(name)s</OPTION>" % { "name":name})
137
138 for name in wikiutil.wikiPlugins('parser', request.cfg):
139 html.append("<OPTION>W-parser:%(name)s</OPTION>" % { "name":name})
140
141
142 formhtml = '''
143 <form method="post" action="">
144 <select name="helpon" size="1">
145 %(option)s
146 </select>
147 <input type="hidden" name="action" value="%(actname)s">
148 <input type="submit" name="button" value="%(button)s">
149 <input type="hidden" name="ticket" value="%(ticket)s">
150 <p>
151 </form>''' % {
152 'actname': 'HelpOn',
153 'ticket' : wikiutil.createTicket(),
154 'option' : string.join(html),
155 'button' : 'Help'}
156
157 return thispage.send_page(request, msg=formhtml)
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.