Difference between revisions of "Examples"
Jump to navigation
Jump to search
(→Intro) |
(→Intro) |
||
Line 5: | Line 5: | ||
* [http://mediawiki-japi.bitplan.com/mw1_23/api.php Version 1.23 API help] | * [http://mediawiki-japi.bitplan.com/mw1_23/api.php Version 1.23 API help] | ||
* [http://mediawiki-japi.bitplan.com/mw1_24/api.php Version 1.24 API help] | * [http://mediawiki-japi.bitplan.com/mw1_24/api.php Version 1.24 API help] | ||
+ | * [https://en.wikipedia.org/w/api.php current API help] | ||
== API usage examples == | == API usage examples == |
Revision as of 07:51, 5 January 2015
Intro
Depending on your version of Mediawiki you'll get different API details and help pages:
API usage examples
Sample query:get a single page
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"));
}
login/logout
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();
}
Edit
https://www.mediawiki.org/wiki/API:Edit
wiki.login("scott","tiger");
wiki.edit("Test Page 1","new content of test page 1","Summary for this edit");