Implements a translator tool for importing MediaWiki data.
Inheritance: ScrewTurn.Wiki.ImportWiki.ITranslator
Beispiel #1
0
		protected void btnGo_click(object sender, EventArgs e) {
			switch(lstOperation.SelectedValue.ToUpperInvariant()) {
				case "PAGE":
					PageAsyncTask task = new PageAsyncTask(
						new BeginEventHandler(BeginPageRequest),
						new EndEventHandler(EndPageRequest),
						new EndEventHandler(TimeoutPageRequest),
						null);
					RegisterAsyncTask(task);
					break;
				case "WIKI":
					AddOnPreRenderCompleteAsync(
						new BeginEventHandler(BeginPagesListRequest),
						new EndEventHandler(EndPagesListRequest)
					);
					break;
				case "TEXT":
					mlwImport.ActiveViewIndex = 3;
					ITranslator translator = new Translator();
					txtTranslated.Text = translator.Translate(txtText.Text);
					break;
			}
		}
Beispiel #2
0
		private void EndPageRequest(IAsyncResult ar) {
			try {
				HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(ar);
				StreamReader reader = new StreamReader(response.GetResponseStream());
				if(lstWiki.SelectedValue.ToUpperInvariant() == "MEDIA") {
					Regex textarea = new Regex(@"(?<=(\<textarea([^>])*?)\>)(.|\s)+?(?=(\<\/textarea\>))");
					Match match = textarea.Match(reader.ReadToEnd());
					if(match.Success) {
						Translator translator = new Translator();
						string text = translator.Translate(match.Value.Replace("&lt;", "<").Replace("&gt;", ">").Replace("&quot;", @""""));
						savePage(text);
					}
				}
				if(lstWiki.SelectedValue.ToUpperInvariant() == "FLEX") {
					Regex textarea = new Regex(@"(?<=(\<textarea class=\'EditBox\'([^>])*?)\>)(.|\s)+?(?=(\<\/textarea\>))");
					Match match = textarea.Match(reader.ReadToEnd());
					if(match.Success) {
						Translator translator = new Translator();
						string text = translator.Translate(match.Value.Replace("&lt;", "<").Replace("&gt;", ">").Replace("&quot;", @""""));
						savePage(text);
					}
				}
				UrlTools.Redirect(UrlTools.BuildUrl(txtPageName.Text.Replace(":", "_").Replace("/", "_").Replace(@"\", "_").Replace('?', '_'), ".ashx"));
			}
			catch(WebException) {
				lblResult.Text = "Web exception";
			}
		}
Beispiel #3
0
		private void endPageDownload(IAsyncResult ar) {
			for(int i = 0; i < pageList.Items.Count; i++) {
				if(pageList.Items[i].Selected) {
					string url = "";
					Regex textarea = null;
					Match match = null;
					ITranslator translator = null;
					if(lstWiki.SelectedValue.ToUpperInvariant() == "MEDIA") {
						url = txtWikiUrl.Text + "?title=" + pageList.Items[i].Value + "&action=edit";
						textarea = new Regex(@"(?<=(\<textarea([^>])*?)\>)(.|\s)+?(?=(\<\/textarea\>))");
						translator = new Translator();
					}
					if(lstWiki.SelectedValue.ToUpperInvariant() == "FLEX") {
						if(txtWikiUrl.Text.EndsWith("/")) url = txtWikiUrl.Text + "wikiedit.aspx?topic=" + pageList.Items[i].Value;
						else url = txtWikiUrl.Text + "/wikiedit.aspx?topic=" + pageList.Items[i].Value;
						textarea = new Regex(@"(?<=(\<textarea class=\'EditBox\'([^>])*?)\>)(.|\s)+?(?=(\<\/textarea\>))");
						translator = new TranslatorFlex();
					}
					try {
						match = textarea.Match(PageRequest(url));
						if(match.Success) {
							string text = translator.Translate(match.Value.Replace("&lt;", "<").Replace("&gt;", ">").Replace("&quot;", @""""));
							string pageName = pageList.Items[i].Value.Replace(":", "_").Replace("/", "_").Replace(@"\", "_").Replace('?', '_');
							string pageTitle = pageList.Items[i].Value;
							Log.LogEntry("Page " + pageName + " created with import whole wiki", EntryType.General, "import");
							PageInfo pg = Pages.FindPage(pageName);
							SaveMode saveMode = SaveMode.Backup;
							if(pg == null) {
								Pages.CreatePage(null as string, pageName);
								pg = Pages.FindPage(pageName);
								saveMode = SaveMode.Normal;
							}
							Log.LogEntry("Page create requested for " + pageName, EntryType.General, "import");
							Pages.ModifyPage(pg, pageTitle, "import", DateTime.Now, "", text, null, null, saveMode);
							pageList.Items.Remove(pageList.Items[i]);
						}
					}
					catch(WebException) { }
				}
			}
			pageList.Visible = true;
			lblPageList.Text = "Import completed!";
		}