Attachment 'RecommendPage-1.3.4-3.py'
Download 1 # -*- coding: iso-8859-1 -*-
2 """
3 MoinMoin - RecommendPage Action Macro
4
5 PURPOSE:
6 This macro is used to recommend a page to an other wiki user.
7
8 CALLING SEQUENCE:
9 http://localhost:8080/WikiName?action=RecommendPage
10
11 PROCEDURE:
12 You get an input mask to enter the username of the one where you like to send the recommendation. This is then stored on a page named WikiName/RecommendedPage as an wiki itemlist with the link and the first five lines in plain text. At the end your user SIG is written.
13 A new entry is always written on top of the page.
14
15 If you don't enter a name the recommendation is done to your name
16
17 Please remove the version number from the filename.
18
19 MODIFICATION HISTORY:
20 @copyright: 2005 by Reimar Bauer (R.Bauer@fz-juelich.de)
21 @license: GNU GPL, see COPYING for details.
22 Version: 1.3.4-1
23
24 2005-04-19 : Version 1.3.4-2
25 acl line on top of recommendation is set for a valid user/RecommendedPage to
26 WikiName:admin,read,write,delete All:read,write
27 otherwise for All:read,write
28 If the page user/RecommendedPage already exist acl right given on that page are used.
29 output changed similiar to the search output.
30
31 2005-04-21 : Version 1.3.4-3
32 output changed into calling ShortText()
33 e.g. * ["RulesForUnzip"] [[ShortText(RulesForUnzip)]] ... @SIG@
34 it is also checked by now if acls are enabled in the config
35
36 """
37
38 import string
39 from MoinMoin import config, wikiutil, user, wikiacl, search
40 from MoinMoin.Page import Page
41 from MoinMoin.PageEditor import PageEditor
42
43 def ACLparse(request, body):
44 """
45 taken from wikiacl and simply changed to return acl text and body without acl definition
46 renamed from parseACL to ACLparse
47 """
48
49 if not request.cfg.acl_enabled:
50 return AccessControlList(request),body
51
52
53 acl_lines = []
54 while body and body[0] == '#':
55 # extract first line
56 try:
57 line, body = body.split('\n', 1)
58 except ValueError:
59 line = body
60 body = ''
61
62 # end parsing on empty (invalid) PI
63 if line == "#":
64 break
65
66 # skip comments (lines with two hash marks)
67 if line[1] == '#':
68 continue
69
70 tokens = line.split(None, 1)
71 if tokens[0].lower() == "#acl":
72 if len(tokens) == 2:
73 args = tokens[1].rstrip()
74 else:
75 args = ""
76 acl_lines.append(args)
77 return acl_lines,body
78
79 def RecommendPage(request,pagename,username):
80 if config.allow_subpages:
81 delimiter = "/"
82 else:
83 delimiter = ""
84
85 name=username + delimiter + "RecommendedPage"
86 page = PageEditor(request,name)
87 if request.user.may.write(name):
88
89 newtext=u" * %(pagename)s %(about)s ...\n %(username)s\n" % {
90 "pagename": '["'+pagename+'"]',
91 "about":"[[ShortText(%(pagename)s)]]" % {
92 "pagename": pagename},
93 "username":"@SIG@"}
94
95 rev = page.current_rev()
96 if not page.exists() :
97 if request.cfg.acl_enabled:
98 if (user.getUserId(request, username) != None):
99 acl="#acl %(username)s:admin,read,write,delete All:read,write\n" % {
100 "username":username}
101 else:
102 acl="#acl All:read,write\n"
103 else:
104 acl=""
105 PageEditor.saveText(page,acl+newtext,rev)
106
107 else:
108 body = page.get_raw_body()
109 given_acl,body = ACLparse(request, body)
110
111 if len(string.join(given_acl,"")) > 0:
112 acl="#acl %(given_acl)s \n" % {
113 "given_acl":string.join(given_acl,"\n")}
114 else:
115 acl=""
116
117 PageEditor.saveText(page,acl+newtext+body,rev)
118
119 msg="recommended to read %(pagename)s to %(username)s" % {
120 "pagename": pagename,
121 "username":username}
122
123 Page(request, pagename).send_page(request, msg=msg)
124 else:
125 Page(request, pagename).send_page(request, msg="You are not allowed to recommend pages")
126
127
128 def execute(pagename, request):
129
130
131 _ = request.getText
132 actname = __name__.split('.')[-1]
133
134
135 if request.user.may.read(pagename):
136
137 thispage=Page(request,pagename)
138
139 if request.form.has_key('button') and request.form.has_key('ticket'):
140 # check whether this is a valid recommention request (make outside
141 # attacks harder by requiring two full HTTP transactions)
142 if not wikiutil.checkTicket(request.form['ticket'][0]):
143 return thispage.send_page(request,
144 msg = _('Please use the interactive user interface to recommend pages!'))
145
146 username=request.form.get('username', [u''])[0]
147 if (len(username.strip()) == 0):
148 username=request.user.name
149 return RecommendPage(request,pagename,username)
150
151 formhtml = '''
152 <form method="post" action="">
153 <strong>%(querytext)s</strong>
154 <input type="hidden" name="action" value="%(actname)s">
155 <input type="submit" name="button" value="%(button)s">
156 <input type="hidden" name="ticket" value="%(ticket)s">
157 <p>
158 Username (WikiName)<br>
159 <input type="text" name="username" size="30" maxlength="40">
160 </form>''' % {
161 'querytext': 'Recommend page to',
162 'actname': 'RecommendPage',
163 'ticket' :wikiutil.createTicket(),
164 'button': 'Recommend'}
165
166 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.