Fandom Developers Wiki
Advertisement
Forums: Index > Help desk > Redirect text

Hi, I'm trying to make a piece of code that would simply add a "What links here?" link on redirect pages. The problem is I don't know how to create the link properly... I have come up with the following JS:

(function ($) {
        $('.redirectText').append('<br />[[Special:Whatlinkshere/{{NAMESPACE}}:{{PAGENAME}}|What links here?]]');
}(jQuery));

However, obviously, the wikitext in there will not work. I need to know how to do that using JS, or using CSS if that is a better option.

Basically I just want a link under the redirect text to make site maintenance easier. Whatever way that can be accomplished is fine with me.
RyaNayR (talk) 05:52, November 12, 2013 (UTC)

Doesn't seem necessary, WhatLinksHere is in the toolbar by default. But anyway, just make a link and use mw.config.get to get the page name. .append('<br /><a href="/wiki/Special:WhatLinksHere/' + mw.config.get('wgPageName') + '">What links here?</a>') ~Bobogoobo (talk) 06:36, November 12, 2013 (UTC)
Thanks! That's exactly what I was looking for, I didn't know about mw.config.get. Also, for some reason I have never seen that toolbar, on any wiki. I've looked it up but I can't find any way to enable it... I'm using firefox 25.0 if that matters at all. Any ideas on that? —RyaNayR (talk) 06:54, November 12, 2013 (UTC)
There should be a little arrow in the far bottom left-hand corner that brings it up when clicked. This is Oasis we're talking about, right? — Foodbandlt (talk) 07:00, November 12, 2013 (UTC)
Ah! I figured it out. For some reason it was being blocked by one of my Adblock Plus filters. I just have to add an exception for it. (And yes, I use Oasis) —RyaNayR (talk) 07:15, November 12, 2013 (UTC)
I also don't know left from right, apparently. The arrow is on the right, hahah. — Foodbandlt (talk) 07:45, November 12, 2013 (UTC)
Hah, yeah I wasn't going to mention it, but I did notice that. —RyaNayR (talk) 08:41, November 12, 2013 (UTC)

On a similar note, how can I change the left-to-right arrow image which is displayed on redirect pages? My wiki has a dark background and the default arrow barely shows up. I would like to replace it with this inverted version Redirectltr-inverted. How can I do that? I have tried:

$('.redirectMsg.img').replace('<img alt="#REDIRECT" src="http://static4.wikia.nocookie.net/dev/images/a/aa/Redirectltr-inverted.png"</img>');

but that doesn't work... Any help will be greatly appreciated! —RyaNayR (talk) 07:03, November 13, 2013 (UTC)

You should learn how HTML and CSS work before using JavaScript. Also, replace is a string function. Try this:
$('.redirectMsg img').replaceWith('<img alt="#REDIRECT" src="http://static4.wikia.nocookie.net/dev/images/a/aa/Redirectltr-inverted.png" />');
~Bobogoobo (talk) 07:15, November 13, 2013 (UTC)
That worked! And, I am fairly familiar with HTML & CSS (fairly).. and I kind of suspected replace being a string function wouldn't work. I just didn't know about replaceWith – Thanks for that! —RyaNayR (talk) 09:45, November 13, 2013 (UTC)
You actually don't need to create your own element. An img is already there; just change its src. Something like:
$('.redirectMsg img').attr('src', 'http://static4.wikia.nocookie.net/dev/images/a/aa/Redirectltr-inverted.png');
--~UltimateSupreme 15:52, November 13, 2013 (UTC)
Oh, I see how that works. Nice tip, thanks! —RyaNayR (talk) 03:33, November 14, 2013 (UTC)
Advertisement