Thread:Project:Support desk/Moving personal tools to the Vector sidebar (2)

I've been struggling to successfully move the personal tools section to the Vector sidebar. Here's the markup I currently have in my MediaWiki:Sidebar page:

In the last part, I would like to replace "test" with a way to determine if the user is logged in or not, so that either Log in or Log out is correctly shown depending on the situation. How could I accomplish this? Additionally, is there a way to replace "My page" with the user's username or IP address here?

Thanks in advance.