-
-
Notifications
You must be signed in to change notification settings - Fork 16
[MediaWiki] Recent changes and patrol
Chen edited this page Nov 19, 2017
·
5 revisions
You can list pages using RecentChangesGenerator.EnumPagesAsync
, just like other generators, while this generator has another powerful method RecentChangesGenerator.EnumRecentChangesAsync
, which can generate a sequence of RecentChangesEntry
, containing the detailed information of each recent change.
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);
}
The code produces the following result
New pages
Bill Eigel 43B 2016/8/27 AM 6:38:46
Cool woods 3971B 2016/8/27 AM 6:46:52
Indian Institute Of Technical Computer Application 56B 2016/8/27 AM 6:59:20
Leslie Bieh Yhan 371B 2016/8/27 AM 6:58:02
Maranathirkku Pinbu Helan 157B 2016/8/27 AM 6:46:17
Mitchell Bolewski 27B 2016/8/27 AM 6:44:45
Palazzo Fani Mignanelli, Siena 1537B 2016/8/27 AM 6:39:52
Punjab Highway Department 1940B 2016/8/27 AM 6:58:32
Shiny waves 968B 2016/8/27 AM 6:53:50
Thailand national football team results (2000-09) 28321B 2016/8/27 AM 6:58:00
Recent changes
855757198,2016/8/27 AM 6:59:39,Edit,None,Melbourne Football Club,update coach
855757197,2016/8/27 AM 6:59:39,Edit,None,The Ocean (Mike Perry song),Undid revision 734440122 by [[Special:Contributions/82.113.183.202|82.113.183.202]] ([[User talk:82.113.183.202|talk]]) Considering Shy Martin doesn't have an article, this gives a tidbit of info about her and shouldn't be removed.
855757193,2016/8/27 AM 6:59:35,Edit,None,User:Lesbyan,db-g3
855757192,2016/8/27 AM 6:59:35,Edit,None,Kashmiri phonology,[[WP:CHECKWIKI]] error fix. Broken bracket problem. Do [[Wikipedia:GENFIXES|general fixes]] and cleanup if needed. - using [[Project:AWB|AWB]] (12082)
855757191,2016/8/27 AM 6:59:34,Edit,Annonymous,ConBravo!,
855757188,2016/8/27 AM 6:59:32,Edit,None,User:Moxy,
855757187,2016/8/27 AM 6:59:31,Edit,Minor, Bot,Society for the Propagation of the Faith,Dating maintenance tags: {{Cn}}
855757186,2016/8/27 AM 6:59:31,Edit,None,1530 in India,
855757185,2016/8/27 AM 6:59:30,Edit,None,User talk:101.98.246.169,Warning [[Special:Contributions/101.98.246.169|101.98.246.169]] - #1
855757184,2016/8/27 AM 6:59:30,Edit,Minor,Bay of Plenty Region,Reverting possible vandalism by [[Special:Contribs/101.98.246.169|101.98.246.169]] to version by Villianifm. [[WP:CBFP|Report False Positive?]] Thanks, [[WP:CBNG|ClueBot NG]]. (2741830) (Bot)
Once you've got an instance of RecentChangesEntry
, you can patrol it, as long as you have the patrol
or autopatrol
right.
static async Task ShowRecentChangesAsync()
{
var generator = new RecentChangesGenerator(myWikiSite)
{
// Choose wisely.
PaginationSize = 50,
// Configure the generator, e.g. setting filter/sorting criteria
NamespaceIds = new[] { BuiltInNamespaces.Main, BuiltInNamespaces.File },
AnonymousFilter = PropertyFilterOption.WithProperty
};
// Gets the latest 50 changes made to article and File: namespace,
// by anonymous users.
var items = await generator.EnumItemsAsync().Take(50).ToList();
foreach (var i in items)
{
Console.WriteLine(i.Title);
// Show revision comments.
Console.Write("\t");
Console.WriteLine(i.Comment);
}
// When you want to fetch extracts for the pages, it's safe to fetch for no more than
// 10 pages at one time.
generator.PaginationSize = 10;
// Gets the latest 50 pages in article and File: namespace that were changed
// by anonymous users.
var pages = await generator.EnumPagesAsync(new WikiPageQueryProvider
{
Properties =
{
new ExtractsPropertyProvider
{
AsPlainText = true,
IntroductionOnly = true,
MaxSentences = 1
}
}
}).Take(50).ToList();
foreach (var i in pages)
{
Console.WriteLine(i.Title);
// Show abstract for each revised page.
Console.Write("\t");
Console.WriteLine(i.GetPropertyGroup<ExtractsPropertyGroup>().Extract);
}
}