Skip to content
Claymore edited this page Sep 13, 2010 · 8 revisions

SharpMediaWiki is yet another C# interface to the MediaWiki API. It was written as a replacement for heavy and slow DotNetWikiBot. The library provides convient interface for continuous property queries, enumerations, page creation / editing and moving. All queries return instances of XmlDocument class which can be searched with XPath.

Dependencies

You will need Microsoft .NET Framework 3.5 to compile and use the library on Windows. It can be also compiled with Mono 2.4 (at least MoMA didn’t report any problems).

License

SharpMediaWiki is licensed under the terms of the BSD License, see the included License.txt file.

Usage

Example usage:


using System;
using System.Xml;
using Claymore.SharpMediaWiki;

namespace Example
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Wiki wiki = new Wiki("http://en.wikipedia.org");
            // Login into en.wikipedia.org as "Username".
            wiki.Login("Username", "Secret");
            // Load raw text of the page titled "Wiki".
            string pageText = wiki.LoadPage("Wiki");
            ParameterCollection parameters = new ParameterCollection();
            // We want page information and automatic resolving of redirects.
            parameters.Add("prop", "info");
            parameters.Add("redirects");
            string[] titles = new string[] { "WikiNode", "WP:HELP" };
            // Make the query.
            XmlDocument xml = wiki.Query(QueryBy.Titles, parameters, titles);
            // Select redirect nodes.
            XmlNodeList redirects = xml.SelectNodes("/api/query/redirects/r");
            Console.Out.WriteLine(string.Format("Found {0} redirects.", redirects.Count));
            wiki.Logout();
        }
    }
}
Clone this wiki locally