2012

    Wow. That’s how it’s done.

    Cappuccino with tulip latte art in a white cup beside a rustic scone with dried fruit on a white plate, on a wooden table.
    • So, how many pieces of candy do you give to trick or treaters? I do 3-5 depending.
    • Estimate 80 trick or treaters so far.
    • Wave 2 of trick or treaters hitting the doorbell now.

    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.

    Mac Wi-Fi menu showing available networks with openwireless.org highlighted and selected as the active open network among 13 nearby options.

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

    There should be an Emoji version of Letterpress.

    Surprised that Letterpress doesn’t have achievements.

    Nice seats for Gopher game! Thanks Kent! 🏈

    Packed TCF Bank Stadium during a Minnesota Gophers football game, seen from field-level seats with cheerleaders on the sideline.

    Double Macchiatos at Urban Bean Coffee with Kent. ☕️

    Two double macchiatos in white ceramic cups on saucers atop a wooden table, topped with espresso crema and a small dot of steamed milk foam.

    Playing Lost Cities this way.

    Hand holding fan of numbered Lost Cities cards over a colorful game board with expedition path tiles and a card face-up in the center.

    Visiting National Eagle Center

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

    Family of four posing beside a live bald eagle perched on a display stand inside the National Eagle Center in Wabasha Minnesota

    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.

    A woman holds a bald eagle on her gloved arm before a seated indoor audience while visitors photograph the bird

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

← Newer Posts Older Posts →