|
10 | 10 | from html.parser import HTMLParser |
11 | 11 | import logging |
12 | 12 | import re |
| 13 | +from urllib.parse import quote, unquote, urlparse |
13 | 14 |
|
14 | 15 | from requests import get |
15 | 16 |
|
16 | 17 | from sopel import plugin |
17 | 18 | from sopel.config import types |
18 | | -from sopel.tools.web import quote, unquote |
19 | 19 |
|
20 | 20 |
|
21 | 21 | LOGGER = logging.getLogger(__name__) |
@@ -321,26 +321,27 @@ def mw_image_description(server, image): |
321 | 321 | return desc |
322 | 322 |
|
323 | 323 |
|
324 | | -# Matches a wikipedia page (excluding spaces and #, but not /File: links), with a separate optional field for the section |
325 | | -@plugin.url(r'https?:\/\/([a-z]+(?:\.m)?\.wikipedia\.org)\/wiki\/((?!File\:)[^ #]+)#?([^ ]*)') |
| 324 | +# Matches a Wikipedia link (excluding /File: pages) |
| 325 | +@plugin.url(r'https?:\/\/([a-z]+(?:\.m)?\.wikipedia\.org)\/wiki\/((?!File\:)[^ ]+)') |
326 | 326 | @plugin.output_prefix(PLUGIN_OUTPUT_PREFIX) |
327 | 327 | def mw_info(bot, trigger, match=None): |
328 | 328 | """Retrieves and outputs a snippet of the linked page.""" |
329 | 329 | server = match.group(1) |
330 | | - query = unquote(match.group(2)) |
331 | | - section = unquote(match.group(3)) |
| 330 | + page_info = urlparse(match.group(2)) |
| 331 | + article = unquote(page_info.path) |
| 332 | + section = unquote(page_info.fragment) |
332 | 333 |
|
333 | 334 | if section: |
334 | 335 | if section.startswith('cite_note-'): # Don't bother trying to retrieve a snippet when cite-note is linked |
335 | | - say_snippet(bot, trigger, server, query, show_url=False) |
| 336 | + say_snippet(bot, trigger, server, article, show_url=False) |
336 | 337 | elif section.startswith('/media'): |
337 | 338 | # gh2316: media fragments are usually images; try to get an image description |
338 | 339 | image = section[7:] # strip '/media' prefix in pre-3.9 friendly way |
339 | 340 | say_image_description(bot, trigger, server, image) |
340 | 341 | else: |
341 | | - say_section(bot, trigger, server, query, section) |
| 342 | + say_section(bot, trigger, server, article, section) |
342 | 343 | else: |
343 | | - say_snippet(bot, trigger, server, query, show_url=False) |
| 344 | + say_snippet(bot, trigger, server, article, show_url=False) |
344 | 345 |
|
345 | 346 |
|
346 | 347 | @plugin.command('wikipedia', 'wp') |
|
0 commit comments