Posts mit dem Label mediawiki werden angezeigt. Alle Posts anzeigen
Posts mit dem Label mediawiki werden angezeigt. Alle Posts anzeigen

Montag, 24. Mai 2010

How to upload files to a MediaWiki using JWBF

This little issue has been nagging me for a while, this is why I post it here hoping it will help others as well.

So if you want to
- upload images to your own (or somebody else's) MediaWiki
and you
- want to do it using java
and
- you happen to use the Java Wiki Bot Framework (aka jwbf)
then this one is for you:

String localPathToFile = "/home/klausbert/tmp/myTestImage.jpg";
String urlToWiki = "http://mydoma.in/wiki/";
String wikiUser = "klausbert";
String wikiPassword = "klausbertsPassword";
String descriptionText = "Some text to describe the image";

MediaWikiBot mwb = new MediaWikiBot(urlToWiki);
mwb.login(wikiUser, wikiPassword);
SimpleFile file = new SimpleFile(localPathToFile);
file.addText(descriptionText);
mwb.performAction(new FileUpload(file, mwb));

Of course you will need some imports and try-catches. But the code is the essence of what you need to upload the file.

Donnerstag, 12. März 2009

MediaWiki #if syntax

Whenever I work on our wiki I have to look up the #if syntax (esp. for the more complex cases) and just do not find the right page on mediawiki.org. So I use this page as my personal cheat sheet.javascript:void(0)

#if:
{{#if: | true | false}} → false
{{#if: string | true | false}} → true
{{#if: {{{TEMPLATEVAR|}}} | true | false}} → true if the TEMPLATEVAR has any value


#ifeq:
{{#ifeq: string1 | string2 | value if true (string1 == string2) | value if false (string1 != string2) }}
{{#ifeq:{{{TEMPLATEVAR|}}} | yes | ja | nein }}


The right page for documentation can be found here: http://www.mediawiki.org/wiki/Help:Extension:ParserFunctions