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