WikiCrawler/Tasks/Commons/FixImplicitCreators.cs
/// <summary>
/// Replace any verifiable implicit creators with creator templates.
/// </summary>
/// <param name="article">Article, already downloaded.</param>
/// <param name="creator">A creator that we have already determined should be used.</param>
Replace any verifiable implicit creators with creator templates.
Replace any verifiable implicit creators with creator templates .
public static void Do(Api commonsApi, Article article, string creator = null)
		{
			string text = article.revisions[0].text;
			Console.WriteLine("FixImplictCreators: checking '" + article.title + "'.");
			if (creator != null && creator.StartsWith("Creator:"))
			{
				creator = creator.Substring("Creator:".Length);
			}
			int authorLoc;
			string author = MediaWiki.WikiUtils.GetTemplateParameter("artist", text, out authorLoc);
			if (string.IsNullOrEmpty(author))
			{
				author = MediaWiki.WikiUtils.GetTemplateParameter("artist_display_name", text, out authorLoc);
			}
			if (string.IsNullOrEmpty(author))
			{
				author = MediaWiki.WikiUtils.GetTemplateParameter("author", text, out authorLoc);
			}
			if (string.IsNullOrEmpty(author))
			{
				author = MediaWiki.WikiUtils.GetTemplateParameter("photographer", text, out authorLoc);
			}
			if (!string.IsNullOrEmpty(author))
			{
				string replaceTemplate = "";
				if (string.Compare("unknown", author, true) == 0)
				{
					replaceTemplate = "{{unknown|author}}";
				}
				else if (string.Compare("anonymous", author, true) == 0)
				{
					replaceTemplate = "{{anonymous}}";
				}
				else if (!string.IsNullOrEmpty(creator))
				{
					if (author == creator)
					{
						replaceTemplate = "{{Creator:" + creator + "}}";
					}
				}
				else
				{
					foreach (string category in MediaWiki.WikiUtils.GetCategories(text))
					{
						if (!category.Contains(" by "))
						{
							continue;
						}
						creator = GetCreatorForCategory(commonsApi, category, 1);
						if (!string.IsNullOrEmpty(creator))
						{
							if (string.Compare(creator, author, true) == 0)
							{
								replaceTemplate = "{{Creator:" + creator + "}}";
								break;
							}
						}
					}
				}
				if (!string.IsNullOrEmpty(replaceTemplate))
				{
					Console.WriteLine("FixImplicitCreators: matched and inserted '" + replaceTemplate + "'.");
					text = text.Substring(0, authorLoc)
						+ replaceTemplate
						+ text.Substring(authorLoc + author.Length);
				}
				if (article.revisions[0].text != text)
				{
					article.revisions[0].text = text;
					article.Changes.Add("replace implicit creator");
					article.Dirty = true;
				}
			}
		}
public static void Do ( Api commonsApi , Article article , string creator = null ) { string text = article . revisions [ 0 ] . text ; Console . WriteLine ( " " + article . title + " " ) ; if ( creator != null && creator . StartsWith ( " " ) ) { creator = creator . Substring ( " " . Length ) ; } int authorLoc ; string author = MediaWiki . WikiUtils . GetTemplateParameter ( " " , text , out authorLoc ) ; if ( string . IsNullOrEmpty ( author ) ) { author = MediaWiki . WikiUtils . GetTemplateParameter ( " " , text , out authorLoc ) ; } if ( string . IsNullOrEmpty ( author ) ) { author = MediaWiki . WikiUtils . GetTemplateParameter ( " " , text , out authorLoc ) ; } if ( string . IsNullOrEmpty ( author ) ) { author = MediaWiki . WikiUtils . GetTemplateParameter ( " " , text , out authorLoc ) ; } if ( ! string . IsNullOrEmpty ( author ) ) { string replaceTemplate = " " ; if ( string . Compare ( " " , author , true ) == 0 ) { replaceTemplate = " " ; } else if ( string . Compare ( " " , author , true ) == 0 ) { replaceTemplate = " " ; } else if ( ! string . IsNullOrEmpty ( creator ) ) { if ( author == creator ) { replaceTemplate = " " + creator + " " ; } } else { foreach ( string category in MediaWiki . WikiUtils . GetCategories ( text ) ) { if ( ! category . Contains ( " " ) ) { continue ; } creator = GetCreatorForCategory ( commonsApi , category , 1 ) ; if ( ! string . IsNullOrEmpty ( creator ) ) { if ( string . Compare ( creator , author , true ) == 0 ) { replaceTemplate = " " + creator + " " ; break ; } } } } if ( ! string . IsNullOrEmpty ( replaceTemplate ) ) { Console . WriteLine ( " " + replaceTemplate + " " ) ; text = text . Substring ( 0 , authorLoc ) + replaceTemplate + text . Substring ( authorLoc + author . Length ) ; } if ( article . revisions [ 0 ] . text != text ) { article . revisions [ 0 ] . text = text ; article . Changes . Add ( " " ) ; article . Dirty = true ; } } }
Replace any verifiable implicit creators with creator templates.
Replace any verifiable implicit creators with creator templates .
// find author // check for "anonymous" and "unknown" //TODO: more parsing (dob-dod, etc) //SPECIAL CASE: ONLY DO THINGS THAT ARE CAUGHT BY THE NEW LOGIC // found it, place creator and update
commonsApi
Api
article
Article
Article, already downloaded.
Article already downloaded .
creator
string
A creator that we have already determined should be used.
A creator that we have already determined should be used .