<div dir="ltr"><div><div><div><div><div><div><div><div>If I want to show anonymous users a message including "You can _login_ or _create an account_ " with returnto support, what's the best way to do it?<br><br>
</div><div><br>Background:<br></div><div><br>All over MediaWiki we display messages to anonymous users with "_login_ or _create an account_" links in them. In most cases we want the user to easily get back to what they were doing, so Special:UserLogin supports returnto and returntoquery parameters which after login or signup make it display a link to go back to the page the user was on, or silently redirect back to it.<br>
<br>The display of login/signup links seems haphazard:<br><br></div><div>1) Many messages don't bother with returnto, and just have wiki links to the special page.  E.g. anontalkpagetext has:<br><br></div>please [[Special:UserLogin/signup|create an account]] or [[Special:UserLogin|log in]] ...<br>
<br></div>2) Some messages try to handle returnto with complicated magic word processing, , e.g. <a href="https://en.wikipedia.org/wiki/MediaWiki:Anoneditwarning">https://en.wikipedia.org/wiki/MediaWiki:Anoneditwarning</a> has:<br>
</div><br>If you '''[{{fullurl:Special:UserLogin|returnto={{FULLPAGENAMEE}}}} log in]''' or '''[{{fullurl:Special:UserLogin/signup|campaign=anoneditwarning&returnto={{FULLPAGENAMEE}}}} create an account]''' ... <br>
<br></div>This is fiddly, the magic words don''t work in JavaScript, and the resulting HTML requires you put class=plainlinks on the enclosing tag to disable the display of the external link icon. On the plus side it's generated entirely in the message string, and wiki admins can tweak parameters, like the signup campaign parameter in this example.<br>
<br></div>3) Often code builds the login/signup links in PHP and passes them to the message.<br><br>3a) OutputPage-> showPermissionsPage() builds a login URL with Linker:LinkKnown. It doesn't provide a sign up link, and the code to build the login link can't be reused. Which may be why WatchAction->checkCanExecute() and SpecialPage::requireLogin copy and paste the code.<br>
</div></div><br></div><div>3b) SkinTemplate.php generates the Login / Create account URLs at the top right of most skins using Skin::makeSpecialUrl. But you can't pass this to a message because it may not start with //<a href="http://myserver.com">myserver.com</a> and if it doesn't then it won't work in a [$1 link text] link.<br>
</div><div><div><div><div><div><div><div><br></div><div>Thanks for any advice,<br><br></div><div>-- <br><div dir="ltr">=S Page  Features engineer<br></div>
</div></div></div></div></div></div></div></div>