Skip to content

[MediaWiki] Advanced usages

Chen edited this page Aug 13, 2018 · 5 revisions

Private Wikis

Private wikis are those wikis where anonymous users have no read access. This can cause problem for ordinary login procedure, because the client can virtually invoke nothing other than action=login. To address the issue, you can use the alternative constructor signature to login to the wiki site before performing any other querying requests

public WikiSite(
	IWikiClient wikiClient,
	SiteOptions options,
	string userName,
	string password
)

As have mentioned in Getting Started page, you need to wait for the initialization to complete using await wikiSite.Initialization, before proceeding with any other operations. If the login failed, you will receive the exception via Initialization task.

Working with custom HTTP credentials

In some cases, your MediaWiki site may be protected by certain HTTP authentication layer. To pass in the appropriate credential information, you need to use WikiClient(HttpMessageHandler handler) constructor to initialize the WikiClient. From here you have a chance to pass in your own HttpClientHandler instance. Especially, you may implement ICredential interface, and set HttpClientHandler.Credentials to it. Then you can create WikiSite instances from this WikiClient.

Miscellaneous API

You can get/set/persist cookies with WikiClient.CookieContainer property.

The following APIs have also been taken or partially taken into the library

  • opensearch: See WikiSite.OpenSearch.
  • parse: See WikiSite.ParsePageAsync, WikiSite.ParseRevisionAsync, and WikiSite.ParseContentAsync. There's also a demo in WpfTestApplication1.

You can search for a valid MediaWiki entry point with WikiSite.SearchApiEndpointAsync, given the URL of the website or the URL of a page on it. See UnitTestProject1.SiteTests.SearchApiEndpointTest for example.

Behaviors

The following behavior has been implemented

  • Request timeout and retry (WikiClient)
  • Throttle before edit/move/delete (WikiSite.Throttler)

The following behavior has yet to be implemented

  • Detect {{inuse}}
  • Detect {{bots}}, {{nobots}}

Issuing custom JSON request to MediaWiki endpoint