Tolkien Gateway

User:Mithbot/Scripts

(Difference between revisions)
m (Changing Categories: Fixed link)
m (Bot: Re-linked to Nirnaeth Arnoediad)
Line 159: Line 159:
 
*''Appendices'' and ''The Appendices'' to [[The Lord of the Rings Appendices]] (7 July 2010);
 
*''Appendices'' and ''The Appendices'' to [[The Lord of the Rings Appendices]] (7 July 2010);
 
*''North-kingdom'' to [[Arnor]] (7 July 2010);
 
*''North-kingdom'' to [[Arnor]] (7 July 2010);
*''Nirnaeth Arnoediad'' and ''Battle of Unnumbered Tears'' to [[Nírnaeth Arnoediad]] (5 August 2010);
+
*''Nirnaeth Arnoediad'' and ''Battle of Unnumbered Tears'' to [[Nirnaeth Arnoediad]] (5 August 2010);
 
*''Bëor the Old'' to [[Bëor]] (5 August 2010);
 
*''Bëor the Old'' to [[Bëor]] (5 August 2010);
 
*''Dragon'' to [[Dragons]] (5 August 2010);
 
*''Dragon'' to [[Dragons]] (5 August 2010);
Line 227: Line 227:
 
*''Vala'' to [[Valar]] (11 January 2011);
 
*''Vala'' to [[Valar]] (11 January 2011);
 
*''Ñoldor'', ''Deep-elves'', ''Ñoldo'', to [[Noldor]] (11 January 2011);
 
*''Ñoldor'', ''Deep-elves'', ''Ñoldo'', to [[Noldor]] (11 January 2011);
*''Nirnaeth Arnoediad'' to [[Nírnaeth Arnoediad]] (11 January 2011);
+
*''Nirnaeth Arnoediad'' to [[Nirnaeth Arnoediad]] (11 January 2011);
 
*''Lúthien Tinúviel'' to [[Lúthien]] (12 January 2011);
 
*''Lúthien Tinúviel'' to [[Lúthien]] (12 January 2011);
 
*''Elu Thingol'' to [[Thingol]] (13 January 2011);
 
*''Elu Thingol'' to [[Thingol]] (13 January 2011);

Revision as of 09:07, 15 July 2011

Changing Internal Links

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

		PageList p = new PageList(site);
 		p.FillFromLinksToPage("Bilbo");
		p.LoadEx();
		foreach (Page i in p)
			i.text = i.text.Replace("[[Bilbo]]", "[[Bilbo Baggins]]");
		p.SaveSmoothly(1, "Bot Message: changing link to [[Bilbo Baggins]]", true);
	} 

}

To avoid certain namespaces, add this before p.LoadEx();, User and Template in this example:-

		p.RemoveNamespaces(new int[] {2,10});

The above code is used to change links to a particular page in order to remove redirects. By changing "Bilbo" and "Bilbo Baggins" this script can be re-used again and again to edit internal links. So far, it has been used for changing:

Changing Categories