<commit_before>using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Html;
using Umbraco.Core;
using Umbraco.Core.Dynamics;
using Umbraco.Web.Mvc;
using umbraco;
using umbraco.cms.businesslogic.member;

namespace Umbraco.Web
{
	/// <summary>
	/// HtmlHelper extensions for use in templates
	/// </summary>
	public static class HtmlHelperRenderExtensions
	{
		public static IHtmlString CachedPartial(
			this HtmlHelper htmlHelper, 
			string partialViewName, 
			object model, 
			int cachedSeconds,
			bool cacheByPage = false,
			bool cacheByMember = false,
			ViewDataDictionary viewData = null)
		{
			var cacheKey = new StringBuilder(partialViewName);
			if (cacheByPage)
			{
				if (UmbracoContext.Current == null)
				{
					throw new InvalidOperationException("Cannot cache by page if the UmbracoContext has not been initialized, this parameter can only be used in the context of an Umbraco request");
				}
				cacheKey.AppendFormat("{0}-", UmbracoContext.Current.PageId);
			}
			if (cacheByMember)
			{
				var currentMember = Member.GetCurrentMember();
				cacheKey.AppendFormat("m{0}-", currentMember == null ? 0 : currentMember.Id);
			}			
			return ApplicationContext.Current.ApplicationCache.CachedPartialView(htmlHelper, partialViewName, model, cachedSeconds, cacheKey.ToString(), viewData);
		}

		public static MvcHtmlString EditorFor<T>(this HtmlHelper htmlHelper, string templateName = "", string htmlFieldName = "", object additionalViewData = null)
			where T : new()
		{
			var model = new T();
			var typedHelper = new HtmlHelper<T>(
				htmlHelper.ViewContext.CopyWithModel(model),
				htmlHelper.ViewDataContainer.CopyWithModel(model));

			return typedHelper.EditorFor(x => model, templateName, htmlFieldName, additionalViewData);
		}

		/// <summary>
		/// A validation summary that lets you pass in a prefix so that the summary only displays for elements 
		/// containing the prefix. This allows you to have more than on validation summary on a page.
		/// </summary>
		/// <param name="htmlHelper"></param>
		/// <param name="prefix"></param>
		/// <param name="excludePropertyErrors"></param>
		/// <param name="message"></param>
		/// <param name="htmlAttributes"></param>
		/// <returns></returns>
		public static MvcHtmlString ValidationSummary(this HtmlHelper htmlHelper,
		                                              string prefix = "",
		                                              bool excludePropertyErrors = false,
		                                              string message = "",
		                                              IDictionary<string, object> htmlAttributes = null)
		{
			if (prefix.IsNullOrWhiteSpace())
			{
				return htmlHelper.ValidationSummary(excludePropertyErrors, message, htmlAttributes);
			}

			//if there's a prefix applied, we need to create a new html helper with a filtered ModelState collection so that it only looks for 
			//specific model state with the prefix.
			var filteredHtmlHelper = new HtmlHelper(htmlHelper.ViewContext, htmlHelper.ViewDataContainer.FilterContainer(prefix));
			return filteredHtmlHelper.ValidationSummary(excludePropertyErrors, message, htmlAttributes);
		}

		#region BeginUmbracoForm

		/// <summary>
		/// Used for rendering out the Form for BeginUmbracoForm
		/// </summary>
		internal class UmbracoForm : MvcForm
		{
			/// <summary>
			/// Creates an UmbracoForm
			/// </summary>
			/// <param name="viewContext"></param>
			/// <param name="surfaceController"></param>
			/// <param name="surfaceAction"></param>
			/// <param name="area"></param>		
			/// <param name="additionalRouteVals"></param>
			public UmbracoForm(
				ViewContext viewContext,
				string surfaceController,
				string surfaceAction,
				string area,
				object additionalRouteVals = null)
				: base(viewContext)
			{
				//need to create a params string as Base64 to put into our hidden field to use during the routes
				var surfaceRouteParams = string.Format("c={0}&a={1}&ar={2}",
														  viewContext.HttpContext.Server.UrlEncode(surfaceController),
														  viewContext.HttpContext.Server.UrlEncode(surfaceAction),
														  area);

				var additionalRouteValsAsQuery = additionalRouteVals.ToDictionary<object>().ToQueryString();

				if (!additionalRouteValsAsQuery.IsNullOrWhiteSpace())
					surfaceRouteParams += "&" + additionalRouteValsAsQuery;

				if (!string.IsNullOrWhiteSpace(surfaceRouteParams))
				{
					_base64String = Convert.ToBase64String(Encoding.UTF8.GetBytes(surfaceRouteParams));
				}

				_textWriter = viewContext.Writer;
			}
<commit_msg>Added null check just in case<commit_after>using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Html;
using Umbraco.Core;
using Umbraco.Core.Dynamics;
using Umbraco.Web.Mvc;
using umbraco;
using umbraco.cms.businesslogic.member;

namespace Umbraco.Web
{
	/// <summary>
	/// HtmlHelper extensions for use in templates
	/// </summary>
	public static class HtmlHelperRenderExtensions
	{
		public static IHtmlString CachedPartial(
			this HtmlHelper htmlHelper, 
			string partialViewName, 
			object model, 
			int cachedSeconds,
			bool cacheByPage = false,
			bool cacheByMember = false,
			ViewDataDictionary viewData = null)
		{
			var cacheKey = new StringBuilder(partialViewName);
			if (cacheByPage)
			{
				if (UmbracoContext.Current == null)
				{
					throw new InvalidOperationException("Cannot cache by page if the UmbracoContext has not been initialized, this parameter can only be used in the context of an Umbraco request");
				}
				cacheKey.AppendFormat("{0}-", UmbracoContext.Current.PageId);
			}
			if (cacheByMember)
			{
				var currentMember = Member.GetCurrentMember();
				cacheKey.AppendFormat("m{0}-", currentMember == null ? 0 : currentMember.Id);
			}			
			return ApplicationContext.Current.ApplicationCache.CachedPartialView(htmlHelper, partialViewName, model, cachedSeconds, cacheKey.ToString(), viewData);
		}

		public static MvcHtmlString EditorFor<T>(this HtmlHelper htmlHelper, string templateName = "", string htmlFieldName = "", object additionalViewData = null)
			where T : new()
		{
			var model = new T();
			var typedHelper = new HtmlHelper<T>(
				htmlHelper.ViewContext.CopyWithModel(model),
				htmlHelper.ViewDataContainer.CopyWithModel(model));

			return typedHelper.EditorFor(x => model, templateName, htmlFieldName, additionalViewData);
		}

		/// <summary>
		/// A validation summary that lets you pass in a prefix so that the summary only displays for elements 
		/// containing the prefix. This allows you to have more than on validation summary on a page.
		/// </summary>
		/// <param name="htmlHelper"></param>
		/// <param name="prefix"></param>
		/// <param name="excludePropertyErrors"></param>
		/// <param name="message"></param>
		/// <param name="htmlAttributes"></param>
		/// <returns></returns>
		public static MvcHtmlString ValidationSummary(this HtmlHelper htmlHelper,
		                                              string prefix = "",
		                                              bool excludePropertyErrors = false,
		                                              string message = "",
		                                              IDictionary<string, object> htmlAttributes = null)
		{
			if (prefix.IsNullOrWhiteSpace())
			{
				return htmlHelper.ValidationSummary(excludePropertyErrors, message, htmlAttributes);
			}

			//if there's a prefix applied, we need to create a new html helper with a filtered ModelState collection so that it only looks for 
			//specific model state with the prefix.
			var filteredHtmlHelper = new HtmlHelper(htmlHelper.ViewContext, htmlHelper.ViewDataContainer.FilterContainer(prefix));
			return filteredHtmlHelper.ValidationSummary(excludePropertyErrors, message, htmlAttributes);
		}

		#region BeginUmbracoForm

		/// <summary>
		/// Used for rendering out the Form for BeginUmbracoForm
		/// </summary>
		internal class UmbracoForm : MvcForm
		{
			/// <summary>
			/// Creates an UmbracoForm
			/// </summary>
			/// <param name="viewContext"></param>
			/// <param name="surfaceController"></param>
			/// <param name="surfaceAction"></param>
			/// <param name="area"></param>		
			/// <param name="additionalRouteVals"></param>
			public UmbracoForm(
				ViewContext viewContext,
				string surfaceController,
				string surfaceAction,
				string area,
				object additionalRouteVals = null)
				: base(viewContext)
			{
				//need to create a params string as Base64 to put into our hidden field to use during the routes
				var surfaceRouteParams = string.Format("c={0}&a={1}&ar={2}",
														  viewContext.HttpContext.Server.UrlEncode(surfaceController),
														  viewContext.HttpContext.Server.UrlEncode(surfaceAction),
														  area);

				var additionalRouteValsAsQuery = additionalRouteVals != null ? additionalRouteVals.ToDictionary<object>().ToQueryString() : null;

				if (!additionalRouteValsAsQuery.IsNullOrWhiteSpace())
					surfaceRouteParams += "&" + additionalRouteValsAsQuery;

				if (!string.IsNullOrWhiteSpace(surfaceRouteParams))
				{
					_base64String = Convert.ToBase64String(Encoding.UTF8.GetBytes(surfaceRouteParams));
				}

				_textWriter = viewContext.Writer;
			}

{'fraction_non_alphanumeric': 0.10505136079635709, 'fraction_numerical': 0.0027533622789367787, 'mean_word_length': 3.2349775784753363, 'pattern_counts': {'":': 0, '<': 71, '<?xml version=': 0, '>': 73, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6098233', 'n_tokens_mistral': 3016, 'n_tokens_neox': 2515, 'n_words': 688}