Skip to content

[MediaWiki] Querying for other page properties

Chen edited this page Nov 21, 2017 · 3 revisions

Prerequisites

Library reference

Geographical coordinates (prop=coordinates)

static async Task GetPageGeoCoordinatesAsync()
{
    var page = new WikiPage(myWikiSite, "france");
    // This will populate "provider" with some basic IWikiPagePropertyProviders,
    // which will make most of the properties in WikiPage have valid values.
    // You can simply use
    //  provider = new WikiPageQueryProvider()
    // if you are not interested in other ordinary properties in WikiPage.
    var provider = WikiPageQueryProvider.FromOptions(PageQueryOptions.None);
    provider.Properties.Add(new GeoCoordinatesPropertyProvider
    {
        QueryPrimaryCoordinate = true,
        QuerySecondaryCoordinate = true,
    });
    await page.RefreshAsync(provider);
    Console.WriteLine("{0}, located at {1}", page.Title,
        page.GetPropertyGroup<GeoCoordinatesPropertyGroup>().PrimaryCoordinate);
}

Page images (prop=pageimages)

static async Task GetPageImagesAsync()
{
    var pages = new[]
    {
        new WikiPage(myWikiSite, "Albert Einstein"),
        new WikiPage(myWikiSite, "Isaac Newton")
    };
    await pages.RefreshAsync(new WikiPageQueryProvider
    {
        Properties =
        {
            new PageImagesPropertyProvider {ThumbnailSize = 100}
        }
    });
    Console.WriteLine("Thumbnails:");
    foreach (var page in pages)
    {
        Console.WriteLine("{0}: {1}", page, page.GetPropertyGroup<PageImagesPropertyGroup>().ThumbnailImage.Url);
    }
}