Getting logged on user name at any Trac wiki page (Trac 0.11)
Asked Answered
F

1

5

When I create a report I can filter the results based on the logged on user name using the $USER magic variable. Is there any equivalent way to get the logged on user name at any Trac wiki page?

E.g.: The logged on user is [[User]].

Fort answered 7/4, 2010 at 14:50 Comment(0)
C
9

Looks like you need a plugin to do it. Nothing complex; just throw this:

from trac.wiki.macros import WikiMacroBase

class UserMacro(WikiMacroBase):
    def expand_macro(self, formatter, name, args):
        return formatter.req.authname;

Into a file like <trac_env>/plugins/username.py and add [[User]] to a wiki page. For non-logged in users, it'll show anonymous.

Coricoriaceous answered 7/4, 2010 at 17:46 Comment(2)
@ing0: It's based on the name of the macro class.Coricoriaceous
Ah I see. So if you called the class HelloMacro, it would work with [[Hello]]?Nietzsche

© 2022 - 2024 — McMap. All rights reserved.