Пример #1
0
        /// <summary>
        /// Constructor/initialisation, called from IAWBPlugin.Initialise
        /// </summary>
        /// <param name="AWBForm"></param>
        internal ServerControl(IAutoWikiBrowser sender)
        {
            InitializeComponent();

            // Store reference to AWB main form:
            AWBForm = sender;

            // Set up our UI objects:
            StatusText.Visible = false;
            StatusText.Margin = new Padding(10, 0, 10, 0);
            StatusText.BorderSides = ToolStripStatusLabelBorderSides.Left | ToolStripStatusLabelBorderSides.Right;
            StatusText.BorderStyle = Border3DStyle.Etched;
            //AWBForm.StatusStrip.ShowItemToolTips = true; // naughty hack in case somebody turns this off in the designer
            EnabledMenuItem.CheckOnClick = true;
            TabPageMenuItem.CheckOnClick = true;

            // Event handlers:
            AboutMenuItem.Click += AboutMenuItemClicked;
            EnabledMenuItem.CheckedChanged += PluginEnabled_CheckedChange;
            TabPageMenuItem.CheckedChanged += TabPageMenuItem_CheckedChange;
            ConfigMenuItem.Click += ShowSettings;
            HideButton.Click += HideButton_Click;
            SettingsButton.Click += ShowSettings;

            // Add our UI objects to the AWB main form:
            AWBForm.StatusStrip.Items.Insert(2, StatusText);
            EnabledMenuItem.DropDownItems.Add(ConfigMenuItem);
            EnabledMenuItem.DropDownItems.Add(TabPageMenuItem);
            AWBForm.PluginsToolStripMenuItem.DropDownItems.Add(EnabledMenuItem);
            AWBForm.HelpToolStripMenuItem.DropDownItems.Add(AboutMenuItem);
            AWBForm.HelpToolStripMenuItem.DropDownItems.Add(AboutMenuItem);
        }
Пример #2
0
        public string ProcessArticle(IAutoWikiBrowser sender, IProcessArticleEventArgs eventargs)
        {
            //If menu item is not checked, then return
            if (!PluginEnabled || Settings.Images.Count == 0)
            {
                eventargs.Skip = false;
                return eventargs.ArticleText;
            }

            eventargs.EditSummary = "";
            string text = eventargs.ArticleText;

            foreach (KeyValuePair<string, string> p in Settings.Images)
            {
                bool noChange;

                if (p.Value.Length == 0)
                {
                    text = Parsers.RemoveImage(p.Key, text, Settings.Comment, "", out noChange);
                    if (!noChange) eventargs.EditSummary += ", removed " + Variables.Namespaces[6] + p.Key;
                }
                else
                {
                    text = Parsers.ReplaceImage(p.Key, p.Value, text, out noChange);
                    if (!noChange) eventargs.EditSummary += ", replaced: " + Variables.Namespaces[6]
                         + p.Key + FindandReplace.Arrow + Variables.Namespaces[6] + p.Value;
                }
                if (!noChange) text = Regex.Replace(text, "<includeonly>[\\s\\r\\n]*\\</includeonly>", "");
            }

            eventargs.Skip = (text == eventargs.ArticleText) && Settings.Skip;

            return text;
        }
Пример #3
0
        public static void LoadNewPlugin(IAutoWikiBrowser awb)
        {
            OpenFileDialog pluginOpen = new OpenFileDialog();
            if (string.IsNullOrEmpty(LastPluginLoadedLocation))
                LoadLastPluginLoadedLocation();

            pluginOpen.InitialDirectory = string.IsNullOrEmpty(LastPluginLoadedLocation) ? Application.StartupPath : LastPluginLoadedLocation;
            
            pluginOpen.DefaultExt = "dll";
            pluginOpen.Filter = "DLL files|*.dll";
            pluginOpen.CheckFileExists = pluginOpen.Multiselect = /*pluginOpen.AutoUpgradeEnabled =*/ true;

            pluginOpen.ShowDialog();
            
            if (!string.IsNullOrEmpty(pluginOpen.FileName))
            {
                string newPath = Path.GetDirectoryName(pluginOpen.FileName);
                if (LastPluginLoadedLocation != newPath)
                {
                    LastPluginLoadedLocation = newPath;
                    SaveLastPluginLoadedLocation();
                }
            }

            Plugin.LoadPlugins(awb, pluginOpen.FileNames, true);
        }
Пример #4
0
        public string ProcessArticle(IAutoWikiBrowser sender, IProcessArticleEventArgs eventargs)
        {
            //If menu item is not checked, then return
            if (!PluginEnabled)
            {
                eventargs.Skip = false;
                return eventargs.ArticleText;
            }

            // Warn if plugin is running, but no fronds have been enabled. A common newbie situation.
            if (Settings.EnabledFilenames.Count == 0)
            {
                DialogResult result = MessageBox.Show(
                    "It looks like you forget to select some fronds to use. You might like to choose some (\"Okay\"), or disable the plugin for now (\"Cancel\").",
                    "Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
                if (result == DialogResult.OK)
                {
                    ConfigMenuItem.PerformClick();
                }
                else
                {
                    EnabledMenuItem.Checked = Settings.Enabled = PluginEnabled = false;
                }
                return eventargs.ArticleText;
            }

            string text = eventargs.ArticleText;
            foreach (Frond f in Replacements)
            {
                text = f.Preform(text);
            }
            return text;
        }
Пример #5
0
        void IAWBPlugin.Initialise(IAutoWikiBrowser sender)
        {
            if (sender == null)
                throw new ArgumentNullException("sender");

            // Delegate UI-setup to our user control object:
            ServerUserControl = new ServerControl(sender);

            // Set up the TabPage and attach the user control to it:
            ServerPluginTabPage.UseVisualStyleBackColor = true;
            ServerPluginTabPage.Controls.Add(ServerUserControl);
        }
Пример #6
0
        public void Initialise(IAutoWikiBrowser sender)
        {
            if (sender == null)
                throw new ArgumentNullException("sender");
            AWB = sender;

            // Menuitem should be checked when Fronds plugin is active and unchecked when not, and default to not!
            EnabledMenuItem.CheckOnClick = true;
            PluginEnabled = Settings.Enabled;

            ConfigMenuItem.Click += ShowSettings;
            EnabledMenuItem.CheckedChanged += PluginEnabledCheckedChange;
            AboutMenuItem.Click += AboutMenuItemClicked;
            PluginAboutMenuItem.Click += AboutMenuItemClicked;

            EnabledMenuItem.DropDownItems.AddRange(new[] {ConfigMenuItem, PluginAboutMenuItem});
            AWB.PluginsToolStripMenuItem.DropDownItems.Add(EnabledMenuItem);
            AWB.HelpToolStripMenuItem.DropDownItems.Add(AboutMenuItem);

            string newVersion = Tools.GetHTML(BaseURL + "version.txt").Replace(".", "");
            if (Int16.Parse(newVersion) > Int16.Parse(CurrentVersion.Replace(".", "")))
            {
                DialogResult result = MessageBox.Show(
                    "A newer version of Fronds is available. Downloading it is advisable, as it may contain important bugfixes.\r\n\r\nLoad update page now?",
                    "New version", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                if (result == DialogResult.Yes)
                {
                    Tools.OpenURLInBrowser("http://en.wikipedia.org/wiki/WP:FRONDS/U");
                }
            }

            XmlDocument xd = new XmlDocument();
            xd.LoadXml(Tools.GetHTML(BaseURL + "index.xml"));

            if (xd["fronds"] == null)
                return;

            foreach (XmlNode xn in xd["fronds"].GetElementsByTagName("frond"))
            {
                if (xn.ChildNodes.Count != 2)
                    continue;

                PossibleFilenames.Add(xn.ChildNodes[0].InnerText);
                PossibleFronds.Add(xn.ChildNodes[1].InnerText + " (" + xn.ChildNodes[0].InnerText + ")");
            }

            //TODO:We should probably load enabled Fronds when the plugin is enabled... (Probably in LoadSettings)
        }
        public void Initialise(IAutoWikiBrowser sender)
        {
            AWB = sender;
            AWB.LogControl.LogAdded += new WikiFunctions.Logging.LogControl.LogAddedToControl(LogControl_LogAdded);
            AWB.AddMainFormClosingEventHandler(new FormClosingEventHandler(UploadFinishedArticlesToServer));
            AWB.AddArticleRedirectedEventHandler(new ArticleRedirected(ArticleRedirected));

            pluginMenuItem.DropDownItems.Add(pluginUploadMenuItem);
            pluginMenuItem.DropDownItems.Add(pluginReAddArticlesMenuItem);
            pluginUploadMenuItem.Click += new EventHandler(pluginUploadMenuItem_Click);

            pluginReAddArticlesMenuItem.Click += new EventHandler(pluginReAddArticlesMenuItem_Click);
            sender.PluginsToolStripMenuItem.DropDownItems.Add(pluginMenuItem);

            aboutMenuItem.Click += new EventHandler(aboutMenuItem_Click);
            sender.HelpToolStripMenuItem.DropDownItems.Add(aboutMenuItem);
        }
        public void Initialise(IAutoWikiBrowser sender)
        {
            AWB = sender;
            AWB.LogControl.LogAdded += LogControl_LogAdded;
            AWB.AddMainFormClosingEventHandler(UploadFinishedArticlesToServer);
            AWB.AddArticleRedirectedEventHandler(ArticleRedirected);

            PluginMenuItem.DropDownItems.Add(PluginUploadMenuItem);
            PluginMenuItem.DropDownItems.Add(PluginReAddArticlesMenuItem);
            PluginUploadMenuItem.Click += pluginUploadMenuItem_Click;

            PluginReAddArticlesMenuItem.Click += pluginReAddArticlesMenuItem_Click;
            sender.PluginsToolStripMenuItem.DropDownItems.Add(PluginMenuItem);

            AboutMenuItem.Click += aboutMenuItem_Click;
            sender.HelpToolStripMenuItem.DropDownItems.Add(AboutMenuItem);
        }
Пример #9
0
        public string ProcessArticle(IAutoWikiBrowser sender, ProcessArticleEventArgs eventargs)
        {
            //If menu item is not checked, then return
            if (!PluginEnabled || Settings.Images.Count == 0)
            {
                eventargs.Skip = false;
                return(eventargs.ArticleText);
            }

            eventargs.EditSummary = "";
            string text = eventargs.ArticleText;

            foreach (KeyValuePair <string, string> p in Settings.Images)
            {
                bool noChange;

                if (p.Value.Length == 0)
                {
                    text = Parsers.RemoveImage(p.Key, text, Settings.Comment, "", out noChange);
                    if (!noChange)
                    {
                        eventargs.EditSummary += ", removed " + Variables.Namespaces[6] + p.Key;
                    }
                }
                else
                {
                    text = Parsers.ReplaceImage(p.Key, p.Value, text, out noChange);
                    if (!noChange)
                    {
                        eventargs.EditSummary += ", replaced: " + Variables.Namespaces[6]
                                                 + p.Key + FindandReplace.Arrow + Variables.Namespaces[6] + p.Value;
                    }
                }
                if (!noChange)
                {
                    text = Regex.Replace(text, "<includeonly>[\\s\\r\\n]*\\</includeonly>", "");
                }
            }

            eventargs.Skip = (text == eventargs.ArticleText) && Settings.Skip;

            return(text);
        }
Пример #10
0
        public void Initialise(IAutoWikiBrowser sender)
        {
            if (sender == null)
                throw new ArgumentNullException("sender");

            AWB = sender;

            // Menuitem should be checked when IFD plugin is active and unchecked when not, and default to not!
            pluginenabledMenuItem.CheckOnClick = true;
            PluginEnabled = Settings.Enabled;

            pluginconfigMenuItem.Click += ShowSettings;
            pluginenabledMenuItem.CheckedChanged += PluginEnabledCheckedChange;
            aboutMenuItem.Click += AboutMenuItemClicked;
            pluginenabledMenuItem.DropDownItems.Add(pluginconfigMenuItem);

            sender.PluginsToolStripMenuItem.DropDownItems.Add(pluginenabledMenuItem);
            sender.HelpToolStripMenuItem.DropDownItems.Add(aboutMenuItem);
        }
        public void Initialise(IAutoWikiBrowser sender)
        {
            AWB = sender;
            AWB.LogControl.LogAdded += new WikiFunctions.Logging.LogControl.LogAddedToControl(LogControl_LogAdded);
            AWB.AddMainFormClosingEventHandler(new FormClosingEventHandler(UploadFinishedArticlesToServer));
            AWB.AddArticleRedirectedEventHandler(new ArticleRedirected(ArticleRedirected));

            pluginMenuItem.DropDownItems.Add(pluginUploadMenuItem);
            pluginMenuItem.DropDownItems.Add(pluginReAddArticlesMenuItem);
            pluginUploadMenuItem.Click += new EventHandler(pluginUploadMenuItem_Click);
#if !DEBUG
            pluginReAddArticlesMenuItem.Enabled = false;
#endif
            pluginReAddArticlesMenuItem.Click += new EventHandler(pluginReAddArticlesMenuItem_Click);
            sender.PluginsToolStripMenuItem.DropDownItems.Add(pluginMenuItem);

            aboutMenuItem.Click += new EventHandler(aboutMenuItem_Click);
            sender.HelpToolStripMenuItem.DropDownItems.Add(aboutMenuItem);
        }
Пример #12
0
        public void Initialise(IAutoWikiBrowser sender)
        {
            if (sender == null)
                throw new ArgumentNullException("sender");

            AWB = sender;

            // Menuitem should be checked when IFD plugin is active and unchecked when not, and default to not!
            pluginenabledMenuItem.CheckOnClick = true;
            PluginEnabled = Settings.Enabled;

            pluginconfigMenuItem.Click += ShowSettings;
            pluginenabledMenuItem.CheckedChanged += PluginEnabledCheckedChange;
            aboutMenuItem.Click += AboutMenuItemClicked;
            pluginenabledMenuItem.DropDownItems.Add(pluginconfigMenuItem);

            sender.PluginsToolStripMenuItem.DropDownItems.Add(pluginenabledMenuItem);
            sender.HelpToolStripMenuItem.DropDownItems.Add(aboutMenuItem);
        }
Пример #13
0
        public void Initialise(IAutoWikiBrowser sender)
        {
            if (sender == null)
                throw new ArgumentNullException("sender");
            AWB = sender;

            // Menuitem should be checked when Fronds plugin is active and unchecked when not, and default to not!
            EnabledMenuItem.CheckOnClick = true;
            PluginEnabled = Settings.Enabled;

            ConfigMenuItem.Click += ShowSettings;
            EnabledMenuItem.CheckedChanged += PluginEnabledCheckedChange;
            AboutMenuItem.Click += AboutMenuItemClicked;
            PluginAboutMenuItem.Click += AboutMenuItemClicked;

            EnabledMenuItem.DropDownItems.AddRange(new[] {ConfigMenuItem, PluginAboutMenuItem});
            AWB.PluginsToolStripMenuItem.DropDownItems.Add(EnabledMenuItem);
            AWB.HelpToolStripMenuItem.DropDownItems.Add(AboutMenuItem);
        }
Пример #14
0
        public string ProcessArticle(IAutoWikiBrowser sender, IProcessArticleEventArgs eventargs)
        {
            if (!Enabled || string.IsNullOrEmpty(Link))
            {
                return(eventargs.ArticleText);
            }

            string articleText = eventargs.ArticleText;

            RefNames.Clear();

            articleText = r4.Replace(articleText, R4Evaluator);

            articleText = r1.Replace(articleText, "");
            articleText = r2.Replace(articleText, "");
            articleText = r3.Replace(articleText, "");

            if (RefNames.Count > 0)
            {
                foreach (string name in RefNames)
                {
                    articleText = Regex.Replace(articleText, @"< ?ref\b[^>]*?name ?= ?""?" + name + "[\" ]? ?/ ?>", "");
                }
            }

            if (articleText == eventargs.ArticleText)
            {
                eventargs.Skip = Skip;
            }
            else
            {
                if (RemoveEmptiedSections && (Variables.LangCode.Equals("en") ||
                                              Variables.LangCode.Equals("de") ||
                                              Variables.LangCode.Equals("ru")))
                {
                    articleText = RemoveSection(articleText);
                }
            }

            return(articleText);
        }
Пример #15
0
        public void Initialise(IAutoWikiBrowser sender)
        {
            if (sender == null)
            {
                throw new ArgumentNullException("sender");
            }
            AWB = sender;

            // Menuitem should be checked when Fronds plugin is active and unchecked when not, and default to not!
            EnabledMenuItem.CheckOnClick = true;
            PluginEnabled = Settings.Enabled;

            ConfigMenuItem.Click           += ShowSettings;
            EnabledMenuItem.CheckedChanged += PluginEnabledCheckedChange;
            AboutMenuItem.Click            += AboutMenuItemClicked;
            PluginAboutMenuItem.Click      += AboutMenuItemClicked;

            EnabledMenuItem.DropDownItems.AddRange(new[] { ConfigMenuItem, PluginAboutMenuItem });
            AWB.PluginsToolStripMenuItem.DropDownItems.Add(EnabledMenuItem);
            AWB.HelpToolStripMenuItem.DropDownItems.Add(AboutMenuItem);
        }
Пример #16
0
        /// <summary>
        /// Send the article to a plugin for processing
        /// </summary>
        /// <param name="plugin">The plugin</param>
        /// <param name="sender">The AWB instance</param>
        public void SendPageToPlugin(IAWBPlugin plugin, IAutoWikiBrowser sender)
        {
            string strTemp = plugin.ProcessArticle(sender, this);

            if (mPluginSkip)
            {
                if (!SkipArticle)
                {
                    /* plugin has told us to skip but didn't log any info about reason
                     * Calling Trace.SkippedArticle() should also result in SkipArticle becoming True
                     * and our caller - MainForm.ProcessPage() - can check this value */
                    Trace.SkippedArticle(plugin.Name, "Skipped by plugin");
                }
            }
            else
            {
                mAWBLogListener.Skipped = false;  // a bit of a hack, if plugin says not to skip I'm resetting the LogListener.Skipped value to False
                PluginChangeArticleText(strTemp);
                AppendPluginEditSummary();
            }
        }
Пример #17
0
        public void Initialise(IAutoWikiBrowser sender)
        {
            if (sender == null)
            {
                throw new ArgumentNullException("sender");
            }

            AWB = sender;

            // Menuitem should be checked when TranslatorExample plugin is active and unchecked when not, and default to not!
            pluginenabledMenuItem.CheckOnClick = true;
            PluginEnabled = Settings.Enabled;

            pluginconfigMenuItem.Click           += ShowSettings;
            pluginenabledMenuItem.CheckedChanged += PluginEnabledCheckedChange;
            aboutMenuItem.Click += AboutMenuItemClicked;
            pluginenabledMenuItem.DropDownItems.Add(pluginconfigMenuItem);

            sender.PluginsToolStripMenuItem.DropDownItems.Add(pluginenabledMenuItem);
            sender.HelpToolStripMenuItem.DropDownItems.Add(aboutMenuItem);

            ruleEditor = new RuleEditor();
            ruleEditor.SetFileName(RuleFileName);

            verbEditor = new RuleEditor();
            verbEditor.SetFileName(VerbListFileName);

            nounEditor = new RuleEditor();
            nounEditor.SetFileName(NounListFileName);

            adjectiveEditor = new RuleEditor();
            adjectiveEditor.SetFileName(AdjectiveListFileName);

            pronounEditor = new RuleEditor();
            pronounEditor.SetFileName(PronounListFileName);

            UsersCustomEditor = new RuleEditor();
            UsersCustomEditor.SetFileName(UsersCustomFileName);
        }
Пример #18
0
        public string ProcessArticle(IAutoWikiBrowser sender, ProcessArticleEventArgs eventargs)
        {
            if (!Enabled)
            {
                return(eventargs.ArticleText);
            }

            string ArticleText = eventargs.ArticleText;

            RefNames.Clear();

            ArticleText = r4.Replace(ArticleText, R4Evaluator);
            ArticleText = r1.Replace(ArticleText, "");
            ArticleText = r2.Replace(ArticleText, "");
            ArticleText = r3.Replace(ArticleText, "");

            if (RefNames.Count > 0)
            {
                foreach (string name in RefNames)
                {
                    ArticleText = Regex.Replace(ArticleText, @"< ?ref\b[^>]*?name ?= ?""?" + name + "[\" ]? ?/ ?>", "");
                }
            }

            if (ArticleText == eventargs.ArticleText)
            {
                eventargs.Skip = Skip;
            }
            else
            {
                if (RemoveEmptiedSections && (Variables.LangCode == LangCodeEnum.en ||
                                              Variables.LangCode == LangCodeEnum.de || Variables.LangCode == LangCodeEnum.ru))
                {
                    ArticleText = RemoveSection(ArticleText);
                }
            }

            return(ArticleText);
        }
        public static void LoadNewPlugin(IAutoWikiBrowser awb)
        {
            OpenFileDialog pluginOpen = new OpenFileDialog();

            if (string.IsNullOrEmpty(LastPluginLoadedLocation))
            {
                LoadLastPluginLoadedLocation();
            }

            if (string.IsNullOrEmpty(LastPluginLoadedLocation))
            {
                pluginOpen.InitialDirectory = Application.StartupPath;
            }
            else
            {
                pluginOpen.InitialDirectory = LastPluginLoadedLocation;
            }

            pluginOpen.DefaultExt      = "dll";
            pluginOpen.Filter          = "DLL files|*.dll";
            pluginOpen.CheckFileExists = pluginOpen.Multiselect = /*pluginOpen.AutoUpgradeEnabled =*/ true;

            pluginOpen.ShowDialog();

            string newPath = "";

            if (!string.IsNullOrEmpty(pluginOpen.FileName))
            {
                newPath = Path.GetDirectoryName(pluginOpen.FileName);
                if (LastPluginLoadedLocation != newPath)
                {
                    LastPluginLoadedLocation = newPath;
                    SaveLastPluginLoadedLocation();
                }
            }

            Plugin.LoadPlugins(awb, pluginOpen.FileNames, true);
        }
Пример #20
0
        public string ProcessArticle(IAutoWikiBrowser sender, IProcessArticleEventArgs eventargs)
        {
            if (!Enabled || string.IsNullOrEmpty(Link)) return eventargs.ArticleText;

            string articleText = eventargs.ArticleText;
            RefNames.Clear();

            articleText = r4.Replace(articleText, R4Evaluator);
            
            articleText = r1.Replace(articleText, "");
            articleText = r2.Replace(articleText, "");
            articleText = r3.Replace(articleText, "");

            if (RefNames.Count > 0)
            {
                foreach (string name in RefNames)
                {
                    articleText = Regex.Replace(articleText, @"< ?ref\b[^>]*?name ?= ?""?" + name + "[\" ]? ?/ ?>", "");
                }
            }

            if (articleText == eventargs.ArticleText)
            {
                eventargs.Skip = Skip;
            }
            else
            {
                if (RemoveEmptiedSections && (Variables.LangCode == "en" ||
                    Variables.LangCode == "de" || Variables.LangCode == "ru"))
                    articleText = RemoveSection(articleText);
            }

            return articleText;
        }
Пример #21
0
        protected virtual EditPageRetvals DoLogEntry(LogEntry logEntry, string logTitle, string logDetails, int pageNumber,
                                                     DateTime startDate, string uploadTo, string editSummary, string username,
                                                     bool addLogArticlesToAnAWBList, IAutoWikiBrowser awb, string sender)
        {
            AWBLogListener awbLogListener = null;

            try
            {
                string strExistingText = GetWikiText(logEntry.Location);

                if (DoAWBLogListener(addLogArticlesToAnAWBList, awb))
                {
                    if (string.IsNullOrEmpty(sender))
                    {
                        sender = "WikiFunctions DLL";
                    }
                    awbLogListener = new AWBLogListener(logEntry.Location);
                }

                Application.DoEvents();

                string tableAddition = "|-" + NewCell + "[[" + uploadTo + "|" + logTitle + "]]" + NewCell +
                                       logDetails + NewCell + "[[" + uploadTo + "|" + pageNumber + "]]" +
                                       (logEntry.LogUserName ? NewCell + "[[User:"******"|" + username + "]]" : "") +
                                       NewCell + string.Format("[[{0:d MMMM}]] [[{0:yyyy}]]", startDate) +
                                       Environment.NewLine + BotTag;

                EditPageRetvals retval;

                if (strExistingText.Contains(BotTag))
                {
                    retval = EditPageEx(logEntry.Location, strExistingText.Replace(BotTag, tableAddition), editSummary, false, true);
                }
                else
                {
                    retval = EditPageAppendEx(logEntry.Location, Environment.NewLine + "<!--bottag-->" +
                                              Environment.NewLine + "{| class=\"wikitable\" width=\"100%\"" +
                                              Environment.NewLine +
                                              (logEntry.LogUserName ? TableHeaderUserName : TableHeaderNoUserName) +
                                              Environment.NewLine + tableAddition, editSummary, false);
                }
                try
                {
                    if (awbLogListener != null)
                    {
                        awbLogListener.WriteLine("Log entry uploaded", sender);
                        //AWB.AddLogItem(true, AWBLogListener);
                    }
                }
                catch { } // errors shouldn't happen here, but even if they do we want to avoid entering the outer catch block

                logEntry.Success = true;
                return(retval);
            }
            catch (Exception ex)
            {
                if (awbLogListener != null)
                {
                    AWBLogListenerUploadFailed(ex, sender, awbLogListener, awb);
                }
                throw;
            }
        }
Пример #22
0
        protected virtual EditPageRetvals DoLogEntry(LogEntry logEntry, string logTitle, string logDetails, int pageNumber,
            DateTime startDate, string uploadTo, string editSummary, string username,
            bool addLogArticlesToAnAWBList, IAutoWikiBrowser awb, string sender)
        {
            AWBLogListener awbLogListener = null;

            try
            {
                editor.Open(logEntry.Location, true);
                editor.Wait();

                string strExistingText = editor.Page.Text;

                if (DoAWBLogListener(addLogArticlesToAnAWBList, awb))
                {
                    if (string.IsNullOrEmpty(sender))
                        sender = "WikiFunctions DLL";
                    awbLogListener = new AWBLogListener(logEntry.Location);
                }

                Application.DoEvents();

                string tableAddition = "|-" + NewCell + "[[" + uploadTo + "|" + logTitle + "]]" + NewCell +
                    logDetails + NewCell + "[[" + uploadTo + "|" + pageNumber + "]]" +
                    (logEntry.LogUserName ? NewCell + "[[User:"******"|" + username + "]]" : "") +
                    NewCell + string.Format("[[{0:d MMMM}]] [[{0:yyyy}]]", startDate) +
                    Environment.NewLine + BotTag;

                SaveInfo save;

                if (strExistingText.Contains(BotTag))
                {
                    save = editor.SynchronousEditor.Save(strExistingText.Replace(BotTag, tableAddition), editSummary, false, WatchOptions.NoChange);
                }
                else
                {
                    save = editor.SynchronousEditor.Save(strExistingText + Environment.NewLine + "<!--bottag-->" +
                                Environment.NewLine + "{| class=\"wikitable\" width=\"100%\"" +
                                Environment.NewLine +
                                (logEntry.LogUserName ? TableHeaderUserName : TableHeaderNoUserName) +
                                Environment.NewLine + tableAddition, editSummary, false, WatchOptions.NoChange);
                }

                EditPageRetvals retval = new EditPageRetvals
                {
                    Article = logEntry.Location,
                    DiffLink = editor.URL + "index.php?oldid=" + save.NewId + "&diff=prev",
                    ResponseText = save.ResponseXml.OuterXml
                };

                try
                {
                    if (awbLogListener != null)
                    {
                        awbLogListener.WriteLine("Log entry uploaded", sender);
                        //AWB.AddLogItem(true, AWBLogListener);
                    }
                }
                catch { } // errors shouldn't happen here, but even if they do we want to avoid entering the outer catch block

                logEntry.Success=true;
                return retval;
            }
            catch (Exception ex)
            {
                if (awbLogListener != null)
                    AWBLogListenerUploadFailed(ex, sender, awbLogListener, awb);
                throw;
            }
        }
Пример #23
0
 private void AWBLogListenerUploadFailed(Exception ex, string sender, AWBLogListener logListener,
     IAutoWikiBrowser AWB)
 {
     logListener.WriteLine("Error: " + ex.Message, sender);
     ((IMyTraceListener)logListener).SkippedArticle(sender, "Error");
     //AWB.AddLogItem(false, logListener);
 }
Пример #24
0
 public void Initialise(IAutoWikiBrowser sender)
 {
     AWB = sender;
 }
Пример #25
0
 public PluginManager(IAutoWikiBrowser iAWB) //, List<string> previousPlugins)
 {
     InitializeComponent();
     AWB = iAWB;
     //prevPlugins = previousPlugins;
 }
Пример #26
0
 private bool DoAWBLogListener(bool DoIt, IAutoWikiBrowser AWB)
 {
     return(DoIt && AWB != null);
 }
Пример #27
0
 public void Initialise(IAutoWikiBrowser sender)
 {
     AWB = sender;
 }
Пример #28
0
 string IAWBPlugin.ProcessArticle(IAutoWikiBrowser sender, ProcessArticleEventArgs eventargs)
 {
     return eventargs.ArticleText;
 }
 public string ProcessArticle(IAutoWikiBrowser sender, ProcessArticleEventArgs eventargs)
 {
     return eventargs.ArticleText;
 }
Пример #30
0
		public void Initialise(IAutoWikiBrowser sender)
		{
			// Store AWB object reference:
			AWBForm = sender;

			// Initialise our settings object:
			PluginSettings = new PluginSettingsControl();


			// Set up our UI objects:
            var _with2 = AWBForm.BotModeCheckbox;
			_with2.EnabledChanged += AWBBotModeCheckboxEnabledChangedHandler;
			_with2.CheckedChanged += AWBBotModeCheckboxCheckedChangeHandler;
            AWBForm.StatusStrip.Items.Insert(2, StatusText);
			StatusText.Margin = new Padding(50, 0, 50, 0);
			StatusText.BorderSides = ToolStripStatusLabelBorderSides.Left | ToolStripStatusLabelBorderSides.Right;
			StatusText.BorderStyle = Border3DStyle.Etched;
            AWBForm.HelpToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[]{
				new ToolStripSeparator(),
				PluginSettings.MenuHelp,
				PluginSettings.MenuAbout
			});

			// UI - addhandlers for Start/Stop/Diff/Preview/Save/Ignore buttons/form closing:
			AWBForm.Form.FormClosing += AWBClosingEventHandler;

			// Handle over events from AWB:
			AWBForm.StopButton.Click += StopButtonClickEventHandler;
			AWBForm.TheSession.StateChanged += EditorStatusChanged;
			AWBForm.TheSession.Aborted += EditorAborted;

			// Track Manual Assessment checkbox:
			PluginSettings.ManuallyAssessCheckBox.CheckedChanged += ManuallyAssessCheckBox_CheckChanged;

			// Tabs:
			KingbotkPluginTab.UseVisualStyleBackColor = true;
			KingbotkPluginTab.Controls.Add(PluginSettings);

			// Show/hide tabs menu:
            MenuShowSettingsTabs.CheckOnClick = true;
            MenuShowSettingsTabs.Checked = true;
		    MenuShowSettingsTabs.Click += MenuShowHide_Click;
			AWBForm.ToolStripMenuGeneral.DropDownItems.Add(MenuShowSettingsTabs);

			// Add-Generic-Template menu:
		    AddGenericTemplateMenuItem.Click += AddGenericTemplateMenuItem_Click;
			AWBForm.PluginsToolStripMenuItem.DropDownItems.Add(AddGenericTemplateMenuItem);

			// Create plugins:
			Plugins.Add("Albums", new WPAlbums());
			Plugins.Add("Australia", new WPAustralia());
			Plugins.Add("India", new WPIndia());
			Plugins.Add("MilHist", new WPMilitaryHistory());
			Plugins.Add("Songs", new WPSongs());
			Plugins.Add("WPNovels", new WPNovels());
			Plugins.Add("Biography", new WPBiography());
			// hopefully if add WPBio last it will ensure that the template gets added to the *top* of pages

			// Initialise plugins:
			foreach (KeyValuePair<string, PluginBase> plugin in Plugins) {
				plugin.Value.Initialise();
			}

			// Add our menu items last:
			AWBForm.PluginsToolStripMenuItem.DropDownItems.Add(PluginSettings.PluginToolStripMenuItem);

			// Reset statusbar text:
			DefaultStatusText();
		}
Пример #31
0
 public PluginManager(IAutoWikiBrowser awb)
 {
     InitializeComponent();
     _awb = awb;
 }
Пример #32
0
            /// <summary>
            /// Loads all the plugins from the directory where AWB resides
            /// </summary>
            /// <param name="awb">IAutoWikiBrowser instance of AWB</param>
            /// <param name="plugins">Array of Plugin Names</param>
            /// <param name="afterStartup">Whether the plugin(s) are being loaded post-startup</param>
            internal static void LoadPlugins(IAutoWikiBrowser awb, string[] plugins, bool afterStartup)
            {
                try
                {
                    // ignore known DLL files that aren't plugins such as WikiFunctions.dll
                    plugins = plugins.Where(p => !NotPlugins.Any(n => p.EndsWith(n + ".dll"))).ToArray();

                    foreach (string plugin in plugins)
                    {
                        Assembly asm;
                        try
                        {
                            asm = Assembly.LoadFile(plugin);
                        }
                        catch (NotSupportedException)
                        {
                            // https://phabricator.wikimedia.org/T208787
                            // Windows is probably blocking loading of the plugin for "Security" reasons
                            // NotSupportedException
                            // On the file, right click, properties, unblock (check or press button), apply, ok.
                            // Need to put it in a message box or something
                            // Else, maybe we want to try https://docs.microsoft.com/en-us/previous-versions/dotnet/netframework-4.0/dd409252(v=vs.100)

                            continue;
                        }
#if DEBUG
                        catch (Exception ex)
                        {
                            Tools.WriteDebug(plugin, ex.ToString());
                            continue;
                        }
#else
                        catch (Exception)
                        {
                            continue;
                        }
#endif

                        if (asm == null)
                        {
                            continue;
                        }

                        try
                        {
                            foreach (Type t in asm.GetTypes())
                            {
                                if (t.GetInterface("IAWBPlugin") != null)
                                {
                                    IAWBPlugin awbPlugin =
                                        (IAWBPlugin)Activator.CreateInstance(t);

                                    if (AWBPlugins.ContainsKey(awbPlugin.Name))
                                    {
                                        MessageBox.Show(
                                            "A plugin with the name \"" + awbPlugin.Name +
                                            "\", has already been added.\r\nPlease remove old duplicates from your AutoWikiBrowser Directory, and restart AWB.\r\nThis was loaded from the plugin file \"" +
                                            plugin + "\".", "Duplicate AWB Plugin");
                                        break;
                                    }

                                    InitialisePlugin(awbPlugin, awb);

                                    AWBPlugins.Add(awbPlugin.Name, awbPlugin);

                                    if (afterStartup)
                                    {
                                        UsageStats.AddedPlugin(awbPlugin);
                                    }
                                }
                                else if (t.GetInterface("IAWBBasePlugin") != null)
                                //IAWBBasePlugin needs to be checked after IAWBPlugin, as IAWBPlugin extends IAWBBasePlugin
                                {
                                    IAWBBasePlugin awbBasePlugin = (IAWBBasePlugin)Activator.CreateInstance(t);

                                    if (AWBBasePlugins.ContainsKey(awbBasePlugin.Name))
                                    {
                                        MessageBox.Show(
                                            "A plugin with the name \"" + awbBasePlugin.Name +
                                            "\", has already been added.\r\nPlease remove old duplicates from your AutoWikiBrowser Directory, and restart AWB.\r\nThis was loaded from the plugin file \"" +
                                            plugin + "\".", "Duplicate AWB Base Plugin");
                                        break;
                                    }

                                    InitialisePlugin(awbBasePlugin, awb);

                                    AWBBasePlugins.Add(awbBasePlugin.Name, awbBasePlugin);

                                    if (afterStartup)
                                    {
                                        UsageStats.AddedPlugin(awbBasePlugin);
                                    }
                                }
                                else if (t.GetInterface("IListMakerPlugin") != null)
                                {
                                    IListMakerPlugin listMakerPlugin =
                                        (IListMakerPlugin)Activator.CreateInstance(t);

                                    if (ListMakerPlugins.ContainsKey(listMakerPlugin.Name))
                                    {
                                        MessageBox.Show(
                                            "A plugin with the name \"" + listMakerPlugin.Name +
                                            "\", has already been added.\r\nPlease remove old duplicates from your AutoWikiBrowser Directory, and restart AWB.\r\nThis was loaded from the plugin file \"" +
                                            plugin + "\".", "Duplicate AWB ListMaker Plugin");
                                        break;
                                    }

                                    WikiFunctions.Controls.Lists.ListMaker.AddProvider(listMakerPlugin);

                                    ListMakerPlugins.Add(listMakerPlugin.Name, listMakerPlugin);

                                    if (afterStartup)
                                    {
                                        UsageStats.AddedPlugin(listMakerPlugin);
                                    }
                                }
                            }
                        }
                        catch (ReflectionTypeLoadException)
                        {
                            PluginObsolete(plugin, asm.GetName().Version.ToString());
                        }
                        catch (MissingMemberException)
                        {
                            PluginObsolete(plugin, asm.GetName().Version.ToString());
                        }
                        catch (Exception ex)
                        {
                            ErrorHandler.HandleException(ex);
                        }
                    }
                }
                catch (Exception ex)
                {
#if DEBUG
                    ErrorHandler.HandleException(ex);
#else
                    MessageBox.Show(ex.Message, "Problem loading plugins");
#endif
                }
            }
Пример #33
0
        public string ProcessArticle(IAutoWikiBrowser sender, IProcessArticleEventArgs eventargs)
        {
            string res;

            if (ActivePlugins.Count == 0)
            {
                return(eventargs.ArticleText);
            }

            Article theArticle;

            StatusText.Text = "Processing " + eventargs.ArticleTitle;
            AWBForm.TraceManager.ProcessingArticle(eventargs.ArticleTitle, eventargs.NameSpaceKey);

            foreach (PluginBase p in ActivePlugins)
            {
                try
                {
                    if (!p.AmReady && p.AmGeneric)
                    {
                        MessageBox.Show(
                            "The generic template plugin \"" + p.PluginShortName + "\"isn't properly configured.",
                            "Can't start", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        StopAWB();
                        goto SkipOrStop;
                    }
                }
                catch
                {
                    StopAWB();
                    goto SkipOrStop;
                }
            }

            switch (eventargs.NameSpaceKey)
            {
            case Namespace.Article:
                if (_pluginSettings.ManuallyAssess)
                {
                    if (eventargs.Exists == Exists.Yes)
                    {
                        StatusText.Text += ": Click Preview to read the article; " +
                                           "click Save or Ignore to load the assessments form";
                        _assessmentsObject.ProcessMainSpaceArticle(eventargs.ArticleTitle);
                        eventargs.EditSummary = "Clean up";
                        goto SkipOrStop;
                    }
                    //FIXME
                    var eaArticleES   = eventargs.EditSummary;
                    var eaArticleSkip = eventargs.Skip;
                    res = Skipping(ref eaArticleES, "", SkipReason.ProcessingMainArticleDoesntExist,
                                   eventargs.ArticleText, ref eaArticleSkip);
                    eventargs.EditSummary = eaArticleES;
                    eventargs.Skip        = eaArticleSkip;
                    goto ExitMe;
                }
                goto SkipBadNamespace;

            //break;
            case Namespace.Talk:
                AsyncApiEdit editor = AWBForm.TheSession.Editor.Clone();

                editor.Open(Tools.ConvertFromTalk(eventargs.ArticleTitle), false);

                editor.Wait();

                if (!editor.Page.Exists)
                {
                    // FIXME
                    var eaNotExistsES   = eventargs.EditSummary;
                    var eaNotExistsSkip = eventargs.Skip;
                    res = Skipping(ref eaNotExistsES, "", SkipReason.ProcessingTalkPageArticleDoesntExist,
                                   eventargs.ArticleText,
                                   ref eaNotExistsSkip, eventargs.ArticleTitle);
                    eventargs.EditSummary = eaNotExistsES;
                    eventargs.Skip        = eaNotExistsSkip;
                }
                else
                {
                    theArticle = new Article(eventargs.ArticleText, eventargs.ArticleTitle, eventargs.NameSpaceKey);

                    bool reqPhoto = ReqPhotoParamNeeded(theArticle);

                    if (_pluginSettings.ManuallyAssess)
                    {
                        // reqphoto byref
                        if (!_assessmentsObject.ProcessTalkPage(theArticle, _pluginSettings, ref reqPhoto))
                        {
                            eventargs.Skip = true;
                            goto SkipOrStop;
                        }
                    }
                    else
                    {
                        reqPhoto = ProcessTalkPageAndCheckWeAddedReqPhotoParam(theArticle, reqPhoto);
                        // We successfully added a reqphoto param
                    }

                    // FIXME
                    var eaTalkSkip = eventargs.Skip;
                    var eaTalkES   = eventargs.EditSummary;
                    res = FinaliseArticleProcessing(theArticle, ref eaTalkSkip, ref eaTalkES, eventargs.ArticleText,
                                                    reqPhoto);
                    eventargs.Skip        = eaTalkSkip;
                    eventargs.EditSummary = eaTalkES;
                }

                break;

            case Namespace.CategoryTalk:
            case 101:     //101 is Portal Talk
            case Namespace.ProjectTalk:
            case Namespace.TemplateTalk:
            case Namespace.FileTalk:
                if (_pluginSettings.ManuallyAssess)
                {
                    MessageBox.Show(
                        "The plugin has received a non-standard namespace talk page in " +
                        "manual assessment mode. Please remove this item from the list and start again.",
                        "Manual Assessments", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    StopAWB();
                    goto SkipOrStop;
                }
                theArticle = new Article(eventargs.ArticleText, eventargs.ArticleTitle, eventargs.NameSpaceKey);

                foreach (PluginBase p in ActivePlugins)
                {
                    p.ProcessTalkPage(theArticle, Classification.Code, Importance.NA, false, false, false,
                                      ProcessTalkPageMode.NonStandardTalk, false);
                    if (theArticle.PluginManagerGetSkipResults == SkipResults.SkipBadTag)
                    {
                        break;     // TODO: might not be correct. Was : Exit For
                    }
                }

                // FIXME
                var eaMiscSkip = eventargs.Skip;
                var eaMiscES   = eventargs.EditSummary;
                res = FinaliseArticleProcessing(theArticle, ref eaMiscSkip, ref eaMiscES, eventargs.ArticleText,
                                                false);
                eventargs.Skip        = eaMiscSkip;
                eventargs.EditSummary = eaMiscES;

                break;

            default:
                goto SkipBadNamespace;
            }

            if (!eventargs.Skip)
            {
                //TempHackInsteadOfDefaultSettings:
                if (AWBForm.EditSummaryComboBox.Text == "clean up")
                {
                    AWBForm.EditSummaryComboBox.Text = "Tagging";
                }
            }
ExitMe:

            if (!_pluginSettings.ManuallyAssess)
            {
                DefaultStatusText();
            }
            AWBForm.TraceManager.Flush();
            return(res);

SkipBadNamespace:

            //FIXME
            var eaES = eventargs.EditSummary;
            var eaSkip = eventargs.Skip;

            res = Skipping(ref eaES, "", SkipReason.BadNamespace, eventargs.ArticleText, ref eaSkip);
            eventargs.EditSummary = eaES;
            eventargs.Skip        = eaSkip;
            goto ExitMe;
SkipOrStop:

            res = eventargs.ArticleText;
            goto ExitMe;
        }
Пример #34
0
        protected virtual EditPageRetvals DoLogEntry(LogEntry logEntry, string logTitle, string logDetails, int pageNumber,
                                                     DateTime startDate, string uploadTo, string editSummary, string username,
                                                     bool addLogArticlesToAnAWBList, IAutoWikiBrowser awb, string sender)
        {
            AWBLogListener awbLogListener = null;

            try
            {
                editor.Open(logEntry.Location);
                editor.Wait();

                string strExistingText = editor.Page.Text;

                if (DoAWBLogListener(addLogArticlesToAnAWBList, awb))
                {
                    if (string.IsNullOrEmpty(sender))
                    {
                        sender = "WikiFunctions DLL";
                    }
                    awbLogListener = new AWBLogListener(logEntry.Location);
                }

                Application.DoEvents();

                string tableAddition = "|-" + NewCell + "[[" + uploadTo + "|" + logTitle + "]]" + NewCell +
                                       logDetails + NewCell + "[[" + uploadTo + "|" + pageNumber + "]]" +
                                       (logEntry.LogUserName ? NewCell + "[[User:"******"|" + username + "]]" : "") +
                                       NewCell + string.Format("[[{0:d MMMM}]] [[{0:yyyy}]]", startDate) +
                                       Environment.NewLine + BotTag;

                SaveInfo save;

                if (strExistingText.Contains(BotTag))
                {
                    save = editor.SynchronousEditor.Save(strExistingText.Replace(BotTag, tableAddition), editSummary, false, WatchOptions.NoChange);
                }
                else
                {
                    save = editor.SynchronousEditor.Save(strExistingText + Environment.NewLine + "<!--bottag-->" +
                                                         Environment.NewLine + "{| class=\"wikitable\" width=\"100%\"" +
                                                         Environment.NewLine +
                                                         (logEntry.LogUserName ? TableHeaderUserName : TableHeaderNoUserName) +
                                                         Environment.NewLine + tableAddition, editSummary, false, WatchOptions.NoChange);
                }

                EditPageRetvals retval = new EditPageRetvals
                {
                    Article      = logEntry.Location,
                    DiffLink     = editor.URL + "index.php?oldid=" + save.NewId + "&diff=prev",
                    ResponseText = save.ResponseXml.OuterXml
                };

                try
                {
                    if (awbLogListener != null)
                    {
                        awbLogListener.WriteLine("Log entry uploaded", sender);
                        //AWB.AddLogItem(true, AWBLogListener);
                    }
                }
                catch { } // errors shouldn't happen here, but even if they do we want to avoid entering the outer catch block

                logEntry.Success = true;
                return(retval);
            }
            catch (Exception ex)
            {
                if (awbLogListener != null)
                {
                    AWBLogListenerUploadFailed(ex, sender, awbLogListener, awb);
                }
                throw;
            }
        }
Пример #35
0
 //, List<string> previousPlugins)
 public PluginManager(IAutoWikiBrowser awb)
 {
     InitializeComponent();
     _awb = awb;
     //prevPlugins = previousPlugins;
 }
Пример #36
0
        /// <summary>
        /// Upload log to the wiki, and optionally add log entries to central log pages
        /// </summary>
        /// <param name="log">The log text</param>
        /// <param name="logTitle">The log title</param>
        /// <param name="logDetails">Details of the job being logged</param>
        /// <param name="uploadTo">Which page to write the log to</param>
        /// <param name="linksToLog">A collection of LogEntry objects detailing pages to list the log page on. Send an empty collection if not needed.</param>
        /// <param name="pageNumber">Log page number</param>
        /// <param name="startDate">When the job started</param>
        /// <param name="openInBrowser">True if the log page should be opened in the web browser after uploading, otherwise false</param>
        /// <param name="addToWatchlist">True if the log page should be added to the user's watchlist, otherwise false</param>
        /// <param name="username">The user id of the user performing the task</param>
        /// <param name="logHeader">Header text</param>
        /// <param name="addLogTemplate">True if a {{log}} template should be added</param>
        /// <param name="editSummary">The edit summary</param>
        /// <param name="logSummaryEditSummary">The edit summary when listing the log page on the LogEntry pages (if applicable)</param>
        /// <param name="sender"></param>
        /// <param name="addLogArticlesToAnAWBList">True if an IAutoWikiBrowser object is being sent and the AWB log tab should be written to</param>
        /// <param name="awb">An IAutoWikiBrowser object, may be null</param>
        public virtual List <EditPageRetvals> LogIt(string log, string logTitle, string logDetails, string uploadTo,
                                                    List <LogEntry> linksToLog, int pageNumber, DateTime startDate, bool openInBrowser,
                                                    bool addToWatchlist, string username, string logHeader, bool addLogTemplate,
                                                    string editSummary, string logSummaryEditSummary, string sender, bool addLogArticlesToAnAWBList,
                                                    IAutoWikiBrowser awb)
        {
            List <EditPageRetvals> retval   = new List <EditPageRetvals>();
            string         uploadToNoSpaces = uploadTo.Replace(" ", "_");
            string         strLogText       = "";
            AWBLogListener awbLogListener   = null;

            if (DoAWBLogListener(addLogArticlesToAnAWBList, awb))
            {
                awbLogListener = new AWBLogListener(uploadTo);
            }

            if (addLogTemplate)
            {
                strLogText = "{{log|name=" + uploadToNoSpaces + "|page=" + pageNumber + "}}" + Environment.NewLine;
            }
            strLogText += logHeader + log;

            Application.DoEvents();

            try
            {
                editor.Open(uploadToNoSpaces);
                editor.Wait();

                SaveInfo save = editor.SynchronousEditor.Save(strLogText, editSummary, false, WatchOptions.NoChange);

                retval.Add(new EditPageRetvals
                {
                    Article      = uploadToNoSpaces,
                    DiffLink     = editor.URL + "index.php?oldid=" + save.NewId + "&diff=prev",
                    ResponseText = save.ResponseXml.OuterXml
                });
            }
            catch (Exception ex)
            {
                if (awbLogListener != null)
                {
                    AWBLogListenerUploadFailed(ex, sender, awbLogListener, awb);
                }
                throw; // throw error and exit
            }

            Application.DoEvents();

            foreach (LogEntry logEntry in linksToLog)
            {
                retval.Add(DoLogEntry(logEntry, logTitle, logDetails, pageNumber, startDate, uploadTo, logSummaryEditSummary,
                                      username, addLogArticlesToAnAWBList, awb, sender));
                Application.DoEvents();
            }

            if (openInBrowser)
            {
                OpenLogInBrowser(uploadTo);
            }

            return(retval);
        }
Пример #37
0
        /// <summary>
        /// Upload log to the wiki, and optionally add log entries to central log pages
        /// </summary>
        /// <param name="Log">The log text</param>
        /// <param name="LogTitle">The log title</param>
        /// <param name="LogDetails">Details of the job being logged</param>
        /// <param name="UploadTo">Which page to write the log to</param>
        /// <param name="LinksToLog">A collection of LogEntry objects detailing pages to list the log page on. Send an empty collection if not needed.</param>
        /// <param name="PageNumber">Log page number</param>
        /// <param name="StartDate">When the job started</param>
        /// <param name="OpenInBrowser">True if the log page should be opened in the web browser after uploading, otherwise false</param>
        /// <param name="AddToWatchlist">True if the log page should be added to the user's watchlist, otherwise false</param>
        /// <param name="Username">The user id of the user performing the task</param>
        /// <param name="LogHeader">Header text</param>
        /// <param name="AddLogTemplate">True if a {{log}} template should be added</param>
        /// <param name="EditSummary">The edit summary</param>
        /// <param name="LogSummaryEditSummary">The edit summary when listing the log page on the LogEntry pages (if applicable)</param>
        /// <param name="AddLogArticlesToAnAWBList">True if an IAutoWikiBrowser object is being sent and the AWB log tab should be written to</param>
        /// <param name="AWB">An IAutoWikiBrowser object, may be null</param>
        public virtual List <Editor.EditPageRetvals> LogIt(string Log, string LogTitle, string LogDetails, string UploadTo,
                                                           List <LogEntry> LinksToLog, int PageNumber, System.DateTime StartDate, bool OpenInBrowser,
                                                           bool AddToWatchlist, string Username, string LogHeader, bool AddLogTemplate,
                                                           string EditSummary, string LogSummaryEditSummary, string sender, bool AddLogArticlesToAnAWBList,
                                                           IAutoWikiBrowser AWB)
        {
            List <Editor.EditPageRetvals> retval = new List <Editor.EditPageRetvals>();
            string         uploadToNoSpaces      = UploadTo.Replace(" ", "_");
            string         strLogText            = "";
            AWBLogListener awbLogListener        = null;

            if (DoAWBLogListener(AddLogArticlesToAnAWBList, AWB))
            {
                awbLogListener = new AWBLogListener(UploadTo);
            }

            if (AddLogTemplate)
            {
                strLogText = "{{log|name=" + uploadToNoSpaces + "|page=" + PageNumber.ToString()
                             + "}}" + NewLine;
            }
            strLogText += LogHeader + Log;

            Application.DoEvents();

            try
            {
                if (AddToWatchlist)
                {
                    retval.Add(base.EditPageEx(uploadToNoSpaces, strLogText, EditSummary, false, true));
                }
                else
                {
                    retval.Add(base.EditPageEx(uploadToNoSpaces, strLogText, EditSummary, false));
                }
            }
            catch (Exception ex)
            {
                if (awbLogListener != null)
                {
                    AWBLogListenerUploadFailed(ex, sender, awbLogListener, AWB);
                }
                throw; // throw error and exit
            }

            //HACK
            //if (AWBLogListener != null)
            //{
            //    AWBLogListener.WriteLine("Log uploaded", sender);
            //}
            //AWB.AddLogItem(Article);
            //AWB.AddLogItem(Article);

            Application.DoEvents();

            foreach (LogEntry logEntry in LinksToLog)
            {
                retval.Add(DoLogEntry(logEntry, LogTitle, LogDetails, PageNumber, StartDate, UploadTo, LogSummaryEditSummary,
                                      Username, AddLogArticlesToAnAWBList, AWB, sender));
                Application.DoEvents();
            }

            if (OpenInBrowser)
            {
                OpenLogInBrowser(UploadTo);
            }

            return(retval);
        }
Пример #38
0
 string IAWBPlugin.ProcessArticle(IAutoWikiBrowser sender, ProcessArticleEventArgs eventargs)
 {
     return(eventargs.ArticleText);
 }
Пример #39
0
 private static bool DoAWBLogListener(bool doIt, IAutoWikiBrowser awb)
 {
     return(doIt && awb != null);
 }
Пример #40
0
            /// <summary>
            /// Loads all the plugins from the directory where AWB resides
            /// </summary>
            /// <param name="awb">IAutoWikiBrowser instance of AWB</param>
            /// <param name="Plugins">Array of Plugin Names</param>
            /// <param name="afterStartup">Whether the plugin(s) are being loaded post-startup</param>
            internal static void LoadPlugins(IAutoWikiBrowser awb, string[] Plugins, bool afterStartup)
            {
                try
                {
                    foreach (string Plugin in Plugins)
                    {
                        if (Plugin.EndsWith("DotNetWikiBot.dll") || Plugin.EndsWith("Diff.dll")
                            || Plugin.EndsWith("WikiFunctions.dll"))
                            continue;

                        Assembly asm = null;
                        try
                        {
                            asm = Assembly.LoadFile(Plugin);
                        }
                        catch { }

                        if (asm != null)
                        {
                            try
                            {
                                foreach (Type t in asm.GetTypes())
                                {
                                    if (t.GetInterface("IAWBPlugin") != null)
                                    {
                                        IAWBPlugin plugin = (IAWBPlugin)Activator.CreateInstance(t);
                                        InitialisePlugin(plugin, awb);
                                        Items.Add(plugin.Name, plugin);

                                        if (afterStartup) UsageStats.AddedPlugin(plugin);
                                    }
                                    else if (t.GetInterface("IListMakerPlugin") != null)
                                    {
                                        IListMakerPlugin plugin = (IListMakerPlugin)Activator.CreateInstance(t);
                                        WikiFunctions.Controls.Lists.ListMaker.AddProvider(plugin);

                                        if (afterStartup) UsageStats.AddedPlugin(plugin);
                                    }
                                }
                            }
                            catch (MissingFieldException) { PluginObsolete(Plugin); }
                            catch (MissingMemberException) { PluginObsolete(Plugin); }
                            catch (Exception ex) { ErrorHandler.Handle(ex); }
                        }
                    }
                }
                catch (Exception ex)
                {
#if debug
                    ErrorHandler.Handle(ex);
#else
                    MessageBox.Show(ex.Message, "Problem loading plugins");
#endif
                }

            }
Пример #41
0
            /// <summary>
            /// Loads all the plugins from the directory where AWB resides
            /// </summary>
            /// <param name="awb">IAutoWikiBrowser instance of AWB</param>
            /// <param name="Plugins">Array of Plugin Names</param>
            /// <param name="afterStartup">Whether the plugin(s) are being loaded post-startup</param>
            internal static void LoadPlugins(IAutoWikiBrowser awb, string[] Plugins, bool afterStartup)
            {
                try
                {
                    foreach (string Plugin in Plugins)
                    {
                        if (Plugin.EndsWith("DotNetWikiBot.dll") || Plugin.EndsWith("Diff.dll") ||
                            Plugin.EndsWith("WikiFunctions.dll"))
                        {
                            continue;
                        }

                        Assembly asm = null;
                        try
                        {
                            asm = Assembly.LoadFile(Plugin);
                        }
                        catch { }

                        if (asm != null)
                        {
                            try
                            {
                                foreach (Type t in asm.GetTypes())
                                {
                                    if (t.GetInterface("IAWBPlugin") != null)
                                    {
                                        IAWBPlugin plugin = (IAWBPlugin)Activator.CreateInstance(t);
                                        InitialisePlugin(plugin, awb);
                                        Items.Add(plugin.Name, plugin);

                                        if (afterStartup)
                                        {
                                            UsageStats.AddedPlugin(plugin);
                                        }
                                    }
                                    else if (t.GetInterface("IListMakerPlugin") != null)
                                    {
                                        IListMakerPlugin plugin = (IListMakerPlugin)Activator.CreateInstance(t);
                                        WikiFunctions.Controls.Lists.ListMaker.AddProvider(plugin);

                                        if (afterStartup)
                                        {
                                            UsageStats.AddedPlugin(plugin);
                                        }
                                    }
                                }
                            }
                            catch (MissingFieldException) { PluginObsolete(Plugin); }
                            catch (MissingMemberException) { PluginObsolete(Plugin); }
                            catch (Exception ex) { ErrorHandler.Handle(ex); }
                        }
                    }
                }
                catch (Exception ex)
                {
#if debug
                    ErrorHandler.Handle(ex);
#else
                    MessageBox.Show(ex.Message, "Problem loading plugins");
#endif
                }
            }
Пример #42
0
 public PluginManager(IAutoWikiBrowser awb) //, List<string> previousPlugins)
 {
     InitializeComponent();
     _awb = awb;
     //prevPlugins = previousPlugins;
 }
Пример #43
0
        /// <summary>
        /// Upload log to the wiki, and optionally add log entries to central log pages
        /// </summary>
        /// <param name="log">The log text</param>
        /// <param name="logTitle">The log title</param>
        /// <param name="logDetails">Details of the job being logged</param>
        /// <param name="uploadTo">Which page to write the log to</param>
        /// <param name="linksToLog">A collection of LogEntry objects detailing pages to list the log page on. Send an empty collection if not needed.</param>
        /// <param name="pageNumber">Log page number</param>
        /// <param name="startDate">When the job started</param>
        /// <param name="openInBrowser">True if the log page should be opened in the web browser after uploading, otherwise false</param>
        /// <param name="addToWatchlist">True if the log page should be added to the user's watchlist, otherwise false</param>
        /// <param name="username">The user id of the user performing the task</param>
        /// <param name="logHeader">Header text</param>
        /// <param name="addLogTemplate">True if a {{log}} template should be added</param>
        /// <param name="editSummary">The edit summary</param>
        /// <param name="logSummaryEditSummary">The edit summary when listing the log page on the LogEntry pages (if applicable)</param>
        /// <param name="sender"></param>
        /// <param name="addLogArticlesToAnAWBList">True if an IAutoWikiBrowser object is being sent and the AWB log tab should be written to</param>
        /// <param name="awb">An IAutoWikiBrowser object, may be null</param>
        public virtual List<EditPageRetvals> LogIt(string log, string logTitle, string logDetails, string uploadTo, 
            List<LogEntry> linksToLog, int pageNumber, DateTime startDate, bool openInBrowser,
            bool addToWatchlist, string username, string logHeader, bool addLogTemplate,
            string editSummary, string logSummaryEditSummary, string sender, bool addLogArticlesToAnAWBList,
            IAutoWikiBrowser awb)
        {
            List<EditPageRetvals> retval = new List<EditPageRetvals>();
            string uploadToNoSpaces = uploadTo.Replace(" ", "_");
            string strLogText = "";
            AWBLogListener awbLogListener = null;

            if (DoAWBLogListener(addLogArticlesToAnAWBList, awb))
                awbLogListener = new AWBLogListener(uploadTo);

            if (addLogTemplate)
            {
                strLogText = "{{log|name=" + uploadToNoSpaces + "|page=" + pageNumber + "}}" + Environment.NewLine;
            }
            strLogText += logHeader + log;

            Application.DoEvents();

            try
            {
                editor.Open(uploadToNoSpaces, true);
                editor.Wait();

                SaveInfo save = editor.SynchronousEditor.Save(strLogText, editSummary, false, WatchOptions.NoChange);

                retval.Add(new EditPageRetvals
                               {
                                   Article = uploadToNoSpaces,
                                   DiffLink = editor.URL + "index.php?oldid=" + save.NewId + "&diff=prev",
                                   ResponseText = save.ResponseXml.OuterXml
                               });
            }
            catch (Exception ex)
            {
                if (awbLogListener != null)
                    AWBLogListenerUploadFailed(ex, sender, awbLogListener, awb);
                throw; // throw error and exit
            }

            Application.DoEvents();

            foreach (LogEntry logEntry in linksToLog)
            {
                retval.Add(DoLogEntry(logEntry, logTitle, logDetails, pageNumber, startDate, uploadTo, logSummaryEditSummary,
                    username, addLogArticlesToAnAWBList, awb, sender));
                Application.DoEvents();
            }

            if (openInBrowser)
                OpenLogInBrowser(uploadTo);

            return retval;
        }
Пример #44
0
            internal static void LoadPlugins(IAutoWikiBrowser awb, string[] Plugins, bool afterStartup)
            {
                try
                {
                    foreach (string Plugin in Plugins)
                    {
                        if (Plugin.EndsWith("DotNetWikiBot.dll") || Plugin.EndsWith("Diff.dll"))
                            continue;

                        Assembly asm = null;
                        try
                        {
                            asm = Assembly.LoadFile(Plugin);
                        }
                        catch { }

                        if (asm != null)
                        {
                            Type[] types = asm.GetTypes();

                            foreach (Type t in types)
                            {
                                if (t.GetInterface("IAWBPlugin") != null)
                                {
                                    IAWBPlugin plugin = (IAWBPlugin)Activator.CreateInstance(t);
                                    Items.Add(plugin.Name, plugin);
                                    if (plugin.Name == "Kingbotk Plugin" && t.Assembly.GetName().Version.Major < 2)
                                        MessageBox.Show("You are using an out of date version of the Kingbotk Plugin. Please upgrade.",
                                            "Kingbotk Plugin", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                                    InitialisePlugin(plugin, awb);

                                    if (afterStartup) UsageStats.AddedPlugin(plugin);
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Problem loading plugins");
                }
            }
Пример #45
0
 private static bool DoAWBLogListener(bool doIt, IAutoWikiBrowser awb)
 {
     return (doIt && awb != null);
 }
Пример #46
0
            /// <summary>
            /// Loads the plugin at startup, and updates the splash screen
            /// </summary>
            /// <param name="awb">IAutoWikiBrowser instance of AWB</param>
            /// <param name="splash">Splash Screen instance</param>
            internal static void LoadPluginsStartup(IAutoWikiBrowser awb, Splash splash)
            {
                splash.SetProgress(75);
                string path = Application.StartupPath;
                string[] pluginFiles = Directory.GetFiles(path, "*.DLL");

                LoadPlugins(awb, pluginFiles, false);
                splash.SetProgress(89);
            }
Пример #47
0
            /// <summary>
            /// Loads all the plugins from the directory where AWB resides
            /// </summary>
            /// <param name="awb">IAutoWikiBrowser instance of AWB</param>
            /// <param name="plugins">Array of Plugin Names</param>
            /// <param name="afterStartup">Whether the plugin(s) are being loaded post-startup</param>
            internal static void LoadPlugins(IAutoWikiBrowser awb, string[] plugins, bool afterStartup)
            {
                try
                {
                    foreach (string plugin in plugins)
                    {
                        if (plugin.EndsWith("DotNetWikiBot.dll") || plugin.EndsWith("Diff.dll") ||
                            plugin.EndsWith("WikiFunctions.dll"))
                        {
                            continue;
                        }

                        Assembly asm = null;
                        try
                        {
                            asm = Assembly.LoadFile(plugin);
                        }
                        catch
                        {
                        }

                        if (asm == null)
                        {
                            continue;
                        }

                        try
                        {
                            foreach (Type t in asm.GetTypes())
                            {
                                if (t.GetInterface("IAWBPlugin") != null)
                                {
                                    IAWBPlugin awbPlugin =
                                        (IAWBPlugin)Activator.CreateInstance(t);

                                    if (AWBPlugins.ContainsKey(awbPlugin.Name))
                                    {
                                        MessageBox.Show(
                                            "A plugin with the name \"" + awbPlugin.Name +
                                            "\", has already been added.\r\nPlease remove old duplicates from your AutoWikiBrowser Directory, and restart AWB.\r\nThis was loaded from the plugin file \"" +
                                            plugin + "\".", "Duplicate AWB Plugin");
                                        break;
                                    }

                                    InitialisePlugin(awbPlugin, awb);

                                    AWBPlugins.Add(awbPlugin.Name, awbPlugin);

                                    if (afterStartup)
                                    {
                                        UsageStats.AddedPlugin(awbPlugin);
                                    }
                                }
                                else if (t.GetInterface("IAWBBasePlugin") != null)
                                //IAWBBasePlugin needs to be checked after IAWBPlugin, as IAWBPlugin extends IAWBBasePlugin
                                {
                                    IAWBBasePlugin awbBasePlugin = (IAWBBasePlugin)Activator.CreateInstance(t);

                                    if (AWBBasePlugins.ContainsKey(awbBasePlugin.Name))
                                    {
                                        MessageBox.Show(
                                            "A plugin with the name \"" + awbBasePlugin.Name +
                                            "\", has already been added.\r\nPlease remove old duplicates from your AutoWikiBrowser Directory, and restart AWB.\r\nThis was loaded from the plugin file \"" +
                                            plugin + "\".", "Duplicate AWB Base Plugin");
                                        break;
                                    }

                                    InitialisePlugin(awbBasePlugin, awb);

                                    AWBBasePlugins.Add(awbBasePlugin.Name, awbBasePlugin);

                                    if (afterStartup)
                                    {
                                        UsageStats.AddedPlugin(awbBasePlugin);
                                    }
                                }
                                else if (t.GetInterface("IListMakerPlugin") != null)
                                {
                                    IListMakerPlugin listMakerPlugin =
                                        (IListMakerPlugin)Activator.CreateInstance(t);

                                    if (ListMakerPlugins.ContainsKey(listMakerPlugin.Name))
                                    {
                                        MessageBox.Show(
                                            "A plugin with the name \"" + listMakerPlugin.Name +
                                            "\", has already been added.\r\nPlease remove old duplicates from your AutoWikiBrowser Directory, and restart AWB.\r\nThis was loaded from the plugin file \"" +
                                            plugin + "\".", "Duplicate AWB ListMaker Plugin");
                                        break;
                                    }

                                    WikiFunctions.Controls.Lists.ListMaker.AddProvider(listMakerPlugin);

                                    ListMakerPlugins.Add(listMakerPlugin.Name, listMakerPlugin);

                                    if (afterStartup)
                                    {
                                        UsageStats.AddedPlugin(listMakerPlugin);
                                    }
                                }
                            }
                        }
                        catch (ReflectionTypeLoadException)
                        {
                            PluginObsolete(plugin, asm.GetName().Version.ToString());
                        }
                        catch (MissingMemberException)
                        {
                            PluginObsolete(plugin, asm.GetName().Version.ToString());
                        }
                        catch (Exception ex)
                        {
                            ErrorHandler.Handle(ex);
                        }
                    }
                }
                catch (Exception ex)
                {
#if debug
                    ErrorHandler.Handle(ex);
#else
                    MessageBox.Show(ex.Message, "Problem loading plugins");
#endif
                }
            }
Пример #48
0
        public string ProcessArticle(IAutoWikiBrowser sender, ProcessArticleEventArgs eventargs)
        {
            if (!Enabled) return eventargs.ArticleText;

            string ArticleText = eventargs.ArticleText;
            RefNames.Clear();

            ArticleText = r4.Replace(ArticleText, R4Evaluator);
            ArticleText = r1.Replace(ArticleText, "");
            ArticleText = r2.Replace(ArticleText, "");
            ArticleText = r3.Replace(ArticleText, "");

            if (RefNames.Count > 0)
                foreach (string name in RefNames)
                {
                    ArticleText = Regex.Replace(ArticleText, @"< ?ref\b[^>]*?name ?= ?""?" + name + "[\" ]? ?/ ?>", "");
                }

            if (ArticleText == eventargs.ArticleText)
            {
                eventargs.Skip = Skip;
            }
            else
            {
                if (RemoveEmptiedSections && (Variables.LangCode == LangCodeEnum.en ||
                    Variables.LangCode == LangCodeEnum.de || Variables.LangCode == LangCodeEnum.ru))
                    ArticleText = RemoveSection(ArticleText);
            }

            return ArticleText;
        }
Пример #49
0
 /// <summary>
 /// Passes a reference of the main form to the plugin for initialisation
 /// </summary>
 /// <param name="plugin">IAWBBasePlugin (Or IAWBPlugin) to initialise</param>
 /// <param name="awb">IAutoWikiBrowser instance of AWB</param>
 private static void InitialisePlugin(IAWBBasePlugin plugin, IAutoWikiBrowser awb)
 {
     plugin.Initialise(awb);
 }
Пример #50
0
        public string ProcessArticle(IAutoWikiBrowser sender, IProcessArticleEventArgs eventargs)
        {
            //MessageBox.Show("Procsssing Article");
            //If menu item is not checked, then return
            if (!PluginEnabled)
            {
                eventargs.Skip = false;
                return(eventargs.ArticleText);
            }
            string text = eventargs.ArticleText;
            string removed = "", replaced = "";


            pr = new PostProcessor(RuleFileName, VerbListFileName, NounListFileName, AdjectiveListFileName, PronounListFileName, UsersCustomFileName);
            pr.LoadTextToTranslate(text);

            // translatorThread = new Thread(new ThreadStart(pr.TranslateVoid));
            text = pr.Translate();
            //translatorThread.Name = "TranslatorThread"; //Name of the thread
            //translatorThread.Start(); //starting translation.
            //pr.OnTranslationComplete += new PostProcessor.TranslationCompleteDelegate(C_TranslationComplete);
            //MessageBox.Show("Translation Complete");
            #region abcd

            //

            //foreach (KeyValuePair<string, string> p in Settings.Categories)
            //{
            //    bool noChange;

            //    if (p.Value.Length == 0)
            //    {
            //        text = Parsers.RemoveCategory(p.Key, text, out noChange);
            //        if (!noChange)
            //        {
            //            if (!string.IsNullOrEmpty(removed))
            //            {
            //                removed += ", ";
            //            }

            //            removed += Variables.Namespaces[Namespace.Category] + p.Key;
            //        }
            //    }
            //    else
            //    {
            //        text = Parsers.ReCategoriser(p.Key, p.Value, text, out noChange);
            //        if (!noChange)
            //        {
            //            if (!string.IsNullOrEmpty(replaced))
            //            {
            //                replaced += ", ";
            //            }

            //            replaced += Variables.Namespaces[Namespace.Category]
            //             + p.Key + FindandReplace.Arrow + Variables.Namespaces[Namespace.Category] + p.Value;
            //        }
            //    }
            //    if (!noChange)
            //    {
            //        text = Regex.Replace(text, "<includeonly>[\\s\\r\\n]*\\</includeonly>", "");
            //    }
            //}

            //string editSummary = "";
            //if (Settings.AppendToEditSummary)
            //{
            //    if (!string.IsNullOrEmpty(replaced))
            //        editSummary = "replaced: " + replaced.Trim();

            //    if (!string.IsNullOrEmpty(removed))
            //    {
            //        if (!string.IsNullOrEmpty(editSummary))
            //            editSummary += ", ";

            //        editSummary += "removed: " + removed.Trim();
            //    }
            //}
            //eventargs.EditSummary = editSummary;

            //eventargs.Skip = (text == eventargs.ArticleText) && Settings.Skip;
            #endregion
            return(text);
        }
Пример #51
0
 private static void InitialisePlugin(IAWBPlugin plugin, IAutoWikiBrowser awb)
 {
     try
     {
         plugin.Initialise(awb);
     }
     catch (Exception ex)
     {
         ErrorHandler.Handle(ex);
     }
 }
Пример #52
0
        public string ProcessArticle(IAutoWikiBrowser sender, IProcessArticleEventArgs eventargs)
        {
            //If menu item is not checked, then return
            if (!PluginEnabled || Settings.Images.Count == 0)
            {
                eventargs.Skip = false;
                return eventargs.ArticleText;
            }

            string text = eventargs.ArticleText;

            string removed = "", replaced = "";

            foreach (KeyValuePair<string, string> p in Settings.Images)
            {
                bool noChange;

                if (p.Value.Length == 0)
                {
                    text = Parsers.RemoveImage(p.Key, text, Settings.Comment, "", out noChange);
                    if (!noChange)
                    {
                        if (!string.IsNullOrEmpty(removed))
                        {
                            removed += ", ";
                        }

                        removed += Variables.Namespaces[Namespace.File] + p.Key;
                    }
                }
                else
                {
                    text = Parsers.ReplaceImage(p.Key, p.Value, text, out noChange);
                    if (!noChange)
                    {
                        if (!string.IsNullOrEmpty(replaced))
                        {
                            replaced += ", ";
                        }

                        replaced += Variables.Namespaces[Namespace.File]
                         + p.Key + FindandReplace.Arrow + Variables.Namespaces[Namespace.File] + p.Value;
                    }
                }
                if (!noChange)
                {
                    text = Regex.Replace(text, "<includeonly>[\\s\\r\\n]*\\</includeonly>", "");
                }
            }

            string editSummary = "";
            if (Settings.AppendToEditSummary)
            {
                if (!string.IsNullOrEmpty(replaced))
                    editSummary = "replaced: " + replaced.Trim();

                if (!string.IsNullOrEmpty(removed))
                {
                    if (!string.IsNullOrEmpty(editSummary))
                        editSummary += ", ";

                    editSummary += "removed: " + removed.Trim();
                }
            }
            eventargs.EditSummary = editSummary;
            eventargs.Skip = (text == eventargs.ArticleText) && Settings.Skip;

            return text;
        }
 public string ProcessArticle(IAutoWikiBrowser sender, ProcessArticleEventArgs eventargs)
 {
     return(eventargs.ArticleText);
 }
Пример #54
0
 /// <summary>
 /// Passes a reference of the main form to the plugin for initialisation
 /// </summary>
 /// <param name="plugin">IAWBPlugin to initialise</param>
 /// <param name="awb">IAutoWikiBrowser instance of AWB</param>
 private static void InitialisePlugin(IAWBPlugin plugin, IAutoWikiBrowser awb)
 {
     plugin.Initialise(awb);
 }
Пример #55
0
            /// <summary>
            /// Loads all the plugins from the directory where AWB resides
            /// </summary>
            /// <param name="awb">IAutoWikiBrowser instance of AWB</param>
            /// <param name="plugins">Array of Plugin Names</param>
            /// <param name="afterStartup">Whether the plugin(s) are being loaded post-startup</param>
            internal static void LoadPlugins(IAutoWikiBrowser awb, string[] plugins, bool afterStartup)
            {
                try
                {
                    foreach (string plugin in plugins)
                    {
                        if (plugin.EndsWith("DotNetWikiBot.dll") || plugin.EndsWith("Diff.dll")
                            || plugin.EndsWith("WikiFunctions.dll"))
                            continue;

                        Assembly asm = null;
                        try
                        {
                            asm = Assembly.LoadFile(plugin);
                        }
                        catch
                        {
                        }

                        if (asm == null)
                            continue;

                        try
                        {
                            foreach (Type t in asm.GetTypes())
                            {
                                if (t.GetInterface("IAWBPlugin") != null)
                                {
                                    IAWBPlugin awbPlugin = (IAWBPlugin) Activator.CreateInstance(t);

                                    if (Items.ContainsKey(awbPlugin.Name))
                                    {
                                        MessageBox.Show("A plugin with the name \"" + awbPlugin.Name + "\", has already been added.\r\nPlease remove old duplicates from your AutoWikiBrowser Directory, and restart AWB.", "Duplicate AWB Plugin");
                                        continue;
                                    }

                                    InitialisePlugin(awbPlugin, awb);

                                    Items.Add(awbPlugin.Name, awbPlugin);

                                    if (afterStartup) UsageStats.AddedPlugin(awbPlugin);
                                }
                                else if (t.GetInterface("IListMakerPlugin") != null)
                                {
                                    IListMakerPlugin listMakerPlugin = (IListMakerPlugin) Activator.CreateInstance(t);
                                    WikiFunctions.Controls.Lists.ListMaker.AddProvider(listMakerPlugin);

                                    if (afterStartup) UsageStats.AddedPlugin(listMakerPlugin);
                                }
                            }
                        }
                        catch (MissingMemberException)
                        {
                            PluginObsolete(plugin);
                        }
                        catch (Exception ex)
                        {
                            ErrorHandler.Handle(ex);
                        }
                    }
                }
                catch (Exception ex)
                {
#if debug
                    ErrorHandler.Handle(ex);
#else
                    MessageBox.Show(ex.Message, "Problem loading plugins");
#endif
                }

            }
Пример #56
0
        public void Initialise(IAutoWikiBrowser sender)
        {
            // Store AWB object reference:
            AWBForm = sender;

            // Initialise our settings object:
            _pluginSettings = new PluginSettingsControl();


            // Set up our UI objects:

            AWBForm.BotModeCheckbox.EnabledChanged += AWBBotModeCheckboxEnabledChangedHandler;
            AWBForm.BotModeCheckbox.CheckedChanged += AWBBotModeCheckboxCheckedChangeHandler;
            AWBForm.StatusStrip.Items.Insert(2, StatusText);
            StatusText.Margin      = new Padding(50, 0, 50, 0);
            StatusText.BorderSides = ToolStripStatusLabelBorderSides.Left | ToolStripStatusLabelBorderSides.Right;
            StatusText.BorderStyle = Border3DStyle.Etched;
            AWBForm.HelpToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[]
            {
                new ToolStripSeparator(),
                _pluginSettings.MenuHelp,
                _pluginSettings.MenuAbout
            });

            // UI - addhandlers for Start/Stop/Diff/Preview/Save/Ignore buttons/form closing:
            AWBForm.Form.FormClosing += AWBClosingEventHandler;

            // Handle over events from AWB:
            AWBForm.StopButton.Click        += StopButtonClickEventHandler;
            AWBForm.TheSession.StateChanged += EditorStatusChanged;
            AWBForm.TheSession.Aborted      += EditorAborted;

            // Track Manual Assessment checkbox:
            _pluginSettings.ManuallyAssessCheckBox.CheckedChanged += ManuallyAssessCheckBox_CheckChanged;

            // Tabs:
            KingbotkPluginTab.UseVisualStyleBackColor = true;
            KingbotkPluginTab.Controls.Add(_pluginSettings);

            // Add-Generic-Template menu:
            AddGenericTemplateMenuItem.Click += AddGenericTemplateMenuItem_Click;
            AWBForm.PluginsToolStripMenuItem.DropDownItems.Add(AddGenericTemplateMenuItem);

            // Create plugins:
            Plugins.Add("Albums", new WPAlbums());
            Plugins.Add("Australia", new WPAustralia());
            Plugins.Add("India", new WPIndia());
            Plugins.Add("MilHist", new WPMilitaryHistory());
            Plugins.Add("Songs", new WPSongs());
            Plugins.Add("WPNovels", new WPNovels());
            Plugins.Add("Biography", new WPBiography());
            // hopefully if add WPBio last it will ensure that the template gets added to the *top* of pages

            // Initialise plugins:
            foreach (KeyValuePair <string, PluginBase> plugin in Plugins)
            {
                plugin.Value.Initialise();
            }

            // Add our menu items last:
            AWBForm.PluginsToolStripMenuItem.DropDownItems.Add(_pluginSettings.PluginToolStripMenuItem);

            // Reset statusbar text:
            DefaultStatusText();
        }
Пример #57
0
 public PluginManager(IAutoWikiBrowser awb) //, List<string> previousPlugins)
 {
     InitializeComponent();
     AWB = awb;
     //prevPlugins = previousPlugins;
 }
Пример #58
0
            /// <summary>
            /// Loads all the plugins from the directory where AWB resides
            /// </summary>
            /// <param name="awb">IAutoWikiBrowser instance of AWB</param>
            /// <param name="Plugins">Array of Plugin Names</param>
            /// <param name="afterStartup">Whether the plugin(s) are being loaded post-startup</param>
            internal static void LoadPlugins(IAutoWikiBrowser awb, string[] Plugins, bool afterStartup)
            {
                try
                {
                    foreach (string Plugin in Plugins)
                    {
                        if (Plugin.EndsWith("DotNetWikiBot.dll") || Plugin.EndsWith("Diff.dll") ||
                            Plugin.EndsWith("WikiFunctions.dll"))
                        {
                            continue;
                        }

                        Assembly asm = null;
                        try
                        {
                            asm = Assembly.LoadFile(Plugin);
                        }
                        catch
                        {
                        }

                        if (asm == null)
                        {
                            continue;
                        }

                        try
                        {
                            foreach (Type t in asm.GetTypes())
                            {
                                if (t.GetInterface("IAWBPlugin") != null)
                                {
                                    IAWBPlugin plugin = (IAWBPlugin)Activator.CreateInstance(t);

                                    if (Items.ContainsKey(plugin.Name))
                                    {
                                        MessageBox.Show("A plugin with the name \"" + plugin.Name + "\", has already been added.\r\nPlease remove old duplicates from your AutoWikiBrowser Directory, and restart AWB.", "Duplicate AWB Plugin");
                                        continue;
                                    }

                                    InitialisePlugin(plugin, awb);

                                    Items.Add(plugin.Name, plugin);

                                    if (afterStartup)
                                    {
                                        UsageStats.AddedPlugin(plugin);
                                    }
                                }
                                else if (t.GetInterface("IListMakerPlugin") != null)
                                {
                                    IListMakerPlugin plugin = (IListMakerPlugin)Activator.CreateInstance(t);
                                    WikiFunctions.Controls.Lists.ListMaker.AddProvider(plugin);

                                    if (afterStartup)
                                    {
                                        UsageStats.AddedPlugin(plugin);
                                    }
                                }
                            }
                        }
                        catch (MissingMemberException)
                        {
                            PluginObsolete(Plugin);
                        }
                        catch (Exception ex)
                        {
                            ErrorHandler.Handle(ex);
                        }
                    }
                }
                catch (Exception ex)
                {
#if debug
                    ErrorHandler.Handle(ex);
#else
                    MessageBox.Show(ex.Message, "Problem loading plugins");
#endif
                }
            }
Пример #59
0
            /// <summary>
            /// Loads all the plugins from the directory where AWB resides
            /// </summary>
            /// <param name="awb">IAutoWikiBrowser instance of AWB</param>
            /// <param name="plugins">Array of Plugin Names</param>
            /// <param name="afterStartup">Whether the plugin(s) are being loaded post-startup</param>
            internal static void LoadPlugins(IAutoWikiBrowser awb, string[] plugins, bool afterStartup)
            {
                try
                {
                    foreach (string plugin in plugins)
                    {
                        if (plugin.EndsWith("DotNetWikiBot.dll") || plugin.EndsWith("Diff.dll")
                            || plugin.EndsWith("WikiFunctions.dll"))
                            continue;

                        Assembly asm = null;
                        try
                        {
                            asm = Assembly.LoadFile(plugin);
                        }
                        catch (Exception ex)
                        {
                #if DEBUG
                            Tools.WriteDebug(plugin, ex.ToString());
                #endif
                            continue;
                        }

                        if (asm == null)
                            continue;

                        try
                        {
                            foreach (Type t in asm.GetTypes())
                            {
                                if (t.GetInterface("IAWBPlugin") != null)
                                {
                                    IAWBPlugin awbPlugin =
                                        (IAWBPlugin)Activator.CreateInstance(t);

                                    if (AWBPlugins.ContainsKey(awbPlugin.Name))
                                    {
                                        MessageBox.Show(
                                            "A plugin with the name \"" + awbPlugin.Name +
                                            "\", has already been added.\r\nPlease remove old duplicates from your AutoWikiBrowser Directory, and restart AWB.\r\nThis was loaded from the plugin file \"" +
                                            plugin + "\".", "Duplicate AWB Plugin");
                                        break;
                                    }

                                    InitialisePlugin(awbPlugin, awb);

                                    AWBPlugins.Add(awbPlugin.Name, awbPlugin);

                                    if (afterStartup) UsageStats.AddedPlugin(awbPlugin);
                                }
                                else if (t.GetInterface("IAWBBasePlugin") != null)
                                //IAWBBasePlugin needs to be checked after IAWBPlugin, as IAWBPlugin extends IAWBBasePlugin
                                {
                                    IAWBBasePlugin awbBasePlugin = (IAWBBasePlugin)Activator.CreateInstance(t);

                                    if (AWBBasePlugins.ContainsKey(awbBasePlugin.Name))
                                    {
                                        MessageBox.Show(
                                            "A plugin with the name \"" + awbBasePlugin.Name +
                                            "\", has already been added.\r\nPlease remove old duplicates from your AutoWikiBrowser Directory, and restart AWB.\r\nThis was loaded from the plugin file \"" +
                                            plugin + "\".", "Duplicate AWB Base Plugin");
                                        break;
                                    }

                                    InitialisePlugin(awbBasePlugin, awb);

                                    AWBBasePlugins.Add(awbBasePlugin.Name, awbBasePlugin);

                                    if (afterStartup) UsageStats.AddedPlugin(awbBasePlugin);
                                }
                                else if (t.GetInterface("IListMakerPlugin") != null)
                                {
                                    IListMakerPlugin listMakerPlugin =
                                        (IListMakerPlugin)Activator.CreateInstance(t);

                                    if (ListMakerPlugins.ContainsKey(listMakerPlugin.Name))
                                    {
                                        MessageBox.Show(
                                            "A plugin with the name \"" + listMakerPlugin.Name +
                                            "\", has already been added.\r\nPlease remove old duplicates from your AutoWikiBrowser Directory, and restart AWB.\r\nThis was loaded from the plugin file \"" +
                                            plugin + "\".", "Duplicate AWB ListMaker Plugin");
                                        break;
                                    }

                                    WikiFunctions.Controls.Lists.ListMaker.AddProvider(listMakerPlugin);

                                    ListMakerPlugins.Add(listMakerPlugin.Name, listMakerPlugin);

                                    if (afterStartup) UsageStats.AddedPlugin(listMakerPlugin);
                                }
                            }
                        }
                        catch (ReflectionTypeLoadException)
                        {
                            PluginObsolete(plugin, asm.GetName().Version.ToString());
                        }
                        catch (MissingMemberException)
                        {
                            PluginObsolete(plugin, asm.GetName().Version.ToString());
                        }
                        catch (Exception ex)
                        {
                            ErrorHandler.Handle(ex);
                        }
                    }
                }
                catch (Exception ex)
                {
                #if debug
                    ErrorHandler.Handle(ex);
                #else
                    MessageBox.Show(ex.Message, "Problem loading plugins");
                #endif
                }
            }
Пример #60
0
        public string ProcessArticle(IAutoWikiBrowser sender, IProcessArticleEventArgs eventargs)
        {
            //If menu item is not checked, then return
            if (!PluginEnabled || Settings.Categories.Count == 0)
            {
                eventargs.Skip = false;
                return(eventargs.ArticleText);
            }

            string text = eventargs.ArticleText;
            string removed = "", replaced = "";

            foreach (KeyValuePair <string, string> p in Settings.Categories)
            {
                bool noChange;

                if (p.Value.Length == 0)
                {
                    text = Parsers.RemoveCategory(p.Key, text, out noChange);
                    if (!noChange)
                    {
                        if (!string.IsNullOrEmpty(removed))
                        {
                            removed += ", ";
                        }

                        removed += Variables.Namespaces[Namespace.Category] + p.Key;
                    }
                }
                else
                {
                    text = Parsers.ReCategoriser(p.Key, p.Value, text, out noChange);
                    if (!noChange)
                    {
                        if (!string.IsNullOrEmpty(replaced))
                        {
                            replaced += ", ";
                        }

                        replaced += Variables.Namespaces[Namespace.Category]
                                    + p.Key + FindandReplace.Arrow + Variables.Namespaces[Namespace.Category] + p.Value;
                    }
                }
                if (!noChange)
                {
                    text = Regex.Replace(text, "<includeonly>[\\s\\r\\n]*\\</includeonly>", "");
                }
            }

            string editSummary = "";

            if (Settings.AppendToEditSummary)
            {
                if (!string.IsNullOrEmpty(replaced))
                {
                    editSummary = "replaced: " + replaced.Trim();
                }

                if (!string.IsNullOrEmpty(removed))
                {
                    if (!string.IsNullOrEmpty(editSummary))
                    {
                        editSummary += ", ";
                    }

                    editSummary += "removed: " + removed.Trim();
                }
            }
            eventargs.EditSummary = editSummary;

            eventargs.Skip = (text == eventargs.ArticleText) && Settings.Skip;

            return(text);
        }