jwbf icon indicating copy to clipboard operation
jwbf copied to clipboard

Test if an article exist or not

Open Hunsu opened this issue 10 years ago • 12 comments

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.

Hunsu avatar Nov 30 '14 12:11 Hunsu

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?

eldur avatar Nov 30 '14 15:11 eldur

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

lorinczz avatar Nov 30 '14 16:11 lorinczz

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?

eldur avatar Nov 30 '14 19:11 eldur

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:

  • Why LIMIT is 50. MediaWiki can return up to 5000 results for bots. In the library we can't change it. I have a bot that make changes on articles that are in given category, the category contains more than 100 000 articles. The bot now will make a lot of request to the server.
  • Why are the save, get methods are syncronized? Two threads can save two diffents articles in the same time and this won't lead to any error.
  • Why there are methods that are coded like this:

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

Hunsu avatar Dec 06 '14 16:12 Hunsu

  • For the lack of documentation: I'm not very good in writing docs (see #22, #23, ...), but if you are, feel free to help us.
  • For the LIMIT: I've also thought about this. What do you think about to create a new issue about configurable limits?
  • For the other points: You are right, feels strange. Can you give me a hint where your last finding is?

eldur avatar Dec 07 '14 00:12 eldur

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

lorinczz avatar Dec 07 '14 00:12 lorinczz

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

eldur avatar Dec 07 '14 00:12 eldur

I mean this function:

public synchronized <T extends ContentProcessable> 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.

Hunsu avatar Dec 07 '14 09:12 Hunsu

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 avatar Dec 07 '14 11:12 eldur

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

bot.readDataOpt("ArticleName").isPresent()

eldur avatar Jan 07 '15 18:01 eldur

Why not create it as a function in MediaWikiBot?

Hunsu avatar Jan 07 '15 18:01 Hunsu

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
}

eldur avatar Jan 07 '15 19:01 eldur