Tapping Into the Wikipedia API with Visual Basic

Introduction

We all love Wikipedia. I wish I had had Wikipedia when I was growing up; it would have made my life much easier. I had to use an old thing named a book, or an encyclopedia, to research my tasks for school. Just shows how the Internet has evolved. Just shows how lazy people has become... It is just my opinion.

Wikipedia

The funny thing is: I am using Wikipedia to find a proper explanation for Wikipedia—for the uninformed, of course... Wikipedia states the following about Wikipedia:

Wikipedia is a multilingual, Web-based, free-content encyclopedia project supported by the Wikimedia Foundation and based on a model of openly editable content. The name "Wikipedia" is a portmanteau of the words wiki (a technology for creating collaborative Web sites, from the Hawaiian word wiki, meaning "quick") and encyclopedia. Wikipedia's articles provide links designed to guide the user to related pages with additional information.

Wikipedia is written collaboratively by largely anonymous volunteers who write without pay. Anyone with Internet access can write and make changes to Wikipedia articles, except in limited cases where editing is restricted to prevent disruption or vandalism. Users can contribute anonymously, under a pseudonym, or, if they choose to, with their real identity.

The Good News!

As with many a known decent online platform, Wikipedia is also built with certain APIs and provides developers with these APIs to make use of their product in the background on your own custom made applications.

This platform is named MediaWiki, which is a free and open-source wiki application. MediaWiki has an extensible Web API (application programming interface) that provides direct, high-level access to the data contained in the MediaWiki databases.

Options Available to Developers

Unfortunately, there aren't many options available for Visual Basic developers, as is usually the case when it comes to Web platforms. This has always baffled me....

The MediaWiki documentation, as well as links, can be found at this link (MediaWiki). As you can see, this is mostly for Web-based platforms such as JSON, XML, and PHP. Still, there is a lot of useful information on how this API works and how Wikipedia makes use of it in the background.

Other options include the following:

  • WikiAccess Library: WikiAccess is a library that provides access to MediaWiki-based wiki sites
  • DotNetWikiBot Framework: Is a full-featured client API, that allows you to build programs and Web robots easily to manage information on MediaWiki-powered sites.

Practical Applications

Let's do a project!

Create a new Visual Basic Console Application project. Set a Reference to the DotNetWikiBot DLL you get after you have downloaded the framework at the link given earlier.

Import the DotNetWikiBot Namespace:

Imports DotNetWikiBot

Make sure your class derives from Bot:

Public Class BotTest
   Inherits Bot

Adding a Category and Saving It

Add the following code to add a new Wikipedia sub category and save a simple comment:

      Dim stWiki As New Site("http://en.wikipedia.org", _
         "Login", "Password")

      Dim pPage As New Page(stWiki, "Music")

      pPage.Load()

      pPage.AddToCategory("Afrikaans")

      pPage.Save("comment: category link added", True)

Saving Wikipedia Files

Add the following code:

      Dim plWiki As New PageList(stWiki)
      plWiki.FillFromGoogleSearchResults("South Africa", 100)

or

      plWiki.FillFromCategoryTree("South Africa")

      pl.SaveToFiles("C:\Hannes")

For more a complete list of all available methods and types of DotNetWikiBot, its Help page is quite thorough.

Conclusion

Gaining access to what makes Wikipedia tick is very easy with the MediaWiki API. Until next time, have a good night.



About the Author

Hannes DuPreez

Hannes du Preez is a Microsoft MVP for Visual Basic for the ninth consecutive year. He loves technology and loves Visual Basic. He loves writing articles and proving that Visual Basic is more powerful than what most believe. His ultimate dream is to write a Visual Basic book, hopefully one day that dream will come true. You are most welcome to reach him at: ojdupreez1978@gmail.com

Related Articles

Comments

  • There are no comments yet. Be the first to comment!

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date