new config option: $wgAllowExternalImagesFrom
authorErik Moeller <erik@users.mediawiki.org>
Wed, 26 Oct 2005 22:13:02 +0000 (22:13 +0000)
committerErik Moeller <erik@users.mediawiki.org>
Wed, 26 Oct 2005 22:13:02 +0000 (22:13 +0000)
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
includes/Parser.php

index 853c8ae..a2eab9c 100644 (file)
@@ -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 */
index 7d76377..4cc0c7d 100644 (file)
@@ -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' );