protected override void ProcessPage(Page p, EditStatus edit)
        {
            if (p.GetNamespace() != 0)
                return;
            p.Load();

            //Nur Seiten mit Vorlage:Infobox NSC
            if (p.GetAllTemplates().All(t => t.Title.ToLower() != "infobox nsc")) return;

            //Nur Seiten, die eine Unterseite mit Angeboten haben...
            var m = Regex.Match(p.text, "\\{\\{:" + p.title + "/([^}]+)}}");
            if (!m.Success) return;

            var subpageTitle = m.Groups[1].Value;

            var subpage = new Page(p.site, p.title + "/" + subpageTitle);
            subpage.Load();
            if (!subpage.Exists())
            {
                p.text = p.text.Replace(m.Value, "");
                edit.EditComment = "Verweis auf nicht vorhandene Angebots-Unterseite „" + subpage.title + "“ entfernt";
                edit.Save = true;
            }
            else
            {
                var pl2 = new PageList(p.site);
                pl2.FillFromLinksToPage(subpage.title);
                if (pl2.Count() > 1) return;

                var subpageContent = Regex.Replace(subpage.text, "<noinclude>.*?</noinclude>", "").Trim();

                p.text = p.text.Replace(m.Value, subpageContent);

                subpage.text = "{{Löschantrag|[Bot] In den Hauptartikel „[[" + p.title + "]]“ verschoben}}\n" +
                               subpage.text;
                subpage.Save("[Bot] In Hauptartikel „[[" + p.title + "]]“ verschoben", true);

                edit.EditComment = "Angebot von „" + subpage.title + "“ in den Hauptartikel verschoben";
                edit.Save = true;
            }
        }
 /// <summary>Undoes the last edit, so page text reverts to previous contents.
 /// The function doesn't affect other operations like renaming.</summary>
 /// <param name="comment">Revert comment.</param>
 /// <param name="isMinorEdit">Minor edit mark (pass true for minor edit).</param>
 public void Revert(string comment, bool isMinorEdit)
 {
     if (string.IsNullOrEmpty(title))
         throw new WikiBotException(Bot.Msg("No title specified for page to revert."));
     PageList pl = new PageList(site);
     if (Bot.useBotQuery == true && site.botQuery == true &&
         site.botQueryVersions.ContainsKey("ApiQueryRevisions.php"))
             pl.FillFromPageHistoryEx(title, 2, false);
     else
         pl.FillFromPageHistory(title, 2);
     if (pl.Count() != 2) {
         Console.Error.WriteLine(Bot.Msg("Can't revert page \"{0}\"."), title);
         return;
     }
     pl[1].Load();
     Save(pl[1].text, comment, isMinorEdit);
     Bot.LogEvent(Bot.Msg("Page \"{0}\" was reverted."), title);
 }
 private static void ShufflePageList(Random r, PageList list)
 {
     for (int i = list.Count() - 1; i >= 1; i--)
     {
         int j = r.Next(0, i + 1);
         Page temp = list[j];
         list[j] = list[i];
         list[i] = temp;
     }
 }
Exemple #4
0
	public static int Main()
	{

		// Se registra en la página y configura el bot
		Site welp = iniciar();

		leerOpciones(Environment.GetCommandLineArgs());

		if (welp == null)
			return 1;

		// Cuenta del número de ediciones
		int cuenta = 0;

		// Obtiene todos los trabajos (de momento en el espacio de nombre Principal)
		PageList todas = new PageList(welp);

		todas.FillFromAllPages("Trabajo:", 0, false, Int32.MaxValue, "Trabajo;");

		foreach (Page pag in todas)
		{
			pag.Load();

			// Si ya hay indicación de curso no hace nada
			List<string> cats = pag.GetCategories();

			if (cats.Exists(patronCCurso.IsMatch))
				continue;

			// Para averiguar el curso obtiene la fecha de la
			// primera edición
			PageList hist = new PageList(welp);

			hist.FillFromPageHistory(pag.title, Int32.MaxValue);

			DateTime fc = hist[hist.Count()-1].timestamp;

			// Distingue en base a ella el curso
			int año = fc.Year;

			// Si es antes del 29 de septiembre (aprox) es que es
			// del curso que empieza en el año anterior
			if (fc.Month < 9 || fc.Month == 9 && fc.Day < 29)
				año--;

			string curso = "Curso " + año + "-" + (año + 1);

			// Muestra información por consola
			Console.Error.WriteLine("«" + pag.title + "» creado en " + fc + " => " + curso);

			cuenta++;

			if (!simulado) {
				pag.AddToCategory(curso);

				pag.Save("bot: categorización de trabajos por curso", true);
			}
		}

		// Resumen de las operaciones
		Console.Error.WriteLine("El bot " + (simulado ? "hubiera realizado " : "realizó ") + cuenta + " ediciones.");

		return 0;
	}
 /// <summary>Undoes the last edit, so page text reverts to previous contents.
 /// The function doesn't affect other actions like renaming.</summary>
 /// <param name="comment">Revert comment.</param>
 /// <param name="minorEditByDefault">Minor edit mark (pass true for minor edit).</param>
 public void Revert(string comment, bool isMinorEdit)
 {
     if (string.IsNullOrEmpty(title))
         throw new WikiBotException(Bot.Msg("No title specified for page to revert."));
     PageList pl = new PageList(site);
     pl.FillFromPageHistory(title, 2);
     if (pl.Count() != 2) {
         Console.Error.WriteLine(Bot.Msg("Can't revert page \"{0}\"."), title);
         return;
     }
     pl[1].Load();
     Save(pl[1].text, comment, isMinorEdit);
     Console.WriteLine(Bot.Msg("Page \"{0}\" was reverted."), title);
 }