Attachment 'HelpOn-1.5.1-5.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 1.5.1-5 removed request.cfg.excluded_actions
32
33 """
34
35 import string, codecs, os
36 from MoinMoin import config, wikiutil, wikiaction, user, macro, action, parser
37 from MoinMoin.Page import Page
38 from MoinMoin.formatter.text_html import Formatter
39
40 def HelpOn_Extract_Help(module_path_name,module_name):
41 file = codecs.open(module_path_name, 'r')
42 lines = file.readlines()
43 file.close()
44
45 index=[]
46 i = 0
47 for line in lines:
48 if line.strip() == '"""' :
49 index.append(i)
50 i+=1
51
52 if len(index) >= 2 :
53 txt = lines[(index[0])+1:index[1]]
54 else :
55 txt = ["no help available for %(name)s" % {"name": module_name}]
56
57 return (txt)
58
59 def HelpOn(request,pagename,module):
60
61 request.formatter = Formatter(request)
62
63 mod = module.split(':')
64 module_type = mod[0]
65
66 this_type= module_type.split('-')
67
68 module_type = this_type[1]
69 module_name = mod[1]
70
71 if this_type[0] == 'MM' :
72
73 module_path_name = "%(path)s/%(module_type)s/%(name)s.py" % {
74 "module_type": module_type,
75 "path" : request.cfg.moinmoin_dir,
76 "name" : module_name }
77
78 if this_type[0] == 'W' :
79 module_path_name = "%(path)s/plugin/%(module_type)s/%(name)s.py" % {
80 "module_type": module_type,
81 "path" : request.cfg.data_dir,
82 "name" : module_name }
83
84 info = HelpOn_Extract_Help(module_path_name,module)
85 html = "<PRE>%(txt)s</PRE>" % {
86 "txt" : string.join(info)}
87
88 request.http_headers()
89 request.setContentLanguage(request.lang)
90 wikiutil.send_title(request, pagename,
91 pagename=pagename)
92 request.write(request.formatter.startContent("content"))
93
94 request.write(html)
95 request.write(request.formatter.endContent())
96 wikiutil.send_footer(request, pagename)
97 msg = None
98
99 if msg:
100 AttachFile.error_msg(pagename, request, msg)
101
102 return()
103
104
105 def execute(pagename, request):
106
107 _ = request.getText
108 actname = __name__.split('.')[-1]
109
110 thispage = Page(request,pagename)
111
112 if request.form.has_key('button') and request.form.has_key('ticket'):
113 # check whether this is a valid ticket request (make outside
114 # attacks harder by requiring two full HTTP transactions)
115 if not wikiutil.checkTicket(request.form['ticket'][0]) :
116 return thispage.send_page(request,
117 msg = _('Please use the interactive user interface for HelpOn extensions!'))
118
119 module = request.form.get('helpon', [u''])[0]
120
121 return (HelpOn(request,pagename,module))
122
123
124 html = []
125 for name in action.extension_actions :
126 html.append("<OPTION>MM-action:%(name)s</OPTION>" % { "name":name})
127
128 for name in wikiaction.getPlugins(request)[1]:
129 html.append("<OPTION>W-action:%(name)s</OPTION>" % { "name":name})
130
131 for name in macro.extension_macros :
132 html.append("<OPTION>MM-macro:%(name)s</OPTION>" % { "name":name})
133
134 for name in wikiutil.wikiPlugins('macro', request.cfg):
135 html.append("<OPTION>W-macro:%(name)s</OPTION>" % { "name":name})
136
137 for name in parser.modules :
138 html.append("<OPTION>MM-parser:%(name)s</OPTION>" % { "name":name})
139
140 for name in wikiutil.wikiPlugins('parser', request.cfg):
141 html.append("<OPTION>W-parser:%(name)s</OPTION>" % { "name":name})
142
143
144 formhtml = '''
145 <form method="post" action="">
146 <select name="helpon" size="1">
147 %(option)s
148 </select>
149 <input type="hidden" name="action" value="%(actname)s">
150 <input type="submit" name="button" value="%(button)s">
151 <input type="hidden" name="ticket" value="%(ticket)s">
152 <p>
153 </form>''' % {
154 'actname': 'HelpOn',
155 'ticket' : wikiutil.createTicket(),
156 'option' : string.join(html),
157 'button' : 'Help'}
158
159 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.