Wikifetch: only show "possible results" in disambiguation pages if parsing succeeds

This commit is contained in:
James Lu 2017-01-27 17:25:43 -08:00
parent d1eea2a0a4
commit 9f1f04d25c

View File

@ -177,20 +177,22 @@ class Wikifetch(callbacks.Plugin):
tree.xpath('//table[@id="setindexbox"]') or \ tree.xpath('//table[@id="setindexbox"]') or \
tree.xpath('//div[contains(@class, "disambig")]') # Wikia (2017-01-27) tree.xpath('//div[contains(@class, "disambig")]') # Wikia (2017-01-27)
if disambig: if disambig:
reply += format(_('%u is a disambiguation page. '), addr)
disambig = tree.xpath('//div[@id="bodyContent"]/div/ul/li') disambig = tree.xpath('//div[@id="bodyContent"]/div/ul/li')
# Hackishly bold all <a> tags
r = [] disambig_results = []
for item in disambig: for item in disambig:
for link in item.findall('a'): for link in item.findall('a'):
if link.text is not None: if link.text is not None:
# Hackishly bold all <a> tags
link.text = "&#x02;%s&#x02;" % link.text link.text = "&#x02;%s&#x02;" % link.text
item = item.text_content().replace('&#x02;', '\x02') item = item.text_content().replace('&#x02;', '\x02')
# Normalize and strip whitespace, to prevent newlines and such # Normalize and strip whitespace, to prevent newlines and such
# from corrupting the display. # from corrupting the display.
item = utils.str.normalizeWhitespace(item).strip() item = utils.str.normalizeWhitespace(item).strip()
r.append(item) disambig_results.append(item)
reply += format(_('%u is a disambiguation page. ' if disambig_results:
'Possible results include: %L'), addr, r) reply += format(_('Possible results include: %L'), disambig_results)
# Catch talk pages # Catch talk pages
elif 'ns-talk' in tree.find("body").attrib['class']: elif 'ns-talk' in tree.find("body").attrib['class']: