Merge "cleanup callback in usort call"
[lhc/web/wiklou.git] / includes / installer / WebInstaller.php
index 4189ece..4f31195 100644 (file)
@@ -2,6 +2,21 @@
 /**
  * Core installer web interface.
  *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
  * @file
  * @ingroup Deployment
  */
@@ -146,7 +161,7 @@ class WebInstaller extends Installer {
                                'Content-Disposition: attachment; filename="LocalSettings.php"'
                        );
 
-                       $ls = new LocalSettingsGenerator( $this );
+                       $ls = InstallerOverrides::getLocalSettingsGenerator( $this );
                        $rightsProfile = $this->rightsProfiles[$this->getVar( '_RightsProfile' )];
                        foreach( $rightsProfile as $group => $rightsArr ) {
                                $ls->setGroupRights( $group, $rightsArr );
@@ -355,6 +370,7 @@ class WebInstaller extends Installer {
 
        /**
         * Show an error message in a box. Parameters are like wfMsg().
+        * @param $msg
         */
        public function showError( $msg /*...*/ ) {
                $args = func_get_args();
@@ -366,6 +382,8 @@ class WebInstaller extends Installer {
 
        /**
         * Temporary error handler for session start debugging.
+        * @param $errno
+        * @param $errstr string
         */
        public function errorHandler( $errno, $errstr ) {
                $this->phpErrors[] = $errstr;
@@ -430,6 +448,7 @@ class WebInstaller extends Installer {
         *
         * @param $name String
         * @param $default
+        * @return null
         */
        public function getSession( $name, $default = null ) {
                if ( !isset( $this->session[$name] ) ) {
@@ -469,7 +488,6 @@ class WebInstaller extends Installer {
                        $this->setVar( '_UserLang', $wgLanguageCode );
                } else {
                        $wgLanguageCode = $this->getVar( 'wgLanguageCode' );
-                       $wgLang = Language::factory( $this->getVar( '_UserLang' ) );
                        $wgContLang = Language::factory( $wgLanguageCode );
                }
        }
@@ -482,7 +500,7 @@ class WebInstaller extends Installer {
        public function getAcceptLanguage() {
                global $wgLanguageCode, $wgRequest;
 
-               $mwLanguages = Language::getLanguageNames();
+               $mwLanguages = Language::fetchLanguageNames();
                $headerLanguages = array_keys( $wgRequest->getAcceptLang() );
 
                foreach ( $headerLanguages as $lang ) {
@@ -630,6 +648,7 @@ class WebInstaller extends Installer {
         * Get small text indented help for a preceding form field.
         * Parameters like wfMsg().
         *
+        * @param $msg
         * @return string
         */
        public function getHelpBox( $msg /*, ... */ ) {
@@ -637,13 +656,12 @@ class WebInstaller extends Installer {
                array_shift( $args );
                $args = array_map( 'htmlspecialchars', $args );
                $text = wfMsgReal( $msg, $args, false, false, false );
-               $html = htmlspecialchars( $text );
                $html = $this->parse( $text, true );
 
                return "<div class=\"mw-help-field-container\">\n" .
-                          "<span class=\"mw-help-field-hint\">" . wfMsgHtml( 'config-help' ) . "</span>\n" .
-                          "<span class=\"mw-help-field-data\">" . $html . "</span>\n" .
-                          "</div>\n";
+                       "<span class=\"mw-help-field-hint\">" . wfMsgHtml( 'config-help' ) . "</span>\n" .
+                       "<span class=\"mw-help-field-data\">" . $html . "</span>\n" .
+                       "</div>\n";
        }
 
        /**
@@ -675,18 +693,20 @@ class WebInstaller extends Installer {
         * @param $status Status
         */
        public function showStatusMessage( Status $status ) {
-               $text = $status->getWikiText();
-               $this->output->addWikiText(
-                       "<div class=\"config-message\">\n" .
-                       $text .
-                       "</div>"
-               );
+               $errors = array_merge( $status->getErrorsArray(), $status->getWarningsArray() );
+               foreach ( $errors as $error ) {
+                       call_user_func_array( array( $this, 'showMessage' ), $error );
+               }
        }
 
        /**
         * Label a control by wrapping a config-input div around it and putting a
         * label before it.
         *
+        * @param $msg
+        * @param $forId
+        * @param $contents
+        * @param $helpData string
         * @return string
         */
        public function label( $msg, $forId, $contents, $helpData = "" ) {
@@ -1013,6 +1033,7 @@ class WebInstaller extends Installer {
        /**
         * Helper for Installer::docLink()
         *
+        * @param $page
         * @return string
         */
        protected function getDocUrl( $page ) {
@@ -1028,6 +1049,9 @@ class WebInstaller extends Installer {
        /**
         * Extension tag hook for a documentation link.
         *
+        * @param $linkText
+        * @param $attribs
+        * @param $parser
         * @return string
         */
        public function docLink( $linkText, $attribs, $parser ) {
@@ -1040,6 +1064,9 @@ class WebInstaller extends Installer {
        /**
         * Helper for "Download LocalSettings" link on WebInstall_Complete
         *
+        * @param $text
+        * @param $attribs
+        * @param $parser
         * @return String Html for download link
         */
        public function downloadLinkHook( $text, $attribs, $parser  ) {
@@ -1053,4 +1080,31 @@ class WebInstaller extends Installer {
                        $img . ' ' . wfMsgHtml( 'config-download-localsettings' ) );
                return Html::rawElement( 'div', array( 'class' => 'config-download-link' ), $anchor );
        }
+
+       /**
+        * @return bool
+        */
+       public function envCheckPath( ) {
+               // PHP_SELF isn't available sometimes, such as when PHP is CGI but
+               // cgi.fix_pathinfo is disabled. In that case, fall back to SCRIPT_NAME
+               // to get the path to the current script... hopefully it's reliable. SIGH
+               $path = false;
+               if ( !empty( $_SERVER['PHP_SELF'] ) ) {
+                       $path = $_SERVER['PHP_SELF'];
+               } elseif ( !empty( $_SERVER['SCRIPT_NAME'] ) ) {
+                       $path = $_SERVER['SCRIPT_NAME'];
+               }
+               if ($path !== false) {
+                       $uri = preg_replace( '{^(.*)/(mw-)?config.*$}', '$1', $path );
+                       $this->setVar( 'wgScriptPath', $uri );
+               } else {
+                       $this->showError( 'config-no-uri' );
+                       return false;
+               }
+               return parent::envCheckPath();
+       }
+
+       protected function envGetDefaultServer() {
+               return WebRequest::detectServer();
+       }
 }