MediaWiki talk:ChatLinkSearch.js

From Guild Wars 2 Wiki
Jump to navigationJump to search

Hey *, hey Poke,

as some of you might know the game opens only the English version of the wiki when you use the /wiki-Command (e.g. /wiki [&B9YyAAA=] for Steal) regardless of the selected language. For the German wiki we have a workaround for normal strings (i.e. /wiki de:Steal) but unfortunately this doesn't work for chat-links as they contain illegal characters (i.e. /wiki de:[&B9YyAAA=] won't redirect). Since the developers currently aren't working on this we thought maybe you guys could integrate this into this ChatLinkSearch.js script, as it gets loaded every time the "de:"-Pattern isn't recognized because of illegal characters (like [) in the string?

An example implementation (pastebin) - insert after line 18:
// redirect to the German wiki if the search begins with "de:"
var deRedirectPattern = /^de:/g;
if(deRedirectPattern.test(searchBar.value)) {
window.location.replace('//wiki-de.guildwars2.com/wiki/index.php?title=Spezial%3ASuche&search=' + encodeURIComponent(searchBar.value.substring(3)) + '&go=Seite');
}
Note: This might not be the best solution, since I'm not a JS-Developer, but at least it'll work The redirect would only be performed if the Search begins with "de:" (so there shouldn't be any drawbacks). --olertu 12:43, 18 July 2015 (UTC)

Hi Olertu. I don't do js often either, but I've cobbled together [[MediaWiki:InterwikiSearchRedirect.js]] which will hopefully do what you require (I've tested it very briefly). I've split it from MediaWiki:ChatLinkSearch.js because I wasn't entirely happy combining chat links ([&...=]) with interwiki links, so some of the code is copied over. -Chieftain AlexUser Chieftain Alex sig.png 22:08, 18 July 2015 (UTC)
... and I've added it to the Mediawiki:Common.js so that it loads - let me know if you find any bugs :p -Chieftain AlexUser Chieftain Alex sig.png 22:14, 18 July 2015 (UTC)
Hi, Chieftain Alex. Thank you very much for the fast integration :) - It seems to work perfectly. Also thanks for the credit and feel free to include yourself as the author if you want (since you improved / extended it and performed the integration). Probably a little improvement: pastebin (if you put the include inside the if it'll load only if a search is performed (but the script should get cached anyways) - you can either put it before or after MediaWiki:ChatLinkSearch.js). --olertu 01:30, 19 July 2015 (UTC)
Good point on including it under Special:Search, I hadn't noticed that statement on common.js ^^. I'll leave the attribution as it currently stands since it doesn't bother me. -Chieftain AlexUser Chieftain Alex sig.png 12:02, 19 July 2015 (UTC)

Skills header[edit]

Seems to now use 0x06. [&Bt1+AAA=] "Guild Objective Aura" (effect) and [&BusnAAA=] "Spatial Surge" (mesmer gs1). --BryghtShadow (talk) 17:10, 16 December 2015 (UTC)

Auto redirect to search result?[edit]

It seems like it'd be useful to automatically redirect to the resulting article if there's precisely one search result (that is, no results from the wiki itself and exactly one successful result from this JS). The only downside I can think of is that it'll make your life worse if the only reason you did the search was to extract the ID from the link (but you could work around it by linking the same item twice -- or perhaps we could just add the plain text ID to infoboxes. I know I'd find that useful.).

In a related vein (although not quite this JS file's responsibility), it'd also be nice if we automatically redirected users who do "/wiki Some thing" to the [[Some Thing]] article, rather than be useless just because they forgot to capitalize the T. This hit Reddit a few hours ago, and it's been bugging me for a long time anyway. The right fix involves making search case-insensitive, but it doesn't seem like Anet have much interest in making that happen. Can we botch it with some JS instead? -- Dagger (talk) 18:33, 27 December 2015 (UTC)

Okay, I wrote it myself. Here's the diff. If it looks sane, could someone update this JS? You should just be able to copy and paste the complete source from User:Dagger/Pull requests/ChatLinkSearch.js to this page (and hit Show Changes to make sure you aren't committing some random crap). You can test it in Firefox's Scratchpad.
I used my "originalsearch=blah" suggestion from Guild Wars 2 Wiki talk:Requests for technical administration#Improved ingame wiki search. You guys have had a year to come up with something better. It doesn't implement the "insert the originalsearch parameter into the search box" part, because that requires JS on the target page and this script is only loaded on Special:Search. You can just copy the link from the URL bar though (and then manually unescape it...). You can also just add anything else at all to your search (some characters or another link) to stop the redirect.
Note that I didn't touch the existing results display, so the end effect is that the link starts to fade in, and then the page redirect interrupts it. If that's too messy, I can rewrite this script to avoid that, but it'll end up being a much bigger set of changes. -- Dagger (talk) 19:33, 8 January 2016 (UTC)
I get the distinct feeling from mw:Manual:Parameters to index.php#View and render that specifying the rdfrom parameter should allow us to fake a "redirected from" message, however I can't get it to do anything at all.
Given that there isn't a way of interrupting the search if you haven't put anything else in the search box (a space is sufficient to stop the redirection), I personally do not plan on implementing redirection code. As it is, if you took the originalsearch and put it in the search box (without anything else) you're straight back to the page you landed on, without any clues as to the item id or chatlink type. -Chieftain AlexUser Chieftain Alex sig.png 00:52, 9 January 2016 (UTC)
I peered at the source; it seems to be trusted wikis only, where the default trusted list is "false".
Okay, how about I redirect only if the go and fulltext parameters are both unset? The search buttons on the wiki set one or the other of those parameters. /wiki from in-game doesn't. So the redirect should only happen if you come directly from in-game. -- Dagger (talk) 02:37, 9 January 2016 (UTC)
Or wait, here's a better idea: store the chat link in session storage when redirecting. If the link is already in session storage, don't redirect. That way you can just hit 'Back' to show the search page again. Session storage is per tab and /wiki loads a new tab (for, I assume, most people) so you can look up the same item twice and it'll redirect both times, but only once in any given tab. Problem sorted?
I'll test it tomorrow, because I'm going back to bed now. -- Dagger (talk) 03:37, 9 January 2016 (UTC)
Seems To Work™. Diff here. You only get one redirect per tab (at least for me in Firefox). Opening a link from in-game opens a new tab, which will redirect once, but you can then hit back to get to the search results page without getting stuck in a redirect loop.
(You could also get the item ID just by hitting Edit and copying it out of the infobox...) -- Dagger (talk) 00:23, 10 January 2016 (UTC)
Well you implemented a very thorough solution. If a page sets Has game id, it probably has the chatlink visible on the page, so I've removed it from the "originalsearch" bit. Otherwise, I've gone with your session store thing so they can go back if they want. -Chieftain AlexUser Chieftain Alex sig.png 16:11, 20 January 2016 (UTC)
I wish the game would pass a flag parameter with the /wiki command. That way, I imagine we can have it redirect if it knows the request came from the game.--Relyk ~ talk < 16:25, 20 January 2016 (UTC)
I'm sure ANet could change that for us if we asked. However I think the search uses a slightly different string to the usual: if you paste a chatlink and hit Enter with monobook (or "go") or vector:
http://wiki.guildwars2.com/index.php?search=[%26AgHbCgEA]+[%26AgH%2FAQBA22AAAA%3D%3D]&title=Special%3ASearch&go=Go
hit search with monobook:
http://wiki.guildwars2.com/index.php?title=Special%3ASearch&search=[%26AgHbCgEA]+[%26AgH%2FAQBA22AAAA%3D%3D]&fulltext=Search
Search from ingame:
http://wiki.guildwars2.com/wiki/?search=[%26AgHbCgEA]+[%26AgH%2FAQBA22AAAA%3D%3D]
Checking the string for the lack of "&" or "go=Go"/"fulltext=Search" could tell us if it came from ingame or not. -Chieftain AlexUser Chieftain Alex sig.png 16:57, 20 January 2016 (UTC)
The problem is that the /wiki command is the only way to get chat links out of the game, short of memory scraping the chat box. Most people will want it to redirect most of the time, but anybody trying to get the link itself will want it to not redirect. What we really want to know isn't where the link came from, but what the user's intent was. (If only we could just ctrl+c the link out... and a right-click -> Wiki would be nice, while I'm asking for things that'll never happen.) -- Dagger (talk) 23:14, 27 January 2016 (UTC)

Link IDs to their API endpoints[edit]

I just found myself looking at this results page:

  • [&AgfujQAA] Greatsaw (item #36334)
  • [&AgXrjQAA] There is no article linked with this ID (36331) yet. If you know what item this chat link links to, please add the ID to the article or create it if it does not exist yet.
  • [&AhD7jQAA] There is no article linked with this ID (36347) yet. If you know what item this chat link links to, please add the ID to the article or create it if it does not exist yet.
  • [&AgXtjQAA] There is no article linked with this ID (36333) yet. If you know what item this chat link links to, please add the ID to the article or create it if it does not exist yet.

Okay, great, but I've since totally forgotten which items those unknown IDs are. Wouldn't it be useful if they linked to https://api.guildwars2.com/v2/items/36331 etc to make it a bit easier for me to create the corresponding pages?

Here's the patch to implement that. Same deal as last time: If it looks sane, could someone update this page? You can copy and paste the complete source from User:Dagger/Pull requests/ChatLinkSearch.js to this page (and hit Show Changes to see exactly what you're committing), and you can test it by copying it into Firefox's Scratchpad first.

Incapable of reading high id skills[edit]

Jade power charge: [&BpMFAQA=] (). Sniper shot: [&BpMFAAA=] ()

See https://wiki.guildwars2.com/index.php?search=Jade+power+charge%3A+[%26BpMFAQA%3D]+(66963).+Sniper+shot%3A+[%26BpMFAAA%3D]+(1427)

Search javascript interprets this both as id 1427. Reported on discord by Adeira Tasharo. -Chieftain AlexUser Chieftain Alex sig.png 12:14, 5 March 2022 (UTC)

Content of MediaWiki talk:InterwikiSearchRedirect.js[edit]

moved from MediaWiki talk:InterwikiSearchRedirect.js

Attribution[edit]

In case anyone wonders where this has come from...

-Chieftain AlexUser Chieftain Alex sig.png 12:02, 19 July 2015 (UTC)

Good idea to make this separate :) I’ve made it a bit simpler, to use only a single regular expression to match them all, and to use a generic URL with English page names (since MediaWiki accepts those with every localization). Also don’t use that meh jQuery DOM-ready event for this, just execute it immediately :) poke | talk 19:43, 19 July 2015 (UTC)
Good work. I knew that interwikis such as de:Special:Search worked (thats how I found the local versions in the first place...) but I didn't think it would work in the url + didn't guess that the go button would accept alternative language options. Thanks for cleaning it up. -Chieftain AlexUser Chieftain Alex sig.png 08:44, 20 July 2015 (UTC)

Change of ingame wiki search behaviour after 2017-06-20 patch[edit]

Per Game updates/2017-06-20, after typing /wiki ingame with the client not set to english, the interwiki prefix is added automatically - which works perfectly with our script. Since using the language specific wiki might not be wanted by everyone (see this reddit thread) I decided to add a check for a cookie that will suppress this behaviour. The cookie is set, unset and checked by visiting Widget:No interwiki search.

I don't know where I should document this behaviour other than on Help:Searching. Any ideas/comments? -Chieftain AlexUser Chieftain Alex sig.png 18:05, 21 June 2017 (UTC)

But searching on non-English clients will still route through our wiki right? They are just adding de:/es:/fr: in front of the query? So they essentially use our interwiki search functionality by default now? :P poke | talk 18:09, 21 June 2017 (UTC)
So, I just tested this out. Turns out, it actively adds the language prefix once you press space after entering /wiki. So you actually have total control over it, and you can still search non-localized wikis as you want. It’s just a bit of a hassle.
Here’s a video: File:User Poke Wiki search after 2017 June update.gif. poke | talk 18:36, 21 June 2017 (UTC)
You know I did actually test the client behaviour ingame first ;) I agree though, I would just have made "/wiki" direct to "wiki-de" (for example). I guess it lets us have a bit more control over it. -Chieftain AlexUser Chieftain Alex sig.png 18:57, 21 June 2017 (UTC)
I wasn’t sure how it would work from the way you explained it, so I had to test it myself and just made a video for others :P
I actually did expect you to test it first before making this change, you know? :P - But I’m also not sure how this cookie thing will help ultimately. How likely is it that people want to search for something prefixed with “de:” now that it’s being added automatically? poke | talk 19:08, 21 June 2017 (UTC)
Fair enough, my explanation was clearer on Help:Searching. Scenarios for non-english clients:
  1. /wiki fr: [&CkgSAAA=] - a chatlink. EN Special:Search > FR Special:Search (via the InterwikiSearchRedirect script) > Decodes chatlink on search page. Cookie can prevent it redirecting.
  2. /wiki fr: Twilight - text. EN Special:Search > Matching FR page title if found. This does not use the InterwikiSearchRedirect script, hence we have no control over it.
I think this is an adequate patch however I wish we could control scenario 2 too. -Chieftain AlexUser Chieftain Alex sig.png 19:52, 21 June 2017 (UTC)
But since the game puts the prefix very visibly into the chat prompt, you can easily remove it there to ensure you do not get redirected off to the language wiki but stay on here. So just type /wiki , then remove the prefix that gets added and continue as you want. So the ability to control it is there. poke | talk 20:42, 21 June 2017 (UTC)

At some point this stopped working[edit]

This javascript fails to intercept the language searches (it used to work) -- they go directly to the other wikis without loading javascript I think.

Called by GW2 when typing "/wiki es:AAaaaahhh" (client set to spanish):

"C:\Program Files\Mozilla Firefox\firefox.exe" -osint -url "http://wiki.guildwars2.com/wiki/?search=es%3AAaaaahhh"
----
Navigated to http://wiki.guildwars2.com/wiki/?search=es%3AAaaaahhh:

GET	https://wiki.guildwars2.com/wiki/?search=es%3AAaaaahhh [HTTP/2.0 302 Found 111ms]
GET	https://wiki.guildwars2.com/wiki/Special:GoToInterwiki/es:Aaaaahhh [HTTP/2.0 301 Moved Permanently 107ms]
GET	https://wiki-es.guildwars2.com/wiki/Aaaaahhh [HTTP/2.0 404 Not Found 84ms]

I think Mediawiki may have improved their interpretation of searches for interwikis. -Chieftain AlexUser Chieftain Alex sig.png 08:15, 18 August 2018 (UTC)

Based on Guild Wars 2 Wiki:Changelog, I think we moved from "MW 1.24.2" when this script was written, to "MW 1.30.0". I guess I can look through the mediawiki change logs to see what changed. -Chieftain AlexUser Chieftain Alex sig.png 08:17, 18 August 2018 (UTC)
https://doc.wikimedia.org/mediawiki-core/master/php/SpecialGoToInterwiki_8php_source.html Looks like it checks if the interwiki is local or not. I can't find any changelog for that special page.
Since its done internally at php level it will not trigger the JS anymore.
Plus because its an interwiki, there will never be any tokens to indicate the request came from ingame, so the other wikis won't be able to redirect us back. -Chieftain AlexUser Chieftain Alex sig.png 08:48, 18 August 2018 (UTC)
and randomly this script works again and is required to make interwiki searches of chatlinks function. -Chieftain AlexUser Chieftain Alex sig.png 20:28, 21 January 2020 (UTC)

April 2022 changes[edit]

Had a bit of discussion on GW2Developer Discord about how unreliable the interwiki redirect was. This seems to have been due to my own lazy implementation of the interwikiRedirect code (race condition). I've reworked this script to include that snippet. -Chieftain AlexUser Chieftain Alex sig.png 17:59, 13 April 2022 (UTC)

Interwikis - Case sensitive search when not a chat link[edit]

This is a bit of a redux of #At some point this stopped working above. This section is prompted by the request that interwiki searches from ingame seem to be case sensitive (e.g. Guardiana ayudante hortensia does not work but Guardiana ayudante Hortensia does work) - the initial question assumed the fault was in this script.

(1) Searching for something without an interwiki - chat link
  • Searching for a chat link in english ingame generates the following URL: https://wiki.guildwars2.com/wiki/?search=[&BhY4AAA=]
  • User lands briefly on Special:Search.
  • Via javascript (MediaWiki:ChatLinkSearch.js and SMW), if the match is a chat link, then the user is directed to the page with the decoded matching id. 1Yes
(2) Searching for something without an interwiki - text - exact match in case
  • Searching for text in english ingame generates the following URL: https://wiki.guildwars2.com/wiki/?search="To+the+Limit!
  • Wiki recognises this is an exact page title, does not bother showing/loading Special:Search, and immediately directs the user to https://wiki.guildwars2.com/wiki/"To_the_Limit!". 1Yes
(3) Searching for something without an interwiki - text - case is not an exact match
  • Searching for text with the wrong case in english ingame generates the following URL: https://wiki.guildwars2.com/wiki/?search="To+ThE+LiMit!"
  • Wiki recognises this is as a similar page title, does not bother showing/loading Special:Search, and immediately directs the user to https://wiki.guildwars2.com/wiki/"To_the_Limit!". 1Yes
(4) Searching for something with an interwiki - chat link
  • Searching ingame with the client language set to anything except english still automatically types the interwiki after a user types "/wiki" ingame - e.g. replaced with "/wiki es:" for the spanish wiki. For example "/wiki es:Guardiana+ayudante+hortensia".
  • This search is actually done via the english wiki! It generates the following URL https://wiki.guildwars2.com/wiki/?search=es:[&BkI4AAA=]
  • I think the EN wiki recognises anything with square brackets cannot be a valid page title at this point, because instead of passing that search term to "Special:GoToInterwiki" it instead passes it to ES wiki's Special:Search.
  • Navigation occurs to https://wiki-es.guildwars2.com/index.php?title=Special:Search&search=[&BkI4AAA=]&fulltext=Search
  • User lands on https://wiki-es.guildwars2.com/index.php?title=Especial:Buscar&search=[&BkI4AAA=]&fulltext=Search
  • Via ES wiki's javascript (MediaWiki:ChatLinkSearch.js and SMW), if the match is a chat link, then the user is directed to the page with the decoded matching id. 1Yes
(5+6) Searching for something with an interwiki - text
  • This search is again done via the english wiki! It generates the following URL: https://wiki.guildwars2.com/wiki/?search=es:Guardiana+ayudante+hortensia
  • The wiki realises that the search term contains the interwiki prefix, and maybe a valid page title (probably does a special character test), and immediately passes the request to https://wiki.guildwars2.com/wiki/Special:GoToInterwiki/es:Guardiana ayudante hortensia
  • This is interpreted by the receiving wiki as a case sensitive page title.
    • (5) Exact case match If the search term matches the case of the page title exactly, then this works fine. 1Yes
    • (6) Non-matching case If the case is slightly different, the end user is dumped at a page that doesn't exist. 0No

Having reviewed precisely what is going on I don't think we can fix the reported annoying 6 case-sensitive behaviour with anything userside.

What we really need is for ArenaNet to modify the behaviour of the /wiki function ingame to point and search on the correct wiki in the first place (e.g. with text language ES, the search should go straight to https://wiki-es.guildwars2.com/wiki/?search=es:Guardiana+ayudante+hortensia). -Chieftain AlexUser Chieftain Alex sig.png 20:19, 25 February 2024 (UTC)