/// <summary> /// Creates a new instance of the ApiEdit class by cloning the current instance /// ATTENTION: the clones will share the same cookie container, so logging off or logging under another username /// with one instance will automatically make another one do the same /// </summary> public ApiEdit Clone() { ApiEdit clone = new ApiEdit(); clone.m_URL = m_URL; clone.m_Maxlag = m_Maxlag; clone.m_Cookies = m_Cookies; clone.ProxySettings = ProxySettings; return clone; }
private void btnLogin_Click(object sender, EventArgs e) { groupBox2.Enabled = false; try { Editor = new ApiEdit(txtURL.Text); Editor.Login(txtUsername.Text, txtPassword.Text); groupBox2.Enabled = true; txtEdit.Text = ""; btnSave.Enabled = false; } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().Name); } }
public ApiException(ApiEdit editor, string message) : base(message) { Editor = editor; }
public SpamlistException(ApiEdit editor, string url) : base(editor, "The link '" + url + "' is blocked by spam blacklist") { URL = url; }
public NewMessagesException(ApiEdit editor) : base(editor, "You have new messages") { }
public MaxlagException(ApiEdit editor, int maxlag, int retryAfter) : base(editor, "maxlag", "Maxlag exceeded by " + maxlag + " seconds, retry in " + retryAfter + " seconds") { Maxlag = maxlag; RetryAfter = retryAfter; }
public InvalidTitleException(ApiEdit editor, string title) : base(editor, "Invalid title: \"" + title + "\"") { InvalidTitle = title; }
public BrokenXmlException(ApiEdit editor, Exception innerException) : base(editor, "Error parsing data returned by server: " + innerException.Message, innerException) { }
public ApiXmlException(ApiEdit editor, XmlException innerException, string get, string post, string content) : base(editor, "XmlException in ApiEdit.CheckForErrors", innerException) { GetUrl = get; PostQuery = post; Content = content; }
public MediaWikiSaysNoException(ApiEdit editor, string message) : base(editor, message) { }
public SharedRepoException(ApiEdit editor, string message) : base(editor, message) { }
public TranslationPageEditException(ApiEdit editor) : base(editor, "tpt-target-page", "Can't edit Translation Pages") { }
public MediaWikiReadOnlyException(ApiEdit editor, string errorMessage) : base(editor, "readonly", errorMessage) { }
public ApiOperationFailedException(ApiEdit editor, string action, string result) : base(editor, "Operation '" + action + "' ended with result '" + result + "'.") { Action = action; Result = result; }
public ApiException(ApiEdit editor, string message, Exception innerException) : base(message, innerException) { Editor = editor; }
public ApiException(ApiEdit editor, string message, Exception innerException) : base(message, innerException) { Editor = editor; }
public Login() { editor = new ApiEdit("http://" + _sourceWiki + ".wikipedia.org/w"); bot = new ApiEdit("http://" + _destinationWiki + ".wikipedia.org/w"); }
public ApiBlankException(ApiEdit editor) : base(editor, "The result returned by server was blank") { }
public BrokenXmlException(ApiEdit editor, string message) : base(editor, message) { }
public BrokenXmlException(ApiEdit editor, string message) : base(editor, message) { }
public FeatureDisabledException(ApiEdit editor, string errorCode, string errorMessage) : base(editor, errorCode, errorMessage) { DisabledFeature = errorCode.Replace("-disabled", ""); }
public BrokenXmlException(ApiEdit editor, string message, Exception innerException) : base(editor, message, innerException) { }
public LoggedOffException(ApiEdit editor) : base(editor, "User is logged off") { }
public BrokenXmlException(ApiEdit editor, Exception innerException) : base(editor, "Error parsing data returned by server: " + innerException.Message, innerException) { }
public MediaWikiSaysNoException(ApiEdit editor, string message) : base(editor, message) { }
public LoginException(ApiEdit editor, string status) : base(editor, GetErrorMessage(status)) { StatusCode = status; }
public RedirectToSpecialPageException(ApiEdit editor) : base(editor, "Redirect target is special page") { }
public MaxlagException(ApiEdit editor, int maxlag, int retryAfter) : base(editor, "maxlag", "Maxlag exceeded by " + maxlag + " seconds, retry in " + retryAfter + " seconds") { Maxlag = maxlag; RetryAfter = retryAfter; }
public ApiErrorException(ApiEdit editor, string errorCode, string errorMessage) : base(editor, "API returned the following error: '" + errorMessage + "'") { ErrorCode = errorCode; ApiErrorMessage = errorMessage; }
public AssertionFailedException(ApiEdit editor, string assertion) : base(editor, "Assertion '" + assertion + "' failed") { }
public ApiException(ApiEdit editor, string message) : base(message) { Editor = editor; }
public SpamlistException(ApiEdit editor, string url) : base(editor, "The link '" + url + "' is blocked by spam blacklist") { URL = url; }
public ApiOperationFailedException(ApiEdit editor, string action, string result) : base(editor, "Operation '" + action + "' ended with result '" + result + "'.") { Action = action; Result = result; }
public LoggedOffException(ApiEdit editor) : base(editor, "User is logged off") { }
public ApiException(ApiEdit editor, string message, Exception innerException) : base(message, innerException) { Editor = editor; ThrowingThread = Thread.CurrentThread; }
public CaptchaException(ApiEdit editor) : base(editor, "Captcha required") { }
public AssertionFailedException(ApiEdit editor, string assertion) : base(editor, "Assertion '" + assertion + "' failed") { }
public InterwikiException(ApiEdit editor) : base(editor, "Page title contains interwiki") { }
public BrokenXmlException(ApiEdit editor, string message, Exception innerException) : base(editor, message, innerException) { }
public NewMessagesException(ApiEdit editor) : base(editor, "You have new messages") { }
public CaptchaException(ApiEdit editor) : base(editor, "Captcha required") { }
public InvalidTitleException(ApiEdit editor, string title) : base(editor, "Invalid title: \"" + title + "\"") { InvalidTitle = title; }
public InterwikiException(ApiEdit editor) : base(editor, "Page title contains interwiki") { }
public RedirectToSpecialPageException(ApiEdit editor) : base(editor, "Redirect target is special page") { }
public AbortedException(ApiEdit editor) : base(editor, "API operation aborted") { }
public ApiException(ApiEdit editor, string message, Exception innerException) : base(message, innerException) { Editor = editor; ThrowingThread = Thread.CurrentThread; }
public LoginException(ApiEdit editor, string status) : base(editor, GetErrorMessage(status)) { StatusCode = status; }
public AbortedException(ApiEdit editor) : base(editor, "API operation aborted") { }
public MediaWikiReadOnlyException(ApiEdit editor, string errorMessage) : base(editor, "readonly", errorMessage) { }
public AsyncApiEdit(string url, Control parentControl, bool php5) { Editor = new ApiEdit(url, php5); State = EditState.Ready; ParentControl = parentControl; }
public ApiBlankException(ApiEdit editor) : base(editor, "The result returned by server was blank") { }
public void CopyTemplatesMethod() { #region resetting things in articlecache articleContentCache.ArticleName = ""; articleContentCache.Article_WikiContent = ""; #endregion List <string> articleList = this.ListOfArticles; string sourceWiki = SourceWiki.Trim(); if (editor == null) { editor = new ApiEdit("http://" + sourceWiki + ".wikipedia.org/w/", false); editor.Login(FormMainWindowUserName, FormMainWindowPassword); } if (editor.User == null) { editor.Login(FormMainWindowUserName, FormMainWindowPassword); } if (editor.User.Name == null) { editor.Login(FormMainWindowUserName, FormMainWindowPassword); } if (bot == null) { bot = new ApiEdit("http://" + m_destinationWiki + ".wikipedia.org/w/", false); bot.Login(FormMainWindowUserName, FormMainWindowPassword); } if (bot.User == null) { bot.Login(FormMainWindowUserName, FormMainWindowPassword); } if (bot.User.Name == null) { bot.Login(FormMainWindowUserName, FormMainWindowPassword); } int _counter = 0; int maxValue = articleList.Count; var completedArticlePercentage = 0; foreach (string articleName in articleList) { _counter++; try{ #region progressbar data if (maxValue > 0) { completedArticlePercentage = ((_counter * 100) / maxValue); } else { completedArticlePercentage = 5; } if (OnRobotPercentageFeedback != null) { OnRobotPercentageFeedback(completedArticlePercentage); } #endregion string TemplateName = "Template:" + articleName; Debug.WriteLine(_counter + ")ArticleName:" + articleName); if (OnRobotLogFeedBack != null) { OnRobotLogFeedBack("\n----------------------------------------------\n"); OnRobotLogFeedBack("Opening article:" + articleName + " from " + editor.ApiURL); } string englishArticle = editor.Open(TemplateName, false); //clearing cache articleContentCache.ClearCache(); articleContentCache.ArticleName = TemplateName; articleContentCache.Article_WikiContent = englishArticle; if (!string.IsNullOrEmpty(articleContentCache.Article_WikiContent)) { if (OnRobotLogFeedBack != null) { OnRobotLogFeedBack("Opening article:" + articleContentCache.ArticleName + " from " + bot.ApiURL); } string nepaliArticle = bot.Open(articleContentCache.ArticleName, false); //Don't know what to do for content "nepaliArticle" //if(sourceWiki.ToLower().Trim()=="hi"){ //this.richTextBoxHindi.Text = englishArticle; //richTextBoxHindi.Invoke(this.OnHindiTextObtained, englishArticle); if (EnableTranslation) { this.TranslateTemplateThread(); if (OnRobotLogFeedBack != null) { if (templateTranslatorThread != null) { OnRobotLogFeedBack("\nThread started : " + templateTranslatorThread.Name); } } //Thread Joining here if (templateTranslatorThread != null) { templateTranslatorThread.Join(); } //end thread join if (OnRobotLogFeedBack != null) { OnRobotLogFeedBack("\nText to translate : " + articleContentCache.Article_WikiContent); } if (OnRobotLogFeedBack != null) { OnRobotLogFeedBack("\ntranslated text : " + articleContentCache.TranslatedArticle_Content); } if (OnArticleCacheReady != null) { if (OnRobotLogFeedBack != null) { OnRobotLogFeedBack("Sending article cache"); } OnArticleCacheReady(articleContentCache); } while (this.templateTranslatorThread.IsAlive) { //MessageBox.Show("Editor is busy"); if (OnRobotLogFeedBack != null) { OnRobotLogFeedBack("\n Editor is busy"); } Thread.Sleep(5000); } } if (!bot.URL.ToLower().Contains("http://en.wikipedia.org/w/") || (!bot.URL.ToLower().Contains("http://" + sourceWiki + ".wikipedia.org/w/"))) //Don't mess with en wikipedia and sourceWikipedia { //Write protect for english wikipedia string editSummary = string.IsNullOrEmpty(EditSummary) ? "Copy template from " + sourceWiki : EditSummary; editSummary = editSummary + " from " + editor.URL + "index.php?oldid=" + editor.Page.RevisionID.ToString() + " [[:" + sourceWiki + ":" + editor.Page.Title + "]]"; bool _templateSaveSuccess = true; if (!bot.Page.Exists) { if (OnRobotLogFeedBack != null) { OnRobotLogFeedBack("Going to save " + bot.Page.Title); } string _nepaliArticleToSave = articleContentCache.Article_WikiContent; if (articleContentCache.IsTranslatedArticle) { _nepaliArticleToSave = articleContentCache.TranslatedArticle_Content; } if (OnArticleCacheReady != null) { OnArticleCacheReady(articleContentCache); } SaveInfo saveInfo = bot.Save(_nepaliArticleToSave, editSummary, false, WatchOptions.NoChange); if (OnRobotLogFeedBack != null) { OnRobotLogFeedBack("Saved : " + bot.Page.Title + saveInfo.ResponseXml.InnerText); } if (!TemplateName.EndsWith("/doc")) { string templateDocName = TemplateName.Trim() + "/doc"; string englishTemplateDoc = editor.Open(templateDocName); if (!string.IsNullOrEmpty(englishTemplateDoc)) { string nepaliArticleDoc = bot.Open(templateDocName, false); if (!bot.Page.Exists) { SaveInfo docSaveInfo = bot.Save(englishTemplateDoc, editSummary, false, WatchOptions.NoChange); if (OnRobotLogFeedBack != null) { OnRobotLogFeedBack("\n Found a template doc, Copied Template doc as well : " + docSaveInfo.ResponseXml); } } } } } } } if (OnArticleProcessed != null) { OnArticleProcessed(articleContentCache); } Thread.Sleep(m_ThreadSleepTime); //Let Wiki Breathe }catch (Exception e) { WikiFunctions.ErrorHandler.Handle(e); } } }
public OperationFailedException(ApiEdit editor, string action, string result, string xml) : base(editor, "Operation '" + action + "' ended with result '" + result + "'.\r\nXml: '" + xml + "'") { Action = action; Result = result; Xml = xml; }
private AsyncApiEdit(ApiEdit editor, Control parentControl) { SynchronousEditor = editor; ParentControl = parentControl; State = EditState.Ready; }
public SharedRepoException(ApiEdit editor, string message) : base(editor, message) { }
public ApiErrorException(ApiEdit editor, string errorCode, string errorMessage) : base(editor, "Bot API returned the following error: '" + errorMessage + "'") { ErrorCode = errorCode; ApiErrorMessage = errorMessage; }
public TranslationPageEditException(ApiEdit editor) : base(editor, "tpt-target-page", "Can't edit Translation Pages") { }
public FeatureDisabledException(ApiEdit editor, string errorCode, string errorMessage) : base(editor, errorCode, errorMessage) { DisabledFeature = errorCode.Replace("-disabled", ""); }
public AsyncApiEdit(string url, Control parentControl, bool php5) { Editor = new ApiEdit(url, php5); State = EditState.Ready; m_ParentControl = parentControl; }
public ApiLoggedOffException(ApiEdit editor) : base(editor, "You are currently logged off") { }