From ce2a4b66aed3aef3839ed4bc14f79be8e77bae34 Mon Sep 17 00:00:00 2001 From: Erik Moeller Date: Wed, 26 Oct 2005 22:13:02 +0000 Subject: [PATCH] new config option: $wgAllowExternalImagesFrom motivation: people want to remove the wikimedia logos, which are non-free, from commons. using this, we could move them to a trusted directory on the wikimedia servers, and access them from all wikis using absolute URLs. --- includes/DefaultSettings.php | 9 +++++++++ includes/Parser.php | 14 +++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 853c8ae620..a2eab9c6ac 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -936,6 +936,15 @@ $wgDisableCookieCheck = false; /** Whether to allow inline image pointing to other websites */ $wgAllowExternalImages = true; +/** If the above is false, you can specify an exception here. Image URLs + * that start with this string are then rendered, while all others are not. + * You can use this to set up a trusted, simple repository of images. + * + * Example: + * $wgAllowExternalImagesFrom = 'http://127.0.0.1/'; + */ +$wgAllowExternalImagesFrom = ''; + /** Disable database-intensive features */ $wgMiserMode = false; /** Disable all query pages if miser mode is on, not just some */ diff --git a/includes/Parser.php b/includes/Parser.php index 7d76377be6..4cc0c7d14e 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -1183,13 +1183,17 @@ class Parser } /** - * make an image if it's allowed + * make an image if it's allowed, either through the global + * option or through the exception * @access private */ function maybeMakeExternalImage( $url ) { $sk =& $this->mOptions->getSkin(); + $imagesfrom = $this->mOptions->getAllowExternalImagesFrom(); + $imagesexception = !empty($imagesfrom); $text = false; - if ( $this->mOptions->getAllowExternalImages() ) { + if ( $this->mOptions->getAllowExternalImages() + || ( $imagesexception && strpos( $url, $imagesfrom ) === 0 ) ) { if ( preg_match( EXT_IMAGE_REGEX, $url ) ) { # Image found $text = $sk->makeExternalImage( htmlspecialchars( $url ) ); @@ -3617,6 +3621,7 @@ class ParserOptions var $mUseDynamicDates; # Use DateFormatter to format dates var $mInterwikiMagic; # Interlanguage links are removed and returned in an array var $mAllowExternalImages; # Allow external images inline + var $mAllowExternalImagesFrom; # If not, any exception? var $mSkin; # Reference to the preferred skin var $mDateFormat; # Date format index var $mEditSection; # Create "edit section" links @@ -3627,6 +3632,7 @@ class ParserOptions function getUseDynamicDates() { return $this->mUseDynamicDates; } function getInterwikiMagic() { return $this->mInterwikiMagic; } function getAllowExternalImages() { return $this->mAllowExternalImages; } + function getAllowExternalImagesFrom() { return $this->mAllowExternalImagesFrom; } function &getSkin() { return $this->mSkin; } function getDateFormat() { return $this->mDateFormat; } function getEditSection() { return $this->mEditSection; } @@ -3638,6 +3644,7 @@ class ParserOptions function setUseDynamicDates( $x ) { return wfSetVar( $this->mUseDynamicDates, $x ); } function setInterwikiMagic( $x ) { return wfSetVar( $this->mInterwikiMagic, $x ); } function setAllowExternalImages( $x ) { return wfSetVar( $this->mAllowExternalImages, $x ); } + function setAllowExternalImagesFrom( $x ) { return wfSetVar( $this->mAllowExternalImagesFrom, $x ); } function setDateFormat( $x ) { return wfSetVar( $this->mDateFormat, $x ); } function setEditSection( $x ) { return wfSetVar( $this->mEditSection, $x ); } function setNumberHeadings( $x ) { return wfSetVar( $this->mNumberHeadings, $x ); } @@ -3663,7 +3670,7 @@ class ParserOptions /** Get user options */ function initialiseFromUser( &$userInput ) { global $wgUseTeX, $wgUseDynamicDates, $wgInterwikiMagic, $wgAllowExternalImages, - $wgAllowSpecialInclusion; + $wgAllowExternalImagesFrom, $wgAllowSpecialInclusion; $fname = 'ParserOptions::initialiseFromUser'; wfProfileIn( $fname ); if ( !$userInput ) { @@ -3677,6 +3684,7 @@ class ParserOptions $this->mUseDynamicDates = $wgUseDynamicDates; $this->mInterwikiMagic = $wgInterwikiMagic; $this->mAllowExternalImages = $wgAllowExternalImages; + $this->mAllowExternalImagesFrom = $wgAllowExternalImagesFrom; wfProfileIn( $fname.'-skin' ); $this->mSkin =& $user->getSkin(); wfProfileOut( $fname.'-skin' ); -- 2.20.1