-
-
Notifications
You must be signed in to change notification settings - Fork 31
Examples
fastily edited this page Mar 25, 2018
·
9 revisions
- Clone the jwiki starter pack with
git clone https://github.com/fastily/jwiki-starter.git
- Make changes to
JwikiExample.java
undersrc/main/java/jwikistarter/
- Have fun!
// Logs in to the English Wikipedia (you must have an account for this to work).
wiki.login("<YOUR_USERNAME>", "<YOUR_PASSWORD>")
// Test edits Wikipedia:Sandbox.
wiki.edit("Wikipedia:Sandbox", "Some test text", "Edit Summary");
// Uploads a file. You need to have an autoconfirmed/confirmed account and be logged in.
wiki.upload(Paths.get("<PATH_TO_YOUR_TEST_FILE>"), "<TITLE_TO_UPLOAD_FILE_TO>", "This is a test", "test summary");
// Gets the text of the main page and prints it.
System.out.println(wiki.getPageText("Main Page"));
// Gets the author of the Main Page and prints it
System.out.println(wiki.getPageCreator("Main Page"));
// Gets the categories on the Main Page and prints them
System.out.println(wiki.getCategoriesOnPage("Main Page"));
// Gets all wiki-links on a page (GitHub) and prints them
System.out.println(wiki.getLinksOnPage("GitHub"));
// Gets all wiki-links pointing to the the Stack Overflow page and prints them
System.out.println(wiki.whatLinksHere("Stack Overflow"));
// Check if a page (GitHub) exists and print true/false.
System.out.println(wiki.exists("GitHub"));
// Uses an efficient multi-query to check if the following pages exist, and then prints the ones that do.
System.out.println(MQuery.exists(wiki, true, FL.toSAL("Stack Overflow", "BlahBlahBlahDoesNotExist", "Main Page"));
// Gets the first paragraph of the Stack Overflow page and prints it.
System.out.println(wiki.getTextExtract("Stack Overflow"));
// Gets 5 random articles (main namespace) on Wikipedia and print the result.
System.out.println(wiki.getRandomPages(5, NS.MAIN));