Attachment 'RecommendPage-1.5.1-9.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 The person is informed by an email notification about the changes
15
16 If you don't enter a name the recommendation is done to your name
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.4-1
24
25 2005-04-19 : Version 1.3.4-2
26 acl line on top of recommendation is set for a valid user/RecommendedPage to
27 WikiName:admin,read,write,delete All:read,write
28 otherwise for All:read,write
29 If the page user/RecommendedPage already exist acl right given on that page are used.
30 output changed similiar to the search output.
31
32 2005-04-21 : Version 1.3.4-3
33 output changed into calling ShortText()
34 e.g. * ["RulesForUnzip"] [[ShortText(RulesForUnzip)]] ... @SIG@
35 it is also checked by now if acls are enabled in the config
36 2005-09-02 : Version 1.3.5-4
37 from SubscribeTo by Raphael Bossek learned to add an subscription for the email notification for a user before the new recommendation is written to the file. This means the user gots informed by an email.
38 2005-09-05 : Version 1.3.5-5
39 isSubscribedTo from user replaced because it could not destinguish between subpage and page
40 my implementation does not understand regular expressions at the moment so this gives by using regular expressions
41 one extraline in the config.
42 2005-09-07 : Version 1.3.5-6
43 text box changed to a selection menu for the user names (sorted by name)
44 2005-09-08 : Version 1.3.5-7
45 bug fix: spaces in html are different in browsers
46 in some browser no selction did not give the user name
47 2005-10-31 : Version 1.3.5-8
48 multiple selection added
49 no acl rights are set on a new recomendation page acls on an existing recommendation page not overwritten
50 non admin users could use this function too.
51 code changed by a version request to be useable with 1.5.0 too
52 2006-02-03 : Version 1.5.1-9 1.3 compatible code removed
53 bug with wrong counted bad user fixed
54
55 """
56
57 import string
58 from MoinMoin import config, wikiutil, user, wikiacl, search, version
59 from MoinMoin.Page import Page
60 from MoinMoin.PageEditor import PageEditor
61
62
63 def ACLparse(request, body):
64 """
65 taken from wikiacl and simply changed to return acl text and body without acl definition
66 renamed from parseACL to ACLparse
67 """
68 acl_lines = []
69 while body and body[0] == '#':
70 # extract first line
71 try:
72 line, body = body.split('\n', 1)
73 except ValueError:
74 line = body
75 body = ''
76
77 # end parsing on empty (invalid) PI
78 if line == "#":
79 break
80
81 # skip comments (lines with two hash marks)
82 if line[1] == '#':
83 continue
84
85 tokens = line.split(None, 1)
86 if tokens[0].lower() == "#acl":
87 if len(tokens) == 2:
88 args = tokens[1].rstrip()
89 else:
90 args = ""
91 acl_lines.append(args)
92 return acl_lines,body
93
94 def RecommendPage(request,pagename,username):
95
96 delimiter = "/"
97
98 err = None
99 name = "%(username)s%(delimiter)sRecommendedPage" % {"username": username, "delimiter": delimiter}
100 page = PageEditor(request,name)
101 if request.user.may.write(name):
102
103 if user.getUserId(request, username) != None:
104 uid = user.getUserId(request, username)
105 recom_user = user.User (request, id = uid)
106
107 subscription_list = recom_user.getSubscriptionList()
108 isSubscribedTo = 0
109 for test in subscription_list :
110 if test == name :
111 isSubsribedTo = 1
112
113 if isSubscribedTo == 0:
114 recom_user.subscribe(name)
115 recom_user.save()
116
117 newtext = u" * %(pagename)s %(about)s ...\n %(username)s\n" % {
118 "pagename": '["'+pagename+'"]',
119 "about":"[[ShortText(%(pagename)s)]]" % {
120 "pagename": pagename},
121 "username":"@SIG@"}
122
123 rev = page.current_rev()
124 if not page.exists() :
125 PageEditor.saveText(page,newtext,rev)
126 else:
127 body = page.get_raw_body()
128 given_acl,body = ACLparse(request, body)
129 if len(string.join(given_acl,"")) > 0:
130 acl = "#acl %(given_acl)s \n" % {
131 "given_acl":string.join(given_acl,"\n")}
132 else:
133 acl=""
134 PageEditor.saveText(page,acl+newtext+body,rev)
135
136 else:
137 err = "Can not write"
138 return err
139
140
141
142
143 def execute(pagename, request):
144
145
146 _ = request.getText
147 actname = __name__.split('.')[-1]
148
149 if request.user.may.read(pagename) :
150
151 thispage = Page(request,pagename)
152
153 if request.form.has_key('button') and request.form.has_key('ticket'):
154 # check whether this is a valid recommention request (make outside
155 # attacks harder by requiring two full HTTP transactions)
156 if not wikiutil.checkTicket(request.form['ticket'][0]) :
157 return thispage.send_page(request,
158 msg = _('Please use the interactive user interface to recommend pages!'))
159
160 selected_users = request.form.get('username', [u''])
161 good = []
162 bad = []
163 for username in selected_users:
164 i = 0
165 if len(username.strip()) == 0 :
166 username = request.user.name
167 selected_users[i] = username
168 i += 1
169
170 err = RecommendPage(request,pagename,username)
171 if err == None:
172 good.append(username)
173 else :
174 bad.append(username)
175
176 msg = "recommended to read %(pagename)s to %(username)s" % {
177 "pagename": pagename,
178 "username":string.join(good)}
179
180 msg_bad = ''
181 if len(bad) > 1 :
182 msg_bad = "\ncan not recommend page to read to %(username)s" % {
183 "username":string.join(bad)}
184
185
186
187 Page(request, pagename).send_page(request, msg=msg+msg_bad)
188 return
189 users = user.getUserList(request)
190 html = []
191 for uid in users:
192 name = user.User(request, id=uid).name
193 html.append("<OPTION>%(name)s</OPTION>" % { "name":name})
194
195 html.sort()
196 n = len(html)
197 if n > 3 :
198 n = 3
199
200 formhtml = '''
201 <form method="post" >
202 <strong>%(querytext)s</strong><BR>
203 <select name="username" size="%(len)s" multiple>
204 %(option)s
205 </select>
206 <input type="hidden" name="action" value="%(actname)s">
207 <input type="submit" name="button" value="%(button)s">
208
209 <BR>
210 (no selection recommends to: %(user)s)
211
212 <input type="hidden" name="ticket" value="%(ticket)s">
213 <p>
214 </form>''' % {
215 'querytext': 'Recommend page to',
216 'actname': 'RecommendPage',
217 'ticket' : wikiutil.createTicket(),
218 'option': string.join(html),
219 'user' : request.user.name,
220 'len': n,
221 'button': 'Recommend'}
222
223
224 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.