示例#1
0
        static async Task HelloRecentChanges()
        {
            // Create a MediaWiki API client.
            var wikiClient = new WikiClient();
            // Create a MediaWiki Site instance.
            var site = new WikiSite(wikiClient, "https://en.wikipedia.org/w/api.php");
            await site.Initialization;
            var rcg = new RecentChangesGenerator(site)
            {
                TypeFilters    = RecentChangesFilterTypes.Create,
                PaginationSize = 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.EnumItemsAsync().Take(10).ToList();

            Console.WriteLine();
            Console.WriteLine("Recent changes");
            foreach (var rc in rcs)
            {
                Console.WriteLine(rc);
            }
        }
示例#2
0
        public async Task WikiaRecentChangesListTest()
        {
            var site      = await WikiaTestSiteAsync;
            var generator = new RecentChangesGenerator(site)
            {
                LastRevisionsOnly = true,
                PaginationSize    = 500
            };
            var rc = await generator.EnumItemsAsync().Take(2000).ToList();

            ShallowTrace(rc, 1);
        }
示例#3
0
        static async Task InteractivePatrol()
        {
            // Patrol the last unpatrolled change.
            // Usually 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 = new WikiSite(wikiClient, Input("Wiki site API URL"));
            await site.Initialization;
            await site.LoginAsync(Input("User name"), Input("Password"));

            var rcg = new RecentChangesGenerator(site)
            {
                TypeFilters     = RecentChangesFilterTypes.Create,
                PaginationSize  = 5,
                PatrolledFilter = PropertyFilterOption.WithoutProperty
            };
            // List the first unpatrolled result.
            var rc = await rcg.EnumItemsAsync().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);
            }
        }
示例#4
0
        public async Task WpTest2PatrolTest1()
        {
            var site      = await WpTest2SiteAsync;
            var generator = new RecentChangesGenerator(site)
            {
                LastRevisionsOnly = true,
            };
            var rc = await generator.EnumItemsAsync().Take(2).ToList();

            Skip.If(rc.Count < 1);
            // We haven't logged in.
            await Assert.ThrowsAsync <UnauthorizedOperationException>(() => rc[0].PatrolAsync());
        }
示例#5
0
        public async Task WpLzhRecentChangesListTest()
        {
            var site      = await WpLzhSiteAsync;
            var generator = new RecentChangesGenerator(site)
            {
                LastRevisionsOnly = true,
                BotFilter         = PropertyFilterOption.WithProperty,
                MinorFilter       = PropertyFilterOption.WithProperty,
                PaginationSize    = 500
            };
            var rc = await generator.EnumItemsAsync().Take(2000).ToList();

            ShallowTrace(rc, 1);
            foreach (var p in rc)
            {
                var flags = p.Flags;
                Assert.True(flags != RevisionFlags.None);
                Assert.True(flags.HasFlag(RevisionFlags.Bot));
                Assert.True(flags.HasFlag(RevisionFlags.Minor));
            }
        }