Page MenuHomePhabricator

Pywikibot doesn't support the wmf interwiki prefix
Closed, ResolvedPublic

Description

Pywikibot doesn't support the wmf interwiki prefix, but the prefix works on wiki and is in the interwikimap (/w/api.php?action=query&format=json&meta=siteinfo&siprop=interwikimap).

An exception shouldn't be raised when the Page object is created based on working links in wikitext (e.g. [[:wmf:Terms of Use|Terms of Use]]).

test case
>>> site = pywikibot.Site('en', 'wikipedia')
>>> wmf_page = pywikibot.Page(site, 'wmf:Terms of Use')
>>> wmf_page.title()
Traceback (most recent call last):
  File "/shared/pywikipedia/core/pywikibot/page.py", line 6098, in parse
    newsite = self._site.interwiki(prefix)
  File "/shared/pywikipedia/core/pywikibot/site.py", line 963, in interwiki
    return self._interwikimap[prefix].site
  File "/shared/pywikipedia/core/pywikibot/site.py", line 709, in __getitem__
    raise self._iw_sites[prefix].site
  File "/shared/pywikipedia/core/pywikibot/site.py", line 659, in site
    self._site = pywikibot.Site(url=self.url)
  File "/shared/pywikipedia/core/pywikibot/__init__.py", line 1229, in Site
    code, fam = _code_fam_from_url(url)
  File "/shared/pywikipedia/core/pywikibot/__init__.py", line 1186, in _code_fam_from_url
    raise SiteDefinitionError("Unknown URL '{0}'.".format(url))
pywikibot.exceptions.SiteDefinitionError: Unknown URL 'https://foundation.wikimedia.org/wiki/$1'.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/shared/pywikipedia/core/pywikibot/tools/__init__.py", line 1744, in wrapper
    return obj(*__args, **__kw)
  File "/shared/pywikipedia/core/pywikibot/page.py", line 328, in title
    title = self._link.canonical_title()
  File "/shared/pywikipedia/core/pywikibot/page.py", line 5809, in canonical_title
    if self.namespace != Namespace.MAIN:
  File "/shared/pywikipedia/core/pywikibot/page.py", line 6205, in namespace
    self.parse()
  File "/shared/pywikipedia/core/pywikibot/page.py", line 6105, in parse
    .format(self._text, self._site, prefix, e))
pywikibot.exceptions.SiteDefinitionError: wmf:Terms of Use is not a local page on wikipedia:en, and the interwiki prefix wmf is not supported by Pywikibot!
Unknown URL 'https://foundation.wikimedia.org/wiki/$1'.
version
Pywikibot: [https] r-pywikibot-core.git (6d8ee14, g1, 2019/11/07, 16:25:26, ok)
Release version: 3.1.dev0
requests version: 2.12.4
  cacerts: /etc/ssl/certs/ca-certificates.crt
    certificate test: ok
Python: 3.5.3 (default, Sep 27 2018, 17:25:39)
[GCC 6.3.0 20170516]
Toolforge hostname: tools-sgebastion-08

Details

Related Changes in Gerrit:

Event Timeline

Kizule subscribed.

Made fix, patch coming:

C:\Users\Kizule\Desktop\development\pywikibot-core>python
Python 3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:21:23) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pywikibot
>>> site = pywikibot.Site('en', 'wikipedia')
>>> wmf_page = pywikibot.Page(site, 'wmf:Terms of Use')
>>> wmf_page.title()
'Terms of Use'
>>>

Change 550039 had a related patch set uploaded (by Zoranzoki21; owner: Zoranzoki21):
[pywikibot/core@master] Create family file for foundation wiki

https://gerrit.wikimedia.org/r/550039

Change 550039 merged by jenkins-bot:
[pywikibot/core@master] Create family file for foundation wiki

https://gerrit.wikimedia.org/r/550039

Patch merged, should works now. Closing as resolved.