eldur / jwbf

Java Wiki Bot Framework is a library to maintain Wikis like Wikipedia based on MediaWiki.
http://jwbf.sourceforge.net/
Apache License 2.0
78 stars 33 forks source link

Test if an article exist or not #39

Open Hunsu opened 9 years ago

Hunsu commented 9 years ago

Is there any function to test if an article exist or not? I have looked to some bots code that I have found and to test if an article exist or not they do :

return !mw.getArticle(title).getText().isEmpty();

If an article is empty (but it exist) this will return false.

PS: This library has many functionalities but it's hard to figure out how to use it.

eldur commented 9 years ago

Sorry there is no function like this, but if you need such function take a look at GetRevision. This class maps absent revision to an empty article. Hope this helps?

Do you have ideas how to make it easier to use the functionalities?

lorinczz commented 9 years ago

Parse the missing field of API result and add exists getter to Article. Redirect information is available only at prop=info :(

eldur commented 9 years ago

Feels strange to get an article and then check if it is exists. Or?

btw: why do you need to know the difference between an empty or absent article?

Hunsu commented 9 years ago

Thanks I will look at it.

I think the library is missing documentation. I was using another library and that library have a function that return all the articles in in given category. It took me a lot of time to figure out how replace this function with this library.

I have also other questions:

public foo(Type bar){ ... return bar; }

eldur commented 9 years ago
lorinczz commented 9 years ago

To be able to use foo(bar) in expressions. Very useful.

eldur commented 9 years ago

do you mean this :wink: https://github.com/eldur/jwbf/search?q=foo

Hunsu commented 9 years ago

I mean this function:

public synchronized T getPerformedAction(T answer) { // TODO transform to throttled performAction(answer); return answer; }

We don't see what the method do. It's the first time I see a method written like this. We don't know what object was changed.

I will try to help when I have time and when I figure out how things work.

eldur commented 9 years ago

At the beginning of this project, immutability wasn't favored as now. So this method mutates the given answer and returns it, so it helps to save lines.

AnyRequest request = ... 
return b.getPerformedAction(request).getWhatever();

vs.

AnyRequest request = ... 
b.performAction(request)
return request.getWhatever();

See: http://en.wikipedia.org/wiki/Fluent_interface

eldur commented 9 years ago

I tend to close this issue, because the question could be answered with

bot.readDataOpt("ArticleName").isPresent()
Hunsu commented 9 years ago

Why not create it as a function in MediaWikiBot?

eldur commented 9 years ago

because it could save a request

MediaWikiBot bot = createNewBot();
if (bot.isArticlePresent("ArticleName")) { // first request to API
  doSomenthingWith(bot.readData("ArticleName")); // second request to API
} else {
  // whatever
}

vs.

MediaWikiBot bot = createNewBot();
Optional<SimpleArticle> result = bot.readDataOpt("ArticleName"); // the only request to API
if (result.isPresent()) {
  doSomenthingWith(result);
} else {
  // whatever
}