User talk:Davidgothberg/Range

Latest comment: 15 years ago by Sardanaphalus in topic Nowrap handling

Background

edit
This is a copy of the discussion on my talk page that led to the creation of this template. --David Göthberg (talk) 04:36, 27 November 2008 (UTC)Reply

Hi again David. As a now-official template guru (congratulations!), here's something which I hope has an easy solution that I'm overlooking. Linking a template, such as Template:Nobel Peace Prize, is straightforward, but how do you link to a template and pass parameters to it at the same time? Sardanaphalus (talk) 11:35, 23 April 2008 (UTC)Reply

Oh, thanks. Or perhaps it is a curse...
Short answer: Well, you can't.
Long answer: Well, linking to a template and using a template is two very different things:
1: When you link to it you only point at it and say "the template is over there, if you want to take a look at it go there". And that is done by writing [[Template:Nobel Peace Prize]]. But then the template is not executed, the template is in fact itself in no way involved in that link. Except for that MediaWiki is smart and shows a red link if the template does not exist. But if you click the link and go to the template page you might see the template since then it is run once to render itself on the template page. But then you are on the template page and that has no relation to the page you came from. So there is no way the other page can feed any parameters to the template then. But the template code itself can contain default values that it can use if it doesn't get any parameters, like when it is run on its own template page. Often good for demonstration purposes. There are several ways to make default values. Perhaps it is default values you are asking for?
2: When you use the template you transclude or substitute the template onto a page. That means you actually fetch a copy of the template and run it, right there in the article. Transclusion is done with the code {{Nobel Peace Prize}} and then you can also feed parameters in several ways: {{Nobel Peace Prize|parameter one|parameter two}} or {{Nobel Peace Prize|color=blue|size=big}}. And the other way, substitution, well I don't recommend using substitution since that usually is a bad thing™ so I think we can skip the explanation of how that works.
3: But could you describe more in detail what you want to achieve?
--David Göthberg (talk) 12:45, 23 April 2008 (UTC)Reply
Thanks for your comprehensive response, as ever. It looks like what I'm after isn't possible (and probably for good background reasons) as I don't think your point 1 above is what I'm heading toward. The current {{Nobel Peace Prize}} is one of a number of award templates I've seen that have separate smaller templates for each group of years -- e.g. see Nobel Peace Prize navigational boxes, Academy Award for Best Actor templates, etc -- so, in the case of {{Nobel Peace Prize}}, I made an amended version of the template (here) that should remove the need for the smaller templates (and then serve as a model for converting the other award templates similarly). I was hoping the new design would extend to the links provided in the below section of the template, which is where template links that also pass parameters seem to be needed. I think, though, I may've overreached myself, or maybe I'm overlooking something simple. Hope so and hope all this makes some sense. Sardanaphalus (talk) 03:34, 24 April 2008 (UTC)Reply
Ohhhh! Now I see what you are after! Man, you ARE smart! This is a problem that has been discussed hundreds of times all over Wikipedia. And you actually have the solution right there. You cracked it! Apart from a last small technical thing but that one I know how to solve for you! You and me are going to make the best navbox of that type ever! (And to 99% it was your idea.)
So, ideally what we want is to have a smaller variant of that navbox in each article, say one that lists some years before and after the "current year" for that article. But we don't want to have to manage one template for each year. (About 93 years so far in the Nobel case...) And that is why people instead have made a handful of navboxes covering some fixed time ranges instead. But that is not so nice for the articles that is in the first or last year of such a smaller time range.
But you pointed out that we can use parameters, and I know the technical details how we can do that. There are several ways we can do this, here is one way:
1: We can make one single huge navbox with all years and with the full names of the laureates. But it should have no year range groups in it. Instead it should take the "year" for the article as a parameter and then simply display some years before and after that. So in the articles the full template will never be shown, just a smaller view of it.
At the footer of the template we should have the "complete roster" link, but I think that one can simply link to the template page, since that means the template will be run without the "year" parameter and then it should display all years. (Or perhaps to a special page that displays the full template but doesn't display the template documentation below it.) We won't need the range links you have now at the bottom of {{Nobel Peace Prize}}.
That's how I see it. And that I know how to code it up. What do you think?
2: We can also do a slightly different variant, but I think this one will display less good in articles and it takes more template pages to manage:
We can have year groups in the big template like you have now. But the big template should display the full names of the laureates. The template should take a "year" parameter and then it will just display that year group when shown in an article. (And perhaps not show the group header then.) This will of course be slightly bad for articles that is in the last or first year of such a group.
At the footer of the template we can have the "complete roster" link, which will go to the template page that will display all years. Or perhaps to a special page that displays the full template but doesn't display the template documentation below it.
We can actually also have range links there like you have now. (But I don't really see any point in them.) They can link to one template page for each range. But those template pages will not need any managing, since all they will contain is a view of the bigger template with the year as parameter.
--David Göthberg (talk) 07:15, 24 April 2008 (UTC)Reply
Wow. I had no idea I'd stumbled over and found a solution to something that's been bugging people. I almost didn't bother you (or myself) with it as it only seemed to apply to a few award templates. I can see now, though, how it may be appropriate to use in templates with many and/or lengthy subsections. I'm also glad you realized the intention behind User:Sardanaphalus/Template workspace#Template:Nobel Peace Prize with parameter as I realize I forgot to explain it above!
Your point 1 is what I had in mind and I agree that the solution to trying to reproduce the range links is not to try -- if someone wants to see more years, they may as well go straight to the overall template. So a single '''[[Template:Nobel Peace Prize|Complete list]]''' link should be enough. Once I had a solution to this situation, I was planning to let AWB work through a list of all the articles transcluding the various smaller templates replacing e.g. {{Nobel Peace Prize Laureates 1901-1925}} → {{Nobel Peace Prize|1901-1925}}, etc. If all that needs to be done is to replace the range links with the single link, I could do this and move straight on to AWB.
However, if you think the bigger picture means something like your point 2 is worth pursuing, naturally I'll wait until all's ready. But if the only difference between the point 1 and point 2 approaches is surnames vs. fullnames, I'm wondering whether it's worth the extra work..? (But perhaps you're seeing that it'd be useful elsewhere.) Sardanaphalus (talk) 08:37, 24 April 2008 (UTC)Reply
Right, this can be used on many sports templates and so on. Even in cases where the range number is not shown. In such cases we can use the numbers internally in the template code anyway, but perhaps (optionally) show the numbers on the template page so it is easy to see which item has which number.
I think it was pretty clear what you were after once you written your second section above and I looked at the template. After all, I have worked with this problem several times in the past together with others, without coming up with a solution. Now that you presented the idea of feeding a parameter to the template it suddenly was "obvious". (And the "obvious" solutions are usually the hardest to discover.)
Right, solution 1 is by far the best. I just mentioned solution 2 as a comparison since that one is more similar to today's solutions.
Well, since I will be doing calculations on the year parameter (using #expr:) and comparisons, then the parameter has to be a number, or two numbers. So I was thinking it would look like one of these:
  • {{Nobel Peace Prize|1913}} – In this case the template will have code to decide what range to show. That is, the template programmer will decide how many years (or what years) to show before and after 1913.
  • {{Nobel Peace Prize|1901|1925}} – In this case the article writer decides what range to show.
The {{Nobel Peace Prize}} is a very good template to start with since it has gaps in the years, thus we have to take that into consideration too. This makes me lean towards letting the article writers set start and end year since then they can handle the gaps and they can choose any size of the template they like in their article. Like in an article with many other navboxes they might choose to show a smaller range. But on the other hand letting the template programmer handle the gaps is nice to, since then the article writers just have to give one year and not think about the gaps.
Much to think about for us...
I will code up a meta-template that should handle most of this so it will be easy to do inside the navboxes.
--David Göthberg (talk) 10:08, 24 April 2008 (UTC)Reply
Thanks. Sounds like what you're thinking of is a whole dimension beyond what I had in mind. Anytime you have something to try or introduce, I'd be glad to know/contribute. Sardanaphalus (talk) 11:28, 24 April 2008 (UTC)Reply
I have built a first working version. Check out {{range}}, {{range/testcases}} and {{range/nobel}}.
While I was at it I threw in nowrap handling in the {{range}} template so we save some code in the Nobel navbox. And that happens to solve the Firefox nowrap bug at the same time! Wasn't even my intention. Sometimes life is nice.
There is one issue left: Currently there is a trailing dot after the last item when showing a subrange. I think I know how to fix that and will code that up later.
--David Göthberg (talk) 16:36, 25 April 2008 (UTC)Reply
Have just had a look at {{range}} and the examples and think I understand the machinery (and probably how you might sort out the trailing dot). Clever stuff. I hesitate to add the following, because I'm aware I'm coming from those award templates, but: Do you think it might be over-engineered? On the other hand, you may already know that broad fixed ranges like 1901-1925 might be fine for award templates and their articles but too chunky for sports and other templates you've seen. Just thought I ought to voice what crossed my mind. I'm not sure and may well have changed it a few minutes from now! Sardanaphalus (talk) 17:57, 25 April 2008 (UTC)Reply
Yeah, it might be over-engineered. Personally I like the fixed ranges since I have no problems with handling a couple of navboxes for one big list.
But I have seen over and over again that many other editors do not like that and I have had lengthy discussions with them. They resort to things like the {{Navigation bar}} in-spite that it seriously breaks some browsers, or they simply make humongous navboxes but perhaps set them to default hidden. Both those "solutions" also mean the whole list gets loaded even though it isn't shown, which makes page loading very slow for modem users (and costs bandwidth for Wikipedia). Our new {{range}} solution means the list first gets shrunk at the server end before sent over the Internet.
So I think we should continue work on {{range}} for a while and see how it feels. I hope it can be an alternative for those editors who refuse to use fixed ranges.
--David Göthberg (talk) 18:16, 25 April 2008 (UTC)Reply
I certainly think {{range}} should be useful, if not very useful. Would you say the editors not happy with with a few fixed 20/25-year ranges are those into sports templates? I don't know as I haven't seen many of these templates yet. Sardanaphalus (talk) 11:37, 26 April 2008 (UTC)Reply
Yes, the ones that I immediately remember I have talked to are makers of sports navboxes, but also of cities and towns navboxes (both in Britain and I think in Asia). Then I have talked to many others that I don't know or don't remember what kind of navboxes they were doing.
--David Göthberg (talk) 21:53, 26 April 2008 (UTC)Reply
I have added "trailing dot" handling to {{range}} now. See examples at {{range/testcases}} and the change in the code that use it in {{range/nobel}}. The new code for {{range}} is slightly large but seems to work very well.
--David Göthberg (talk) 11:36, 25 May 2008 (UTC)Reply
I'm impressed because you seem to be busy in so many other places. I haven't tried testing {{range/nobel}} "to destruction" but agree that the code looks sound. I hope the awards and sports folk appreciate and adopt your work. Sardanaphalus (talk) 16:25, 26 May 2008 (UTC)Reply
End, copy of the discussion on my talk page that led to the creation of this template. --David Göthberg (talk) 04:36, 27 November 2008 (UTC)Reply

Nowrap handling

edit

This template normally makes it so that the item it is fed does not line wrap. That is, it does the same thing as if the item are surrounded by a {{nowrap}}. This means that when this template is used for lists we only get line breaks between the items (after the trailing separators), which is usually what we want.

Sardanaphalus: I see you added an option to disable the nowrap of the list items. Personally I could see no reason why anyone would want to enable wrapping of items, but I see you have come up with a usage case over at User:Sardanaphalus/Template:SCOTUS courts. However, you added the option as an unnamed (numbered) 7th parameter. I think that will be somewhat messy. Since in the cases when no separator and no "nextitemyear" are fed (parameters 5 and 6), then we have to keep count and put two empty parameters before your "wrap" parameter. And keeping count on empty parameters is hard for human editors. Like this:

{{range|start_year|end_year|item_year|item|separator|nextitemyear|wrap}}

{{range | {{{1|}}} | {{{2|}}} | 1969 | [[Apollo 11]] ||| wrap }}

Thus I think it is better we instead add this option as a named parameter, like this:

{{range|start_year|end_year|item_year|item|separator|nextitemyear|wrap=yes/no}}

{{range | {{{1|}}} | {{{2|}}} | 1969 | [[Apollo 11]] | wrap=yes }}

And of course, if the wrap parameter is not fed it should default to nowrap, just as you did it. What do you think?

--David Göthberg (talk) 05:15, 27 November 2008 (UTC)Reply