From f7f43c1332dff0657b822cf0960190851d81d1a0 Mon Sep 17 00:00:00 2001 From: Chad Horohoe Date: Wed, 23 Feb 2011 17:54:45 +0000 Subject: [PATCH] (bug 25855) Installer does not validate Memcached server settings --- includes/installer/Installer.i18n.php | 9 ++++- includes/installer/WebInstaller.php | 46 +++++++++++++++++++++++++ includes/installer/WebInstallerPage.php | 24 ++++++++++++- 3 files changed, 77 insertions(+), 2 deletions(-) diff --git a/includes/installer/Installer.i18n.php b/includes/installer/Installer.i18n.php index 210bf638e9..2fdb11ea1c 100644 --- a/includes/installer/Installer.i18n.php +++ b/includes/installer/Installer.i18n.php @@ -438,7 +438,14 @@ Medium to large sites are highly encouraged to enable this, and small sites will 'config-cache-memcached' => 'Use Memcached (requires additional setup and configuration)', 'config-memcached-servers' => 'Memcached servers:', 'config-memcached-help' => 'List of IP addresses to use for Memcached. -Should be separated with commas and specify the port to be used (for example: 127.0.0.1:11211, 192.168.1.25:11211).', +Should specify one per line and specify the port to be used. For example: + 127.0.0.1:11211 + 192.168.1.25:1234', + 'config-memcache-needservers' => 'You selected Memcached as your cache type but did not specify any servers', + 'config-memcache-badip' => 'You have entered an invalid IP address for Memcached: $1', + 'config-memcache-noport' => 'You did not specify a port to use for Memcached server: $1. +If you do not know the port, the default is 11211', + 'config-memcache-badport' => 'Memcached port numbers should be between $1 and $2', 'config-extensions' => 'Extensions', 'config-extensions-help' => 'The extensions listed above were detected in your ./extensions directory. diff --git a/includes/installer/WebInstaller.php b/includes/installer/WebInstaller.php index 6588291819..a40d14cfee 100644 --- a/includes/installer/WebInstaller.php +++ b/includes/installer/WebInstaller.php @@ -745,6 +745,52 @@ class WebInstaller extends Installer { ); } + /** + * Get a labelled textarea to configure a variable + * + * @param $params Array + * Parameters are: + * var: The variable to be configured (required) + * label: The message name for the label (required) + * attribs: Additional attributes for the input element (optional) + * controlName: The name for the input element (optional) + * value: The current value of the variable (optional) + * help: The html for the help text (optional) + */ + public function getTextArea( $params ) { + if ( !isset( $params['controlName'] ) ) { + $params['controlName'] = 'config_' . $params['var']; + } + + if ( !isset( $params['value'] ) ) { + $params['value'] = $this->getVar( $params['var'] ); + } + + if ( !isset( $params['attribs'] ) ) { + $params['attribs'] = array(); + } + if ( !isset( $params['help'] ) ) { + $params['help'] = ""; + } + return + $this->label( + $params['label'], + $params['controlName'], + Xml::textarea( + $params['controlName'], + $params['value'], + 30, + 5, + $params['attribs'] + array( + 'id' => $params['controlName'], + 'class' => 'config-input-text', + 'tabindex' => $this->nextTabIndex() + ) + ), + $params['help'] + ); + } + /** * Get a labelled password box to configure a variable. * diff --git a/includes/installer/WebInstallerPage.php b/includes/installer/WebInstallerPage.php index e166dd36d7..5ab4a4d9f1 100644 --- a/includes/installer/WebInstallerPage.php +++ b/includes/installer/WebInstallerPage.php @@ -867,7 +867,7 @@ class WebInstaller_Options extends WebInstallerPage { ) ) . $this->parent->getHelpBox( 'config-cache-help' ) . '
' . - $this->parent->getTextBox( array( + $this->parent->getTextArea( array( 'var' => '_MemCachedServers', 'label' => 'config-memcached-servers', 'help' => $this->parent->getHelpBox( 'config-memcached-help' ) @@ -1002,6 +1002,28 @@ class WebInstaller_Options extends WebInstallerPage { } } $this->parent->setVar( '_Extensions', $extsToInstall ); + + if( $this->getVar( 'wgMainCacheType' ) == 'memcached' ) { + $memcServers = explode( "\n", $this->getVar( '_MemCachedServers' ) ); + if( !$memcServers ) { + $this->parent->showError( 'config-memcache-needservers' ); + return false; + } + + foreach( $memcServers as $server ) { + $memcParts = explode( ":", $server ); + if( !IP::isValid( $memcParts[0] ) ) { + $this->parent->showError( 'config-memcache-badip', $memcParts[0] ); + return false; + } elseif( !isset( $memcParts[1] ) ) { + $this->parent->showError( 'config-memcache-noport', $memcParts[0] ); + return false; + } elseif( $memcParts[1] < 1 || $memcParts[1] > 65535 ) { + $this->parent->showError( 'config-memcache-badport', 1, 65535 ); + return false; + } + } + } return true; } -- 2.20.1