r40426 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r40425‎ | r40426 | r40427 >
Date:10:44, 4 September 2008
Author:siebrand
Status:old
Tags:
Comment:
Copy ExternalImageWhitelist to REL1_13. Obsolete in trunk, because this feature was added to core in r40310.
Modified paths:
  • /branches/REL1_13/extensions/ExternalImageWhitelist (added) (history)
  • /branches/REL1_13/extensions/ExternalImageWhitelist (added) (history)

Diff [purge]

Index: branches/REL1_13/extensions/ExternalImageWhitelist/ExternalImageWhitelist.i18n.php
@@ -0,0 +1,23 @@
 2+<?php
 3+
 4+/**
 5+ * Internationalisation file for extension External image whitelist
 6+ *
 7+ * @addtogroup Extensions
 8+ */
 9+
 10+$messages = array();
 11+
 12+/** English
 13+ * @author Skizzerz
 14+ */
 15+$messages['en'] = array(
 16+ 'external_image_whitelist' => " #<pre>Leave this line exactly as it is
 17+#Put regular expression fragments (just the part that goes between the //) below
 18+#These will be matched with the URLs of external (hotlinked) images
 19+#Those that match will be displayed as images, otherwise only a link to the image will be shown
 20+#Lines beginning with # are treated as comments
 21+
 22+#Put all regex fragments above this line. Leave this line exactly as it is</pre>",
 23+ 'externalimagewhitelist-desc' => 'Only allow external (hotlinked) images to be displayed when they match a regex on an on-wiki whitelist',
 24+);
\ No newline at end of file
Property changes on: branches/REL1_13/extensions/ExternalImageWhitelist/ExternalImageWhitelist.i18n.php
___________________________________________________________________
Name: svn:eol-style
125 + native
Index: branches/REL1_13/extensions/ExternalImageWhitelist/ExternalImageWhitelist.php
@@ -0,0 +1,51 @@
 2+<?php
 3+/**
 4+ * External image whitelist
 5+ * Only allow external (hotlinked) images to be displayed when they match a regex on an on-wiki whitelist
 6+ * Won't work with $wgAllowExternalImages set to true, but DOES work with $wgAllowExternalImagesFrom set
 7+ * @license GPL
 8+*/
 9+
 10+if(!defined('MEDIAWIKI')) {
 11+ echo "This file is an extension to the MediaWiki software and cannot be used standalone.";
 12+ die(1);
 13+}
 14+
 15+$wgExtensionCredits['other'][] = array(
 16+ 'name' => 'External image whitelist',
 17+ 'author' => 'Ryan Schmidt',
 18+ 'url' => 'http://www.mediawiki.org/wiki/Extension:External_image_whitelist',
 19+ 'version' => '1.0',
 20+ 'description' => 'Only allow external (hotlinked) images to be displayed when they match a regex on an on-wiki whitelist',
 21+ 'descriptionmsg' => 'externalimagewhitelist-desc',
 22+);
 23+
 24+$wgExtensionMessagesFiles['Extimgwl'] = dirname(__FILE__) . '/ExternalImageWhitelist.i18n.php';
 25+
 26+$wgHooks['LinkerMakeExternalLink'][] = 'efExtImgWl';
 27+
 28+//image extensions to check for
 29+$wgExtImgWlExtensions = array('gif', 'jpg', 'jpeg', 'bmp', 'png', 'svg');
 30+
 31+function efExtImgWl(&$url, &$text, &$html) {
 32+ global $wgAllowExternalImages, $wgExtImgWlExtensions;
 33+
 34+ if($wgAllowExternalImages)
 35+ return true;
 36+ $ext = implode('|', preg_replace('[^a-zA-Z0-9]', '', $wgExtImgWlExtensions));
 37+ if(!preg_match('/\.'.$ext.'$/i', $url))
 38+ return true;
 39+ $whitelist = explode("\n", wfMsgForContent('external_image_whitelist'));
 40+ foreach($whitelist as $entry) {
 41+ $entry = trim($entry);
 42+ if($entry == '')
 43+ continue;
 44+ if(strpos($entry, '#') === 0)
 45+ continue;
 46+ if(preg_match('/'.str_replace('/', '\\/', $entry).'/i', $url)) {
 47+ $html = '<img src="'.$url.'" />';
 48+ return false;
 49+ }
 50+ }
 51+ return true;
 52+}
\ No newline at end of file
Property changes on: branches/REL1_13/extensions/ExternalImageWhitelist/ExternalImageWhitelist.php
___________________________________________________________________
Name: svn:eol-style
153 + native

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r40310* $wgAllowExternalImagesFrom may now be an array of multiple strings....skizzerz18:49, 1 September 2008