User:Yobot/Task 17
// Fixes priority and listas parameter in WikiProject Biography
private static readonly Regex WPBiography = Tools.NestedTemplateRegex(new List<string>("WPBiography,WikiProject Biography,Wikiproject Biography,WP Biography,WPBIO".Split(',')));
private static readonly Regex WorkGroup = new Regex(@"^([\w&]+)\-work\-group\s*=\s*", RegexOptions.Compiled);
public string ProcessArticle(string ArticleText, string ArticleTitle, int wikiNamespace, out string Summary, out bool Skip)
{
// WPBiography priority fixes
Skip = true;
Summary = "Set WPBiography work group priorities: ";
// process each WPBiography
foreach(Match m in WPBiography.Matches(ArticleText))
{
string WPBiographyCall = m.Value, newValue = m.Value;
// rename old importance field
newValue = Tools.RenameTemplateParameter(newValue, "importance", "priority");
string priority = Tools.GetTemplateParameterValue(newValue, "priority");
string listas = Tools.GetTemplateParameterValue(newValue, "listas");
//bool removePriority = false;
bool addListas = false;
//if(priority.Length == 0)
//continue;
int WPBiographyArgs = Tools.GetTemplateArgumentCount(WPBiographyCall);
// process each parameter for work groups
for(int a = 1; a <= WPBiographyArgs; a++)
{
string param = Tools.GetTemplateArgument(WPBiographyCall, a);
param = WikiRegexes.Comments.Replace(param, "").Trim();
if(WorkGroup.IsMatch(param))
{
string GroupName = WorkGroup.Match(param).Groups[1].Value;
// set work group priority if not already set
if(Tools.GetTemplateParameterValue(newValue, GroupName + "-work-group").Length > 0 &&
Tools.GetTemplateParameterValue(newValue, GroupName + @"-priority").Length == 0)
{
if(Tools.GetTemplateParameterValue(newValue, "priority").Length > 0)
{
newValue = Tools.RenameTemplateParameter(newValue, "priority", GroupName + @"-priority");
}
else
{
newValue = Tools.SetTemplateParameterValue(newValue, GroupName + @"-priority", priority);
}
Skip = false;
Summary += GroupName + @", ";
}
// remove empty work groups
if(Tools.GetTemplateParameterValue(newValue, GroupName + "-work-group").Length == 0)
{
newValue = Tools.RemoveTemplateParameter(newValue, GroupName + "-work-group");
}
// remove empty priority
if(Tools.GetTemplateParameterValue(newValue, "priority").Length == 0)
{
newValue = Tools.RemoveTemplateParameter(newValue, "priority");
}
}
// add listas if missing
if(listas.Length == 0)
{
string newListas = Tools.MakeHumanCatKey(ArticleTitle.Replace("Talk:", ""), ArticleText);
listas = newListas;
newValue = Tools.SetTemplateParameterValue(newValue, "listas", newListas);
addListas = true;
Skip = false;
}
// move listas to the bottom
string ListasValue = Tools.GetTemplateParameterValue(newValue,"listas");
newValue = Tools.RemoveTemplateParameter(newValue,"listas");
newValue = Tools.SetTemplateParameterValue(newValue,"listas",ListasValue);
// trim whitespace
newValue=newValue.Replace(" |","|");
newValue=newValue.Replace("| ","|");
}
// merge changes
if(!m.Value.Equals(newValue))
{
ArticleText = ArticleText.Replace(m.Value, newValue);
if(addListas)
{
Summary += "added listas";
}
}
}
return ArticleText;
}
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.