User:KingAragorn Bot/Scripts: Difference between revisions

From Tolkien Gateway
(→‎Mass re-linking: quicker to scroll script)
Line 73: Line 73:


                 PageList p = new PageList(site);
                 PageList p = new PageList(site);
                 p.FillFromCustomSpecialPage("Whatlinkshere/Of Beleriand and Its Realms", 500);
                 p.FillFromCustomSpecialPage("Whatlinkshere/Narn i Hîn Húrin", 500);
                 p.Load();
                 p.Load();
                 foreach (Page i in p)
                 foreach (Page i in p)
                         i.text = i.text.Replace("Of Beleriand and Its Realms|", "Of Beleriand and its Realms|");
                         i.text = i.text.Replace("Narn i Hîn Húrin|", "Narn i Chîn Húrin|");
                 foreach (Page j in p)
                 foreach (Page j in p)
                         j.text = j.text.Replace("[[Of Beleriand and Its Realms]]", "[[Of Beleriand and its Realms]]");
                         j.text = j.text.Replace("[[Narn i Hîn Húrin]]", "[[Narn i Chîn Húrin]]");
                 p.SaveSmoothly(3, "changing link to [[Of Beleriand and its Realms]]", true);
                 p.SaveSmoothly(2, "Re-linking.", true);
         }  
         }  


}
}
</pre>
</pre>
Task history:
Task history:
Line 92: Line 91:
*<s>''Of Beleriand and its Realms'' to '''Of Beleriand and Its Realms''' (3 July 2010)</s>
*<s>''Of Beleriand and its Realms'' to '''Of Beleriand and Its Realms''' (3 July 2010)</s>
*''Of Beleriand and Its Realms'' to [[Of Beleriand and its Realms]] (20 January 2011)
*''Of Beleriand and Its Realms'' to [[Of Beleriand and its Realms]] (20 January 2011)
*Etc.


==Changing categories==
==Changing categories==

Revision as of 18:45, 16 June 2011

Note: This code may need to be updated/amended before it can be used on different Wikis.

Tolkien Gateway

Mass re-linking

using System;
using DotNetWikiBot;
class MyBot : Bot 
{ 
        public static void Main() 
        { 
                Site site = new Site("http://tolkiengateway.net", "KingAragorn Bot", "PASSWORD"); 



                PageList b = new PageList(site);
                b.FillFromFile("PageList.txt");
                foreach (Page c in b) {
                PageList i = new PageList(site);
                i.FillFromLinksToPage(c.title);
            i.LoadEx3();    
                foreach (Page p in i) {

                      p.text = p.text.Replace("[[Rankin/Bass' The Hobbit]]", "[[The Hobbit (1977 film)]]");


                      p.text = p.text.Replace("Rankin/Bass' The Hobbit|", "The Hobbit (1977 film)|");



                      p.text = p.text.Replace("[[Ralph Bakshi's The Lord of the Rings]]", "[[The Lord of the Rings (1978 film)]]");



                      p.text = p.text.Replace("Ralph Bakshi's The Lord of the Rings|", "The Lord of the Rings (1978 film)|");



                      p.text = p.text.Replace("[[Rankin/Bass' The Return of the King]]", "[[The Return of the King (1980 film)]]");



                      p.text = p.text.Replace("Rankin/Bass' The Return of the King|", "The Return of the King (1980 film)|");





                p.Save("Bot comment: fixing links", true);
}
}
        } 

}

Task history:

Re-linking

using System;
using DotNetWikiBot;
class MyBot : Bot 
{ 
        public static void Main() 
        { 
                Site site = new Site("http://tolkiengateway.net", "KingAragorn Bot", "PASSWORD"); 

                PageList p = new PageList(site);
                p.FillFromCustomSpecialPage("Whatlinkshere/Narn i Hîn Húrin", 500);
                p.Load();
                foreach (Page i in p)
                        i.text = i.text.Replace("Narn i Hîn Húrin|", "Narn i Chîn Húrin|");
                foreach (Page j in p)
                        j.text = j.text.Replace("[[Narn i Hîn Húrin]]", "[[Narn i Chîn Húrin]]");
                p.SaveSmoothly(2, "Re-linking.", true);
        } 

}

Task history:

Changing categories

using System;
using DotNetWikiBot;
class MyBot : Bot 
{ 
public static void Main() 
{ 
Site site = new Site("http://tolkiengateway.net", "KingAragorn Bot", "PASSWORD"); 

 PageList p = new PageList(site);
  p.FillAllFromCategory("Images of The Lord of the Rings: The White Council");
  p.Load();
  p.RemoveFromCategory("Images of The Lord of the Rings: The White Council");
  p.AddToCategory("Images from The Lord of the Rings: The White Council");
  p.SaveSmoothly(5, "Bot Comment: Changing Categories", true);
} 

}

One Wiki to Rule them All

Add Category to Recently Uploaded Images

using System;
using DotNetWikiBot;
class MyBot : Bot 
{ 
public static void Main() 
{ 
Site site = new Site("http://tolkiengateway.net", "KingAragorn Bot", "PASSWORD"); 

 PageList p = new PageList(site);
        p.FillFromCustomSpecialPage("Log/Upload", 29);
        p.Load();
        p.AddToCategory("Images of Tengwar");
        p.SaveSmoothly(3, "Bot Comment: adding category", true);
} 
}

Removal of Spoiler Template from every page which has it

using System;
using DotNetWikiBot;
class MyBot : Bot 
{ 
public static void Main() 
{ 
Site site = new Site("http://lotr.wikia.com", "KingAragorn Bot", "PASSWORD"); 
 PageList p = new PageList(site);
        p.FillFromCustomSpecialPage("Whatlinkshere/Template:Spoiler", 500);
        p.Load();
        p.RemoveTemplate("Spoiler");
        p.SaveSmoothly(3, "Bot Comment: removing spoiler template", true);
} 
}

Reverting a Vandal Accounts Contributions (not tested + needs rollback rights)

using System;
using DotNetWikiBot;	

class MyBot : Bot	
{
    public static void Main()
    {
        Site enLOTR = new Site("http://lotr.wikia.com/wiki/", "KingAragorn Bot", "PASSWORD")
        p.FillFromUserContributions ("VANDAL USERNAME" "500",);
        p.Load();
        p.Revert("Bot Comment: Automatic Reverting of a vandal accounts contributions", false);
    }
}

Adding the Stub template to all pages in Special:Shortpages

using System;
using DotNetWikiBot;	

class MyBot : Bot	
{
    public static void Main()
    {
        Site enLOTR = new Site("http://lotr.wikia.com/wiki/", "KingAragorn Bot", "PASSWORD");
        PageList p = new PageList(enLOTR);
        p.FillFromCustomSpecialPage("Shortpages", 1000);
        p.Load();
        p.RemoveTemplate("stub");
        p.AddTemplate("{{stub}}");
        p.SaveSmoothly(5, "Bot Comment: Adding stub template - article is listed under [[Special:Shortpages]]", true);
    }
}

Changing Categories

using System;
using DotNetWikiBot;	

class MyBot : Bot	
{
 public static void Main()
{
  Site enLOTR = new Site("http://lotr.wikia.com/wiki/", "KingAragorn Bot", "PASSWORD");
  PageList p = new PageList(enLOTR);
  p.FillAllFromCategory("Mountains of Middle-earth");
  p.load();
  p.RemoveFromCategory("Mountains of Middle-earth ")
  p.AddToCategory("Mountains")
  p.SaveSmoothly(5, "Bot Comment: Changing Categories", true)
  }
}