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