Attachment 'User.py'
Download 1 # -*- coding: iso-8859-1 -*-
2 """
3 MoinMoin - User macro
4
5 Syntax:
6 [[User]]
7 Displays the name of the current user
8
9 [[User(homepage)]]
10 Displays a link to the user's homepage
11
12 [[User(homepage=Your link text)]]
13 Displays a renamed link to the user's homepage
14
15 [[User(preferences)]]
16 Display the user's preferences
17
18 @copyright: 2007 by Oliver Siemoneit
19 @license: GNU GPL, see COPYING for details.
20 """
21
22 from MoinMoin import user, wikiutil
23
24 def _getArgs(given_arguments, allowed_arguments):
25 if not given_arguments:
26 return {}
27
28 args = {}
29 for s in given_arguments.split(','):
30 if s and s.find('=') > 0:
31 key, value = s.split('=', 1)
32 key = key.strip()
33 if key and value:
34 if key in allowed_arguments:
35 args[key] = wikiutil.escape(value.strip())
36 else:
37 if key in allowed_arguments:
38 args[key] = None
39 else:
40 key = s.strip()
41 if key in allowed_arguments:
42 args[key] = None
43
44 return args
45
46 def _displayUserName(request):
47 _ = request.getText
48
49 if request.user.isCurrentUser():
50 name = request.user.name
51 aliasname = request.user.aliasname
52 if not aliasname:
53 aliasname = name
54 if aliasname == "":
55 return _('<unknown>')
56 return aliasname
57
58 return _('<unknown>')
59
60 def _displayHomepageLink(request, linktext):
61 _ = request.getText
62
63 if request.user.valid and request.user.name:
64 interwiki = wikiutil.getInterwikiHomePage(request)
65 name = request.user.name
66 aliasname = request.user.aliasname
67 if not aliasname:
68 aliasname = name
69 title = "%s @ %s" % (aliasname, interwiki[0])
70 # link to (interwiki) user homepage
71 if linktext is None:
72 homelink = "%s%s%s" % (request.formatter.interwikilink(1, title=title, id="userhome", generated=True, *interwiki),
73 request.formatter.text(name),
74 request.formatter.interwikilink(0, title=title, id="userhome", *interwiki))
75 return homelink
76 else:
77 homelink = "%s%s%s" % (request.formatter.interwikilink(1, title=title, id="userhome", generated=True, *interwiki),
78 request.formatter.text(linktext),
79 request.formatter.interwikilink(0, title=title, id="userhome", *interwiki))
80 return homelink
81 else:
82 if linktext is None:
83 return _('<unknown>')
84 else:
85 return linktext
86
87 def _displayUserPreferences(request):
88 from MoinMoin import userform
89
90 return request.formatter.rawHTML(userform.getUserForm(request, create_only=False))
91
92
93 def execute(macro, given_args):
94 request = macro.request
95
96 allowed_args = ['homepage', 'preferences']
97 args = _getArgs(given_args, allowed_args)
98
99 if not args:
100 return _displayUserName(request)
101
102 elif args.has_key('homepage'):
103 return _displayHomepageLink(request, args['homepage'])
104
105 elif args.has_key('preferences'):
106 return _displayUserPreferences(request)
107
108 return
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.