private DoneReplacement ( string old, string replacement ) : void | ||
old | string | |
replacement | string | |
return | void |
protected void ReplaceATemplateWithAYesParameter(Regex r, string paramName, string templateCall, bool replace = true) { if ((r.Matches(TheArticle.AlteredArticleText).Count > 0)) { if (replace) { TheArticle.AlteredArticleText = r.Replace(TheArticle.AlteredArticleText, ""); } TheArticle.DoneReplacement(templateCall, paramName + "=yes"); Template.NewOrReplaceTemplateParm(paramName, "yes", TheArticle, false, false); TheArticle.ArticleHasAMinorChange(); } }
private bool ReplaceTemplateParm(string parameterName, string parameterValue, Article theArticle, bool logItAndUpdateEditSummary, bool dontChangeIfSet) { string existingValue = WikiRegexes.Comments.Replace(Parameters[parameterName].Value, "").Trim(); // trim still needed because altho main regex shouldn't give us spaces at the end of vals any more, the .Replace here might // Contains parameter with a different value if (existingValue != parameterValue) { // Contains parameter with a different value, and _ if (string.IsNullOrEmpty(existingValue) || !dontChangeIfSet) { // we want to change it; or contains an empty parameter Parameters[parameterName].Value = parameterValue; theArticle.ArticleHasAMajorChange(); if (logItAndUpdateEditSummary) { if (string.IsNullOrEmpty(existingValue)) { theArticle.ParameterAdded(parameterName, parameterValue); } else { theArticle.DoneReplacement(parameterName + "=" + existingValue, parameterValue); } } return(true); // Contains param with a different value, and we don't want to change it } } // Else: Already contains parameter and correct value; no need to change return(false); }
/// <summary> /// Checks if params which have two names (V8, v8) exist under both names /// </summary> /// <returns>True if BAD TAG</returns> protected bool CheckForDoublyNamedParameters(string Name1, string Name2) { var _with6 = Template.Parameters; if (_with6.ContainsKey(Name1) && _with6.ContainsKey(Name2)) { if (_with6[Name1].Value == _with6[Name2].Value) { _with6.Remove(Name2); article.DoneReplacement(Name2, "", true, PluginShortName); } else { return(true); } } return(false); }
private bool ReplaceTemplateParm(string ParameterName, string ParameterValue, Article TheArticle, bool LogItAndUpdateEditSummary, bool DontChangeIfSet, string PluginName) { string ExistingValue = WikiRegexes.Comments.Replace(Parameters[ParameterName].Value, "").Trim(); // trim still needed because altho main regex shouldn't give us spaces at the end of vals any more, the .Replace here might // Contains parameter with a different value if (ExistingValue != ParameterValue) { // Contains parameter with a different value, and _ if (string.IsNullOrEmpty(ExistingValue) || !DontChangeIfSet) { // we want to change it; or contains an empty parameter Parameters[ParameterName].Value = ParameterValue; TheArticle.ArticleHasAMajorChange(); if (LogItAndUpdateEditSummary) { if (string.IsNullOrEmpty(ExistingValue)) { TheArticle.ParameterAdded(ParameterName, ParameterValue, PluginName); } else { TheArticle.DoneReplacement(ParameterName + "=" + ExistingValue, ParameterValue, true, PluginName); } } return true; // Contains param with a different value, and we don't want to change it } } // Else: Already contains parameter and correct value; no need to change return false; }
private static string FinaliseArticleProcessing(Article theArticle, ref bool skip, ref string summary, string articleText, bool reqPhoto) { SkipReason skipReason = SkipReason.Other; if (theArticle.PluginManagerGetSkipResults == SkipResults.NotSet) { _pluginSettings.PluginStats.Tagged += 1; } else { switch (theArticle.PluginManagerGetSkipResults) { case SkipResults.SkipBadTag: // always skip if (_pluginSettings.SkipBadTags) { _pluginSettings.PluginStats.SkippedBadTagIncrement(); if (_pluginSettings.OpenBadInBrowser) { theArticle.EditInBrowser(); } skip = true; // always skip skipReason = SkipReason.BadTag; } else { // the plugin manager stops processing when it gets a bad tag. We know however // that one plugin found a bad template and possibly replaced it with // conTemplatePlaceholder. We're also not skipping, so we need to remove the placeholder theArticle.AlteredArticleText = theArticle.AlteredArticleText.Replace(Constants.TemplaterPlaceholder, ""); MessageBox.Show("Bad tag. Please fix it manually or click ignore.", "Bad tag", MessageBoxButtons.OK, MessageBoxIcon.Warning); _pluginSettings.PluginStats.Tagged += 1; } break; case SkipResults.SkipRegex: case SkipResults.SkipNoChange: if (theArticle.ProcessIt) { _pluginSettings.PluginStats.Tagged += 1; } else { if (theArticle.PluginManagerGetSkipResults == SkipResults.SkipRegex) { _pluginSettings.PluginStats.SkippedMiscellaneousIncrement(); skip = true; skipReason = SkipReason.Regex; // No change: } else { if (_pluginSettings.SkipWhenNoChange) { _pluginSettings.PluginStats.SkippedNoChangeIncrement(); skipReason = SkipReason.NoChange; skip = true; } else { _pluginSettings.PluginStats.Tagged += 1; skip = false; } } } break; } } if (skip) { return(Skipping(ref summary, theArticle.EditSummary, skipReason, articleText, ref skip)); } if (reqPhoto) { theArticle.AlteredArticleText = ReqPhotoNoParamsRegex.Replace(theArticle.AlteredArticleText, ""); theArticle.DoneReplacement("{{reqphoto}}", "template param(s)"); theArticle.ArticleHasAMajorChange(); } theArticle.FinaliseEditSummary(); summary = theArticle.EditSummary; return(theArticle.AlteredArticleText); }
private static string FinaliseArticleProcessing(Article theArticle, ref bool skip, ref string summary, string articleText, bool reqPhoto) { SkipReason skipReason = SkipReason.Other; if (theArticle.PluginManagerGetSkipResults == SkipResults.NotSet) { _pluginSettings.PluginStats.Tagged += 1; } else { switch (theArticle.PluginManagerGetSkipResults) { case SkipResults.SkipBadTag: // always skip if (_pluginSettings.SkipBadTags) { _pluginSettings.PluginStats.SkippedBadTagIncrement(); if (_pluginSettings.OpenBadInBrowser) theArticle.EditInBrowser(); skip = true; // always skip skipReason = SkipReason.BadTag; } else { // the plugin manager stops processing when it gets a bad tag. We know however // that one plugin found a bad template and possibly replaced it with // conTemplatePlaceholder. We're also not skipping, so we need to remove the placeholder theArticle.AlteredArticleText = theArticle.AlteredArticleText.Replace(Constants.TemplaterPlaceholder, ""); MessageBox.Show("Bad tag. Please fix it manually or click ignore.", "Bad tag", MessageBoxButtons.OK, MessageBoxIcon.Warning); _pluginSettings.PluginStats.Tagged += 1; } break; case SkipResults.SkipRegex: case SkipResults.SkipNoChange: if (theArticle.ProcessIt) { _pluginSettings.PluginStats.Tagged += 1; } else { if (theArticle.PluginManagerGetSkipResults == SkipResults.SkipRegex) { _pluginSettings.PluginStats.SkippedMiscellaneousIncrement(); skip = true; skipReason = SkipReason.Regex; // No change: } else { if (_pluginSettings.SkipWhenNoChange) { _pluginSettings.PluginStats.SkippedNoChangeIncrement(); skipReason = SkipReason.NoChange; skip = true; } else { _pluginSettings.PluginStats.Tagged += 1; skip = false; } } } break; } } if (skip) { return Skipping(ref summary, theArticle.EditSummary, skipReason, articleText, ref skip); } if (reqPhoto) { theArticle.AlteredArticleText = ReqPhotoNoParamsRegex.Replace(theArticle.AlteredArticleText, ""); theArticle.DoneReplacement("{{reqphoto}}", "template param(s)"); theArticle.ArticleHasAMajorChange(); } theArticle.FinaliseEditSummary(); summary = theArticle.EditSummary; return theArticle.AlteredArticleText; }