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.

Hannes DuPreez
Hannes DuPreez
Ockert J. du Preez is a passionate coder and always willing to learn. He has written hundreds of developer articles over the years detailing his programming quests and adventures. He has written the following books: Visual Studio 2019 In-Depth (BpB Publications) JavaScript for Gurus (BpB Publications) He was the Technical Editor for Professional C++, 5th Edition (Wiley) He was a Microsoft Most Valuable Professional for .NET (2008–2017).

More by Author

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Must Read