Page MenuHomePhabricator

MediaWiki API is not returning blocks when start/end dates are set
Closed, InvalidPublic

Event Timeline

It also doesn't change if I change the date range from just 3 days to 90 days or over a full year.

DannyS712 subscribed.

Its because of the direction being used. By default its "older", i.e. start with the most recent block and work backwards
Your example uses lestart=2021-02-20T16:58:50.000Z&leend=2021-02-23T16:58:50.000Z which I guess is interpreted as
"Starting at February 20, go backwards in time/go in the older direction until February 23", which means
"Find all blocks that are older than/placed before February 20 and are also newer than/placed after February 23", which is an empty set.

You need to either flip the dates, or specify that the direction should be newer, like https://en.wikipedia.org/w/api.php?action=query&format=json&list=logevents&leaction=block/block&lelimit=max&lestart=2021-02-20T16:58:50.000Z&leend=2021-02-23T16:58:50.000Z&ledir=newer

It turns out there is an additional parameter "ledir" (assuming dir for "direction") and the default for it is "older". And if it's set to older then the _start date must be AFTER the end date_ which is very confusing.

Changing the direction from default and adding ledir=newer makes it work with a start date earlier than the end date.

https://en.wikipedia.org/w/api.php?action=query&format=json&list=logevents&leaction=block/block&leend=2021-03-29T16:58:50.000Z&lestart=2021-03-01T16:58:50.000Z&ledir=newer

Thanks to @Urbanecm for pointing out https://www.mediawiki.org/wiki/API:Logevents

@DannyS712 Thank you, you are right. Found out the same thing while talking with Urbanecm meanwhile. Hence the "duplicate" comment.

I looked into this and I noticed https://www.mediawiki.org/wiki/API:Logevents says that when ledir=older [the default, and confusingly lists the newest events first], then "lestart has to be later than leend". If it's newer, then it has to be the other way around.

https://en.wikipedia.org/w/api.php?action=query&format=json&list=logevents&leaction=block/block&lelimit=max&lestart=2021-02-20T16:58:50.000Z&leend=2021-02-23T16:58:50.000Z has no results, but https://en.wikipedia.org/w/api.php?action=query&format=json&list=logevents&leaction=block/block&lelimit=max&lestart=2021-02-20T16:58:50.000Z&leend=2021-02-23T16:58:50.000Z&ledir=newer works, and so does

The very good question is...why is this working in such a confusing way? It looks like it interprets all of the parameters in the opposite way than what I would expect it to. At least, the docs explained what happened well :).

Maybe we should add an error is such cases:
If start is before end, and direction is older, or start is after end, and direction is newer, fail with a warning to the user that they may have messed up

That’s a good idea Danny. I support.

Should probably be in ApiQueryBase::addTimestampWhereRange or addWhereRange instead of the specific ApiQueryLogEvents to warn on other suggest queries too

@Urbanecm I imagine most folks making the mistake expect "xxdir" to be a "sorted by," so likely misread "in which direction to enumerate" as "sort by" when it actually means "items move in this direction." Similar to if you're driving south, you'll pass the most-northern exit first.