Russell Blau has submitted this change and it was merged.
Change subject: (bug 66403) enable redirect.py follows section links
......................................................................
(bug 66403) enable redirect.py follows section links
site.getredirtarget() didn't take into account sections and also
page.getRedirectTarget() didn't find the section. This is a
breaking change againts compat behaviour and causes redirect.py
to fail. This patch looks for the section in the redirect target.
Additional improvements:
- normalize title by api result
- title encoding for Exception messages
Change-Id: I4b6d7f32fc1ec79eb962fa8d21d283b4fe783fbf
---
M pywikibot/site.py
1 file changed, 15 insertions(+), 6 deletions(-)
Approvals:
Russell Blau: Verified; Looks good to me, approved
diff --git a/pywikibot/site.py b/pywikibot/site.py
index 971edc5..203bd7b 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -1438,17 +1438,26 @@
if "query" not in result or "redirects" not in
result["query"]:
raise RuntimeError(
"getredirtarget: No 'redirects' found for page %s."
- % title)
- redirmap = dict((item['from'], item['to'])
+ % title.encode(self.encoding()))
+ redirmap = dict((item['from'],
+ {'title': item['to'],
+ 'section': u'#' + item['tofragment']
+ if 'tofragment' in item and item['tofragment']
+ else ''})
for item in result['query']['redirects'])
+ if 'normalized' in result['query']:
+ for item in result['query']['normalized']:
+ if item['from'] == title:
+ title = item['to']
+ break
if title not in redirmap:
raise RuntimeError(
"getredirtarget: 'redirects' contains no key for page
%s."
- % title)
- target_title = redirmap[title]
+ % title.encode(self.encoding()))
+ target_title = u'%(title)s%(section)s' % redirmap[title]
if target_title == title or "pages" not in result['query']:
# no "pages" element indicates a circular redirect
- raise pywikibot.CircularRedirect(redirmap[title])
+ raise pywikibot.CircularRedirect(target_title)
pagedata = list(result['query']['pages'].values())[0]
# there should be only one value in 'pages', and it is the target
if self.sametitle(pagedata['title'], target_title):
@@ -1542,7 +1551,7 @@
raise Error(
u"token: Query on page %s returned data on page [[%s]]"
% (page.title(withSection=False, asLink=True),
- item['title']))
+ item['title']))
api.update_page(page, item)
pywikibot.debug(unicode(item), _logger)
return item[tokentype + "token"]
--
To view, visit
https://gerrit.wikimedia.org/r/138794
To unsubscribe, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I4b6d7f32fc1ec79eb962fa8d21d283b4fe783fbf
Gerrit-PatchSet: 5
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Alex S.H. Lin <alexsh(a)mail2000.com.tw>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Legoktm <legoktm.wikipedia(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Ricordisamoa <ricordisamoa(a)openmailbox.org>
Gerrit-Reviewer: Russell Blau <russblau(a)imapmail.org>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>