From Wikipedia, the free encyclopedia
Jump to navigation Jump to search
This is incomplete and outdated draft



WikiSite is basically a pointer to a MediaWiki site and it's API. Every Page, List, etc. must have a specific WikiSite attached to them. By default all new objects get the WikiSite.defaultWikiSite, which must be set unless each object is passed another WikiSite. WikiSite handles login/logout and makes sure session data and cookies are stored and passed.

// Create the default WikiSite for use by all new objects
WikiSite.defaultWikiSite = new WikiSite("");

// Login into the API with the user account
if (WikiSite.defaultWikiSite.Login(ACCOUNT_NAME, ACCOUNT_PASS)) { ... }

// Create alternative WikiSite to other MediaWiki site
WikiSite deWPWikiSite = new WikiSite("");

// Create a page with the default WikiSite (WikiSite.defaultWikiSite)
WikiPage enpage = new WikiPage("Kangaroo");
// Create a page with a custom WikiSite
WikiPage enpage = new WikiPage("Kängurus", deWPWikiSite);

APIGlobal.defaultWikiSite.loginStatus contains the login status — loggedOut, loggingIn, loggedIn, loggingOut, loginFailed, or logoutFailed.

new WikiSite("", "custom user agent 2.0") can also be initialized with a custom user agent string. Note that empty agent string will most likely result in a fail response.



WikiSite is a list/collection of WikiPages.

PageList pages = new PageList();
pages.AddPages(new string[] { "Dog", "Rat", "Bird" });
pages.AddPagesFromCategory("Category: Cats");
pages.AddPagesUsingTemplate(Namespace.Article, "Template: Feline");

Brief intro[edit]

// Read a page and append it with a new section
<s>WikiPage page = enWikipedia.ReadPage("User:" + loginName + "/Sandbox");</s>
page.Append("Hello world. ~~~~", "New section");

// Work directly with page's content
page.content.Replace("world", "World");
page.Write("Capitalized all World");

// Build a list of pages from a category
<s>PageList videoGamePages = enWikipedia.GetCategoryPageList("Category:2010 video games");</s>


// Simplest way to retrieve a category's page list
<s>PageList videoGamePages = enWikipedia.GetCategoryPageList("Category:2010 video games");</s>

// Longer way to do the same thing
PageList filmPages = new PageList(enWikipedia);
filmPages.AddPagesFromCategory("Category:2010 films");

// Adding more pages to a page list
filmPages.AddPagesFromCategory("Category:2009 films");
filmPages.AddPagesFromCategory("Category:2008 films");

// Limiting the number of retrieved pages
<s>PageList bookPages = enWikipedia.GetCategoryPageList("Category:2010 books", 25);</s>
// -or-
filmPages.AddPagesFromCategory("Category:2007 films", 50);