This post brought to you by http://www.greatplay.net by Peter Hurford.
Check out the homepage for games, projects, and more blog posts.

Ads, woo!

 

Random Featured Article for Wikipedia (And the Making Thereof)

I’ve been to the wonderful resource that is Wikipedia a lot, and even blogged about it several times. I’ve always particularly enjoyed pressing the random article button, as I’ve shared in this article, but I’m always a little annoyed when I keep arriving at three sentence paragraph “stubs” (what Wikipedia calls articles that need great improvement), which unfortunately make up the majority of Wikipedia.

One one hand, I could become a subject expert and attempt to enlarge any Wikipedia article I come across, or I could just find a way to create my own Wikipedia Random Article link that ignores stubs. I’ve decided that the second one would require less work, so I decided to program one myself.

At this point in time, you can either just enjoy the button I made by clicking here or finding it in the Stuff section — or you can read more about how I made the button, because I figured it might interest at least someone. Warning: It’s boring.

The easiest way I found to approach gathering a list of the best Wikipedia articles was to use the provided list of Featured Articles, which Wikipedia claims are the articles that are:

considered to be the best articles in Wikipedia, as determined by Wikipedia’s editors. Before being listed here, articles are reviewed at featured article candidates for accuracy, neutrality, completeness, and style according to our featured article criteria.

 

This method seemed to get a very large sample size of solid Wikipedia articles, all of which are — at least — guaranteed not to be annoyingly short. If you still want the fun of totally random off the wall articles, the old Random Article button is still provided on Wikipedia itself.

So once I had a list of articles I wanted to browse, I was able to find a way to harvest the page for a random link, using PHP and the Sean Huber Curl Library.

Assuming you’re now magically familiar with CURL and the provided library, I then did this:

include "lib.php"; //includes the Sean Huber CURL Library

$curl = new CURL(); //Call a new CURL

$return = $curl->get("http://en.wikipedia.org/wiki/Wikipedia:Featured_articles"); //Get data from the list of Featured articles

preg_match_all("|<a href=\"/wiki/(.*)\" title=\"|U", $return, $urls); //Search them for all URLs relating to Wikipedia

$urls = $urls[1]; //Get the array that contains the data

$length = count($urls) – 44; //Count how many there are, then trim off the 44 last links which aren’t articles.

$random = rand(25, $length); //Generate a proper random number, must be above 24 because the first 24 links are pages about Wikipedia, similar to above.

$title = $urls[$random]; //Use the random number to select a random page title from the list.

$page = "http://en.wikipedia.org/wiki/$title"; //Generate the name of the page.

 

Then I displayed the information in an iframe and added a few suitable links, coming up with the page here.

Yay!

But Wait! There's More!

3 Comments

  1. This is an awesome idea that I wish I came up with first. As if I needed another way to get lost in Wikipedia…

  2. Peter says:

    @Jordon Kalilich: Thanks! I think this improves people’s ability to get lost in Wikipedia a lot!

  3. Morpheus says:

    Cool. Do the Wikipedia folks know about this? Why not tell ‘em?

Leave a Reply