HomePhabricator

[FIX] Allow dynamic interwiki links

Tags
None
Referenced Files
None
Subscribers
None

Description

[FIX] Allow dynamic interwiki links

This uses the 'interwikimap' siteinfo to determine the Site an
interwiki prefix is redirecting to. A Family supports 'from_url' which
returns the 'code' (an entry in 'langs') to which the URL belongs to.
If no code of that family does support that URL 'None' is returned.

Because both the test and wikipedia family support the URL
test.wikipedia.org, the test family returns always None so it chooses the
wikipedia family. This is then consistent with the test wikidata instance
which is in the wikidata family and not in a separate test family.

To get the family for a specific URL it might need to iterate through all
families, which are loaded in the process. Each site has a local cache which
holds the Site represented by a specific interwiki prefix. There is also a
global cache which stores the family name and code for each URL so that later
searches for the URL don't require to iterate through all families.

This also adds an parameter "url" to pywikibot.Site function which can
only be set when neither "code" nor "fam" are set.

The code used in 'nice_get_address' should be returned when the url is parsed
by 'from_url'. This also fixes all link tests so that the 'show_failures'
features could be removed.

It also changes the exception from Error in InvalidTitle, when there is
no title given and it has a namespace or no interwiki link. It also only
throws an InvalidTitle if an interwiki link links to a non local page
via a local interwiki link. Previously all interwiki links which
referred to it's own site wouldn't be allowed.

Change-Id: Iec4f32fdefde15b2330dbb191fb3bbb0d04803e2