Attachment 'RecommendPage-1.3.5-7.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
48 """
49
50 import string
51 from MoinMoin import config, wikiutil, user, wikiacl, search
52 from MoinMoin.Page import Page
53 from MoinMoin.PageEditor import PageEditor
54
55
56 def ACLparse(request, body):
57 """
58 taken from wikiacl and simply changed to return acl text and body without acl definition
59 renamed from parseACL to ACLparse
60 """
61
62 if not request.cfg.acl_enabled:
63 return AccessControlList(request),body
64
65
66 acl_lines = []
67 while body and body[0] == '#':
68 # extract first line
69 try:
70 line, body = body.split('\n', 1)
71 except ValueError:
72 line = body
73 body = ''
74
75 # end parsing on empty (invalid) PI
76 if line == "#":
77 break
78
79 # skip comments (lines with two hash marks)
80 if line[1] == '#':
81 continue
82
83 tokens = line.split(None, 1)
84 if tokens[0].lower() == "#acl":
85 if len(tokens) == 2:
86 args = tokens[1].rstrip()
87 else:
88 args = ""
89 acl_lines.append(args)
90 return acl_lines,body
91
92 def RecommendPage(request,pagename,username):
93
94 if config.allow_subpages:
95 delimiter = "/"
96 else:
97 delimiter = ""
98
99
100 name = "%(username)s%(delimiter)sRecommendedPage" % {"username": username, "delimiter": delimiter}
101 page = PageEditor(request,name)
102 if request.user.may.write(name):
103
104 if user.getUserId(request, username) != None:
105 uid = user.getUserId(request, username)
106 recom_user = user.User (request, id = uid)
107
108 subscription_list = recom_user.getSubscriptionList()
109 isSubscribedTo = 0
110 for test in subscription_list :
111 if test == name :
112 isSubsribedTo = 1
113
114 if isSubscribedTo == 0:
115 recom_user.subscribePage(name)
116 recom_user.save()
117
118 newtext = u" * %(pagename)s %(about)s ...\n %(username)s\n" % {
119 "pagename": '["'+pagename+'"]',
120 "about":"[[ShortText(%(pagename)s)]]" % {
121 "pagename": pagename},
122 "username":"@SIG@"}
123
124 rev = page.current_rev()
125 if not page.exists() :
126 if request.cfg.acl_enabled:
127 if user.getUserId(request, username) != None :
128 acl="#acl %(username)s:admin,read,write,delete All:read,write\n" % {
129 "username":username}
130 else:
131 acl="#acl All:read,write\n"
132 else:
133 acl=""
134 PageEditor.saveText(page,acl+newtext,rev)
135
136 else:
137 body = page.get_raw_body()
138 given_acl,body = ACLparse(request, body)
139
140 if len(string.join(given_acl,"")) > 0:
141 acl = "#acl %(given_acl)s \n" % {
142 "given_acl":string.join(given_acl,"\n")}
143 else:
144 acl=""
145
146 PageEditor.saveText(page,acl+newtext+body,rev)
147
148 msg = "recommended to read %(pagename)s to %(username)s" % {
149 "pagename": pagename,
150 "username":username}
151 Page(request, pagename).send_page(request, msg=msg)
152
153 else:
154 Page(request, pagename).send_page(request, msg="You are not allowed to recommend pages")
155
156
157 def execute(pagename, request):
158
159
160 _ = request.getText
161 actname = __name__.split('.')[-1]
162
163 if request.user.may.read(pagename) :
164
165 thispage = Page(request,pagename)
166
167 if request.form.has_key('button') and request.form.has_key('ticket'):
168 # check whether this is a valid recommention request (make outside
169 # attacks harder by requiring two full HTTP transactions)
170 if not wikiutil.checkTicket(request.form['ticket'][0]) :
171 return thispage.send_page(request,
172 msg = _('Please use the interactive user interface to recommend pages!'))
173
174 username = request.form.get('username', [u''])[0]
175 if len(username.strip()) == 0 :
176 username = request.user.name
177 return RecommendPage(request,pagename,username)
178
179 users = user.getUserList(request)
180
181
182 html=[]
183 html.append("<OPTION></OPTION>")
184 for uid in users:
185 name = user.User(request, id=uid).name
186 html.append("<OPTION>%(name)s</OPTION>" % { "name":name})
187
188 html.sort()
189 formhtml = '''
190 <form method="post" action="">
191 <strong>%(querytext)s</strong><BR>
192 <select name="username" size="1">
193 %(option)s
194 </select>
195 <input type="hidden" name="action" value="%(actname)s">
196 <input type="submit" name="button" value="%(button)s">
197
198 <BR>
199 (no selection recommends to: %(user)s)
200
201 <input type="hidden" name="ticket" value="%(ticket)s">
202 <p>
203 </form>''' % {
204 'querytext': 'Recommend page to',
205 'actname': 'RecommendPage',
206 'ticket' : wikiutil.createTicket(),
207 'option': string.join(html),
208 'user' : request.user.name,
209 'button': 'Recommend'}
210
211
212 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.