Template talk:VideoGallery/sandbox

From Dolphin Emulator Wiki
Jump to navigation Jump to search

Randomization Seeds

So one other template we might want to consider for use as a randomization seed would be :{{CurrentGitRevision}}. It definitely seems to update regularly, though there are likely still concerns with caching. Things like NUMBEROFARTICLES and NUMBEROFPAGES will stop updating (or slow down significantly) once we complete generating title pages.

{{CurrentGitRevision}} should already trigger page refreshes anyways since all pages call it from version compatibility, so using it as a seed shouldn't change behavior from how it is currently at all. - Xerxes (talk) 08:32, 29 January 2018 (CET)
It will likely need a regex to purge out the hyphen and period though. Kolano (talk) 08:36, 29 January 2018 (CET)
Doesn't seem to be a problem with hyphen and period apparently I think. Lucario (talk) 08:58, 29 January 2018 (CET)
PAGES:R picks up even redirect and other pages while ARTICLES:R only focuses on number of article pages. The PAGES:R will change more frequently so it was used. Also, this template already use template:CurrentRevision and I believe it's not much of a difference from the "Git" one when it comes to randomization generation, because each time CurrentRevision has +1 then the Git will have +1 as well. It'd be awesome when there's something we can capture from within this wiki that changes constantly. CurrentVersion, PAGES:R, and #time:U are the best ones I can think of... Lucario (talk) 08:58, 29 January 2018 (CET)

Do these issues matter?

Are there any one or more issues listed in Template:VideoGallery/sandbox#Cons/Issues a big deal to some of us? Lucario (talk) 01:50, 31 January 2018 (CET)

I'd like to take a look at what all you did if that's alright. I've been waiting until you were satisfied with it first to poke around figuring out how it works exactly. The listed cons themselves don't seem like a problem to me though, I'm just curious. - Xerxes (talk) 02:19, 31 January 2018 (CET)
Yeah, I'm mostly satisfied with the current sandbox considering my limited abilities. It could be better optimized and issues could be sorted out in no added complexity hopefully. I'm glad there aren't any bigger issues. Lucario (talk) 02:47, 31 January 2018 (CET)
I think it's fine honestly, besides the pedantic formatting stuff. I didn't even know you could use a variable within a regex string, so that's cool. I'd have to really sit down with a pen and paper and do the math on the random logic in there to have any comment on it, and I haven't yet. My only gripe is that the template should skip over the legacy version if {{{1|}}} is defined, but that would hurt how nicely they're split up currently. - Xerxes (talk) 05:59, 31 January 2018 (CET)
Okay! I know the code in template is getting quite complicated, it took time for me to understand which code is responsible for what went wrong in live page. I've explored through potential workarounds, looked on internet for examples and lot of guess, then lot of edit previews and lately, things work out fine. I feel accomplished. NOW it'd be hard for people other than me to understand how they work unless they study lot on it! Haha! Anyway, I was thinking of keeping the legacy version just in case we've had to work through the existing videos those that have not adapted to the new format yet. Then if all the videos are converted into new format then the legacy codes can be purged out. Or we can just ask Kolano or someone else mass edit and convert the existing videos to new format, and if they will, the legacy codes can be dropped beforehand. Lucario (talk) 07:17, 31 January 2018 (CET)
  • #vardefineecho: Would be preferable to not have it, but shouldn't be a big problem.
  • Listed in reverse order: Probably doesn't matter, though aren't they in random order? I think I'm confused by this.
  • Videos without caption will have empty caption: This no longer seems like a con, I think it's leftover from when oddball captions were generated.
  • Square Brackets: Could be a problem as lots of YouTube vids use square brackets in their titles, but double / unmatched ones should be fairly rare.
Kolano (talk) 02:26, 31 January 2018 (CET)
It's a bit unfortunate that the #vardefineecho: is an requirement for the parameterless version. I've completely forgotten that it was needed when I moved code from my talk page to sandbox. The differences between my talk page and this sandbox template is that my talk page isn't even a template, so the equal sign problem is invalid there. So I've copied how template:Problems worked out with contents that have equal sign. I was hoping nobody would mind it. Though it'll require mass edit to add #vardefineecho: to every VideoGallery template. I think the regex mass edit will gonna be easy, just don't do it on VideoGallery that has videos, only the empty ones.
Hrm, ok, seems you're bringing up an additional complexity there. So #vardefineecho: doesn't work out if VideoGallery is using the old parameter format? Kolano (talk) 03:53, 31 January 2018 (CET)
The template won't see parameters such as |vid#= as parameter any more if they were moved into #vardefineecho:, but I think it'll be alright if #vardefineecho: was added but keep parameters out of it. Lucario (talk) 04:09, 31 January 2018 (CET)
All the empty videogalleries were copy/pasted, so regex replacing only those ones to add the echo should be alright. (Though we could've just regex'd everything to begin with, but don't tell anyone I said that.) - Xerxes (talk) 04:16, 31 January 2018 (CET)
I'd guess it probably wouldn't be too hard to work out regex to convert the old parameter format to the new one. I have some concerns over having a mixed bag of formats. Kolano (talk) 06:22, 31 January 2018 (CET)
Multiple regex mass edit could work out. I just can't think of what regex that will add #vardefineecho: and then convert between old and new format in one go. Lucario (talk) 07:17, 31 January 2018 (CET)
Also, like sandbox, VideoGallery never had the list in random order, just the featured videos. Lucario (talk) 02:47, 31 January 2018 (CET)

Okay, thanks, I've now not looking at cons or issues as true problematic, I've moved them to Template:VideoGallery/sandbox#Quirks except I think #vardefineecho: is still a con. I don't think I'm going to treat double open bracket as con of this template, it's an outside problem. Lucario (talk) 03:49, 31 January 2018 (CET)


Ready to go live out of sandbox? I'll reassure you that pages will still work fine without undergoing mass edit. Then mass edit whenever you feel like it, yes? Lucario (talk) 00:35, 7 August 2018 (CEST)

Would want to hold that off for now, I want to offload most stuff to JavaScript. Goal is using this template for category abilities for typo mistakes and they will just display as hyperlinked fixed list, then JavaScript will randomize and embed three featured videos. The extension #ev will have to be dropped because after going through JS it isn't going to be possible to go back to the Wiki side. Lucario (talk) 02:55, 4 February 2022 (CET)
Or we can still deploy it as part of slow transition, the parameterless version works and the legacy code will be there until there are no more pages using it. JS can adopt parameterless version. Lucario (talk) 03:07, 4 February 2022 (CET)


function shuffle(a) {
  for (let i = a.length - 1; i > 0; i--) {
    const j = Math.floor(Math.random() * (i + 1));
    [a[i], a[j]] = [a[j], a[i]];
  return a;

function isYT(url){
  if(url.match(/.*\//) == 'https://www.youtube.com/embed/') return true;
  if(url.match(/.*\//) == 'https://www.dailymotion.com/embed/video/') return true;
  return false;

function embedYT(e){
  var div = e.getElementsByTagName("div")[0];
  var url = div.getAttribute("data-src");
  var iframe = document.createElement("iframe");
  if (isYT(url)) iframe.src = url;
  iframe.setAttribute("allowfullscreen", true);
  iframe.setAttribute("frameborder", 0);
  iframe.style = div.getAttribute("data-style");
  var hl = div.getElementsByTagName("a")[0];
  var new_div = document.createElement("div");
  new_div.style = "background-color:#f8f9fa; border:1px solid #c8ccd1; padding:3px;"
  new_div.innerHTML += "<br><span style='text-overflow:ellipsis; white-space:nowrap; overflow:hidden; display:inline-block; vertical-align:top; width:calc(" + iframe.style.width + " - 10px); font-size:94%;' title='" + hl.innerHTML + "'>" + hl.outerHTML + "</span>";
  return new_div;

function VideoGallery(e){
  var ul = e.getElementsByTagName("ul");
  ul = [...ul]
  var new_vg = document.createElement("div");
  var new_obj;
  for(let i = 0; i < ul.length; i++){
    if (i < 3){
      new_obj = document.createElement("div");
      new_obj.style = "float:left; margin:0.5em 0 1.3em 1.4em;"
    } else {
      if (i == 3) new_vg.innerHTML += "<div style='clear:left'></div>";
      new_obj = ul[i];
  e.innerHTML = new_vg.innerHTML;

window.onload = () => {
  var vg = document.getElementById("VideoGallery");
  if (vg) VideoGallery(vg);

Untested outside Firefox with TamperMonkey addon, may need a few clean up before putting it into MediaWiki:Common.js but everything looks good to me. Some CSS codes used inline in the JS could be moved to MediaWiki:Common.css. Lucario (talk) 10:43, 5 February 2022 (CET)