写了一个MediaWiki客户端库

基于.NET PCL的一个异步访问的MediaWiki客户端库,支持.NET Framework 4.5、ASP.NET Core 1.0、Xamarin.iOS和Xamarin.Android,MediaWiki API最低尝试过MediaWiki 1.19 (Wikia)。欢迎前来围观!

坑址:https://github.com/CXuesong/WikiClientLibrary

其他MediaWiki客户端库:https://www.mediawiki.org/wiki/API:Client_code

宣传一下:好像还没想好可以怎么宣传。总之,支持大部分常见的增删查改API,支持生成器,支持文件上传,查询结果无痛分页(使用IAsyncEnumerable)。

下面给点客户端程序的小样(好吧其实复制的README.md)

static async Task HelloWikiWorld()
{
    // Create a MediaWiki API client.
    var wikiClient = new WikiClient
    {
        // UA of Client Application. The UA of WikiClientLibrary will
        // be append to the end of this when sending requests.
        ClientUserAgent = "ConsoleTestApplication1/1.0",
    };
    // Create a MediaWiki Site instance with the URL of API endpoint.
    var site = await Site.CreateAsync(wikiClient, "https://test2.wikipedia.org/w/api.php");
    // Access site information via Site.SiteInfo
    Console.WriteLine("API version: {0}", site.SiteInfo.Generator);
    // Access user information via Site.UserInfo
    Console.WriteLine("Hello, {0}!", site.UserInfo.Name);
    Console.WriteLine("You're in the following groups: {0}.", string.Join(",", site.UserInfo.Groups));
    // Site login
    if (Confirm($"Do you want to login into {site.SiteInfo.SiteName}?"))
    {
        await site.LoginAsync(Input("Username"), Input("Password"));
        Console.WriteLine("You have successfully logged in as {0}.", site.UserInfo.Name);
    }
    // Find out more members in Site class, such as
    //  site.Namespaces
    //  site.InterwikiMap

    // Page Operations
    // Fetch information and content
    var page = new Page(site, site.SiteInfo.MainPage);
    Console.WriteLine("Retriving {0}...", page);
    await page.RefreshAsync(PageQueryOptions.FetchContent);

    Console.WriteLine("Last touched at {0}.", page.LastTouched);
    Console.WriteLine("Last revision {0} by {1} at {2}.", page.LastRevisionId,
        page.LastRevision.UserName, page.LastRevision.TimeStamp);
    Console.WriteLine("Content length: {0} bytes ----------", page.ContentLength);
    Console.WriteLine(page.Content);
    // Purge the page
    if (await page.PurgeAsync())
        Console.WriteLine("  The page has been purged successfully.");
    // Edit the page
    page = new Page(site, "Project:Sandbox");
    await page.RefreshAsync(PageQueryOptions.FetchContent);
    if (!page.Exists) Console.WriteLine("Warning: The page {0} doesn't exist.", page);
    page.Content += "\n\n'''Hello''' ''world''!";
    await page.UpdateContentAsync("Test edit from WikiClientLibrary.");
    Console.WriteLine("{0} has been saved. RevisionId = {1}.", page, page.LastRevisionId);
    // Find out more operations in Page class, such as
    //  page.MoveAsync()
    //  page.DeleteAsync()
    // Logout
    await site.LogoutAsync();
    Console.WriteLine("You have successfully logged out.");
}

 

3 Replies to “写了一个MediaWiki客户端库”

  1. 你好,有个问题想请教下你。
    我在用VS2015打开你的mediawiki 0.5.0.5版本项目时候,提示WikiClientLibrary加载失败,显示该项目需要用户输入,有关更多信息,请重新加载该项目。错误提示显示为WikiClientLibrary.csproj : error : 项目的默认 XML 命名空间必须为 MSBuild XML 命名空间。如果项目是用 MSBuild 2003 格式创建的,请将 xmlns=”http://schemas.microsoft.com/developer/msbuild/2003″ 添加到 元素中。如果项目是用旧的 1.0 或 1.2 格式创建的,请将其转换为 MSBuild 2003 格式。 我按照要求加入编码格式,然后又提示无法识别元素 中的特性“Version”。

    1. 哦,我最近把整个项目升级到了VS2017……所以……抱歉啦😭

      不过VS2015还是可以引用打包之后的NuGet程序包的。

      1. 多谢您的回复,因为想写个基于wiki的windows程序,所以看到你的项目想看下你的项目源码,学习下您的代码。再次感谢您的回复,希望以后有问题还能得到您的解答多谢。

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

ERROR: si-captcha.php plugin: GD image support not detected in PHP!

Contact your web host and ask them to enable GD image support for PHP.

ERROR: si-captcha.php plugin: imagepng function not detected in PHP!

Contact your web host and ask them to enable imagepng for PHP.

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据

Content is available under CC BY-SA 3.0 unless otherwise noted.