r40310 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r40309‎ | r40310 | r40311 >
Date:18:49, 1 September 2008
Author:skizzerz
Status:old
Tags:
Comment:
* $wgAllowExternalImagesFrom may now be an array of multiple strings.
* Added an on-wiki external image whitelist. Items in this whitelist are
treated as regular expression fragments to match for when possibly
displaying an external image inline. Controlled by $wgEnableImageWhitelist
(true by default)
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/DefaultSettings.php (modified) (history)
  • /trunk/phase3/includes/parser/Parser.php (modified) (history)
  • /trunk/phase3/includes/parser/ParserOptions.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesEn.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/parser/Parser.php
@@ -1442,7 +1442,7 @@
14431443
14441444 /**
14451445 * make an image if it's allowed, either through the global
1446 - * option or through the exception
 1446+ * option, through the exception, or through the on-wiki whitelist
14471447 * @private
14481448 */
14491449 function maybeMakeExternalImage( $url ) {
@@ -1450,13 +1450,41 @@
14511451 $imagesfrom = $this->mOptions->getAllowExternalImagesFrom();
14521452 $imagesexception = !empty($imagesfrom);
14531453 $text = false;
 1454+ # $imagesfrom could be either a single string or an array of strings, parse out the latter
 1455+ if( $imagesexception && is_array( $imagesfrom ) ) {
 1456+ $imagematch = false;
 1457+ foreach( $imagesfrom as $match ) {
 1458+ if( strpos( $url, $match ) === 0 ) {
 1459+ $imagematch = true;
 1460+ break;
 1461+ }
 1462+ }
 1463+ } elseif( $imagesexception ) {
 1464+ $imagematch = (strpos( $url, $imagesfrom ) === 0);
 1465+ } else {
 1466+ $imagematch = false;
 1467+ }
14541468 if ( $this->mOptions->getAllowExternalImages()
1455 - || ( $imagesexception && strpos( $url, $imagesfrom ) === 0 ) ) {
 1469+ || ( $imagesexception && $imagematch ) ) {
14561470 if ( preg_match( self::EXT_IMAGE_REGEX, $url ) ) {
14571471 # Image found
14581472 $text = $sk->makeExternalImage( $url );
14591473 }
14601474 }
 1475+ if( !$text && $this->mOptions->getEnableImageWhitelist()
 1476+ && preg_match( self::EXT_IMAGE_REGEX, $url ) ) {
 1477+ $whitelist = explode( "\n", wfMsgForContent( 'external_image_whitelist' ) );
 1478+ foreach( $whitelist as $entry ) {
 1479+ # Sanitize the regex fragment, make it case-insensitive, ignore blank entries/comments
 1480+ if( strpos( $entry, '#' ) === 0 || $entry === '' )
 1481+ continue;
 1482+ if( preg_match( '/' . str_replace( '/', '\\/', $entry ) . '/i', $url ) ) {
 1483+ # Image matches a whitelist entry
 1484+ $text = $sk->makeExternalImage( $url );
 1485+ break;
 1486+ }
 1487+ }
 1488+ }
14611489 return $text;
14621490 }
14631491
Index: trunk/phase3/includes/parser/ParserOptions.php
@@ -13,6 +13,7 @@
1414 var $mInterwikiMagic; # Interlanguage links are removed and returned in an array
1515 var $mAllowExternalImages; # Allow external images inline
1616 var $mAllowExternalImagesFrom; # If not, any exception?
 17+ var $mEnableImageWhitelist; # If not or it doesn't match, should we check an on-wiki whitelist?
1718 var $mSkin; # Reference to the preferred skin
1819 var $mDateFormat; # Date format index
1920 var $mEditSection; # Create "edit section" links
@@ -37,6 +38,7 @@
3839 function getInterwikiMagic() { return $this->mInterwikiMagic; }
3940 function getAllowExternalImages() { return $this->mAllowExternalImages; }
4041 function getAllowExternalImagesFrom() { return $this->mAllowExternalImagesFrom; }
 42+ function getEnableImageWhitelist() { return $this->mEnableImageWhitelist; }
4143 function getEditSection() { return $this->mEditSection; }
4244 function getNumberHeadings() { return $this->mNumberHeadings; }
4345 function getAllowSpecialInclusion() { return $this->mAllowSpecialInclusion; }
@@ -77,6 +79,7 @@
7880 function setInterwikiMagic( $x ) { return wfSetVar( $this->mInterwikiMagic, $x ); }
7981 function setAllowExternalImages( $x ) { return wfSetVar( $this->mAllowExternalImages, $x ); }
8082 function setAllowExternalImagesFrom( $x ) { return wfSetVar( $this->mAllowExternalImagesFrom, $x ); }
 83+ function setEnableImageWhitelist( $x ) { return wfSetVar( $this->mEnableImageWhitelist, $x ); }
8184 function setDateFormat( $x ) { return wfSetVar( $this->mDateFormat, $x ); }
8285 function setEditSection( $x ) { return wfSetVar( $this->mEditSection, $x ); }
8386 function setNumberHeadings( $x ) { return wfSetVar( $this->mNumberHeadings, $x ); }
@@ -109,7 +112,7 @@
110113 /** Get user options */
111114 function initialiseFromUser( $userInput ) {
112115 global $wgUseTeX, $wgUseDynamicDates, $wgInterwikiMagic, $wgAllowExternalImages;
113 - global $wgAllowExternalImagesFrom, $wgAllowSpecialInclusion, $wgMaxArticleSize;
 116+ global $wgAllowExternalImagesFrom, $wgEnableImageWhitelist, $wgAllowSpecialInclusion, $wgMaxArticleSize;
114117 global $wgMaxPPNodeCount, $wgMaxTemplateDepth, $wgMaxPPExpandDepth, $wgCleanSignatures;
115118 $fname = 'ParserOptions::initialiseFromUser';
116119 wfProfileIn( $fname );
@@ -131,6 +134,7 @@
132135 $this->mInterwikiMagic = $wgInterwikiMagic;
133136 $this->mAllowExternalImages = $wgAllowExternalImages;
134137 $this->mAllowExternalImagesFrom = $wgAllowExternalImagesFrom;
 138+ $this->mEnableImageWhitelist = $wgEnableImageWhitelist;
135139 $this->mSkin = null; # Deferred
136140 $this->mDateFormat = null; # Deferred
137141 $this->mEditSection = true;
Index: trunk/phase3/includes/DefaultSettings.php
@@ -1583,12 +1583,24 @@
15841584 /** If the above is false, you can specify an exception here. Image URLs
15851585 * that start with this string are then rendered, while all others are not.
15861586 * You can use this to set up a trusted, simple repository of images.
 1587+ * You may also specify an array of strings to allow multiple sites
15871588 *
1588 - * Example:
 1589+ * Examples:
15891590 * $wgAllowExternalImagesFrom = 'http://127.0.0.1/';
 1591+ * $wgAllowExternalImagesFrom = array( 'http://127.0.0.1/', 'http://example.com' );
15901592 */
15911593 $wgAllowExternalImagesFrom = '';
15921594
 1595+/** If $wgAllowExternalImages is false, you can allow an on-wiki
 1596+ * whitelist of regular expression fragments to match the image URL
 1597+ * against. If the image matches one of the regular expression fragments,
 1598+ * The image will be displayed.
 1599+ *
 1600+ * Set this to true to enable the on-wiki whitelist (MediaWiki:External image whitelist)
 1601+ * Or false to disable it
 1602+ */
 1603+$wgEnableImageWhitelist = true;
 1604+
15931605 /** Allows to move images and other media files. Experemintal, not sure if it always works */
15941606 $wgAllowImageMoving = false;
15951607
Index: trunk/phase3/languages/messages/MessagesEn.php
@@ -3588,4 +3588,13 @@
35893589 'blankpage' => 'Blank page',
35903590 'intentionallyblankpage' => 'This page is intentionally left blank',
35913591
 3592+# External image whitelist
 3593+'external_image_whitelist' => ' #Leave this line exactly as it is<pre>
 3594+#Put regular expression fragments (just the part that goes between the //) below
 3595+#These will be matched with the URLs of external (hotlinked) images
 3596+#Those that match will be displayed as images, otherwise only a link to the image will be shown
 3597+#Lines beginning with # are treated as comments
 3598+
 3599+#Put all regex fragments above this line. Leave this line exactly as it is</pre>',
 3600+
35923601 );
Index: trunk/phase3/RELEASE-NOTES
@@ -43,7 +43,10 @@
4444 * Editing the MediaWiki namespace is now unconditionally restricted to people
4545 with the editinterface right, configuring this in $wgNamespaceProtection
4646 is not required.
47 -
 47+* $wgAllowExternalImagesFrom may now be an array of multiple strings.
 48+* Introduced $wgEnableImageWhitelist to toggle the on-wiki external image
 49+ whitelist on or off.
 50+
4851 === New features in 1.14 ===
4952
5053 * New URL syntaxes for Special:ListUsers - 'Special:ListUsers/USER' and
@@ -106,6 +109,9 @@
107110 * (bug 11884) Now support Flash EXIF attribute
108111 * Show thumbnails in the file history list, patch by User:Agbad
109112 * Added support of piped wikilinks using double-width brackets
 113+* Added an on-wiki external image whitelist. Items in this whitelist are
 114+ treated as regular expression fragments to match for when possibly
 115+ displaying an external image inline.
110116
111117 === Bug fixes in 1.14 ===
112118

Follow-up revisions

RevisionCommit summaryAuthorDate
r40426Copy ExternalImageWhitelist to REL1_13. Obsolete in trunk, because this featu...siebrand10:44, 4 September 2008
r40427Obsolete in trunk, because this feature was added to core in r40310. Availabl...siebrand10:47, 4 September 2008