Admin Forum:WantedFiles issue

I'm having an issue with Special:WantedFiles at Gran Turismo Wiki. Whenever I click a red-link in the Wanted Files list, I am sent to an edit page, rather than an upload page. Can I change some settings to fix this?

Thanks

MTracey1 PSN/XBL: Mackem1985 23:54, March 5, 2012 (UTC)


 * I don't think there is a setting to fix this lameness, but you can make some Javascript to fix it. When I get more time I'll post some JS to remove the &action=edit from the redlink which should make it do what you want. -- Fandyllic (talk &middot; contr) 6 Mar 2012 2:32 PM Pacific


 * Okay, I tested this here on Community at User:Fandyllic/wikia.js and it seems to work. It basically changes the link into an upload link.

 function ImgDescEditLink2Upload { $('ol.special > li > a.new').each(function {   this.setAttribute("href", this.getAttribute("href").replace(/\&action\=edit\&redlink\=1/, ""));    this.setAttribute("href", this.getAttribute("href").replace(/File:/, "Special:Upload&wpDestFile="));  }); } addOnloadHook(ImgDescEditLink2Upload);
 * As with all my JS code, I have to give a standard disclaimer: I'm not the best coder, so it is probably not the most efficient way to do this and it may have unintended consequences, since testing was minimal. I think it will only affect links of this sort on Special:WantedFiles, but it might work too globally. -- Fandyllic (talk &middot; contr) 6 Mar 2012 4:05 PM Pacific


 * Here's a simplified version of the above that just removes &action=edit:

 function ImgDescEditLink2ImgLink { $('ol.special > li > a.new').each(function {   this.setAttribute("href", this.getAttribute("href").replace(/\&action\=edit/, ""));  }); } addOnloadHook(ImgDescEditLink2ImgLink);
 * -- Fandyllic (talk &middot; contr) 6 Mar 2012 4:26 PM Pacific


 * Thanks. I assume if I put this into User:MTracey1/wikia.js it will only affect my editing, but if I add it to MediaWiki/Common.js (which I don't intend to) it would affect everyone?  Please excuse my lack of knowledge on the subject - I know my WikiMarkup pretty well, but js gives me a headache.
 * MTracey1 PSN/XBL: Mackem1985 01:58, March 7, 2012 (UTC)

This is more along the speed of what you are wanting. This takes all red linked files on Special:WantedFiles and changes them into a Special:Upload link with the correct filename. This will only affect red linked files on this page and only within the list. You can place this in Special:MyPage/global.js to work on all wikis that you view this special page on or in Special:MyPage/common.js on the specific wiki of choice.

Working example here. Let me know if you notice any issues. Rappy 05:31, March 7, 2012 (UTC)
 * I've added that code to User:MTracey1/common.js and to User:MTracey1/global.js and I'm not seeing any difference. I can see why it should work (although I'm certainly no expert), but it isn't. I don't understand what I'm doing wrong.
 * MTracey1 PSN/XBL: Mackem1985 05:48, March 7, 2012 (UTC)


 * Global.js would have been for here on Central. As for Gran Turismo Wiki, apparently, common.js does not work for both skins. If you're using Oasis, place the code in Wikia.js. For Monobook, place it in Monobook js. Rappy 05:58, March 7, 2012 (UTC)


 * Did you manage to get that to work on gt-wiki? I'm still having trouble with it.  If so, maybe it's a JavaScript problem on my computer.  Either way, it's about time I got some sleep, so I'll get back to this tomorrow.  It's not imperative that I get this working, but it would be helpful.
 * Thanks
 * MTracey1 PSN/XBL: Mackem1985 06:14, March 7, 2012 (UTC)


 * Yes, it is working for me. It could be a cache issue on your end. It should show for you by tomorrow. Rappy 06:15, March 7, 2012 (UTC)

Logged in this afternoon and it's working perfectly! Thanks for your help. MTracey1 PSN/XBL: Mackem1985 16:48, March 7, 2012 (UTC)


 * Hi Rappy! There's a little bug in your JS: In the second line you use an assignment instead of a comparison.


 * Apart from that detail, I'm totally stealing your idea:


 * Pecoes 00:29, March 8, 2012 (UTC)


 * Can someone add this to Dev wiki? -- Fandyllic (talk &middot; contr) 7 Mar 2012 7:01 PM Pacific


 * Sure. I can do that. I'll file it under "Fix for Special:WantedFiles" and credit you and Rappy. Alright? -- Pecoes 04:10, March 8, 2012 (UTC)

Okay. It's been added to the dev wiki. I decided against using a importScriptPage, though. It's a little too short for that IMHO.

Here's the latest version:

Pecoes 05:24, March 8, 2012 (UTC)


 * I wish I knew about  beforehand. I do like the   better than  . Only one issue. '&' is a valid character in a file name. I am not sure if Special:WantedFiles encodes that to %26 or not (I highly doubt it). The above code will bug on those files. I shortened the href and changed your code to...


 * I changed the 'undefined' part of  since I read up on  . "'.match will only ever return a non-empty array or null.'" So that means it will never be 'undefined'. Rappy 07:19, March 8, 2012 (UTC)


 * That's not quite correct. Yes, match will return an empty array, but a non-existing index of an empty array is undefined.


 * EDIT: Oh, and the ampersand is an illegal name character in URLs. It must be encoded as %26. You can take that much for granted -- Pecoes 07:27, March 8, 2012 (UTC)


 * I had a moment to run a few tests and you were right after all. Simply testing for m is completely sufficient. My suggestion was plain wrong. Pecoes 11:42, March 8, 2012 (UTC)


 * Yep. Tested with a few files with an '&' in the name. On the page itself, it shows up with the '&', but the href is %26. I changed the last code above back the other regex. Rappy 21:26, March 8, 2012 (UTC)

I see you've re-arranged the if condition. Again. Look: It doesn't really matter, but when you compare two values it's more convenient to put the constant expression first and the variable second. That way you'll get a syntax error if you accidentally forget the second equals sign:

if ('Special:WantedFiles' = wgPageName) { /* ... */ }

If you put the variable first and the constant expression second:

if (wgPageName = 'Special:WantedFiles') { /* ... */ }

You get a hard-to-detect logical error instead of a syntax error.

Just a little trick. :) -- Pecoes 21:57, March 8, 2012 (UTC)


 * On dev wiki the infobox says, "Languages	irrelevant", but aren't some special pages named differently in different languages? I'm just mentioning this, because the pagename check would fail if Special:WantedFiles was returned localized by wgPageName. If wgPageName always returns the canonical English version than ignore me. -- <span style="border-bottom:1px dotted; cursor:help;" title="Who?">Fandyllic (talk &middot; contr) 8 Mar 2012 2:34 PM Pacific


 * I just visited a German wiki and the page is called "Spezial:Fehlende_Dateien". That's what it says in the URL and that's what wgPageName says. There is however wgCanonicalNamespace (which says "Special" and wgCanonicalSpecialPageName (which says "Wantedfiles"). I'll change the code. -- Pecoes 22:44, March 8, 2012 (UTC)