Wikia

RuneScape Wiki

Image optimisation bot/Source

Discuss0
25,202pages
on this wiki

< User:Image optimisation bot | Redirected from User:PNGOptimisationBot/Source

This page links to the 2 source code files for Image optimisation bot.

MediaWiki.java Edit

MediaWiki.java is the wiki bot framework for Java written by A proofreader and required by the bot to function. It is released under the GPLv3.

The package for this file is org.mediawiki. Make sure you save this file to org/mediawiki/MediaWiki.java on your local filesystem if you download it. (That is, create the folder 'org', then 'mediawiki' inside it, then save the file in 'mediawiki').

ImageOptimisationBot.java Edit

ImageOptimisationBot.java is the main code file for Image optimisation bot, written by A proofreader. It is released under the GPLv3.

The package for this file is com.wikia.runescape. Make sure you save this file to com/wikia/runescape/ImageOptimisationBot.java on your local filesystem if you download it.

Tools required Edit

In addition to the two compiled Java source files, the following tools are required:

  • OptiPNG (or your Linux distribution's optipng package);
  • advdef and advpng of the AdvanceCOMP project (or your Linux distribution's advancecomp package);
  • jpegoptim (or your Linux distribution's jpegoptim package);
  • gifsicle (or your Linux distribution's gifsicle package);
  • the Java 2 Standard Edition Development Kit (JDK), or your distribution's choice of Java Virtual Machine. Generally, on Windows, you have to download the JDK; on Linux, gcj will be available, as well as openjdk-7-jre; on Mac OS X, Apple provides the Java Development Kit.

Installation instructions are found on the respective projects' pages. Please make sure that the three tools are in the PATH before running the bot.

Compiling Edit

As this bot has 2 files, you can use your favourite Java IDE to import and compile the files, or you can use javac on the two files' paths:

javac org/mediawiki/MediaWiki.java com/wikia/runescape/ImageOptimisationBot.java

If using the javac command, it needs to be used in the folder containing 'org' and 'com'. For example, if you saved the two files as

/home/me/wikibots/imgopt/org/mediawiki/MediaWiki.java  (on Linux)
/home/me/wikibots/imgopt/com/wikia/runescape/ImageOptimisationBot.java  (on Linux)
C:\Users\Me\Wikibots\ImgOpt\org\mediawiki\MediaWiki.java  (on Windows)
C:\Users\Me\Wikibots\ImgOpt\com\wikia\runescape\ImageOptimisationBot.java  (on Windows)

you would use this command before javac to change to the correct directory:

cd /home/me/wikibots/imgopt  (on Linux)
CD C:\Users\Me\Wikibots\ImgOpt  (on Windows)

Configuration Edit

This bot uses a configuration file to do its work. Its location is $HOME/.imgoptbot.conf. ($HOME is going to be /home/youruser on Unix, /Users/You on Mac OS, and C:\Documents and Settings\You or C:\Users\You on Windows.) Here is a brief description of each configuration directive:

  • Wiki=runescape.wikia.com (this is the domain of the wiki to work on)
  • RunInterval=3600 (this is the number of seconds to wait between reads of the RequestPage)
  • LoginName=Image optimisation bot
  • LoginPassword=NotWritingItHere
  • BlockedFileRegex=^File:GEM[HV] (this is a regular expression, in the format accepted by java.util.regex.Pattern, to avoid optimising if the full name of a page matches it)
  • BlockedPageRegex=\\{\\{(Template:)?([Ss]d|[Aa]nti-aliased|[Tt]rans(parency)?|[Tt]ranslucency|[Ii]nterfering[ _]combat|[Ii]nventory[ _]shadow|[Ss]eparate|[Oo]bfile|[Cc]leanup[ _]image|[Gg]reater[ _]detail|[Ll]ighting[ _]detail)\\}\\} (this is a regular expression, in the format accepted by java.util.regex.Pattern, to avoid optimising if the content of the file's page matches it; in this case, the templates from the RuneScape:Image Maintenance page that can apply to PNG images are preloaded)
  • PNGMinimumCompressionRatio=10 (optional, defaults to 0; this is the percentage of an original PNG file's size that must be cut down for a new recompressed version to be re-uploaded to the wiki)
  • JPEGMinimumCompressionRatio=99 (optional, defaults to 0; this is the percentage of an original JPEG file's size that must be cut down for a new recompressed version to be re-uploaded to the wiki)
  • GIFMinimumCompressionRatio=0 (optional, defaults to 0; this is the percentage of an original GIF file's size that must be cut down for a new recompressed version to be re-uploaded to the wiki)

Running Edit

The bot can then be launched from the command line, using this command in the correct directory:

java com.wikia.runescape.ImageOptimisationBot

Logging to a file Edit

If you wish to log to a file, and are running Windows XP, Unix, Linux or Mac OS X, you can start the bot with this command instead:

java com.wikia.runescape.ImageOptimisationBot 2>> log.log

Around Wikia's network

Random Wiki