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