[Mediawiki-api] blredirect

Roan Kattouw roan.kattouw at home.nl
Mon Feb 25 14:45:26 UTC 2008


As of r31260 [1], the blredirect, eiredirect and iuredirect parameters, 
for the backlinks, embeddedin and imageusage modules respectively, are 
now available. Setting these parameters will make the API list links 
through redirects as well, à la Special:Whatlinkshere. Since this is not 
really useful for embeddedin (redirects hardly ever embed pages) or for 
imageusage (image redirects haven't been implemented yet), I'll use 
blredirect in the example below.

api.php?action=query&list=backlinks&bltitle=Foo&blredirect&bllimit=3 
will generate the following output:

<?xml version="1.0" encoding="utf-8"?>
<api>
  <query-continue>
    <backlinks blcontinue="0|Foo|44|72" />
  </query-continue>
  <query>
    <backlinks>
      <bl pageid="36" ns="0" title="Test" />
      <bl pageid="44" ns="0" title="Redir" redirect="">
        <redirlinks>
          <bl pageid="34" ns="0" title="Bar" />
          <bl pageid="45" ns="0" title="Blah" />
          <bl pageid="54" ns="0" title="Main Page" />
        </redirlinks>
      </bl>
      <bl pageid="57" ns="0" title="New page" />
    </backlinks>
  </query>
</api>

This means [[Test]] and [[New page]] link to [[Foo]], while [[Bar]], 
[[Blah]] and [[Main Page]] link to [[Redir]], which in turn redirects to 
[[Foo]]. Note that bllimit=3 applies both to the first level (three 
pages linking to [[Foo]] are listed) and the second level (three pages 
linking to redirects to [[Foo]] are listed) separately. Because of this, 
bllimit is capped at 250 (2500 for bots and sysops) if blredirect is set.

We continue the request with:
api.php?action=query&list=backlinks&blcontinue=0|Foo|44|72&blredirect&bllimit=3

<?xml version="1.0" encoding="utf-8"?>
<api>
  <query>
    <backlinks>
      <bl pageid="44" ns="0" title="Redir" redirect="">
        <redirlinks>
          <bl pageid="72" ns="0" title="Dummy1" />
        </redirlinks>
      </bl>
      <bl pageid="57" ns="0" title="New page" />
      <bl pageid="71" ns="0" title="Redir2" redirect="">
        <redirlinks>
          <bl pageid="72" ns="0" title="Dummy1" />
        </redirlinks>
      </bl>
    </backlinks>
  </query>
</api>

Because the list of links to [[Redir]] wasn't finished yet, the continued request starts there, and lists [[New page]] again.

Of course, list=backlinks behaves exactly the way it used to when blredirect is not set, so this is not a breaking change.

Roan Kattouw (Catrope)

[1] http://svn.wikimedia.org/viewvc/mediawiki?view=rev&revision=31260





More information about the Mediawiki-api mailing list