static async Task HelloRecentChanges() { // Create a MediaWiki API client. var wikiClient = new WikiClient(); // Create a MediaWiki Site instance. var site = await WikiSite.CreateAsync(wikiClient, "https://en.wikipedia.org/w/api.php"); var rcg = new RecentChangesGenerator(site) { TypeFilters = RecentChangesFilterTypes.Create, PagingSize = 50, // We already know we're not going to fetch results as many as 500 or 5000 // so this will help. }; // List the 10 latest new pages var pages = await rcg.EnumPagesAsync().Take(10).ToList(); Console.WriteLine("New pages"); foreach (var p in pages) { Console.WriteLine("{0, -30} {1, 8}B {2}", p, p.ContentLength, p.LastTouched); } // List the 10 latest recent changes rcg.TypeFilters = RecentChangesFilterTypes.All; var rcs = await rcg.EnumRecentChangesAsync().Take(10).ToList(); Console.WriteLine(); Console.WriteLine("Recent changes"); foreach (var rc in rcs) { Console.WriteLine(rc); } }
private async Task RefreshRecentActivitiesAsync(int msDelay, int token) { if (msDelay > 0) { await Task.Delay(msDelay); } if (token != RefreshRecentActivitiesToken) { return; } while (IsBusy) { // Wait until the previous RefreshRecentActivitiesAsync has finished/cancelled. if (token != RefreshRecentActivitiesToken) { return; } await Task.Delay(2000); } IsBusy = true; Status = Tx.T("please wait"); try { var rcg = new RecentChangesGenerator(await SiteContext.GetSiteAsync()) { PagingSize = RecentChangesPagingSize + 10, }; if (token != RefreshRecentActivitiesToken) { return; } RecentChangesFilter.ConfigureGenerator(rcg); var rcs = await rcg.EnumRecentChangesAsync() .Take(RecentChangesPagingSize).ToArray(); if (token != RefreshRecentActivitiesToken) { return; } RecentChangesList.Clear(); foreach (var rc in rcs) { var vm = _ViewModelFactory.CreateRecentChange(rc, SiteContext); var date = rc.TimeStamp.Date; RecentChangesList.Add(vm); } } finally { IsBusy = false; Status = null; } }
static async Task InteractivePatrol() { // Patrol the last unpatrolled change. // Ususally a user should have the patrol right to perform such operation. // Create a MediaWiki API client. var wikiClient = new WikiClient(); // Create a MediaWiki Site instance. var site = await WikiSite.CreateAsync(wikiClient, Input("Wiki site API URL")); await site.LoginAsync(Input("Username"), Input("Password")); var rcg = new RecentChangesGenerator(site) { TypeFilters = RecentChangesFilterTypes.Create, PagingSize = 5, PatrolledFilter = PropertyFilterOption.WithoutProperty }; // List the first unpatrolled result. var rc = await rcg.EnumRecentChangesAsync().FirstOrDefault(); if (rc == null) { Console.WriteLine("Nothing to patrol."); return; } Console.WriteLine("Unpatrolled:"); Console.WriteLine(rc); // Show the involved revisions. if (rc.OldRevisionId > 0 && rc.RevisionId > 0) { var rev = await Revision.FetchRevisionsAsync(site, rc.OldRevisionId, rc.RevisionId).ToList(); // Maybe we'll use some 3rd party diff lib Console.WriteLine("Before, RevId={0}, {1}", rev[0].Id, rev[0].TimeStamp); Console.WriteLine(rev[0].Content); Console.WriteLine("After, RevId={0}, {1}", rev[1].Id, rev[1].TimeStamp); Console.WriteLine(rev[1].Content); } else if (rc.RevisionId > 0) { var rev = await Revision.FetchRevisionAsync(site, rc.RevisionId); Console.WriteLine("RevId={0}, {1}", rev.Id, rev.TimeStamp); Console.WriteLine(rev.Content); } if (Confirm("Mark as patrolled?")) { await rc.PatrolAsync(); Console.WriteLine("The change {0} has been marked as patrolled.", (object)rc.Title ?? rc.Id); } }