Attachment 'RecommendPage-1.6.0-10.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 Syntax:
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 MoinMoin:ReimarBauer
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 2008-01-11 : Version 1.6.0-10 refactored for 1.6
55
56 """
57 from MoinMoin import wikiutil, user
58 from MoinMoin.Page import Page
59 from MoinMoin.PageEditor import PageEditor
60
61 def RecommendPage(request, pagename, username):
62 err = None
63 name = "%(username)s/RecommendedPage" % {"username": username}
64 page = PageEditor(request, name)
65 if request.user.may.write(name):
66 if user.getUserId(request, username) is not None:
67 uid = user.getUserId(request, username)
68 recom_user = user.User (request, id=uid)
69
70 subscription_list = recom_user.getSubscriptionList()
71 isSubscribedTo = 0
72 for test in subscription_list:
73 if test == name:
74 isSubsribedTo = 1
75
76 if isSubscribedTo == 0:
77 recom_user.subscribe(name)
78 recom_user.save()
79
80 newtext = u" * [[%(pagename)s]] <<ShortText(%(pagename)s)>> ...\n %(username)s\n" % {
81 "pagename": pagename,
82 "username":"@SIG@"}
83
84 if not page.exists():
85 PageEditor.saveText(page, newtext, 0)
86 else:
87 body = page.get_data()
88 meta = page.get_meta()
89 text_meta = ''
90 for command, attrib in meta:
91 text_meta = '#%s %s\n%s' % (command, attrib, text_meta)
92
93 text = "%s\n%s\n%s\n" % (text_meta, newtext, body)
94 PageEditor.saveText(page, text, 0)
95 else:
96 err = "Can not write"
97 return err
98
99 def execute(pagename, request):
100 _ = request.getText
101 actname = __name__.split('.')[-1]
102
103 if request.user.may.read(pagename):
104 thispage = Page(request, pagename)
105 if request.form.has_key('button') and request.form.has_key('ticket'):
106 if not wikiutil.checkTicket(request, request.form['ticket'][0]):
107 return thispage.send_page(msg=_('Please use the interactive user interface to recommend pages!'))
108
109 selected_users = request.form.get('username', [u''])
110 good = []
111 bad = []
112 for username in selected_users:
113 i = 0
114 if len(username.strip()) == 0:
115 username = request.user.name
116 selected_users[i] = username
117 i += 1
118
119 err = RecommendPage(request, pagename, username)
120 if err is None:
121 good.append(username)
122 else:
123 bad.append(username)
124
125 msg = "recommended to read %(pagename)s to %(username)s" % {
126 "pagename": pagename,
127 "username": ' '.join(good)}
128
129 msg_bad = ''
130 if len(bad) > 1:
131 msg_bad = "\ncan not recommend page to read to %(username)s" % {
132 "username":' '.join(bad)}
133
134 msg = "%s%s" % (msg, msg_bad)
135 Page(request, pagename).send_page(msg=msg)
136 return
137 users = user.getUserList(request)
138 html = []
139 for uid in users:
140 name = user.User(request, id=uid).name
141 html.append("<OPTION>%(name)s</OPTION>" % {"name":name})
142
143 html.sort()
144 n = min([3, len(html)])
145
146 formhtml = '''
147 <form method="post" >
148 <strong>%(querytext)s</strong><BR>
149 <select name="username" size="%(len)s" multiple>
150 %(option)s
151 </select>
152 <input type="hidden" name="action" value="%(actname)s">
153 <input type="submit" name="button" value="%(button)s">
154
155 <BR>
156 (no selection recommends to: %(user)s)
157
158 <input type="hidden" name="ticket" value="%(ticket)s">
159 <p>
160 </form>''' % {
161 'querytext': 'Recommend page to',
162 'actname': 'RecommendPage',
163 'ticket': wikiutil.createTicket(request),
164 'option': ' '.join(html),
165 'user': request.user.name,
166 'len': n,
167 'button': 'Recommend'}
168
169 return thispage.send_page(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.