mirror of https://github.com/zulip/zulip.git
markdown: Only attempt to adjust /wiki/File: paths on Wikipedia.
This commit is contained in:
parent
533f929591
commit
ff53ee8e28
|
@ -698,13 +698,14 @@ class InlineInterestingLinkProcessor(markdown.treeprocessors.Treeprocessor):
|
||||||
# structurally very similar to dropbox_image, and possibly
|
# structurally very similar to dropbox_image, and possibly
|
||||||
# should be rewritten to use open graph, but has some value.
|
# should be rewritten to use open graph, but has some value.
|
||||||
parsed_url = urllib.parse.urlparse(url)
|
parsed_url = urllib.parse.urlparse(url)
|
||||||
if parsed_url.netloc.lower().endswith(".wikipedia.org"):
|
if parsed_url.netloc.lower().endswith(".wikipedia.org") and parsed_url.path.startswith(
|
||||||
|
"/wiki/File:"
|
||||||
|
):
|
||||||
# Redirecting from "/wiki/File:" to "/wiki/Special:FilePath/File:"
|
# Redirecting from "/wiki/File:" to "/wiki/Special:FilePath/File:"
|
||||||
# A possible alternative, that avoids the redirect after hitting "Special:"
|
# A possible alternative, that avoids the redirect after hitting "Special:"
|
||||||
# is using the first characters of md5($filename) to generate the URL
|
# is using the first characters of md5($filename) to generate the URL
|
||||||
domain = parsed_url.scheme + "://" + parsed_url.netloc
|
newpath = parsed_url.path.replace("/wiki/File:", "/wiki/Special:FilePath/File:", 1)
|
||||||
correct_url = domain + parsed_url.path[:6] + "Special:FilePath" + parsed_url.path[5:]
|
return parsed_url._replace(path=newpath).geturl()
|
||||||
return correct_url
|
|
||||||
if parsed_url.netloc == "linx.li":
|
if parsed_url.netloc == "linx.li":
|
||||||
return "https://linx.li/s" + parsed_url.path
|
return "https://linx.li/s" + parsed_url.path
|
||||||
return None
|
return None
|
||||||
|
|
|
@ -757,6 +757,11 @@ class MarkdownTest(ZulipTestCase):
|
||||||
converted = render_markdown(msg, content)
|
converted = render_markdown(msg, content)
|
||||||
self.assertEqual(converted.rendered_content, expected)
|
self.assertEqual(converted.rendered_content, expected)
|
||||||
|
|
||||||
|
content = "https://en.wikipedia.org/static/images/icons/wikipedia.png"
|
||||||
|
expected = '<div class="message_inline_image"><a href="https://en.wikipedia.org/static/images/icons/wikipedia.png"><img data-src-fullsize="/thumbnail?url=https%3A%2F%2Fen.wikipedia.org%2Fstatic%2Fimages%2Ficons%2Fwikipedia.png&size=full" src="/thumbnail?url=https%3A%2F%2Fen.wikipedia.org%2Fstatic%2Fimages%2Ficons%2Fwikipedia.png&size=thumbnail"></a></div>'
|
||||||
|
converted = render_markdown(msg, content)
|
||||||
|
self.assertEqual(converted.rendered_content, expected)
|
||||||
|
|
||||||
@override_settings(INLINE_IMAGE_PREVIEW=False)
|
@override_settings(INLINE_IMAGE_PREVIEW=False)
|
||||||
def test_image_preview_enabled(self) -> None:
|
def test_image_preview_enabled(self) -> None:
|
||||||
ret = image_preview_enabled()
|
ret = image_preview_enabled()
|
||||||
|
|
Loading…
Reference in New Issue