Topic on Project:Support desk

Grab URL parameter from $1?

5
Summary by Knomanii

The login link for MediaWiki:Loginreqpagetext can be added into a button using $1 if formatted correctly.

The full URL can be accessed with $2, however if $wgExternalLinkTarget is set to "_blank", then the link's target will open in a new tab like an external link.

Knomanii (talkcontribs)

So I created a Login button for my login page (MediaWiki:Loginreqpagetext):


       Please $1 to view other pages.
       {{Login Button|link=Special:UserLogin|name=Log in}}
       

Problem is my button link doesn't have the &returnto=Page+Title part. So links to specific pages won't work if the user clicks the login button.

Is it possible to grab the URL parameter from the $1 variable? i.e. $1['url']

Or is there another way to dynamically add the "&returnto=" parameter into the link?

Thanks in advance for any help.

Knomanii (talkcontribs)

This code I found came close to working:

{{fullurl:Special:UserLogin|returnto={{FULLPAGENAMEE}}}}

It works on normal pages but not on Mediawiki:Loginreqpagetext.

When added to MediaWiki:Loginreqpagetext, the &returnto={{FULLPAGENAMEE}} breaks.

The bad link it generated is:

example.com/w/index.php?title=Special:UserLogin&returnto=Special:BadTitle%7c.

Close but no cigar… Any other ideas?

Knomanii (talkcontribs)

I solved it!

After looking at the Login Required page with ?uselang=qqx added to the end of the url, I realized the URL appeared to be a second variable or parameter.

So I put $2 on the page and indeed it printed out the URL with a correct &returnto= parameter when tested live on the Login Page.

Then I tried using link=$2 in my button and it mostly worked!

A few slight styling issues, but that's pretty easy to fix from here.

I'm all set, thanks for reading.

Knomanii (talkcontribs)

Crap, I spoke too soon.

The problem with the $2 link is it's formatted like an external link:

https://example.com/w/index.php?title=Page_title&returnto=Return+page

And since I set $wgExternalLinkTarget = '_blank';, external links open in a new tab.

So every time someone logs in, it opens up their login in a new tab, which is unacceptably weird.

Any ideas how to bypass the $wgExternalLinkTarget just for one link?

It seems unnecessary to disable it entirely just to get a login link to work.

Any help would be appreciated.

Knomanii (talkcontribs)

I solved this in a different way.

I added $1 as the span text (name=) attribute of a button template.

Here is how my final Login Required page looks:

Loginreqpagetext button

Here is my final MediaWiki:Loginreqpagetext:


       $1 to view other pages.

       {{Button| $1 |color=blue }}
      

I'm all set, thanks for reading!