thingelstad

Jamie Thingelstad's personal website

Month: October 2012

MediaWiki Template Filter Title

I was recently doing some cleaning on our Read/Write Book Club website and ran into an interesting challenge. All of the books in the wiki are in a couple of categories, but I wanted them sorted right ignoring A, An and The beginning of the title. MediaWiki supports this in the category tag allowing you to specify [Category:Book|Sort Title] and early on in the wiki I had a second field in the form for Sort Title asking the person editing the book to do this.

The result was nobody did it and all the books with “The” in the beginning of the title were all under T. Shouldn’t this be easy to just deal with in the wiki itself?

Well, it turned out to be much harder than you would think in large part because MediaWiki doesn’t honor spaces in template tags. My first attempt to do this was rather brute force, simply look for the three cases that I want to get rid of in the title and chop it off.

<includeonly>
{{#if:{{{1|}}} | {{#vardefine:title_filter_temp|{{{1}}} }}
{{#if: {{#pos:{{#var:title_filter_temp}}|The }} | {{#ifexpr: {{#pos:{{#var:title_filter_temp}}|The }} = 0 | {{#vardefine:title_filter_temp| {{#sub:{{#var:title_filter_temp}}|4}} }} }} }}
{{#if: {{#pos:{{#var:title_filter_temp}}|A }} | {{#ifexpr: {{#pos:{{#var:title_filter_temp}}|A }} = 0 | {{#vardefine:title_filter_temp| {{#sub:{{#var:title_filter_temp}}|2}} }} }} }}
{{#if: {{#pos:{{#var:title_filter_temp}}|An }} | {{#ifexpr: {{#pos:{{#var:title_filter_temp}}|An }} = 0 | {{#vardefine:title_filter_temp| {{#sub:{{#var:title_filter_temp}}|3}} }} }} }}
{{#var:title_filter_temp}}
| No parameter passed to [[Template:Filter title]]. }}</includeonly>

This worked in many cases, but not all. A book like Antifragile got in trouble with this approach since the “An” matched it got sorted in “T”. You would think this would be an easy fix right? Don’t look for “An” but instead for “An “, including the space in the match. Unfortunately it is nearly impossible to pass a space into a MediaWiki template. MediaWiki effectively trims all template inputs of spaces so a space by itself becomes, effectively, null. A different approach was needed.

After some consideration I came up with this approach that uses the Arrays extension. I like it a lot more than the first attempt! The basic idea is to break the title into an array of strings on the space (note that #arraydefine allowed me to use a regex pattern to avoid the problem of not being able to pass in a space). I then check if the first element in that array matches a set of targets (in the #switch statement). If it does, set the index to 1, otherwise 0, and build a new array from that index offset. Like this:

<includeonly>{{
#arraydefine:filter_title_temp|{{{1|No title was provided}}}|/\s/}}{{
#switch: {{#arrayindex:filter_title_temp|0}}
 | A | An | The = {{#vardefine:filter_title_i|1}}
 | #default = {{#vardefine:filter_title_i|0}}
}}{{
#arrayslice: filter_title_new | filter_title_temp | {{#var:filter_title_i}} }}{{
#arrayprint: filter_title_new | _ | @@@@ | @@@@ }}{{
#arrayreset:filter_title_temp|filter_title_new}}</includeonly>

This works great with one exception. I still get confounded with the space problem when assembling the new title in the #arrayprint method. I decided to print the new title with underscores where the spaces were. Since this is used for the sorting condition, this is fine. The end user never sees the title and the wiki will sort right if given Title_of_the_Book.

Now the sortable titles are all generated and the Book Category page looks awesome.

Guest network now openwireless.org

For years I’ve ran a guest WiFi network at home that has been called “Thingelstad Guest”. It makes it super easy for people that are visiting to hop online when they are visiting. I also don’t have to share the key for the “Thingelstad Home” network with people that are visiting which is a plus.

Last night my buddy Ry4an Brase posted on Google+ this EFF Open Wireless project. I’m a proponent of allowing unfettered access to the Internet so I decided to join up and rename our guest network.

Does your router support a guest network? How about doing the same on your network?

Visiting National Eagle Center

While in Wabasha for the weekend we spent the morning at the National Eagle Center.

Mazie and I also attended one of their workshops and learned a lot about the Bald Eagles and got to see one of them have lunch.

Definitely a fun place to stop in Wabasha on your next trip!

New Standards at The Dakota

We returned to The Dakota last night after seeing Robyn Hitchcock the night before for The New Standards.

We’ve seen The New Standards play at the Dakota at least six times before, and every time it’s a treat. Last night we got to enjoy the show with our friends Kent and Marilee celebrating Kent’s birthday! That only made it even better. It was also great to hear that the new album is on the way, and by the sound of it the recording was done and it should be coming relatively soon. They seemed to be really on, playing extra well together and having a lot of fun. It was a great show. You really shouldn’t pass up the opportunity to see them, especially at The Dakota.

Robyn Hitchcock at The Dakota

On Friday night we went to The Dakota to see Robyn Hitchcock. Tammy enjoyed his music a lot in high school and college. I knew of him, but didn’t know his music well. We ended up getting there at 6:40p and realizing the show started at 8:00p so we had plenty of time for dinner and drinks.

Richard Lloyd

Richard Lloyd opened up with a few songs on the guitar. I don’t know his work at all and it seemed like the kind of thing that you liked if you knew him and knew his music, but we didn’t and neither of us were very thrilled with it.

Robyn Hitchcock

Robyn Hitchcock was very good. He was funny in a completely nonsensical way. He went off on these stories that you had no idea where they were going. It was a fun show and he was a very good performer. Neither of us knew the songs very well, but that didn’t dampen the enjoyment at all.

Pedal Pub in the Rain

It wasn’t a good day yesterday to do the Pedal Pub. Cold, rainy.

AT&T LTE Spotting

AT&T has announced that they are working to bring LTE to the Twin Cities market by the end of the year. Yesterday while driving by the River Center I saw LTE on my phone for the first time. I loaded a few web pages and it was very fast, pretty much WiFi like experience.

Pictures from 2012 Dallas Oktoberfest Kubb Tournament

The Kubbchucks played at the 2012 Dallas Oktoberfest Kubb Tournament on Saturday. In between games I took out the camera.

Happy Birthday Mom!

Today is my Mom’s 60th Birthday! Happy Birthday Mom! If my Mom is any indicator, 60 is the new 30! :-)

To mark the day we get family together at the Minneapolis Photo Center and I took a ton of family photos for everyone. It was a really fun evening with great images to remember the day with.

© 2014 thingelstad

Theme by Anders NorenUp ↑