Jump to content

API talk:Links

Add topic
From mediawiki.org
Latest comment: 5 years ago by Inductiveload in topic Not all external links shown?
[edit]

As the subject implies, I'm interested in getting the links on Wikipedia article provided a revision id, or possibly a date. Are there any thoughts on this? Rodricios (talk) 21:03, 18 June 2016 (UTC)Reply

I believe you'd have to go through API:Parse. The request would look something like this: https://en.wikipedia.org/w/api.php?action=parse&oldid=123456&prop=links
I don't think there's any direct way to get the links based on date, so you'd have to search the revisions for the date you want, get the revision id, then provide that as the "oldid" value. Robin Hood  (talk) 05:05, 19 June 2016 (UTC)Reply
[edit]

I created a sandbox page on w:User:CXuesong/sandbox/1, and used prop=links to get all the linked pages. Note the sequence is ordered alphabetically here. Then I used generator instead. The result is unordered. As I have told in API talk:Search, for certain generators, they have "index" property in the JSON response and I can reorder the returned items, but for this case, there is no such property.

I'm not seeking for a change on the API. I just wonder, can I assume that the items in the pages property in the JSON response of generators are inherently unordered? (After all, it's a dictionary.) Because I have used generator=recentchanges to enumerate all the pages that have been changed recently, and I used to assume they are ordered chronologically. Was I wrong at that time? CXuesong (talk) 03:24, 21 October 2017 (UTC)Reply

[edit]

When I look at https://en.wikipedia.org/w/api.php?action=query&prop=links&titles=Purdue%20University&pllimit=max I see a number of links to pages that do not appear on https://en.wikipedia.org/wiki/Purdue_University


The most obvious are a number of links to other Universities, such as the Columbia University and Colorado State University. Where are these coming from? Jdfoote (talk) 21:11, 3 March 2020 (UTC)Reply

Links are defined as both direct links in the body of the article itself, as well as links found in templates that are embedded in the article. So, using the two you mentioned, both can be found linked at the very bottom of the article in the auto-hidden footer "Links to related articles", then either "Association of American Universities" or "Universities Research Association". Robin Hood  (talk) 21:17, 3 March 2020 (UTC)Reply
[edit]

When I try to get the links of a file on Commons with a view to extracting an Internet Archive URL, I find the IA link isn't included in the results: https://commons.wikimedia.org/w/api.php?action=query&format=json&prop=extlinks&titles=File%3AThe_Works_of_Arthur_Murphy_-_Volume_4.djvu&ellimit=100

However, the links from the Creator template are all shown. What am I doing wrong here? Inductiveload (talk) 21:26, 23 October 2020 (UTC)Reply

The IA template is using an Interwiki link to link to the Internet Archive instead of a direct external link. So, to find it, you'd have to use the iwlinks module instead of extlinks, like this: https://commons.wikimedia.org/w/api.php?action=query&format=jsonfm&prop=iwlinks&titles=File%3AThe_Works_of_Arthur_Murphy_-_Volume_4.djvu&iwlimit=100. If you look for "iarchive" in the results, that's the link you want.
The obvious problem there is that you have no guarantee that people are using the IA template. They could be specifying the address as a normal http link instead. So, you'd probably want to check both at the same time with this query: https://commons.wikimedia.org/w/api.php?action=query&format=jsonfm&prop=extlinks|iwlinks&titles=File%3AThe_Works_of_Arthur_Murphy_-_Volume_4.djvu&ellimit=100&iwlimit=100
There's also API:Parsing wikitext, which can do some things that property queries can't. I don't think it would do anything useful in this instance, but I don't use it myself, so you may want to poke around it a little to see if there's anything useful there. Robin Hood  (talk) 22:55, 23 October 2020 (UTC)Reply
Thank you very much! I was parsing the wikitext before and looking for the right href, but this is a much better solution! Inductiveload (talk) 23:25, 23 October 2020 (UTC)Reply