@@ -327,12 +327,22 @@ def mw_image_description(server, image):
327327def mw_info (bot , trigger , match = None ):
328328 """Retrieves and outputs a snippet of the linked page."""
329329 server = match .group (1 )
330- page_info = urlparse (match .group (2 ))
331- article = unquote (page_info .path )
330+ page_info = urlparse (match .group (0 ))
331+ # in Python 3.9+ this can be str.removeprefix() instead, but we're confident that
332+ # "/wiki/" is at the start of the path anyway since it's part of the pattern
333+ trim_offset = len ("/wiki/" )
334+ article = unquote (page_info .path )[trim_offset :]
332335 section = unquote (page_info .fragment )
333336
337+ if article .startswith ("Special:" ):
338+ # The MediaWiki query API does not include pages in the Special:
339+ # namespace, so there's no point bothering when we know this will error
340+ LOGGER .debug ("Ignoring page in Special: namespace" )
341+ return False
342+
334343 if section :
335- if section .startswith ('cite_note-' ): # Don't bother trying to retrieve a snippet when cite-note is linked
344+ if section .startswith ('cite_note-' ):
345+ # Don't bother trying to retrieve a section snippet if cite-note is linked
336346 say_snippet (bot , trigger , server , article , show_url = False )
337347 elif section .startswith ('/media' ):
338348 # gh2316: media fragments are usually images; try to get an image description
@@ -363,6 +373,11 @@ def wikipedia(bot, trigger):
363373 if not query :
364374 bot .reply ('What do you want me to look up?' )
365375 return plugin .NOLIMIT
376+
377+ if query .startswith ("Special:" ):
378+ bot .reply ("Sorry, the MediaWiki API doesn't support querying the Special: namespace." )
379+ return False
380+
366381 server = lang + '.wikipedia.org'
367382 query = mw_search (server , query , 1 )
368383 if not query :
0 commit comments