(bug 25855) Installer does not validate Memcached server settings
authorChad Horohoe <demon@users.mediawiki.org>
Wed, 23 Feb 2011 17:54:45 +0000 (17:54 +0000)
committerChad Horohoe <demon@users.mediawiki.org>
Wed, 23 Feb 2011 17:54:45 +0000 (17:54 +0000)
includes/installer/Installer.i18n.php
includes/installer/WebInstaller.php
includes/installer/WebInstallerPage.php

index 210bf63..2fdb11e 100644 (file)
@@ -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 <code>./extensions</code> directory.
 
index 6588291..a40d14c 100644 (file)
@@ -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.
         *
index e166dd3..5ab4a4d 100644 (file)
@@ -867,7 +867,7 @@ class WebInstaller_Options extends WebInstallerPage {
                        ) ) .
                        $this->parent->getHelpBox( 'config-cache-help' ) .
                        '<div id="config-memcachewrapper">' .
-                       $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;
        }