WikiCrawler/Utility/CategoryTranslation.cs
/// <summary>
/// If the specified article is a category redirect, returns the article redirected to.
/// </summary>
If the specified article is a category redirect, returns the article redirected to.
If the specified article is a category redirect returns the article redirected to .
private static MediaWiki.Article ProcessCategoryRedirects(MediaWiki.Api api, MediaWiki.Article art)
		{
			if (art != null)
			{
				string arttext = art.revisions[0].text;
				string catRedir1 = "category redirect";
				string catRedir2 = "seecat";
				int redir1 = arttext.IndexOf(catRedir1, StringComparison.InvariantCultureIgnoreCase);
				int redir2 = arttext.IndexOf(catRedir2, StringComparison.InvariantCultureIgnoreCase);
				int catstart = -1;
				if (redir1 >= 0)
				{
					catstart = redir1 + catRedir1.Length + 1;
				}
				else if (redir2 >= 0)
				{
					catstart = redir2 + catRedir2.Length + 1;
				}
				if (catstart >= 0)
				{
					string cat = arttext.Substring(catstart, arttext.IndexOf("}}", catstart) - catstart);
					cat = cat.Split('|')[0];
					if (cat.Contains("=")) cat = cat.Split('=')[1];
					MediaWiki.Article redir = TryFetchCategory(api, cat);
					return redir;
				}
				else
				{
					return art;
				}
			}
			else
			{
				return null;
			}
		}
private static MediaWiki . Article ProcessCategoryRedirects ( MediaWiki . Api api , MediaWiki . Article art ) { if ( art != null ) { string arttext = art . revisions [ 0 ] . text ; string catRedir1 = " " ; string catRedir2 = " " ; int redir1 = arttext . IndexOf ( catRedir1 , StringComparison . InvariantCultureIgnoreCase ) ; int redir2 = arttext . IndexOf ( catRedir2 , StringComparison . InvariantCultureIgnoreCase ) ; int catstart = - 1 ; if ( redir1 >= 0 ) { catstart = redir1 + catRedir1 . Length + 1 ; } else if ( redir2 >= 0 ) { catstart = redir2 + catRedir2 . Length + 1 ; } if ( catstart >= 0 ) { string cat = arttext . Substring ( catstart , arttext . IndexOf ( " " , catstart ) - catstart ) ; cat = cat . Split ( ' ' ) [ 0 ] ; if ( cat . Contains ( " " ) ) cat = cat . Split ( ' ' ) [ 1 ] ; MediaWiki . Article redir = TryFetchCategory ( api , cat ) ; return redir ; } else { return art ; } } else { return null ; } }
If the specified article is a category redirect, returns the article redirected to.
If the specified article is a category redirect returns the article redirected to .
//Check for category redirect //found redirect, look it up //no redirect, just return
api
MediaWiki.Api
art
MediaWiki.Article