Turn getStatusErrorBox() into getStatusBox() so it can handle warnings too
[lhc/web/wiklou.git] / includes / installer / WebInstaller.php
index 44c5b52..bbdbb7f 100644 (file)
@@ -207,7 +207,11 @@ class WebInstaller extends Installer {
        function startSession() {
                $sessPath = $this->getSessionSavePath();
                if( $sessPath != '' ) {
-                       if( !is_dir( $sessPath ) || !is_writeable( $sessPath ) ) {
+                       if( strval( ini_get( 'open_basedir' ) ) != '' ) {
+                               // we need to skip the following check when open_basedir is on.
+                               // The session path probably *wont* be writable by the current
+                               // user, and telling them to change it is bad. Bug 23021.
+                       } elseif( !is_dir( $sessPath ) || !is_writeable( $sessPath ) ) {
                                $this->showError( 'config-session-path-bad', $sessPath );
                                return false;
                        }
@@ -234,7 +238,7 @@ class WebInstaller extends Installer {
        /**
         * Get the value of session.save_path
         *
-        * Per http://www.php.net/manual/en/ref.session.php#ini.session.save-path,
+        * Per http://www.php.net/manual/en/session.configuration.php#ini.session.save-path,
         * this might have some additional preceding parts which need to be
         * ditched
         *
@@ -267,9 +271,8 @@ class WebInstaller extends Installer {
 
        /**
         * Clean up from execute()
-        * @private.
         */
-       function finish() {
+       private function finish() {
                $this->output->output();
                $this->session['happyPages'] = $this->happyPages;
                $this->session['skippedPages'] = $this->skippedPages;
@@ -728,14 +731,21 @@ class WebInstaller extends Installer {
        }
 
        /**
-        * Output an error box using a Status object
+        * Output an error or warning box using a Status object
         */
-       function showStatusErrorBox( $status ) {
-               $text = $status->getWikiText();
-               $this->output->addHTML( $this->getErrorBox( $text ) );
+       function showStatusBox( $status ) {
+               if( !$status->isGood() ) {
+                       $text = $status->getWikiText();
+                       if( $status->isOk() ) {
+                               $box = $this->getWarningBox( $text );
+                       } else {
+                               $box = $this->getErrorBox( $text );
+                       }
+                       $this->output->addHTML( $box );
+               }
        }
 
-       function showStatusError( $status ) {
+       function showStatusMessage( $status ) {
                $text = $status->getWikiText();
                $this->output->addWikiText(
                        "<div class=\"config-message\">\n" .
@@ -799,7 +809,7 @@ class WebInstaller extends Installer {
        }
 }
 
-class WebInstallerPage {
+abstract class WebInstallerPage {
        function __construct( $parent ) {
                $this->parent = $parent;
        }
@@ -859,15 +869,7 @@ class WebInstallerPage {
                return array_search( $this->getName(), $this->parent->pageSequence );
        }
 
-       function execute() {
-               if ( $this->parent->request->wasPosted() ) {
-                       return 'continue';
-               } else {
-                       $this->startForm();
-                       $this->addHTML( 'Mockup' );
-                       $this->endForm();
-               }
-       }
+       abstract function execute();
 
        function getVar( $var ) {
                return $this->parent->getVar( $var );
@@ -990,7 +992,7 @@ class WebInstaller_DBConnect extends WebInstallerPage {
                                $this->setVar( '_UpgradeDone', false );
                                return 'continue';
                        } else {
-                               $this->parent->showStatusErrorBox( $status );
+                               $this->parent->showStatusBox( $status );
                        }
                }
 
@@ -1117,7 +1119,7 @@ class WebInstaller_DBSettings extends WebInstallerPage {
                        } elseif ( $status->isGood() ) {
                                return 'continue';
                        } else {
-                               $this->parent->showStatusErrorBox( $status );
+                               $this->parent->showStatusBox( $status );
                        }
                }
 
@@ -1401,17 +1403,16 @@ class WebInstaller_Options extends WebInstallerPage {
                                'label' => 'config-upload-deleted',
                        ) ) .
                        $this->parent->getHelpBox( 'config-upload-deleted-help' ) .
+                       '</div>' .
                        $this->parent->getTextBox( array(
                                'var' => 'wgLogo',
                                'label' => 'config-logo'
                        ) ) .
                        $this->parent->getHelpBox( 'config-logo-help' ) .
-                       '</div>' .
                        $this->parent->getFieldsetEnd()
                );
 
-               $caches = array( 'none', 'anything', 'db' );
-               $selected = 'db';
+               $caches = array( 'none' );
                if( count( $this->getVar( '_Caches' ) ) ) {
                        $caches[] = 'accel';
                        $selected = 'accel';
@@ -1576,13 +1577,25 @@ class WebInstaller_Install extends WebInstallerPage {
                }
                $this->startForm();
                $this->addHTML("<ul>");
-               foreach( $this->parent->getInstallSteps() as $step ) {
+               foreach( $this->parent->getInstallSteps() as $stepObj ) {
+                       $step = is_array( $stepObj ) ? $stepObj['name'] : $stepObj;
                        $this->startStage( "config-install-$step" );
-                       $func = 'install' . ucfirst( $step );
-                       $status = $this->parent->{$func}();
+                       $status = null;
+
+                       # Call our working function
+                       if ( is_array( $step ) ) {
+                               # A custom callaback
+                               $callback = $stepObj['callback'];
+                               $status = call_user_func_array( $callback, array() );
+                       } else {
+                               # Boring implicitly named callback
+                               $func = 'install' . ucfirst( $step );
+                               $status = $this->parent->{$func}();
+                       }
+
                        $ok = $status->isGood();
                        if ( !$ok ) {
-                               $this->parent->showStatusErrorBox( $status );
+                               $this->parent->showStatusBox( $status );
                        }
                        $this->endStage( $ok );
                }
@@ -1659,6 +1672,8 @@ abstract class WebInstaller_Document extends WebInstallerPage {
        }
 
        protected function formatTextFile( $text ) {
+               $text = str_replace( array( '<', '{{', '[[' ),
+                       array( '&lt;', '&#123;&#123;', '&#91;&#91;' ), $text );
                // replace numbering with [1], [2], etc with MW-style numbering
                $text = preg_replace( "/\r?\n(\r?\n)?\\[\\d+\\]/m", "\\1#", $text );
                // join word-wrapped lines into one