Topic on User talk:PerfektesChaos/js/resultListSort

PerfektesChaos (talkcontribs)

Continuing Help talk:CirrusSearch

@ YaganZ asked:

Maybe I'm missing something, but I expected the result to be sorted. I'm sorry, my knowledge of JavaScript applied to MediaWiki context is quite poor, so I might have not understood the help page completely.
Well, you get the result as usual. This saves time.
If you are not happy with the order of this particular search you may request in the Vector more menu (desktop top line) the sorting (manually triggered by default).
The Blankpage offers, if and only if the tool is active, the possibility to automatically sort every Cirrus result, if you enter Search into the configuration field and submit by [+].
YaganZ (talkcontribs)

@PerfektesChaos, thanks for your help. "Sort result" under "More" did the job. Very simple, if you know where to look.

Now I'm going to try embedding "resultListSort" as a gadget on la.wiktionary. I'm not sure how to load an external script. As I remember only local scripts worked as gadgets. But I might have done something wrongly. Do you know of any project that's using "resultListSort" as a gadget? It might be useful to examine the code in "MediaWiki:Gadgets-definition" as an example.

PerfektesChaos (talkcontribs)

Since you put that on meta:User:YaganZ/global.js it will work with every wiki project in WMF.

However, you have mentioned that there was something blocking you. Note the remark in guideline:

  • If you are blocking scripts from sites other than your local Wiki you might need to put www.mediawiki.org on the whitelist.

BTW: These weeks I am working on sorting Cirrus results by page size and most recent modification time.

PerfektesChaos (talkcontribs)

Oh, sorry, I might have missed your point.

You want to extend wikt:la:MediaWiki:Gadgets-definition don’t you?

Well, you will need a very small page wikt:la:MediaWiki:Gadget-resultListSort.js and just put the same code (one statement mw.loader.load(...)) into this page as on your global.js, and some more administrative business.

For you the script will be loaded twice, one time from global and one from wikt:la – the script is prepared for this situation and will ignore itself at the second loading. However, that will cost you time and networking, and you should not tic the local gadget.

I would not recommend to copy the entire code from here, since you would not participate in updates.

Five years ago MediaWiki announced to provide “global gadgets” (Gadgets 2.0) to be maintained globally. That is the reason why the code is resident right here, but nothing happened.

Salve.

YaganZ (talkcontribs)
Yes, that's the point. After some strange experiences where global JavaScript interfered with local scripts, I'm trying to keep my global.js empty. Gadgets can be simply disabled if there are problems. At the moment I need the sorting option only at la.wiktionary and will try your proposal to create a local gadget page containing the loader statement only. That's the trick I didn't hit on!
I know that copying the code is no good idea. I had to do this once when I imported the translations editor script from en.wiktionary, including the entire legacy script package. To make it run on la.wiktionary I had to modify a lot of code that would have to be modified again, if there were any updates.
YaganZ (talkcontribs)
The gadget version is running. Thanks so much for your help!
PerfektesChaos (talkcontribs)

@YaganZ

Than I have an accelerating improvement I left out to avoid confusion. You may enclose the statement into a namespace query, avoiding loading for regular pages:

if ( mw.config.get( "wgNamespaceNumber" )  ===  -1 ) {
   mw.loader.load(...);
}

Since sorting is defined for special pages only, skip the entire stuff on all other pages.

Reply to "YaganZ question"