public void Should_Fail_With_Wrong_Geo() { const double latitude = 307.786971; const double longitude = 200.399677; Assert.Throws <ApiException>(() => WikiApi.Geosearch(latitude, longitude)); }
public void Verbose_With_Levenstein() { const double latitude = 37.786971; const double longitude = -122.399677; IStringMetric metric = new Levenstein(); ITokenizer tokenizer = new Tokenizer(); var geopages = WikiApi.Geosearch(latitude, longitude); foreach (var geopage in geopages) { output.WriteLine($"[{geopage.Pageid}] {geopage.Title}"); var images = WikiApi.Images(geopage.Pageid); var imagesWithMetrics = images .Select(image => new { Image = image, Similarity = image.CalcMetric(geopage.Title, tokenizer, metric) }) .ToList(); var title = imagesWithMetrics.Aggregate((image, next) => next.Similarity > image.Similarity ? next : image); output.WriteLine($"\t*[{title.Image.Ns}] {title.Image.Title} {title.Similarity}"); foreach (var image in imagesWithMetrics) { output.WriteLine($"\t[{image.Image.Ns}] {image.Image.Title} {image.Similarity}"); } } }
public void createGui_EditUsingCategories(Control hostControl, string title1, string title2) { hostControl.clear(); var usersGui = hostControl.add_1x1(title1, title2, true, hostControl.width() / 3); var pageEditor = usersGui[1].Parent.clear().add_Control <ascx_MediaWiki_PageEditor_Simple>().buildGui(WikiApi); var controls = usersGui[0].Parent.clear().add_1x1("Category Names", "Pages in Selected Category", false); var Categories_TreeView = controls[0].add_TreeView(); var PagesInCategories_TreeView = controls[1].add_TreeView(); MethodInvoker loadData = () => { //Categories_TreeView.clear(); Categories_TreeView = controls[0].add_TreeViewWithFilter(WikiApi.categoryPages()) .afterSelect <string>( (value) => { PagesInCategories_TreeView = controls[1].add_TreeViewWithFilter(WikiApi.pagesInCategory(value)) .afterSelect <string>((page) => pageEditor.openPage(page)); pageEditor.openPage(value); addEditMenuItemsToTreeView(PagesInCategories_TreeView); }); addEditMenuItemsToTreeView(Categories_TreeView); }; //PagesInCategories_TreeView.clear(); //Categories_TreeView.add_Nodes(WikiApi.categoryPages()); controls[1].insert_Below <Panel>(20) .add_Link("Reload data", 0, 0, () => loadData()) .click(); }
public void backup_Files(string backupFolder) { var files_BackupFolder = backupFolder.pathCombine("Files"); files_BackupFolder.createDir(); var files = WikiApi.allImages(); "there are {0} files to download".info(files.size()); Status_ProgressBar.maximum(files.size()); Status_ProgressBar.value(0); foreach (var file in files) { if (CancelBackup) { "In backup_Files, CancelBackup was set, so aborting backup".error(); break; } var web = new Web(); if (WikiApi.BasicAuth.valid()) { web.Headers_Request.add("Authorization", "Basic " + WikiApi.BasicAuth); } web.downloadBinaryFile(file, files_BackupFolder); Status_ProgressBar.increment(1); } }
public void backup_Pages(string backupFolder) { var pages_BackupFolder = backupFolder.pathCombine("Pages"); pages_BackupFolder.createDir(); var categories = WikiApi.pages(); savePages(backupFolder, pages_BackupFolder, categories, "pagesMappings.txt"); /*var pages_BackupFolder = backupFolder.pathCombine("Pages"); * pages_BackupFolder.createDir(); * * string pageMappings = ""; * * // backup pages * var pages = WikiApi.pages(); * "there are: {0} pages to backup".info(pages.size()); * foreach(var page in pages) * { * pageMappings += "{0} {1}".format(page, page.base64Encode()).line(); * var saveFileName = "{0}.wikitext.txt".format(Files.getSafeFileNameString(page)); * WikiApi.raw(page).saveAs(pages_BackupFolder.pathCombine(saveFileName)); * } * pageMappings.saveAs(backupFolder.pathCombine("pagesMappings.txt")); */ }
public void setup() { var backupFolder = @"C:\O2\_USERDATA\WikiBackup".pathCombine(WikiApi.typeName()) .pathCombine(Files.getFileSaveDateTime_Now()); BackupFolder_TextBox.set_Text(backupFolder); }
public void Should_Work_Empty_With_Missing_Page() { const int pageid = 1; var images = WikiApi.Images(pageid); Assert.NotNull(images); Assert.Empty(images); }
public void Should_Work() { const int pageid = 40413203; var images = WikiApi.Images(pageid); Assert.NotNull(images); Assert.NotEmpty(images); }
public void showRawWikiText() { var defaultTopPanelText = "You can refresh the Html view using F5 or Ctrl+R (or via the context menu (right-click on WikiText))"; var panel = MainDocumentPane.add_DocumentContent("Raw Wiki Text") .setAsActive() .add_WinForms_Panel(); //panel.clear(); //var wikiApi = new O2PlatformWikiAPI(); var topPanel = panel.add_1x1(false); var rawWiki = topPanel[0].add_TextArea(); var bottomPanel = topPanel[1].add_1x1x1("Pure Html", "Browser (pure html View)", "Browser (view using site's Styles)"); var htmlViewer = bottomPanel[0].add_RichTextBox(); var browserSimple = bottomPanel[1].add_WebBrowser(); var browserWithSyles = bottomPanel[2].add_WebBrowser(); Action <string> processWikiText = (wikiText) => { var htmlCode = WikiApi.parseText(wikiText); htmlViewer.set_Text(htmlCode); browserSimple.set_Text(htmlCode); browserWithSyles.set_Text(WikiApi.wrapOnHtmlPage(htmlCode)); }; MethodInvoker refresh = () => { topPanel[0].set_Text("Retrieving RawWiki Html code"); rawWiki.backColor(Color.LightPink); O2Thread.mtaThread( () => { processWikiText(rawWiki.get_Text()); rawWiki.backColor(Color.White); topPanel[0].set_Text(defaultTopPanelText); }); }; Action <KeyEventArgs> handlePressedKeys = (e) => { if (e.KeyValue == 116 || // F5 (key 116) or (e.Modifiers == Keys.Control && e.KeyValue == 'R')) // Ctrl+R it { refresh(); } }; rawWiki.KeyUp += (sender, e) => handlePressedKeys(e); //rawWiki.onEnter(processWikiText); rawWiki.add_ContextMenu().add_MenuItem("Show Html for Wiki Text", refresh); rawWiki.set_Text("===Raw WikiText===".line() + "this is simple text".line() + "* this is a bullet point"); refresh(); //panel_add_1x1( }
public void Should_Work() { const double latitude = 37.786971; const double longitude = -122.399677; var geopages = WikiApi.Geosearch(latitude, longitude); Assert.NotNull(geopages); Assert.NotEmpty(geopages); }
public void backup_CategoryPages(string backupFolder) { var categories_BackupFolder = backupFolder.pathCombine("Categories"); categories_BackupFolder.createDir(); var categories = WikiApi.categoryPages(); savePages(backupFolder, categories_BackupFolder, categories, "categoryPagesMappings.txt"); }
public void backup_Users(string backupFolder) { var templates_BackupFolder = backupFolder.pathCombine("Users"); templates_BackupFolder.createDir(); var categories = WikiApi.userPages(); savePages(backupFolder, templates_BackupFolder, categories, "userPagesMappings.txt"); }
public void setWikiApi(O2MediaWikiAPI newWikiApi) { //perform a shallow copy from newWikiApi to WikiApi) //"before:{0}".info(WikiApi.HostUrl); foreach (var property in WikiApi.type().properties()) { Reflection_ExtensionMethods_Properties.prop(WikiApi, property.Name, newWikiApi.prop(property.Name)); } //"after:{0}".info(WikiApi.HostUrl); }
public void Should_Work_Multi_Page() { const int pageid1 = 40413203; const int pageid2 = 40377676; var images = WikiApi.Images(new [] { pageid1, pageid2 }); Assert.NotNull(images); Assert.NotEmpty(images); Assert.NotEmpty(images[pageid1].Images); Assert.NotEmpty(images[pageid2].Images); }
public bool pasteImageFromClipboard() { if (Clipboard.ContainsImage()) { "Image in Clipboard".debug(); O2Thread.mtaThread( () => { var tempImageTag = "[[Uploading_Image_tmp{0}]]".format(5.randomNumbers()); WikiTextEditor.insertText(tempImageTag); var imageUrl = WikiApi.uploadImage_FromClipboard(); var wikiTextForImage = WikiApi.getWikiTextForImage(imageUrl); WikiTextEditor.replaceText(tempImageTag, wikiTextForImage); }); return(true); } return(false); }
public void addEditMenuItemsToTreeView(TreeView treeView) { var contextMenu = treeView.add_ContextMenu(); contextMenu.add_MenuItem("delete selected page (you must be an admin)", () => { var pageToDelete = treeView.selected().get_Text(); if (pageToDelete.valid()) { if (WikiApi.deletePage(pageToDelete)) { treeView.remove_Node(treeView.selected()); } } }); /* contextMenu.add_MenuItem("reload all pages", * ()=>{ * treeView.clear(); * treeView.add_Nodes(WikiApi.allPages()); * }); */ var renameMenuItem = contextMenu.add_MenuItem("rename (user will copy, admin will move)"); var renameTextBox = renameMenuItem.add_TextBox("rename"); renameMenuItem.add_MenuItem("rename page with new title (set above)", () => { var currentTitle = treeView.selected().get_Text(); var newTitle = renameTextBox.get_Text(); if (WikiApi.movePage(currentTitle, newTitle)) { treeView.selected().set_Text(newTitle); } //"renaming page '{0}' to '{1}'".info(currentTitle, newTitle); }); treeView.afterSelect <string>( (page) => { renameTextBox.set_Text(page); renameTextBox.width(page.size() * 7); }); }
public void login() { LoggedInStatus_Label.set_Text("trying to login to: {0}".format(MediaWikiUrl_TextBox.get_Text())) .textColor(Color.Black); var username = UserName_TextBox.get_Text(); var password = Password_TextBox.get_Text(); WikiApi.login(username, password).isFalse(); if (WikiApi.loggedIn()) { LoggedInStatus_Label.set_Text("Logged in as user: {0}".format(username)) .textColor(Color.Green); } else { LoggedInStatus_Label.set_Text("Login failed for user {0}".format(username)) .textColor(Color.Red); } SetWikiApi(WikiApi); }
public void savePages(string backupFolder, string targetFolder, List <string> pages, string mappingsFileName) { string pageMappings = ""; "there are: {0} pages to save".info(pages.size()); Status_ProgressBar.maximum(pages.size()); Status_ProgressBar.value(0); foreach (var page in pages) { if (CancelBackup) { "In savePages, CancelBackup was set, so aborting backup".error(); break; } pageMappings += "{0} {1}".format(page, page.base64Encode()).line(); var saveFileName = "{0}.wikitext.txt".format(Files.getSafeFileNameString(page)); WikiApi.raw(page).saveAs(targetFolder.pathCombine(saveFileName)); Status_ProgressBar.increment(1); } pageMappings.saveAs(backupFolder.pathCombine(mappingsFileName)); }
public void loadPage() { var pageToLoad = WikiPage_TextBox.get_Text(); WikiTextEditor.backColor(Color.LightPink); StatusLabel.set_Text("Opening page: {0}".format(pageToLoad)).textColor(Color.Black); CurrentPageUrl.insert_Item("{0}/{1}".format(WikiApi.IndexPhp, pageToLoad)); O2Thread.mtaThread(() => { var wikiText = WikiApi.wikiText(pageToLoad); WikiTextEditor.set_Text(wikiText); if (wikiText.valid().isFalse()) { StatusLabel.set_Text("This is a new Page (there was no content retrived from the server").textColor(Color.DarkBlue); } BrowserPreview.open("about:blank"); BrowserCurrent.open("about:blank"); WikiTextEditor.backColor(Color.White); //BrowserPreview.set_Text(WikiApi.parseText(wikiText,true)); //BrowserCurrent.set_Text(WikiApi.html(pageToLoad)); }); }
public void saveCurrentPage() { var currentPage = WikiPage_TextBox.get_Text(); if (WikiApi.loggedIn().isFalse()) { StatusLabel.set_Text("You need to be logged in to save pages").textColor(Color.Red); var credential = ascx_AskUserForLoginDetails.ask(); if (credential.notNull()) { WikiApi.login(credential.UserName, credential.Password); if (WikiApi.loggedIn()) { StatusLabel.set_Text("You are now logged in as user: {0}".format(credential.UserName)).textColor(Color.DarkGreen); } else { StatusLabel.set_Text("Login failed for user: {0}".format(credential.UserName)).textColor(Color.Red); } } } else { StatusLabel.set_Text("saving page {0} ".format(currentPage)).textColor(Color.Black); // save content WikiApi.save(currentPage, WikiTextEditor.get_Text()); // reload content and show it var wikiText = WikiApi.wikiText(currentPage); BrowserPreview.open("about:blank"); //BrowserPreview.set_Text(WikiApi.parseText(wikiText,true)); BrowserCurrent.set_Text(WikiApi.html(currentPage)); StatusLabel.set_Text("Page {0} saved".format(currentPage)).textColor(Color.DarkGreen); } }
public WikiPedia(IVkApi vkApi, WikiApi wikiApi) { _vkApi = vkApi; _wikiApi = wikiApi; }
public void TestInstantiation() { Assert.IsTrue(WikiApi.IsValidWikiUrl("https://www.wikipedia.org")); Assert.IsFalse(WikiApi.IsValidWikiUrl("255.255.255.255")); Assert.IsFalse(WikiApi.IsValidWikiUrl("www.google.com")); }
public TriviaManagementTester() { InitializeComponent(); t = new TriviaManagement(); w = new WikiApi(); }