Attachment 'RecommendPage-1.3.4-1.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 file.
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 """
25
26 import string
27 from MoinMoin import config, wikiutil
28 from MoinMoin.Page import Page
29 from MoinMoin.PageEditor import PageEditor
30
31 def RecommendPage(request,pagename,user):
32 if config.allow_subpages:
33 delimiter = "/"
34 else:
35 delimiter = ""
36
37 name=user + delimiter + "RecommendedPage"
38 page = PageEditor(request,name)
39 if request.user.may.write(name):
40
41 thispage=Page(request,pagename)
42 thisraw=thispage.get_raw_body()
43 lines = thisraw.split('\n')
44
45 if (lines[0].find('#acl') > -1):
46 lines=lines[1:]
47
48 if (len(lines) > 5):
49 result=string.join(lines[0:4],'\n')
50 else:
51 result=string.join(lines,'\n')
52
53 newtext=u" * %(pagename)s {{{\n%(about)s\n}}} %(user)s \n" % {
54 "pagename": '["'+pagename+'"]',
55 "about":result,
56 "user":"@SIG@"}
57
58 rev = page.current_rev()
59 if (rev == 99999999) :
60 PageEditor.saveText(page,newtext,rev)
61 else:
62 raw = page.get_raw_body()
63 PageEditor.saveText(page,newtext+raw,rev)
64
65 msg="recommended to read %(pagename)s to %(user)s" % {
66 "pagename": pagename,
67 "user":user}
68
69 Page(request, pagename).send_page(request, msg=msg)
70 else:
71 Page(request, pagename).send_page(request, msg="You are not allowed to recommend pages")
72
73
74 def execute(pagename, request):
75
76
77 _ = request.getText
78 actname = __name__.split('.')[-1]
79
80
81 if request.user.may.read(pagename):
82
83 thispage=Page(request,pagename)
84
85 if request.form.has_key('button') and request.form.has_key('ticket'):
86 # check whether this is a valid recommention request (make outside
87 # attacks harder by requiring two full HTTP transactions)
88 if not wikiutil.checkTicket(request.form['ticket'][0]):
89 return thispage.send_page(request,
90 msg = _('Please use the interactive user interface to recommend pages!'))
91
92 user=request.form.get('username', [u''])[0]
93 if (len(user.strip()) == 0):
94 user=request.user.name
95 return RecommendPage(request,pagename,user)
96
97 formhtml = '''
98 <form method="post" action="">
99 <strong>%(querytext)s</strong>
100 <input type="hidden" name="action" value="%(actname)s">
101 <input type="submit" name="button" value="%(button)s">
102 <input type="hidden" name="ticket" value="%(ticket)s">
103 <p>
104 Username (WikiName)<br>
105 <input type="text" name="username" size="30" maxlength="40">
106 </form>''' % {
107 'querytext': 'Recommend page to',
108 'actname': 'RecommendPage',
109 'ticket' :wikiutil.createTicket(),
110 'button': 'Recommend'}
111
112 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.