Menu

Tree [f09e96] master /
 History

HTTPS access


File Date Author Commit
 src 2014-11-20 eldurloki eldurloki [f09e96] Improved Windows testsupport
 .checkstyle 2013-03-03 eldurloki eldurloki [a75662] Enable checkstyle plugin
 .gitattributes 2014-11-03 eldurloki eldurloki [d66f6f] Enabled line ending normalization
 .gitignore 2014-02-08 eldurloki eldurloki [280678] Runtime version detection rewritten
 .rsyncSourceForge.sh 2013-05-26 eldurloki eldurloki [6047ff] Remove rsync dry run option
 .travis.yml 2013-05-22 Loki Loki [d96849] Create .travis.yml
 CHANGELOG.txt 2014-11-05 eldurloki eldurloki [da1a00] Reformated testdata, line endings and whitespace
 LICENCE.txt 2014-11-05 eldurloki eldurloki [da1a00] Reformated testdata, line endings and whitespace
 README.md 2014-10-03 eldurloki eldurloki [4068bb] Removed deprecated and unsed exception handler
 checkstyle.xml 2014-07-18 eldurloki eldurloki [8586ee] Improved readability and checkstyle conformance
 dependency.tree 2014-10-20 eldurloki eldurloki [45cd1f] Stabilized development version output and added...
 pom.xml 2014-11-05 eldurloki eldurloki [239886] Moved java8 doclint activation to a profile
 rsyncSourceForgeJavadoc.sh 2013-05-24 eldurloki eldurloki [531751] Enable and hide sourceforge uploader
 rsyncSourceForgeSnapshots.sh 2014-06-29 eldurloki eldurloki [913a54] Removed trailing whitespace

Read Me

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>2.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>3.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