Variable in MediaWiki for the current user
Asked Answered
K

2

8

In MediaWiki, you can use a variable ("Magic Word") such as

{{PAGENAME}}

or

{{REVISIONDAY}}

to get specific information related to the current page being viewed. Is there a similar variable (or perhaps a different way) to get the current user who is logged in to the wiki, i.e. something like

{{USERNAME}}

context: Trying to use the #ask query in Semantic MediaWiki to narrow the list of resulting pages to show those only the user has created or edited:

{{#ask: [[Case Reflection:+]] [[Contributing User::{{USERNAME}}]]
 | format=template
 | template=Case Reflection Form Summary
 | link=all
 | sort=Last Edited
 | order=DESC
 | default=You have no case reflections related to this Case Study.}}
Krasner answered 17/10, 2012 at 4:8 Comment(1)
If someone is looking for the variable of this in the code base, it's the global $wgUser object. (That's how I bumped into this question.)Yoicks
C
2

There are a bunch of extensions for that such as GetUserName, MyVariables, UserInfo. The whole concept of showing usernames is incompatible with page caching though (you need to parse the page again every time someone looks at it) so generally not a good idea.

Cadenza answered 18/10, 2012 at 11:40 Comment(1)
Thanks, I used Extension:MyVariables and it works.Pratique
L
1

I was just searching for the same thing, and looking to see if I could do it without extensions. It looks like there's a default feature that allows this, as long as you want it as part of writing a static version to a page, not to say "Hello, Username!" (That last case is why they have not implemented it as a standard variable, because it causes caching problems.)

Wikimedia feature request T14733 resolves with:

{{subst:REVISIONUSER}}

{{REVISIONUSER}} will dynamically show the last editor, which is usually not what you want. But if you want, for example, to make a template that includes the user's handle as part of some inserted text, this should do the job. I think in your example above,

[[Contributing User::{{subst:REVISIONUSER}}]]

(I'm not sure if Semantic Mediawiki will make you escape out the substitutions, but if it does, further instructions are at Manual:Substitution, Multilevel substitution section.)

Lupelupee answered 6/3, 2015 at 5:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.