Forum:Getting the current user's username
I want it to say "Hello, USERNAME". Like to use it on my userpage! Thanks if it's possible :D Mistress of the Clow ~ Cardcaptor Stacey [Talk] [Work] [Uncyclopedia Fanlisting] 14:41, 16 August 2006
{{USERNAME}}, just the word username inside {{}}.---Asteroid B612 (aka Rataube) - Ñ 17:48, 16 August 2006 (UTC)
- {{USERNAME}} - no, Rataube, that doesn't work. ~ 17:51, 16 August 2006 (UTC)
I don't see anything like that on wikipedia:meta:Help:Magic_words, wikipedia:meta:Help:Variable, wikipedia:meta:ParserFunctions or wikipedia:meta:Template:Wikivar.
{{USERNAME}} just gives {{USERNAME}}.
Drats.
- Really? ups... I thought we had that magic word.---Asteroid B612 (aka Rataube) - Ñ 19:14, 16 August 2006 (UTC)
I can't even get {{PRETTYPLEASE}} to work as a magic word :( --Carlb 21:13, 16 August 2006 (UTC)
Funnily enough, I've written an extension that can do exactly this, as well as allowing the display of different content to anonymous and banned users. However, it's currently not installed, as I have some concerns about abuse. --Algorithm 23:53, 16 August 2006 (UTC)
- What do you mean different content? t o m p k i n s blah. ﺞوﻦ וףה ՃՄ ண்ஸ ފއހ วอฏม +տ trade websites 00:39, 17 August 2006 (UTC)
- Presumably he means showing different versions of the page to different users, using parser functions that do conditional branching. Algo, can you write it in such a way that it can't be used in a {{switch}} or {{ifeq}} construct? I'd assume that would be difficult and maybe impossible, but you're more into this stuff than I am... If it's not possible, then I agree, there'd be a huge potential for abuse there. It's too bad, because I could think of dozens of cool things you could do with that, some of which wouldn't be naughty in the slightest. c • > • cunwapquc? 00:54, 17 August 2006 (UTC)
Implemented
This will probably never be supported in MediaWiki natively as it breaks caching (same as {{USERLANGUAGE}} would). It can only currently be done (barring an extension) with Javascript. Hang on, I'll try to write a working one. --Splaka 03:52, 17 August 2006 (UTC)
-> Hello <insert name here>!
You can even link it with: [[Special:Mypage|<span id="insertusername"></span>]]. It can not be used for any parserfunctions as it executes a text change onload, and parserfunctions are server-side. Note that this is a gay hack. --Splaka 04:15, 17 August 2006 (UTC)
- Addendum: it only works in one occurance per page, and I decided that that is fine, too abuseable otherwise. Also note I've made it into {{USERNAME}} (and commented out the other occurences of that template on this page as, stated before, it only works once per page). --Splaka 04:15, 17 August 2006 (UTC)
- Addendum 2: it doesn't work for anonymous users, and can't anyway (as the text of the IP is not on the page anymore). I suppose it *could* do a separate check and assign 'anonymous user' to the field, but nobody cares. --Splaka 04:22, 17 August 2006 (UTC)
- You're a very clever individual, Splaka, as I've stated on many occasions. Hmmm, on more complex pages it seems to take a split second to process, so you see "Anonymous user" change to your user name just after the page loads. Which I guess is what you'd expect with client-side scripting... It doesn't work inside of a Wikilink, either, which is probably a good thing. I might try it inside of a raw-HTML link though... This could still get interesting, but I think you may have done it just right! Give yourself a pat on the back! c • > • cunwapquc? 04:48, 17 August 2006 (UTC)
- It can't be abused in any links, as the links are generated by the wikicode, and the script doesn't modify any anchor tags. Algo's is probably better though. --Splaka 06:01, 17 August 2006 (UTC)
- I gotta tell you, I was surprised as hell to see my username up there... until I figured out what was going on. Congrats for making me feel special even if only for a moment, Splak! --The King In Yellow (Talk to the Dalek.) 17:44, 17 August 2006 (UTC)
Alternative
Well Splaka, you beat me to it, but I feel okay since my version doesn't have your limitations: m:UserMagic
With this extension installed, __USERNAME__ becomes the name of the current user, and __USERPAGE__ becomes a link to the user page. Neither of these words are replaced until after the HTML is rendered and the content is returned from the cache, which means they can't be abused with parserfunctions, don't affect the page cache, and can be used as often as you like. --Algorithm 05:56, 17 August 2006 (UTC)
- Yah, but yours requires extensions! icky ^_^. --Splaka 05:59, 17 August 2006 (UTC)
<brion> that would break caching, clearly <brion> can't replace an IP when your code isn't being run at all, can you?
--Splaka 06:08, 17 August 2006 (UTC)
- Yeah, that works for me. Be really handy if you could install it on Uncyclopedia :) Mistress of the Clow ~ Cardcaptor Stacey [Talk] [Work] [Uncyclopedia Fanlisting] 20:56, 17 August 2006
Disabling it
What I don't like about this is that it's a bit annoying to have to check the page source on the off chance someone is actually mentioning you. And there's currently no way to disable this function, only change the appearance of it with personal css. And I wouldn't like to touch splarka's code in case he cries. Anyway, just saying I don't like this function until there's an option to have it turned off. • Spang • ☃ • talk • 15:41, 20 August 2006 (UTC)