Category Archives: Techie

Display MediaWiki job queue size inside your wiki

I wanted to find an easy way to show the current size of the MediaWiki job queue on WikiApiary. When you make changes to templates that are used on thousands of pages the queue can get backed up and it’s nice to have an easy way to keep an eye on this. The job queue is even one of the data points WikiApiary tracks and graphs. But I wanted something that was as close to realtime as possible. It wasn’t hard to do. This solution uses the External Data (see WikiApiary usage page) extension.

First we need to get the data. Let’s start by calling the siteinfo API method. The magic words are used to make this generic, and this should result in the right URL. If you are using a protocol-relative server setting you will have to modify this.

{{#get_web_data: url={{SERVER}}{{SCRIPTPATH}}/api.php?action=query&meta=siteinfo&siprop=statistics&format=json
  | format=JSON
  | data=jobs=jobs}}

Now External Data has done the work and the value is stored for us. Now we get it by simply calling:

{{#external_value:jobs}}

I like to put that in a style so it’s big and obvious.

If you’re thinking ahead you’ll now be saying “Yeah, that’s neat, but it will be cached in MediaWiki for a hours!”. Yes, it will be unless you add a __NOCACHE__ directive to the page and use the MagicNoCache extension. This extension allows you to disable the MediaWiki cache on a page-by-page basis, very handy.

If you wanted to use this in multiple places you could even put an <onlyinclude> around it and transclude the job queue size in other pages, however I would be cautious about that if using the __NOCACHE__ directive as well.

“Uncomfortable about how the internet’s developing”

Sue Gardner announced that she is moving on as Executive Director of the Wikimedia Foundation today. She highlighted where she wants to direct her energy next:

Increasingly, I’m finding myself uncomfortable about how the internet’s developing, who’s influencing its development, and who is not. Last year we at Wikimedia raised an alarm about SOPA/PIPA, and now CISPA is back. Wikipedia has experienced censorship at the hands of industry groups and governments, and we are –increasingly, I think– seeing important decisions made by unaccountable, non-transparent corporate players, a shift from the open web to mobile walled gardens, and a shift from the production-based internet to one that’s consumption-based. There are many organizations and individuals advocating for the public interest online — what’s good for ordinary people — but other interests are more numerous and powerful than they are. I want that to change. And that’s what I want to do next.

So much about that mirrors concerns I have as well. My book club read The Master Switch two years ago. After reading that book I realized how real it was that the open Internet we’ve come to embrace won’t just continue magically. It will need people like Tim Wu, and soon Sue Gardner, fighting to keep it that way.

Google Reader RIP; Long Live RSS!

Today Google announced that they are shutting down Google Reader. People on Twitter are apoplectic about it all. I get to feel a little smug since I decided a couple of years ago that I needed to move away from Google Reader. It was clear that their vision of what Google Reader should be didn’t match with what I wanted an RSS Reader to be. I had no interest in it being social and integrated with Google Plus.

It feels a little rebellious being an active user of an RSS reader these days. It’s like we are the Mad Max’s of the Internet. We want to get content in our own feeds. We want to actually decide which feeds we want. We aren’t interested in the marketing departments bundling of feeds. We even believe that this type of plumbing an openness is key to the health of the web. We are so audacious to think that we deserve feed interfaces to our services. We don’t need or even want someone in the middle of our feeds deciding what we think is important. Sadly, we and RSS itself seems to not fit into anyones marketing plans.

Max-Max

I am surprised that Google can glean enough personal information from your email reading that they can afford to store a ridiculous amount of data for you and still make a profitable service offering. It seems that knowing what feeds you read, and which items in those feeds you read the most, must not be worth as much money to them. The five engineers that Google had on this product couldn’t have cost that much right?

I spent a long time trying to figure out what I could use instead of Google Reader. It is (was) a nice service with some great features. I ultimately decided to host my own instance of Fever and I’ve been really happy with it. It does require that you run your own server, but it’s the only solution that has given me the complete confidence that I’m in control of something that I feel is as important as  email. (By the way, I don’t use Gmail for email. I pay Tuffmail a monthly fee to host email and they do an amazing job.)

Sadly, the world of RSS readers is battered and beaten. It would be really great if you could just jump to some other product. Readers even have a format for this, OPML, that allows you to move all your feeds from one service to another with a simple export and import. But, you won’t be doing that. Why? Because Google systematically removed all economic upside from this segment. There was a day when there were dozens of feed readers. Some hosted, many desktop software. For years these services grew and thrived and then Google entered the market. For free. And it was Google (insert fawning praise of all things Google here). One by one all of these services died. How could they compete?

To be fair, it wasn’t all Google. Google made it economically difficult but many services made terrible product decisions. RSS readers are products that benefit from “keep it simple, stupid” and many went against that. But I can say without doubt that a lot of people that were looking to enter that space with great ideas sat it out, the entire segment had been neutralized for anyone seeking direct revenue.

Enough of that. I hate this cycle. And this isn’t the first time or last time we will see it.

If your replacement for Google Reader is another free app you picked up in the App Store, you are going to be here again. You need to pay for this service. Either with a direct fee, or by hosting it on your own web server or running your own application on your computer. I don’t believe RSS Readers are products that can be offered for free. They use resources, and are complicated. If you agree to pay for this valuable service, you’ll make a market for it! If Google couldn’t do it for free, do you really think others can? I say no.

I only know of two solutions for RSS that put you completely in control. One is to use a planet feed system to build your own aggregation. I’m not even going to discuss this because it is ridiculous. The bar is so high to make it work. Purely insane.

The best solution I found is to run my own instance of Fever. Pay the one time software fee and I run it on my own server. It’s not that hard to run, but it requires some basic web server know-how.

I’ll make an offer right now. If I have a few friends that are stranded by Google for RSS services, I will happily create a Linode instance just for Fever installs. You buy a license, and I’ll set up the instance for you. We could easily run 10-20 Fever installs on a single web server. $5/month? Comment or email if your interested.

I’m left wondering if we’ve seen a forest fire. The forest was the RSS ecosystem, the fire was Google Reader. It’s blazed for years and burned down every tree in the forest. There are some birds flying around, those are the apps that use Google Reader as an API (which nearly all RSS readers built for your phone do, and was never really supported by Google). Now the fire has ended. The land is scorched and barren. Some folks have left, like me. They are running on their own infrastructure. All Mad Max. Maybe some new saplings will sprout in the charred landscape. I’m not sure how long that will take.

Adding Email Mention Notification to WordPress P2

I’m using the P2 theme on a couple of websites, one of them is for the team minne✱ to help coordination and collaboration. P2 supports the ability to use a @user notation to mention other users on the site, but it doesn’t do anything other than highlight the user. This snippet of PHP added to the bottom of the P2 functions.php will send email notifications on those mentions. This isn’t heavily tested but it works well for me.

/**
 * Custom code added to P2 to enable email notifications
 * when a user is @mentioned in the site.
 *
 * Original at http://trepmal.com/2011/06/24/using-wordpress-multisite-p2-and-more/
 * and modified from there.
 */
add_action('publish_post','send_email_notification_once',9);
function send_email_notification_once($postID) {
	$post = get_post($postID);
	$author = get_userdata($post->post_author);
	global $p2;
	$mentions = $p2->components['mentions']->find_mentions($post->post_content);
	$permalink = get_permalink($postID);
	$blog_title = get_bloginfo('name');
	foreach ( $mentions as $match ) {
		$email = get_user_by('slug',$match)->user_email;
		$message = "You have been mentioned in this post:\n $permalink \n\n {$post->post_content} ";
		wp_mail($email, "[$blog_title] You've been mentioned by {$author->display_name}", $message);
	}
}

add_action('comment_post','send_email_notification_once_comment',9);
function send_email_notification_once_comment($commentID){
	$comment = get_comment($commentID);
	global $p2;
	$mentions = $p2->components['mentions']->find_mentions($comment->comment_content);
	$permalink = get_permalink($comment->comment_post_ID);
	$blog_title = get_bloginfo('name');
	foreach ( $mentions as $match ) {
		$email = get_user_by('slug',$match)->user_email;
		$message = "You have been mentioned by {$comment->comment_author} in this comment:\n $permalink \n\n {$comment->comment_content} ";
		wp_mail($email, "[$blog_title] You've been mentioned in a comment by {$comment->comment_author}", $message);
	}
}

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?

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.