Attachment 'autosub.py'
Download 1 """
2 MoinMoin - autosub-Macro
3
4 Copyright (c) 2003 by Daniela Nicklas <nicklas@informatik.uni-stuttgart.de>
5 All rights reserved.
6
7 Subscribe another user to a wiki page. Syntax:
8 [[autosub(username1,User Name2,UserName3)]]
9 Do not use spaces after the ,!
10
11 for German i18n: Add to de.py:
12
13 '''
14 <b>This wiki is not enabled for mail processing.<br>
15 Contact the owner of the wiki, who can either enable email,
16 or do not use the autosub macro.</b>
17 ''':
18 '''
19 <b>Dieses Wiki unterstützt keine E-Mail Verarbeitung.<br>
20 Kontaktieren sie den Adminstrator dieses Wikis, der die E-Mail-Unterstützung
21 aktivieren kann, oder verwenden sie das autosub-Macro nicht.
22 ''',
23 'Not a user:':
24 'Kein Benutzer:'
25
26
27 """
28
29 from MoinMoin import config, user
30 from MoinMoin.Page import Page
31 from MoinMoin.i18n import _
32
33 def subscribe_users(request, usernamelist, pagename):
34 result = ''
35 # icon in front of username, if subscribe succeeds:
36 subicon='<img src="%s/img/moin-email.gif" width="14" height="10" border="0" alt="Subscribed">'%config.url_prefix
37 # icon, if not:
38 nosubicon='<img src="%s/img/moin-email-x.gif" width="14" height="10" border="0" alt="Subscribed">'%config.url_prefix
39
40 # check config
41 if not config.mail_smarthost:
42 return _('''
43 <b>This wiki is not enabled for mail processing.<br>
44 Contact the owner of the wiki, who can either enable email,
45 or do not use the autosub macro.</b>
46 ''')
47
48 realusers = [] # usernames that are really wiki-users
49 success = 0 # did the subscription succeed?
50
51 # get user object - only with IDs!
52 useridlist = user.getUserList();
53 for userid in useridlist:
54 success = 0
55 userobj = user.User(request, userid)
56
57 if userobj.name in usernamelist: # found a user
58 realusers.append(userobj.name)
59 # check if user is already subscribed:
60 if userobj.isSubscribedTo([pagename]):
61 success = 1
62 # check whether the user has an email address
63 elif not userobj.email:
64 success = 0
65 # subscribe user
66 elif userobj.subscribePage(pagename):
67 userobj.save()
68 success = 1
69 # append user to result
70 if success == 1:
71 result += subicon
72 else:
73 result += nosubicon
74 userpage = Page(userobj.name)
75 result += userpage.link_to()
76 result += " "
77
78 # check for args that are not users
79 for un in usernamelist:
80 if un not in realusers:
81 result += nosubicon
82 result += _("Not a user:")
83 # check if un is a page
84 unpage = Page(un)
85 if unpage.exists():
86 result += unpage.link_to()
87 else:
88 result += un
89 return result
90
91 def execute(macro, args):
92 # parse args
93 usernamelist = [] # users to be subscribed
94 usernamelist = args.split(",")
95
96 pagename = macro.formatter.page.page_name # this page
97
98 # result of the macro
99 result = subscribe_users(macro.request, usernamelist, pagename)
100
101
102 return result
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.