Java library to call Mediawiki API described at http://www.mediawiki.org/wiki/API:Main_page
Maven dependency
<!-- Java library to call Mediawiki API described at http://www.mediawiki.org/wiki/API:Main_page http://mediawiki-japi.bitplan.com/index.php/Main_Page -->
<dependency>
<groupId>com.bitplan</groupId>
<artifactId>mediawiki-japi</artifactId>
<version>0.2.3</version>
</dependency>
Current release at repo1.maven.org
git clone https://github.com/WolfgangFahl/Mediawiki-Japi
cd Mediawiki-Japi
mvn install
See also Examples on the Mediawiki-Japi Wiki
http://www.mediawiki.org/wiki/API:Query#Sample_query
Mediawiki wiki=new Mediawiki("http://en.wikipedia.org");
String content=wiki.getPageContent("Main Page");
/**
* http://www.mediawiki.org/wiki/API:Query#Sample_query
* http://en.wikipedia.org/w/api.php?action=query&prop=revisions&rvprop=content&titles=Main%20Page&format=xml
* @throws Exception
*/
@Test
public void testSampleQuery() throws Exception {
Mediawiki wiki=new Mediawiki("http://en.wikipedia.org");
String content=wiki.getPageContent("Main Page");
assertTrue(content.contains("Wikipedia"));
}
http://www.mediawiki.org/wiki/API:Login
Login login=wiki.login("scott","tiger");
wiki.logout();
/**
* test Login and logout
* see <a href='http://www.mediawiki.org/wiki/API:Login'>API:Login</a>
* @throws Exception
*/
@Test
public void testLogin() throws Exception {
WikiUser wuser=WikiUser.getUser("mediawiki_org");
Login login=wiki.login(wuser.getUsername(),wuser.getPassword());
assertEquals("Success",login.getResult());
assertNotNull(login.getLguserid());
assertEquals(wuser.getUsername(),login.getLgusername());
assertNotNull(login.getLgtoken());
wiki.logout();
}
This is a semi-automatic process. The resulting java code needs to be adapted to be workable. For a start 18 Java classes have been generated that allow some 19 JUnit tests to pass (to a total of 43 including the 24 unit tests supplied with Wiki.java).