WikiCrawler/Tasks/Commons/PdOldAuto.cs
/// <summary>
/// Attempts to update appropriate PD-old templates in the article.
/// </summary>
/// <param name="article">Article, already downloaded.</param>
Attempts to update appropriate PD-old templates in the article.
Attempts to update appropriate PD - old templates in the article .
public static void Do(Api commonsApi, Api wikidataApi,
			Article article)
		{
			if (MediaWiki.Article.IsNullOrEmpty(article))
			{
				Console.WriteLine("PdOldAuto: FATAL: Article missing.");
				return;
			}
			Console.WriteLine("PdOldAuto: checking '" + article.title + "'.");
			string text = article.revisions[0].text;
			string author = MediaWiki.WikiUtils.GetTemplateParameter("artist", text);
			if (string.IsNullOrEmpty(author))
			{
				author = MediaWiki.WikiUtils.GetTemplateParameter("author", text);
			}
			author = author.Trim();
			if (string.IsNullOrEmpty(author))
			{
				Console.WriteLine("PdOldAuto: FATAL: No author.");
				return;
			}
			List<Tuple<string, string>> replacements = new List<Tuple<string, string>>();
			string deathyear = "";
			if (author.StartsWith("{{Creator:"))
			{
				deathyear = GetCreatorDeathYear(commonsApi, wikidataApi, author);
			}
			if (string.IsNullOrEmpty(deathyear))
			{
				Console.WriteLine("PdOldAuto: FATAL: No deathyear found.");
			}
			else
			{
				Console.WriteLine("PdOldAuto: deathyear is '" + deathyear + "'.");
				foreach (string template in s_TemplatesOld)
				{
					if (ReplaceLicenseTemplate(ref text, template, "PD-old-auto", deathyear))
					{
						replacements.Add(new Tuple<string, string>(template, "PD-old-auto"));
					}
					if (ReplaceLicenseTemplate(ref text, "PD-Art|" + template, "PD-Art|PD-old-auto", deathyear))
					{
						replacements.Add(new Tuple<string, string>(template, "PD-old-auto"));
					}
				}
				foreach (string template in s_Templates1923)
				{
					if (ReplaceLicenseTemplate(ref text, template, "PD-old-auto-1923", deathyear))
					{
						replacements.Add(new Tuple<string, string>(template, "PD-old-auto-1923"));
					}
					if (ReplaceLicenseTemplate(ref text, "PD-Art|" + template, "PD-Art|PD-old-auto-1923", deathyear))
					{
						replacements.Add(new Tuple<string, string>(template, "PD-old-auto-1923"));
					}
				}
				foreach (string template in s_Templates1996)
				{
					if (ReplaceLicenseTemplate(ref text, template, "PD-old-auto-1996", deathyear))
					{
						replacements.Add(new Tuple<string, string>(template, "PD-old-auto-1996"));
					}
					if (ReplaceLicenseTemplate(ref text, "PD-Art|" + template, "PD-Art|PD-old-auto-1996", deathyear))
					{
						replacements.Add(new Tuple<string, string>(template, "PD-old-auto-1996"));
					}
				}
			}
			if (article.revisions[0].text != text)
			{
				StringBuilder summary = new StringBuilder();
				summary.Append("Refine license tag based on Creator: ");
				foreach (Tuple<string, string> rep in replacements)
				{
					summary.Append("{{[[Template:" + rep.Item1 + "|" + rep.Item1 + "]]}}→{{[[Template:" + rep.Item2 + "|" + rep.Item2 + "]]}}");
					summary.Append(", ");
				}
				summary.Remove(summary.Length - 2, 2);
				article.revisions[0].text = text;
				article.Changes.Add(summary.ToString());
				article.Dirty = true;
			}
		}
public static void Do ( Api commonsApi , Api wikidataApi , Article article ) { if ( MediaWiki . Article . IsNullOrEmpty ( article ) ) { Console . WriteLine ( " " ) ; return ; } Console . WriteLine ( " " + article . title + " " ) ; string text = article . revisions [ 0 ] . text ; string author = MediaWiki . WikiUtils . GetTemplateParameter ( " " , text ) ; if ( string . IsNullOrEmpty ( author ) ) { author = MediaWiki . WikiUtils . GetTemplateParameter ( " " , text ) ; } author = author . Trim ( ) ; if ( string . IsNullOrEmpty ( author ) ) { Console . WriteLine ( " " ) ; return ; } List < Tuple < string , string > > replacements = new List < Tuple < string , string > > ( ) ; string deathyear = " " ; if ( author . StartsWith ( " " ) ) { deathyear = GetCreatorDeathYear ( commonsApi , wikidataApi , author ) ; } if ( string . IsNullOrEmpty ( deathyear ) ) { Console . WriteLine ( " " ) ; } else { Console . WriteLine ( " " + deathyear + " " ) ; foreach ( string template in s_TemplatesOld ) { if ( ReplaceLicenseTemplate ( ref text , template , " " , deathyear ) ) { replacements . Add ( new Tuple < string , string > ( template , " " ) ) ; } if ( ReplaceLicenseTemplate ( ref text , " " + template , " " , deathyear ) ) { replacements . Add ( new Tuple < string , string > ( template , " " ) ) ; } } foreach ( string template in s_Templates1923 ) { if ( ReplaceLicenseTemplate ( ref text , template , " " , deathyear ) ) { replacements . Add ( new Tuple < string , string > ( template , " " ) ) ; } if ( ReplaceLicenseTemplate ( ref text , " " + template , " " , deathyear ) ) { replacements . Add ( new Tuple < string , string > ( template , " " ) ) ; } } foreach ( string template in s_Templates1996 ) { if ( ReplaceLicenseTemplate ( ref text , template , " " , deathyear ) ) { replacements . Add ( new Tuple < string , string > ( template , " " ) ) ; } if ( ReplaceLicenseTemplate ( ref text , " " + template , " " , deathyear ) ) { replacements . Add ( new Tuple < string , string > ( template , " " ) ) ; } } } if ( article . revisions [ 0 ] . text != text ) { StringBuilder summary = new StringBuilder ( ) ; summary . Append ( " " ) ; foreach ( Tuple < string , string > rep in replacements ) { summary . Append ( " " + rep . Item1 + " " + rep . Item1 + " + r p.I t em2 + " " + r p.I t em2 + " ] ; summary . Append ( " " ) ; } summary . Remove ( summary . Length - 2 , 2 ) ; article . revisions [ 0 ] . text = text ; article . Changes . Add ( summary . ToString ( ) ) ; article . Dirty = true ; } }
Attempts to update appropriate PD-old templates in the article.
Attempts to update appropriate PD - old templates in the article .
// search for creator // search for auto templates missing deathdate //TODO: // search for non-auto templates to replace
commonsApi
Api
wikidataApi
Api
article
Article
Article, already downloaded.
Article already downloaded .