API talk:Lists

Latest comment: 3 months ago by DavidBrooks in topic Order of results in usercontribs list

rc_id parameterEdit

Would it be possible to add the column 'rc_id' to the recentchanges query report? [user:jldupont|Jean-Lou Dupont] 14:45, 10 July 2007 (UTC)Reply[reply]

log_id parameterEdit

Would it be possible to add the column 'log_id' to the logevents query report? [user:jldupont|Jean-Lou Dupont] 14:50, 10 July 2007 (UTC)Reply[reply]

Good idea. That way if polling every 2 minutes and a burst of 1000 changes come in, you can tell it the last id (or even unix timestamp) of the last change you received and continue polling from there, confident that you won't lose events.

LogEvents Bug for MW1.11 SVN trunkEdit

The response XML always returns 'logid="0"' Jean-Lou Dupont 21:08, 19 July 2007 (UTC)Reply[reply]

Filed a bug 10660. --Yurik 22:15, 22 July 2007 (UTC)Reply[reply]

Taking to longEdit

[1] takes very long on the first load. I guess this is performance issue. Bryan Tong Minh 21:03, 10 August 2007 (UTC)Reply[reply]

I think I know why: Title::makeTitle() is called for *separately* for *every* title when backlinks/templatelinks/embeddedin is used in generator mode. See here. I'm gonna try to fix that now. --Catrope 18:32, 10 September 2007 (UTC)Reply[reply]
Hmm, apparently that's not the problem. I'll post a list of SQL queries this request makes and have domas or another DB techie look at it. --Catrope 18:54, 10 September 2007 (UTC)Reply[reply]
I imported some of those templates from Commons and ran a test request against it:
 SQL:  /* ApiQueryBacklinks::run Catrope */ SELECT  tl_namespace,tl_title,page_id,page_namespace,page_title,page_is_redirect,page_is_new,page_counter,page_touched,page_latest,page_len FROM `templatelinks`,`page`  WHERE (tl_from=page_id) AND tl_namespace = '10' AND tl_title = 'PD-Layout' AND page_namespace IN ('10') ORDER BY tl_namespace, tl_title, tl_from LIMIT 11
SQL: SELECT /* ApiQueryInfo::execute Catrope */  pr_page,pr_type,pr_level,pr_expiry FROM `page_restrictions`  WHERE pr_page IN ('14','15','16','18','19','20','21','22','23','24')
When I ran EXPLAIN against these queries, only the templatelinks part of the first query mentioned using an index. I don't know if that's the problem, though, so I'll ask an expert. --Catrope 19:54, 10 September 2007 (UTC)Reply[reply]

Small bug in categorymember?Edit

Does "categorymember" work different from the others? When I try http://en.wikipedia.org/w/api.php?format=xmlfm&action=query&list=embeddedin&eilimit=20&eititle=Template:LGBTProject it returns exactly the same results as http://en.wikipedia.org/w/api.php?format=xmlfm&action=query&list=embeddedin&eilimit=20&eititle=LGBTProject

"categorymember" doesn't seem to be the same - http://en.wikipedia.org/w/api.php?format=xmlfm&action=query&list=categorymembers&cmlimit=20&cmcategory=Category:Compositions_by_Alexander_Glazunov returns nothing, while http://en.wikipedia.org/w/api.php?format=xmlfm&action=query&list=categorymembers&cmlimit=20&cmcategory=Compositions_by_Alexander_Glazunov returns the list of articles. -- SatyrTN 20:40, 18 September 2007 (UTC)Reply[reply]


Is there not an "action=query&list=allcategories"? Any plans for development? -- SatyrTN 03:18, 8 December 2007 (UTC)Reply[reply]

Request for redirect info in backlinks queryEdit


I see that the backlinks query can already filter results depending if a backlink is a redirect or not (with blfiterredir) but I don't see a way to see in the result if backlinks are actually redirect or not. Could it be added to the API ?

I need to retrieve all backlinks (recursively through redirects), so currently I call recursively the backlinks query and the redirect query. Retrieving the 2 informations in one query would be very useful for me to speed up requests ;)

I quickly looked at the code of the backlinks query and it seems simple to do (I may be overlooking things because I don't know how the API is working) :

  • In run(), call $this->addField('page_is_redirect'); if needed.
  • In extractRowInfo(), add something like $vals['redirect'] = intval($row->page_is_redirect);.

--NicoV 18:06, 4 January 2008 (UTC)Reply[reply]

Dude, just use api.php?action=query&generator=backlinks&prop=info --Catrope 22:04, 4 January 2008 (UTC)Reply[reply]

allpages and apprefixEdit


I am trying to use allpages with the apprefix parameter, but so far I have no results at all. Am I doing something wrong or is there a bug ?

Example: http://en.wikipedia.org/w/api.php?action=query&list=allpages&apprefix=Bal&apfrom=bal

Result: No pages at all

Edit: Also, is there a way to request all page titles containing a given word ?

--NicoV 20:06, 13 January 2008 (UTC)Reply[reply]

Ok, I got the answer: http://en.wikipedia.org/w/api.php?action=query&list=allpages&apprefix=Bal
--NicoV 17:56, 14 January 2008 (UTC)Reply[reply]

apprefix with namespaceEdit

Hello. I dont know if i am wrong, but we can't use namespace in prefix for the moment :

I would like to know if its possible to do something like that, because over request, the title param allow to use it, and it more usefull for transwiki tools, because we dont need to encode/decode the namespace.

-fr:user:bayo 19:06, 23 January 2008 (UTC)Reply[reply]

It would be very hard to do. It's probably easier if you just fetched the namespace list. --Catrope 21:40, 23 February 2008 (UTC)Reply[reply]

Fulltext SearchEdit

I would love to be able to use this, but it doesn't appear to work. The example isn't exactly functional either. [2]

Is this telling me that there are no articles on Wikipedia about Wikipedia?

Wikipedia uses the Lucene search engine, which isn't supported by the API yet. On wikis using MediaWiki's built-in search engine, list=search will work. --Catrope 21:38, 23 February 2008 (UTC)Reply[reply]

backlinks minus transcluded templatesEdit

I'm trying I get the list of all pages that link to w:PAX9, but minus the pages that only link through the commmonly-transcluded w:Template:Transcription factors. Can't seem to find the right combination of parameters here to do it. Suggestions? 08:12, 29 February 2008 (UTC)Reply[reply]

Just wanted to check again to see if anyone had any thoughts at all about this question. Or perhaps there is a better place to ask? 06:37, 4 March 2008 (UTC)Reply[reply]
You can try the mailing listmail:mediawiki-api--NicoV 16:01, 4 March 2008 (UTC)Reply[reply]


Hello. I would like to know if its possible to order this list by pageid, like Special:WhatLinkHere work ? Sure i can do it myself, but with it for exemple we can request only smallest or biggest id. Maybe it can be something common for pagelist request. Thanks. -fr:user:bayo 12:31, 30 March 2008 (UTC)Reply[reply]

Backlinks, embeddedin and imageusage are already sorted by page ID. --Catrope 13:34, 30 March 2008 (UTC)Reply[reply]
That's inexact, because the display is sort by namespace [3] (all categories are on the bottom, the id of the first one is smaller than the id of the last article). -fr:user:bayo 02:47, 2 April 2008 (UTC)Reply[reply]
Better example, look at the id and the position of the namespace 102 page in this short list [4] Bayo 10:26, 14 April 2008 (UTC)Reply[reply]


Can the API be used to find by which rangeblock an IP is blocked? --Beetstra 14:29, 10 April 2008 (UTC)Reply[reply]

Not yet, I'll work on that. --Catrope 14:51, 10 April 2008 (UTC)Reply[reply]
Let me expand on this. I am running unblockbot on IRC (channel #wikipedia-en-unblock). It would be great if the api could be polled for the rangeblock, would make life for the people watching that channel much easier. Thanks already! --Beetstra 15:04, 10 April 2008 (UTC)Reply[reply]
Similarly, but probably more difficult, autoblocks. I am not sure how they would need to be identified, but also that would be great. Thanks again! --Beetstra 15:13, 10 April 2008 (UTC)Reply[reply]
Alright, this is where we stand now: anyone trying to unblock an IP that's part of a range block will be informed which range it's part of (you need unblock rights, though). Also, list=blocks can be used to find out whether a certain IP was autoblocked (see the bkuser and bkprop=flags parameters). Looking up whether a certain IP is rangeblocked without trying to unblock it is not yet implemented, please request it here (don't forget to set Component to API) if you want it. --Catrope 14:37, 11 April 2008 (UTC)Reply[reply]
Those are the functions that I already have. What I would like to have is a function to find the range in which it is, but it is merely a service to the admins who are on IRC watching the unblock requests. They can do the same routine as you describe, but if the bot were to say which range the IP is affected by would result in less clicks and quicker unblock of the users. I'll consider filing a request, thanks anyway. --Beetstra 15:44, 11 April 2008 (UTC)Reply[reply]

allcategories limited to 500Edit

"allcategories / ac" can return at most 500 categories (MediaWiki 1.12.0). What is the recommended technique for obtaining the full category list? Maiden taiwan 17:53, 10 April 2008 (UTC)Reply[reply]

Never mind, I found the answer at API:Query#Continuing_queries. Maiden taiwan 17:56, 10 April 2008 (UTC)Reply[reply]


Not sure if this is a bug or something I miss, but it may need clarification:

When getting category information, you can use:

But, when asking for the unblock info:

then the first does not seem to work, while the second one does .. this got me puzzled for quite some time, is there something that I missed? --Beetstra 17:59, 25 April 2008 (UTC)Reply[reply]

It is kind of arbitrary. The difference is that user names currently aren't rewritten (like Foo_bar is rewritten to Foo bar), I'll fix that. --Catrope 13:15, 26 April 2008 (UTC)Reply[reply]
Fixed in r33908. --Catrope 15:34, 26 April 2008 (UTC)Reply[reply]
Thanks! --Beetstra 14:08, 13 May 2008 (UTC)Reply[reply]

Backlinks from Template:Edit

Hi all, I've been trying to use the API to find backlinks: First example "What are the pages linked to Einstein" ?

OK, works fine.

Now "What are the pages using the Template:Infobox_Scientist" ?

Hum, it returns no data; And (no namespace)

returns a few 'Talks' pages . Whereas I expected much more pages: See w:en:Special:WhatLinksHere/Template:Infobox_Scientist

Is it a bug ? I'm I wrong  ? Thank you for your answer --Plindenbaum 14:04, 2 July 2008 (UTC)Reply[reply]

got an anwser on the mailing list, the correct url is http://en.wikipedia.org/w/api.php?action=query&list=embeddedin&eititle=Template:Infobox_Scientist --Plindenbaum 16:59, 5 August 2008 (UTC)Reply[reply]

Articles from several categoriesEdit

Is there any way to get all members of several categories with one request? I.e. I can get parameters needed for several normal pages with request like this, but I cannot do something like that. As far as I know there are no parameter like "prop=categorymembers". Why not? || WASD 14:10, 17 July 2008 (UTC)Reply[reply]

Getting the members of 500 categories at once is too hard on the database, unless we sort by category first, which makes it kind of useless. --Catrope 18:57, 6 September 2008 (UTC)Reply[reply]

Watchlist bugEdit

If I do this query:


I get a list of articles whose most recent edit fell in that time period. About 26 with revision ID's climbing from 241956897 to 241992028. So far so good.

But if I want to see if there are articles on my watchlist that haven't been edited in a long time something odd happens. I tried to make a kind of test case:


This should fetch articles last changed between 20 August 2008 and 28 August 2008. It turns out that I have at least one article that fits on my watchlist. (I haven't looked to see if there are more.) It was last edited on 25 August 2008 and it's revision ID is 234013275. However, an empty list is returned.

I've had a look at the source code but it just does:

$this->addWhereRange('rc_timestamp', $dir, $start, $end);

Which doesn't exclude the page, and neither do the other conditions as far as I can tell. Does anyone know what causes this bug? 17:08, 1 October 2008 (UTC)Reply[reply]

It's technically not a bug. If you look closely, you'll see the page also disappeared from Special:Watchlist, because data about watched articles is fetched from the recentchanges table, which doesn't contain changes older than $wgRCMaxAge. Of course the full list of watched pages (also accessible through a link on Special:Watchlist) should be available through the API as well, but we already have a bug for that. --Catrope 17:57, 1 October 2008 (UTC)Reply[reply]

That's what I'm using now: reading the full watchlist and querying the touch date etc. in small batches. But I think this should work as well, as I think things can be done more efficiently when the API implements this directly. I don't know if MySQL allows you to append tables to each other in a query, but perhaps the API could use some kind of fallback query in the case that the start timestamp is too early. Anyway, thanks for the quick reply, because I was really puzzled there for a bit. Now I know why it didn't work, I'll know when to use and when not to use the watchlist API. Thanks, 20:40, 1 October 2008 (UTC)Reply[reply]

categorymembers expansionEdit

from a question over at Wikipedia willage pump (technical): is is possible to tweak the categorymembers query to let 'cmstart' and 'cmend' use sort order as well as timestamps? the effect would be to get a short list of category member pages starting at page A and ending at page B according to the category sorting. this would be somewhat more meaningful than using timestamps. in fact, I'm really not sure what timestamp is being referred to here. the date the pages were last edited? the date the pages were added to the category? I suppose I could figure that out by experimenting, though... --Ludwigs2 08:33, 15 October 2008 (UTC)Reply[reply]

I don't exactly know what the timestamp refers to either. cmstart and cmend are parameters of type timestamp, so they don't allow other types of input. Also, changing the semantics of existing parameters would break code actually using cmstart or cmend in combination with cmsort=sortkey. New parameters to start/end based on sortkey could be added, of course; they could even replace cmcontinue. To get this fixed, please provide a link to the request of file a bug at BugZilla. --Catrope 14:24, 15 October 2008 (UTC)Reply[reply]
ok, I've filed something over at bugzilla. --Ludwigs2 19:30, 15 October 2008 (UTC)Reply[reply]

several key wordsEdit


How can I make a query on several key words avoiding to launch the API call each time?

I tried "action=query&list=search&srsearch=word1,_word2" but it does not work... Is it possible?

I mean I want to search the article with one of the 2 key words (or both) but not the articles with both words only.

Thank you


Use this character: | (I don't know its name) instead of comma, like


Winston 10:42, 13 July 2009 (UTC)Reply[reply]

Global rightsEdit

Can I find lists of users which have global rights somewhere in the API? I don't see it. I mean queries like:


But then for global groups (global rollbacker, etc.). Thanks. --Beetstra 12:50, 24 April 2009 (UTC)Reply[reply]

Don't know about you, but that sample query there returns an error for me. —Anonymous DissidentTalk 15:11, 24 April 2009 (UTC)Reply[reply]
Nope, seems to work, for clarity, I have removed the formatting -> http://en.wikipedia.org/w/api.php?action=query&list=allusers&augroup=sysop&aulimit=500 .. gives the first 500 sysops on en. --Beetstra 12:48, 25 April 2009 (UTC)Reply[reply]

API internal errorEdit

Problem also reported on MediaWiki API mailing list : a few hours ago, some queries lead to API internal errors. For example, this query generates an internal error Exception Caught: Internal error in ApiResult::setElement: Attempting to add element backlinks=500, existing value is 500. It's related to gbllimit=max parameter : removing it or replacing it with a fixed value works. --NicoV 11:51, 28 July 2010 (UTC)Reply[reply]

get sizes of diffs?Edit

I wonder the best way to get sizes of diffs resulting from a usercontribs list query, sort of like the ones seen in copyright investigations (example). The sizes like (+1583) make it easy to tell large edits from small ones without having to examine them individually. The only way I can think of to get these numbers is to run multiple queries, get the parent revisions from the usercontribs, then run revision queries on the parent revisions, and compare the sizes. That seems somewhat costly and it would be good if there was a way to do it with a generator. Am I missing something? Is it worth writing an RFE? Thanks for any advice. 05:42, 28 December 2010 (UTC)Reply[reply]

Orphan pagesEdit

Is there a way of getting a list of orphan pages better than simply list=allpages and then checking list=backlinks on each on them? - 13:49, 17 October 2013 (UTC)Reply[reply]

Maybe API:Querypage with Lonelypages ? https://en.wikipedia.org/w/api.php?action=query&list=querypage&qppage=Lonelypages&qplimit=10 --NicoV (talk) 14:01, 17 October 2013 (UTC)Reply[reply]
Wow, that was quick! Exactly what I wanted. Thanks - 14:07, 17 October 2013 (UTC)Reply[reply]

More than one namespace for API query listEdit

I figuered out that more than one namespace can be involved using pipe as delmiter, e.g. for the embeddedin API using "&einamespace=5|10". I haven't found this in the documentation. I think this applies to many API functions. Where could be an appropriate place to document this? --Cactus26 (talk) 06:44, 20 January 2014 (UTC)Reply[reply]

exclude some pages belonging to a particular categoryEdit

Is it possible to exclude some pages belonging to a particular category? Farvardyn (talk) 08:02, 9 May 2020 (UTC)Reply[reply]

Order of results in usercontribs listEdit

I realize the API descriptions aren't fully detailed specs, but the API:Usercontribs page strongly suggests that the results, assuming default settings, are in reverse timestamp order. In reality (on en.wikipedia.org) the primary sort key is username in reverse order, and timestamp is second.

In general, to retrieve all contribs from more than one user in time order, instead of streaming them I'll have to cache them all and sort (boo) (yes, I could cache all but one and interleave the last). I could interleave separate one-user streams client-side, but that's putting extra work on the servers instead. But even that wouldn't work with a uciprange parameter. In particular, assuming a /64 CIDR range is all the same user, I don't know the names in advance, so they have to be all sorted client-side. Example from what is clearly one user:


Fortunately such lists are usually mercifully small: currently 71 total in this example.

I don't know why I only just noticed this. Is it a bug? Can it be fixed? Should it be? (I'm familiar with the danger of changing previousy unspecified but reliable behavior in legacy code, which would apply to my cache-all-but-one solution above). DavidBrooks (talk) 19:10, 26 November 2022 (UTC)Reply[reply]

It occurred to me to look at phabricator and I guess I wasn't the first to ask about this. Currently task T180153 is blocked because it's too complex. DavidBrooks (talk) 21:30, 28 November 2022 (UTC)Reply[reply]
Return to "Lists" page.