Add setting for disabling inline image preview.

(imported from commit 2321390eb14cfe5701347861b9ae5ad6fdac0cbb)
This commit is contained in:
Tim Abbott 2013-11-14 08:37:39 -05:00
parent f9707dd903
commit 870ae09aae
3 changed files with 10 additions and 2 deletions

View File

@ -158,6 +158,8 @@ class InlineHttpsProcessor(markdown.treeprocessors.Treeprocessor):
class InlineInterestingLinkProcessor(markdown.treeprocessors.Treeprocessor):
def is_image(self, url):
if not settings.INLINE_IMAGE_PREVIEW:
return False
parsed_url = urlparse.urlparse(url)
# List from http://support.google.com/chromeos/bin/answer.py?hl=en&answer=183093
for ext in [".bmp", ".gif", ".jpg", "jpeg", ".png", ".webp"]:
@ -175,6 +177,8 @@ class InlineInterestingLinkProcessor(markdown.treeprocessors.Treeprocessor):
return None
def youtube_image(self, url):
if not settings.INLINE_IMAGE_PREVIEW:
return None
# Youtube video id extraction regular expression from http://pastebin.com/KyKAFv1s
# If it matches, match.group(2) is the video id.
youtube_re = r'^((?:https?://)?(?:youtu\.be/|(?:\w+\.)?youtube(?:-nocookie)?\.com/)(?:(?:(?:v|embed)/)|(?:(?:watch(?:_popup)?(?:\.php)?)?(?:\?|#!?)(?:.+&)?v=)))?([0-9A-Za-z_-]+)(?(1).+)?$'
@ -328,8 +332,7 @@ class InlineInterestingLinkProcessor(markdown.treeprocessors.Treeprocessor):
if embedly_client.is_supported(url):
embedly_urls.append(url)
continue
# NOTE: The youtube code below is inactive at least on
# staging because embedy.ly is currently handling those
# NOTE: settings.USING_EMBEDLY will prevent the below from running
youtube = self.youtube_image(url)
if youtube is not None:
add_a(root, youtube, url)

View File

@ -61,6 +61,10 @@ ENABLE_FEEDBACK = True
# questions.
ERROR_REPORTING = True
# Controls whether or not Zulip will provide inline image preview when
# a link to an image is referenced in a message.
INLINE_IMAGE_PREVIEW = True
# By default, files uploaded by users and user avatars are stored
# directly on the Zulip server. If file storage in Amazon S3 (or
# elsewhere, e.g. your corporate fileshare) is desired, please contact

View File

@ -258,6 +258,7 @@ DEFAULT_SETTINGS = {'TWITTER_CONSUMER_KEY': '',
'FEEDBACK_BOT_NAME': 'Zulip Feedback Bot',
'API_SUPER_USERS': set(),
'ADMINS': '',
'INLINE_IMAGE_PREVIEW': True,
'ENABLE_FEEDBACK': True,
}