Java Wiki Bot Framework is a library to maintain Wikis like Wikipedia based on MediaWiki.
Java Shell
Latest commit 2b5eb4b Jun 13, 2016 Leonard Brünings committed with Fix #61 FileUpload uses wrong input for GetApiToken
Failed to load latest commit information.
src Fix #61 FileUpload uses wrong input for GetApiToken Jun 29, 2016
.checkstyle Added possibility to get watchlist of another user Jan 6, 2015
.gitattributes Enabled line ending normalization Nov 3, 2014
.gitignore Runtime version detection rewritten Feb 9, 2014
.rsyncSourceForge.sh
.travis.yml disabled sudo for travis builds Jul 29, 2015
CHANGELOG.txt Reformated testdata, line endings and whitespace Nov 6, 2014
LICENCE.txt Reformated testdata, line endings and whitespace Nov 5, 2014
README.md
checkstyle.xml
dependency.tree Dependecy updates Aug 4, 2015
pom.xml Dependecy updates Aug 4, 2015
rsyncSourceForgeJavadoc.sh Enable and hide sourceforge uploader May 24, 2013
rsyncSourceForgeSnapshots.sh Removed trailing whitespace Jun 29, 2014

README.md

JWBF - JavaWikiBotFramework.

Build Status Coverage Status Maven Central

The Java Wiki Bot Framework is a library to retrieve data from and maintain MediaWiki-based wikis such as Wikipedia. It has packages that handle basic tasks (login, cookies, encoding, token management) so that you can write your wiki bot without being a MediaWiki API expert. JWBF requires JRE 1.7.

Code sample

  /**
   * Sample bot that retrieves and edits an article.
   */
  public static void main(String[] args) {
    MediaWikiBot wikiBot = new MediaWikiBot("https://en.wikipedia.org/w/");
    Article article = wikiBot.getArticle("42");
    System.out.println(article.getText().substring(5, 42));
    // HITCHHIKER'S GUIDE TO THE GALAXY FANS
    applyChangesTo(article);
    wikiBot.login("user", "***");
    article.save();
  }

  static void applyChangesTo(Article article) {
    // edits the article...
  }

Table of contents

Code sample | Developer resources | Getting started | Dependencies | Working with Wikimedia | More resources

Developer resources

Getting started

JWBF uses Maven to automatically resolve dependencies. To use Maven to start a new project, follow the Maven in Five Minutes tutorial. For a more detailed introduction, see Maven's Getting Started guide.

The Java Wiki Bot Framework is available from two repositories. For a more stable version of JWBF, use the most recent version in the RELEASES repository at Maven Central. For the development version, which will be most up-to-date, use the most recent version in the SNAPSHOTS repository at oss.sonatype.org.

Dependencies

Once you have started your project in Maven and have a pom.xml file for your bot's project, add the appropriate JWBF dependency to the <dependencies> section. When you build your project, JWBF and its own dependencies will be downloaded automatically.

From RELEASES:

<dependency>
  <groupId>net.sourceforge</groupId>
  <artifactId>jwbf</artifactId>
  <version>3.1.0</version>
</dependency>

If you want to use a different release of JWBF, find your desired version in RELEASES and change <version> to its listed title.

From SNAPSHOTS:

Add this to your <repositories> section:

<repository>
  <id>sonatype-nexus-snapshots</id>
  <name>Sonatype Nexus Snapshots</name>
  <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
  <snapshots>
    <enabled>true</enabled>
  </snapshots>
</repository>

Add this to your <dependencies> section:

<dependency>
  <groupId>net.sourceforge</groupId>
  <artifactId>jwbf</artifactId>
  <version>4.0.0-SNAPSHOT</version>
</dependency>

If you want to use a different snapshot of JWBF, find your desired version in SNAPSHOTS and change <version> to its listed title.

Examples

Here is one example of using JWBF to write a bot that can retrieve and edit an article on a desired wiki.

More Java examples (e.g. for queries) can be found at unit- and integration-test packages.

Working with Wikimedia

If you are working with Wikimedia sites, set an informative User-Agent header, because all Wikimedia sites require a HTTP User-Agent header for all requests.

//Creating a new MediaWikiBot with an informative user agent
HttpActionClient client = HttpActionClient.builder() //
  .withUrl("https://en.wikipedia.org/w/") //
  .withUserAgent("BotName", "1.0", "your Email or Maintainer UserName") //
  .withRequestsPerUnit(10, TimeUnit.MINUTES) //
  .build();
MediaWikiBot wikiBot = new MediaWikiBot(client);

See also