MediaWiki talk:Gadget-GalleryFilterExtension.js

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search


Broken for anyone else?[edit]

Mine stopped working a little while ago -- ok more like several months. Has anyone else had a problem?Smasongarrison (talk) 03:47, 18 August 2023 (UTC)[reply]

@Smasongarrison: Should hopefully be fixed with Special:Diff/795401340. Lucas Werkmeister (talk) 17:40, 23 August 2023 (UTC)[reply]
Excellent! It works again. Thanks so much! Smasongarrison (talk) 20:52, 23 August 2023 (UTC)[reply]

Audio/video DOM changed[edit]

{{Edit request}} @Lucas Werkmeister: Are you able to apply a few more fixes to the gadget?

  1. The gadget doesn't recognize audio and video files any more because of related DOM changes. We need to replace
    if(t.getElementsByClassName('mediaContainer')[0])
    with
    if(t.getElementsByTagName('audio')[0] || t.getElementsByClassName('mediaContainer')[0])
    I'm not sure if it's a good idea to keep the old code around for maximum compatibility. That might not be necessary.
  2. Same for video files. Here we need to replace
    e = t.getElementsByClassName('PopUpMediaTransform')[0];
    with
    e = t.getElementsByTagName('video')[0] || t.getElementsByClassName('PopUpMediaTransform')[0];
  3. Videos are currently not sub-categorized by file extension. This is rather easy to add by copying what's done for images. Change the line
    if (e) ext = mime = "videos";
    to
    if (e) ext = mime = "videos";
    e = li.getElementsByClassName('galleryfilename')[0];
    if (e && e.title)
        ext = e.title.match(/\.(\w+)$/)[1].toUpperCase();
    

These changes have been requested via Reparatursommer. --Thiemo Kreuz (WMDE) (talk) 15:48, 12 September 2023 (UTC)[reply]

Maybe helpful – lines to be edited:
— Speravir – 00:36, 13 September 2023 (UTC)[reply]
✓ Done, with minor tweaks (using querySelector() to combine the two DOM queries into one) --Lucas Werkmeister (talk) 18:04, 14 September 2023 (UTC)[reply]
Thanks, a huge update! Works great on selected random categories, but, Lucas and Thiemo, strangely not fully on the random gallery Henry Lehrman (used by Lucas as example in MediaWiki talk:Gadget-LargerGallery.js): There are 4 videos with 2 different file types. Actually, in galleries I could live with a simple differentiation images vs. audio vs. videos vs. other, but images are still listed by file extension. Another example: Animal locomotion has 9 videos, 6 OGV and 3 WEBM files. In Videos the gadget fails, though there is at least one other file than WEBM (an MP3, so an audio file). For audios I found National anthem with the same behaviour (there are both OGA and OGG files). (Add.:) In Music there are 3 audios (2 MID, 1 OGG; edit because of the MID). Looking into another namespace: Commons:Featured media, list works fine, but the two audio files are recognized as “other”. C.Suthorn, as original requester at Reparatursommer, what do you think? — Speravir – 00:12, 16 September 2023 (UTC)[reply]
Yes, a huge improvement. (I am only interested in images and webm videos, so it is fine for me, but WRT audio etc more improvement is possible) C.Suthorn (@Life_is@no-pony.farm - p7.ee/p) (talk) 04:58, 16 September 2023 (UTC)[reply]
@Lucas Werkmeister: We did indeed made a tiny mistake. In this edit we add 3 new lines that reuse the existing variable e. This messes up the following code a bit. Instead the 3 lines need to use a new variable name.
Alternatively we can undo this edit and make another one instead. In detail:
  1. Revert 'video, .PopUpMediaTransform' back to '.PopUpMediaTransform'.
  2. Remove the 3 new lines.
  3. Change 'audio, .mediaContainer' to 'audio, video, .mediaContainer'.
  4. Change ext = mime = "audios" to ext = mime = t.querySelector('video') ? 'video' : 'audios'.
The other issues described above appear to be related to how the gadget behaves on galleries vs. categories. For example, it's not guaranteed it can extract the file extension in a gallery that doesn't show the file extension. I think these are older issues – possibly even by design – and probably out of scope of our Reparatursommer. --Thiemo Kreuz (WMDE) (talk) 11:31, 17 September 2023 (UTC)[reply]
“possibly even by design” – What I said: In galleries (aka main namespace in Commons) I could live with a simple differentiation images vs. audio vs. videos vs. other (e.g. in other are embedded, but deleted files found). But if this namespace distinction is hard to reach, then all fie types should be handled the same. — Speravir – 23:14, 17 September 2023 (UTC)[reply]
✓ Done (changing 'video' to 'videos' for consistency) Lucas Werkmeister (talk) 18:36, 29 September 2023 (UTC)[reply]
Cool. So why the page Videos still does not insert the form of this gadget? I did not look at this last time, but now: All videos embedded on that page are WEBM files, and in every case where only one file type is found the gadget is not visible. This is the normal behaviour also with image files. — Speravir – 21:12, 29 September 2023 (UTC)[reply]