MediaWiki r11531 - Code Review

Jump to: navigation, search
Repository:MediaWiki
Revision:r11530‎ | r11531 (on ViewVC)‎ | r11532 >
Date:22:13, 26 October 2005
Author:eloquence
Status:old
Tags:
Comment:
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.
Modified paths:

Diff [purge]

Index: trunk/phase3/includes/Parser.php
===================================================================
--- trunk/phase3/includes/Parser.php	(revision 11530)
+++ trunk/phase3/includes/Parser.php	(revision 11531)
@@ -1183,13 +1183,17 @@
 	}
 
 	/**
-	 * 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 @@
 	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 @@
 	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 @@
 	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 @@
 	/** 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 @@
 		$this->mUseDynamicDates = $wgUseDynamicDates;
 		$this->mInterwikiMagic = $wgInterwikiMagic;
 		$this->mAllowExternalImages = $wgAllowExternalImages;
+		$this->mAllowExternalImagesFrom = $wgAllowExternalImagesFrom;
 		wfProfileIn( $fname.'-skin' );
 		$this->mSkin =& $user->getSkin();
 		wfProfileOut( $fname.'-skin' );
Index: trunk/phase3/includes/DefaultSettings.php
===================================================================
--- trunk/phase3/includes/DefaultSettings.php	(revision 11530)
+++ trunk/phase3/includes/DefaultSettings.php	(revision 11531)
@@ -936,6 +936,15 @@
 /**  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 */

Status & tagging log

  • 01:58, 13 October 2010 ^demon (Talk | contribs) changed the status of r11531 [removed: new added: old]
Personal tools
Namespaces
Variants
Views
Actions
Site
Support
Download
Development
Communication
Toolbox