维基百科:AutoWikiBrowser/定製模組


Using multiple Custom Modules

编辑

By default, you can't actually use multiple custom modules; by using simple coding techniques, you can use multiple.

Just be aware, you may need to tweak your summary and skip changes (if you're not using skip, it's easier). Summary, just use +=, to append onto the summary

        public string ProcessArticle(string ArticleText, string ArticleTitle, int wikiNamespace, out string Summary, out bool Skip)
        {
            ArticleText = CustomModule1(ArticleText, ArticleTitle, wikiNamespace, out Summary, out Skip);
            ArticleText = CustomModule2(ArticleText, ArticleTitle, wikiNamespace, out Summary, out Skip);

            return ArticleText;
        }

        public string CustomModule1(string ArticleText, string ArticleTitle, int wikiNamespace, out string Summary, out bool Skip)
        {
            //Blah, code goes here

            return ArticleText;
        }

        public string CustomModule2(string ArticleText, string ArticleTitle, int wikiNamespace, out string Summary, out bool Skip)
        {
            //Blah, code goes here

            return ArticleText;
        }

Mass AfD Tagging

编辑

Go to "Tools" → "Make module" and paste the following code:

         public string ProcessArticle(string ArticleText, string ArticleTitle, int wikiNamespace, out string Summary, out bool Skip)
         {
             Skip = false;
             Summary = "EDIT_SUMMARY_HERE";
 
             ArticleText = "TAG_TO_ADD_HERE\r\n" + ArticleText;
 
             return ArticleText;
         }

Replacing EDIT_SUMMARY_HERE with the desired edit summary (keep the quotes around the summary; if you want actual quotes in the summary write them as \") and TAG_TO_ADD_HERE with the tag you want to add to the top of the page (again keep the quotes around the summary and the \r\n after it). If you want the tag to be at the end of the page replace the line

             ArticleText = "TAG_TO_ADD_HERE\r\n" + ArticleText;

With

            ArticleText = ArticleText + "TAG_TO_ADD_HERE\r\n";

Then check the "Enabled" box, press "Make module", and then "Done". Keep the "edit summary" box in the main AWB form empty.

Passing text to external program for processing

编辑

Note: An interface now exists in AWB for this

        public string ProcessArticle(string ArticleText, string ArticleTitle, int wikiNamespace, out string Summary, out bool Skip)
        {
            string OrigText = ArticleText;
            Skip = false;
            Summary = "";

            try
            {
                System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo();
                psi.WorkingDirectory = "C:\\Path";
                psi.FileName = "script.ext";
                psi.Arguments = "";

                System.IO.StreamWriter writer = new System.IO.StreamWriter("input.txt");
                writer.Write(ArticleText);

                writer.Close();

                System.Diagnostics.Process p = System.Diagnostics.Process.Start(psi);
                p.WaitForExit();

                if (System.IO.File.Exists(psi.WorkingDirectory + "\\output.txt"))
                {
                    System.IO.StreamReader reader = System.IO.File.OpenText(psi.WorkingDirectory + "\\output.txt");

                    ArticleText = reader.ReadToEnd();

                    reader.Close();

                    if (ArticleText == OrigText)
                        Skip = true;
                }
                else
                    Skip = true;

                return ArticleText;
            }
            catch
            {
                Skip = true;
                return OrigText;
            }
        }
psi.WorkingDirectory = "C:\\Path";
psi.FileName = "script.ext";
psi.Arguments = "";

So, working directory, is where the file you want to run is. File name is obvious, arguments, is probably how you want to pass it the article text or similar.

Inserting text just before categories

编辑

Could be easily adapted for inserting into other parts of the page.

        public string ProcessArticle(string ArticleText, string ArticleTitle, int wikiNamespace, out string Summary, out bool Skip)
        {
            Skip = false;
            Summary = "";

            Match m = Regex.Match(ArticleText, @"\[\[[Cc]ategory:");

            if (m.Success) ArticleText = ArticleText.Insert(m.Index, "foo\r\n");
            else ArticleText += "\r\nfoo";

            return ArticleText;
        }

Add template if not already on talk page

编辑

This example will add {{Talk header}} if it doesn't exist on the page already

        public string ProcessArticle(string ArticleText, string ArticleTitle, int wikiNamespace, out string Summary, out bool Skip)
        {
            Regex header = new Regex(@"\{\{Talk header}}", RegexOptions.IgnoreCase);
            Summary = "Adding {{Talk header}}";

            Skip = (header.Match(ArticleText).Success || !Namespace.IsTalk(ArticleTitle));
            if (!Skip)
                ArticleText = "{{Talk header}} \r\n\r\n" + ArticleText;

            return ArticleText;
        }

Rough archiving template insert after last template on page

编辑
        public string ProcessArticle(string ArticleText, string ArticleTitle, int wikiNamespace, out string Summary, out bool Skip)
        {
            Skip = false;
            Summary = "Adding archiving templates";

            int insertPos = ArticleText.LastIndexOf("}}") + 2;

            if (insertPos < 2)
                insertPos = 0;

            ArticleText = ArticleText.Insert(insertPos, @"{{autoarchivingnotice|bot=MiszaBot I|age=28}}
{{User:MiszaBot/config
|archiveheader = {{talkarchivenav}}
|maxarchivesize = 31K
|counter = 3
|algo = old(28d)
|archive = Talk:{{subst:FULLPAGENAME}}/Archive %(counter)d
}}
");

            return ArticleText;
        }

Customised "General Fixes"

编辑

A way was requested to run the general fixes, but to disable certain specific ones. Therefore, the code has basically just been duplicated as a Custom Module, and the lines with "//" specify the lines where a general fix has been disabled.

  1. Paste the following into the "Make Module" window at "Tools". Leave language at "C# 2.0", click "enabled" and "make module". The below sample has the insertion of &nbsp; disabled.
  2. In the "Options" tab, disable "Apply general fixes"
WikiFunctions.Parse.Parsers parser = new WikiFunctions.Parse.Parsers();
WikiFunctions.Parse.HideText removeText = new WikiFunctions.Parse.HideText(false, true, false);
 
public string ProcessArticle(string ArticleText, string ArticleTitle, int wikiNamespace, out string Summary, out bool Skip)
{
	Skip = false;
	Summary = "";
 
	Article a = new Article(ArticleTitle, ArticleText);
	a.InitialiseLogListener("test", awb.TraceManager);
 
	a.HideText(removeText);

        a.AWBChangeArticleText("Template redirects", WikiFunctions.Parse.Parsers.TemplateRedirects(a.ArticleText, WikiRegexes.TemplateRedirects), false);
 
	//a.FixHeaderErrors(parser, Variables.LangCode, false);
	a.SetDefaultSort(Variables.LangCode, false);
 
        a.AWBChangeArticleText("Fixes for {{multiple issues}}", parser.MultipleIssues(a.ArticleText), true);

	a.AWBChangeArticleText("Fix categories", WikiFunctions.Parse.Parsers.FixCategories(a.ArticleText), true);
 
	a.AWBChangeArticleText("Fix images", WikiFunctions.Parse.Parsers.FixImages(a.ArticleText), true);
 
	a.AWBChangeArticleText("Fix whitespace in links", WikiFunctions.Parse.Parsers.FixLinkWhitespace(a.ArticleText, ArticleTitle), true);

	a.BulletExternalLinks(false);
 
	a.AWBChangeArticleText("Fix syntax", WikiFunctions.Parse.Parsers.FixSyntax(a.ArticleText), true, true);
 
	a.AWBChangeArticleText("Fix temperatures", WikiFunctions.Parse.Parsers.FixTemperatures(a.ArticleText), true);
	// The two slashes below are inserted to disable the insertion of non-breaking spaces HTML markup (sample) 

	// a.AWBChangeArticleText("Fix non-breaking spaces", parser.FixNonBreakingSpaces(a.ArticleText), true);
 
	a.AWBChangeArticleText("Fix main article", WikiFunctions.Parse.Parsers.FixMainArticle(a.ArticleText), true);
 
	a.AWBChangeArticleText("Fix reference tags", WikiFunctions.Parse.Parsers.FixReferenceListTags(a.ArticleText), true);
 
	a.AWBChangeArticleText("Fix empty links and templates", WikiFunctions.Parse.Parsers.FixEmptyLinksAndTemplates(a.ArticleText), true);
 
	a.AWBChangeArticleText("FixReferenceTags", WikiFunctions.Parse.Parsers.FixReferenceTags(a.ArticleText), true);

	a.AWBChangeArticleText("Fix empty references", WikiFunctions.Parse.Parsers.SimplifyReferenceTags(a.ArticleText), true);
 
	a.AWBChangeArticleText("ReorderReferences", WikiFunctions.Parse.Parsers.ReorderReferences(a.ArticleText), true);
  
        if(a.IsMissingReferencesDisplay)
	  a.AWBChangeArticleText("Add missing {{reflist}}", WikiFunctions.Parse.Parsers.AddMissingReflist(a.ArticleText), true, true);
 
	a.AWBChangeArticleText("Mdashes", parser.Mdashes(a.ArticleText, ArticleTitle), true);
 
        a.EmboldenTitles(parser, false);

	a.FixLinks(false);
 
	a.AWBChangeArticleText("Remove empty comments", WikiFunctions.Parse.Parsers.RemoveEmptyComments(a.ArticleText), false);
 
	a.AWBChangeArticleText("Fix Date Ordinals/Of", parser.FixDateOrdinalsAndOf(a.ArticleText, ArticleTitle), true, true);
 

        a.AWBChangeArticleText("Format sticky links", WikiFunctions.Parse.Parsers.SimplifyLinks(a.ArticleText), true);
 
	a.AWBChangeArticleText("FixHeadings", WikiFunctions.Parse.Parsers.FixHeadings(a.ArticleText, ArticleTitle), true);

	a.UnHideText(removeText);

	a.AWBChangeArticleText("Sort meta data", parser.SortMetaData(a.ArticleText, ArticleTitle), true);
 
	return a.ArticleText;
}

Use HideMore function to hide templates, images and text in quotes

编辑
//...
	WikiFunctions.Parse.HideText htmore = new WikiFunctions.Parse.HideText();

	ArticleText = htmore.HideMore(ArticleText);

	// make your changes to ArticleText here

	ArticleText = htmore.AddBackMore(ArticleText);
//...

Getting hold of the status of tagger, RETF etc.

编辑
//...
bool TyposEnabled = awb.RegexTypoFix.Checked;
bool TaggerEnabled = awb.AutoTagCheckBox.Checked; 
//...

Skip if no Persondata changes

编辑
WikiFunctions.Parse.Parsers parser = new WikiFunctions.Parse.Parsers();
WikiFunctions.Parse.HideText removeText = new WikiFunctions.Parse.HideText(false, true, false);
        public string ProcessArticle(string ArticleText, string ArticleTitle, int wikiNamespace, out string Summary, out bool Skip)
        {
            Skip = false;
            Summary = " ";
   
string old = ArticleText;
Article a = new Article(ArticleTitle, ArticleText);
 
 a.HideText(removeText);
 
 a.AWBChangeArticleText("Persondata", WikiFunctions.Parse.Parsers.PersonData(a.ArticleText, ArticleTitle), true);
            
a.UnHideText(removeText);
if(old.Equals(a.ArticleText))
Skip = true;
 
 return a.ArticleText;
        }

参见

编辑