|
39 | 39 | import natsort
|
40 | 40 | import mimetypes
|
41 | 41 | try:
|
42 |
| - from urlparse import urlparse, urlsplit, urlunsplit, urljoin, unquote |
| 42 | + from urlparse import urlparse, urlsplit, urlunsplit, urljoin, unquote, parse_qs |
43 | 43 | except ImportError:
|
44 |
| - from urllib.parse import urlparse, urlsplit, urlunsplit, urljoin, unquote # NOQA |
| 44 | + from urllib.parse import urlparse, urlsplit, urlunsplit, urljoin, unquote, parse_qs # NOQA |
45 | 45 |
|
46 | 46 | try:
|
47 | 47 | import pyphen
|
@@ -1433,7 +1433,14 @@ def url_replacer(self, src, dst, lang=None, url_type=None):
|
1433 | 1433 | # Refuse to replace links that are full URLs.
|
1434 | 1434 | if dst_url.netloc:
|
1435 | 1435 | if dst_url.scheme == 'link': # Magic link
|
1436 |
| - dst = self.link(dst_url.netloc, dst_url.path.lstrip('/'), lang) |
| 1436 | + if dst_url.query: |
| 1437 | + # If query strings are used in magic link, they will be |
| 1438 | + # passed to the path handler as keyword arguments (strings) |
| 1439 | + link_kwargs = {k: v[-1] for k, v in parse_qs(dst_url.query).items()} |
| 1440 | + else: |
| 1441 | + link_kwargs = {} |
| 1442 | + |
| 1443 | + dst = self.link(dst_url.netloc, dst_url.path.lstrip('/'), lang, **link_kwargs) |
1437 | 1444 | # Assuming the site is served over one of these, and
|
1438 | 1445 | # since those are the only URLs we want to rewrite...
|
1439 | 1446 | else:
|
@@ -1688,7 +1695,7 @@ def generic_rss_renderer(self, lang, title, link, description, timeline, output_
|
1688 | 1695 | data = data.decode('utf-8')
|
1689 | 1696 | rss_file.write(data)
|
1690 | 1697 |
|
1691 |
| - def path(self, kind, name, lang=None, is_link=False): |
| 1698 | + def path(self, kind, name, lang=None, is_link=False, **kwargs): |
1692 | 1699 | r"""Build the path to a certain kind of page.
|
1693 | 1700 |
|
1694 | 1701 | These are mostly defined by plugins by registering via the
|
@@ -1725,7 +1732,7 @@ def path(self, kind, name, lang=None, is_link=False):
|
1725 | 1732 | lang = utils.LocaleBorg().current_lang
|
1726 | 1733 |
|
1727 | 1734 | try:
|
1728 |
| - path = self.path_handlers[kind](name, lang) |
| 1735 | + path = self.path_handlers[kind](name, lang, **kwargs) |
1729 | 1736 | path = [os.path.normpath(p) for p in path if p != '.'] # Fix Issue #1028
|
1730 | 1737 | if is_link:
|
1731 | 1738 | link = '/' + ('/'.join(path))
|
@@ -1804,9 +1811,9 @@ def register_path_handler(self, kind, f):
|
1804 | 1811 | else:
|
1805 | 1812 | self.path_handlers[kind] = f
|
1806 | 1813 |
|
1807 |
| - def link(self, *args): |
| 1814 | + def link(self, *args, **kwargs): |
1808 | 1815 | """Create a link."""
|
1809 |
| - url = self.path(*args, is_link=True) |
| 1816 | + url = self.path(*args, is_link=True, **kwargs) |
1810 | 1817 | url = utils.encodelink(url)
|
1811 | 1818 | return url
|
1812 | 1819 |
|
|
0 commit comments