Generating dynamic content with MediaWiki/2009
OK. It's 20241123211029 - That's from the {{CURRENTTIMESTAMP}} as you should know. Generating dynamic content with MediaWiki is something that we do "on the fly" as time goes by. It's a pretty good indication that the Humans, bots and dynamic pages are populated when you see content changing a lot. This part of the study is from mw:Help:Extension:ParserFunctions in the MediaWiki Handbook that all users and sysops should be familiar with.
This Year
[edit | edit source]We're going to break it all down.
The parser function #time breaks down the {{CURRENTTIMESTAMP}}:
{{#time:Y|{{CURRENTTIMESTAMP}}}} is evaluated 2024
[[{{#titleparts:{{FULLPAGENAME}}|2|1}}|{{#time:Y|{{CURRENTTIMESTAMP}}}}]] to give us:
2024
We Used [[{{#titleparts:{{FULLPAGENAME}}|2|1}}]] to hide our main namespace title which is rather long.
Generating dynamic content with MediaWiki/2009
Today
[edit | edit source]Today is Saturday
{{#time:l|{{CURRENTTIMESTAMP}}}}
Now, depending on your language's support, that should evaluate to a friendly name for the DOW - Day Of the Week. As I'm writing this it is:
{{subst:CURRENTTIMESTAMP}} = 20090905164321
To make it a bit friendlier we use
{{#time: d F Y |{{subst:CURRENTTIMESTAMP}}}} = 05 September 2009
..to give us a snapshot marking the beginning of this part of the project. We can call that a record.
MediaWiki is very good at keeping track of things that happened in the past on wikis like Wikipedia and Wikiversity, so we're not too concerned about using its dynamics to track the past. What we want to do is use MediaWiki's parser functions to build a structure for the future. To do that we need to look at numeric representations of yesterday, today and tomorrow to get a sense of what dynamic content is about. We can call this a project!
Tomorrow
[edit | edit source]Tomorrow = today + 1
There are several ways we can look at today as a numeric value. Arguably, the most natural way of looking at a day is as one rotation of the Earth around its axis. That rotation is relative to to other nearby bodies floating out here with us in space, notably the Sun and the Moon. A Day in relation to the Sun is of course the Day of the Year. For that, MediaWiki uses the z argument:
{{#time:z|{{CURRENTTIMESTAMP}}}} = 327
So as we go through the Year, this numeric position is unique over the range 001 .. 365 (366 in leap years). Usining Y and z together, these form ordinal dates and are pretty handy.
- A year ago today: {{#expr:{{#time:Y|{{CURRENTTIMESTAMP}}}}-1}}-{{#time:z|{{CURRENTTIMESTAMP}}}} => 2023-327
- Yesterday: {{#time:Y|{{CURRENTTIMESTAMP}}}}-{{#expr:{{#time:z|{{CURRENTTIMESTAMP}}}}-1}} => 2024-326
- Today: {{#time:Y|{{CURRENTTIMESTAMP}}}}-{{#time:z|{{CURRENTTIMESTAMP}}}} => 2024-327
- Tomorrow: {{#time:Y|{{CURRENTTIMESTAMP}}}}-{{#expr:{{#time:z|{{CURRENTTIMESTAMP}}}}+1}} => 2024-328
- A year from today: {{#expr:{{#time:Y|{{CURRENTTIMESTAMP}}}}+1}}-{{#time:z|{{CURRENTTIMESTAMP}}}} => 2025-327
I know it's not pretty or easy to do manually, but MediaWiki parser functions can be used to build tools and tables for dynamic content that regular folks can appreciate. These examples themselves are always going to be current. The code:
{| class="prettytable"
|+{{#time:Y|{{CURRENTTIMESTAMP}}}}
!yesterday !! today !! tomorrow
|-
|{{#expr:({{#time:z|{{CURRENTTIMESTAMP}}}}-1)}}
|{{#time:z|{{CURRENTTIMESTAMP}}}}
|{{#expr:({{#time:z|{{CURRENTTIMESTAMP}}}}+1)}}
|}
Will produce a "prettytable" on most wikis running MediaWiki.
yesterday | today | tomorrow |
---|---|---|
326 | 327 | 328 |
This Week
[edit | edit source]This week is 2024-W47 and today is Saturday or Day #6 of that week.
This week is {{#time:Y"-W"W|{{CURRENTTIMESTAMP}}}} and today is {{#time:l|{{CURRENTTIMESTAMP}}}} or Day #{{#time:N|{{CURRENTTIMESTAMP}}}} of that week.
That is dynamic, thus still true for the both of us. So now we want to see what the future looks like. What's in the future for me, is in the past for you. As I sit here, the Earth, Sun and Moon articles are only 2/3 started. One is a red link. The Sun module is a stub about Sun Microsystems and not about the celestial orb at all. The Earth module is a learning resourse about our planet and the Moon module is non-existent. This week and for all weeks to come the red link page is to remain non-existent, so it has a policy-directed status with no expiry.
{{#ifexist: red link|Call a custodian!|All is well at Wikiversity}} => All is well at Wikiversity
Since I'm in 2009-W36 I'll move this to a subpage -> [[/W{{#time:W|{{subst:CURRENTTIMESTAMP}}}}]] => /W36