/// <summary>Gets subcategories titles for this PageList from specified wiki category page, /// excluding other pages. Use FillFromCategory function to get other pages.</summary> /// <param name="categoryName">Category name, with or without prefix.</param> public void FillSubsFromCategory(string categoryName) { int count = pages.Count; PageList pl = new PageList(site); pl.FillAllFromCategory(categoryName); pl.FilterNamespaces(new int[] {14}); pages.AddRange(pl.pages); if (pages.Count != count) Bot.LogEvent(Bot.Msg("PageList filled with {0} subcategory page titles, " + "found in \"{1}\" category."), (pages.Count - count).ToString(), categoryName); else Console.Error.WriteLine( Bot.Msg("Nothing was found in \"{0}\" category."), categoryName); }
public override void Load() { try { ch = core.getChannel(RequestLabs.RequestCh); if (ch == null) { Log("CRITICAL: the bot isn't in " + RequestLabs.RequestCh + " unloading requests", true); return; } RequestCache.Load(); notifications = new Thread(Run); notifications.Start(); Site wikitech = new Site("https://wikitech.wikimedia.org", "wmib", ""); while (true) { try { List<string> shell = new List<string>(); List<string> tooldata = new List<string>(); PageList requests = new PageList(wikitech); requests.FillAllFromCategory("Shell Access Requests"); foreach (Page page in requests) { string title = page.title.Replace("Shell Request/", ""); if (RequestCache.Contains(title)) { continue; } page.Load(); if (!Matches(page.text)) { RequestCache.Insert(title); lock (Shell) { // this one was already processed RequestLabs previous = Contains(title); if (previous != null) { Shell.Remove(previous); } } continue; } else { if (!shell.Contains(title)) { shell.Add(title); } lock (Shell) { if (Contains(title) == null) { Shell.Add(new RequestLabs(title)); } } } } requests = new PageList(wikitech); requests.FillAllFromCategory("Tools_Access_Requests"); foreach (Page page in requests) { string title = page.title.Replace("Nova Resource:Tools/Access Request/", ""); if (RequestCache.ContainsLabs(title)) { continue; } page.Load(); if (!(Matches(page.text))) { RequestCache.InsertLabs(title); lock (Tools) { // this one was already processed RequestLabs previous = ContainsLabs(title); if (previous != null) { Tools.Remove(previous); } } continue; } else { if (!tooldata.Contains(title)) { tooldata.Add(title); } lock (Tools) { if (ContainsLabs(title) == null) { Tools.Add(new RequestLabs(title)); } } } } Thread.Sleep(60000); } catch (ThreadAbortException) { notifications.Abort(); return; } catch (Exception fail) { handleException(fail); } } } catch (Exception fail) { handleException(fail); notifications.Abort(); } }
/// <summary>Fills this PageList with pages from specified category page. Subcategories are /// not included, call <see cref="PageList.FillAllFromCategory(string)"/> function instead /// to get category contents with subcategories.</summary> /// <param name="categoryName">Category name, with or without namespace prefix.</param> public void FillFromCategory(string categoryName) { int count = pages.Count; PageList pl = new PageList(site); pl.FillAllFromCategory(categoryName); pl.RemoveNamespaces(new int[] {14}); pages.AddRange(pl.pages); if (pages.Count != count) Console.WriteLine( Bot.Msg("PageList has been filled with {0} page titles found in \"{1}\"" + " category."), (pages.Count - count).ToString(), categoryName); else Console.Error.WriteLine( Bot.Msg("Nothing was found in \"{0}\" category."), categoryName); }
static void Main(string[] args) { Site site = new Site("http://commons.wikimedia.org", args[0], args[1]); while (true) { PageList list = new PageList(site); list.FillAllFromCategory("Category:Rotate270"); foreach (Page page in list) { if (!page.title.ToLower().EndsWith(".jpg")) continue; page.Load(); if (!page.text.Contains("{{rotate")) { page.text = "{{rotate|270}}\n" + page.text; page.Save("Add {{rotate|270}} tag since it's in Category:Rotate270", /*isMinorEdit*/false); } } list = new PageList(site); list.FillAllFromCategory("Category:Images requiring rotation"); foreach (Page page in list) { Regex regex = new Regex(@"\{\{Rotate\|nobot=true\|reason='''Reason''': corrupt JPEG file.\|([^}]*)\}\}", RegexOptions.IgnoreCase); page.Load(); Match m = regex.Match(page.text); if (m.Success) { page.text = regex.Replace(page.text, "{{Rotate|" + m.Groups[1].Value + "}}"); page.Save("Undo mistagging by [[User:Rotatebot]], JPEG should not be corrupt", /*isMinorEdit*/false); } } list = new PageList(site); list.FillAllFromCategory("Category:Images requiring rotation by bot"); try { foreach (Page page in list) { if (!page.title.ToLower().EndsWith(".jpg")) continue; page.Load(); MatchCollection matches = new Regex(@"\{\{rotate\|([0-9]+)\}\}", RegexOptions.IgnoreCase).Matches(page.text); if (matches.Count == 0) { matches = new Regex(@"\{\{rotate\|degree=([0-9]+)\}\}", RegexOptions.IgnoreCase).Matches(page.text); if (matches.Count == 0) { matches = new Regex(@"\{\{rotate\|([0-9]+)\|[^}]*\}\}", RegexOptions.IgnoreCase).Matches(page.text); if (matches.Count == 0) { continue; } } } if (matches.Count > 1) { while (matches.Count > 1) { page.text = page.text.Remove(matches[0].Index, matches[0].Length); matches = new Regex(@"\{\{rotate\|([0-9]+)\}\}", RegexOptions.IgnoreCase).Matches(page.text); if (matches.Count == 0) { matches = new Regex(@"\{\{rotate\|degree=([0-9]+)\}\}", RegexOptions.IgnoreCase).Matches(page.text); if (matches.Count == 0) { matches = new Regex(@"\{\{rotate\|([0-9]+)\|[^}]*\}\}", RegexOptions.IgnoreCase).Matches(page.text); } } } page.Save("Remove redundant rotate tags", /*isMinorEdit*/false); } Match m = matches[0]; int degrees = int.Parse(m.Groups[1].Value); page.DownloadImage("tempin.jpg"); File.Delete("tempout.jpg"); ProcessStartInfo info = new ProcessStartInfo(@"..\..\jpegtran.exe", "-rotate " + degrees + " tempin.jpg tempout.jpg"); info.CreateNoWindow = true; info.UseShellExecute = false; Process p = Process.Start(info); p.WaitForExit(); if (File.Exists("tempout.jpg")) { page.UploadImage("tempout.jpg", "Losslessly rotate by " + degrees + " degrees per request using jpegtran", "", "", ""); page.Load(); page.text = page.text.Replace(m.Value + "\n", ""); page.text = page.text.Replace(m.Value, ""); page.text = page.text.Replace("[[Category:Rotate270]]\n", ""); page.text = page.text.Replace("[[Category:Rotate270]]", ""); page.Save("Done with rotation by " + degrees + " degrees, removing tag", /*isMinorEdit*/false); } } System.Threading.Thread.Sleep(new TimeSpan(0, 2, 0)); } catch (Exception e) { Console.WriteLine("Caught exception: " + e.Message + e.StackTrace); } } }
public override void Load() { try { ch = core.getChannel("#wikimedia-labs"); if (ch == null) { core.Log("CRITICAL: the bot isn't in #wikimedia-labs unloading requests"); return; } RequestCache.Load(); notifications = new Thread(Run); notifications.Start(); while (true) { try { List<string> list = new List<string>(); Site wikitech = new Site("https://wikitech.wikimedia.org", "wmib", ""); PageList requests = new PageList(wikitech); requests.FillAllFromCategory("Shell Access Requests"); foreach (Page page in requests) { string title = page.title.Replace("Shell Request/", ""); if (RequestCache.Contains(title)) { continue; } page.Load(); if (!(page.text.Contains("|Completed=No") || page.text.Contains("|Completed=false"))) { RequestCache.Insert(title); lock (DB) { // this one was already processed RequestLabs previous = Contains(title); if (previous != null) { DB.Remove(previous); } } continue; } else { if (!list.Contains(title)) { list.Add(title); } lock (DB) { if (Contains(title) == null) { DB.Add(new RequestLabs(title)); } } } // now we need to remove all processed requests that were in a list /*List<RequestLabs> tr = new List<RequestLabs>(); lock (DB) { foreach (RequestLabs x in DB) { if (!list.Contains(x.user)) { tr.Add(x); } } foreach (RequestLabs x in tr) { DB.Remove(x); } } */ } Thread.Sleep(60000); } catch (ThreadAbortException) { notifications.Abort(); return; } catch (Exception fail) { core.handleException(fail); } } } catch (Exception fail) { core.handleException(fail); notifications.Abort(); } }