Merge "Fix trailing whitespace (and mixed spaces) in XSD files"
[lhc/web/wiklou.git] / includes / installer / WebInstallerPage.php
index e56db83..b6e7717 100644 (file)
@@ -2,6 +2,21 @@
 /**
  * Base code for web installer pages.
  *
+ * 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
  */
@@ -32,6 +47,16 @@ abstract class WebInstallerPage {
                $this->parent = $parent;
        }
 
+       /**
+        * Is this a slow-running page in the installer? If so, WebInstaller will
+        * set_time_limit(0) before calling execute(). Right now this only applies
+        * to Install and Upgrade pages
+        * @return bool
+        */
+       public function isSlow() {
+               return false;
+       }
+
        public function addHTML( $html ) {
                $this->parent->output->addHTML( $html );
        }
@@ -60,7 +85,8 @@ abstract class WebInstallerPage {
                if ( $continue ) {
                        // Fake submit button for enter keypress (bug 26267)
                        $s .= Xml::submitButton( wfMsg( "config-$continue" ),
-                               array( 'name' => "enter-$continue", 'style' => 'visibility:hidden;overflow:hidden;width:1px;margin:0' ) ) . "\n";
+                               array( 'name' => "enter-$continue", 'style' =>
+                                       'visibility:hidden;overflow:hidden;width:1px;margin:0' ) ) . "\n";
                }
 
                if ( $back ) {
@@ -113,7 +139,7 @@ abstract class WebInstallerPage {
        /**
         * Get the end tag of a fieldset.
         *
-        * @returns string
+        * @return string
         */
        protected function getFieldsetEnd() {
                return "</fieldset>\n";
@@ -124,9 +150,11 @@ abstract class WebInstallerPage {
         */
        protected function startLiveBox() {
                $this->addHTML(
-                       '<div id="config-spinner" style="display:none;"><img src="../skins/common/images/ajax-loader.gif" /></div>' .
+                       '<div id="config-spinner" style="display:none;">' .
+                       '<img src="../skins/common/images/ajax-loader.gif" /></div>' .
                        '<script>jQuery( "#config-spinner" ).show();</script>' .
-                       '<div id="config-live-log"><textarea name="LiveLog" rows="10" cols="30" readonly="readonly">'
+                       '<div id="config-live-log">' .
+                       '<textarea name="LiveLog" rows="10" cols="30" readonly="readonly">'
                );
                $this->parent->output->flush();
        }
@@ -146,9 +174,10 @@ class WebInstaller_Language extends WebInstallerPage {
        public function execute() {
                global $wgLang;
                $r = $this->parent->request;
-               $userLang = $r->getVal( 'UserLang' );
+               $userLang = $r->getVal( 'uselang' );
                $contLang = $r->getVal( 'ContLang' );
 
+               $languages = Language::fetchLanguageNames();
                $lifetime = intval( ini_get( 'session.gc_maxlifetime' ) );
                if ( !$lifetime ) {
                        $lifetime = 1440; // PHP default
@@ -169,7 +198,6 @@ class WebInstaller_Language extends WebInstallerPage {
                                }
                                $this->parent->showError( $msg, $wgLang->formatTimePeriod( $lifetime ) );
                        } else {
-                               $languages = Language::getLanguageNames();
                                if ( isset( $languages[$userLang] ) ) {
                                        $this->setVar( '_UserLang', $userLang );
                                }
@@ -181,7 +209,8 @@ class WebInstaller_Language extends WebInstallerPage {
                } elseif ( $this->parent->showSessionWarning ) {
                        # The user was knocked back from another page to the start
                        # This probably indicates a session expiry
-                       $this->parent->showError( 'config-session-expired', $wgLang->formatTimePeriod( $lifetime ) );
+                       $this->parent->showError( 'config-session-expired',
+                               $wgLang->formatTimePeriod( $lifetime ) );
                }
 
                $this->parent->setSession( 'test', true );
@@ -194,8 +223,10 @@ class WebInstaller_Language extends WebInstallerPage {
                }
                $this->startForm();
                $s = Html::hidden( 'LanguageRequestTime', time() ) .
-                       $this->getLanguageSelector( 'UserLang', 'config-your-language', $userLang, $this->parent->getHelpBox( 'config-your-language-help' ) ) .
-                       $this->getLanguageSelector( 'ContLang', 'config-wiki-language', $contLang, $this->parent->getHelpBox( 'config-wiki-language-help' ) );
+                       $this->getLanguageSelector( 'uselang', 'config-your-language', $userLang,
+                               $this->parent->getHelpBox( 'config-your-language-help' ) ) .
+                       $this->getLanguageSelector( 'ContLang', 'config-wiki-language', $contLang,
+                               $this->parent->getHelpBox( 'config-wiki-language-help' ) );
                $this->addHTML( $s );
                $this->endForm( 'continue', false );
        }
@@ -203,6 +234,10 @@ class WebInstaller_Language extends WebInstallerPage {
        /**
         * Get a <select> for selecting languages.
         *
+        * @param $name
+        * @param $label
+        * @param $selectedCode
+        * @param $helpHtml string
         * @return string
         */
        public function getLanguageSelector( $name, $label, $selectedCode, $helpHtml = '' ) {
@@ -210,13 +245,13 @@ class WebInstaller_Language extends WebInstallerPage {
 
                $s = $helpHtml;
 
-               $s .= Html::openElement( 'select', array( 'id' => $name, 'name' => $name ) ) . "\n";
+               $s .= Html::openElement( 'select', array( 'id' => $name, 'name' => $name,
+                               'tabindex' => $this->parent->nextTabIndex() ) ) . "\n";
 
-               $languages = Language::getLanguageNames();
+               $languages = Language::fetchLanguageNames();
                ksort( $languages );
-               $dummies = array_flip( $wgDummyLanguageCodes );
                foreach ( $languages as $code => $lang ) {
-                       if ( isset( $dummies[$code] ) ) continue;
+                       if ( isset( $wgDummyLanguageCodes[$code] ) ) continue;
                        $s .= "\n" . Xml::option( "$code - $lang", $code, $code == $selectedCode );
                }
                $s .= "\n</select>\n";
@@ -261,7 +296,7 @@ class WebInstaller_ExistingWiki extends WebInstallerPage {
                        $this->startForm();
                        $this->addHTML( $this->parent->getInfoBox(
                                wfMsgNoTrans( 'config-upgrade-key-missing',
-                                       "<pre>\$wgUpgradeKey = '" . $this->getVar( 'wgUpgradeKey' ) . "';</pre>" )
+                                       "<pre dir=\"ltr\">\$wgUpgradeKey = '" . $this->getVar( 'wgUpgradeKey' ) . "';</pre>" )
                        ) );
                        $this->endForm( 'continue' );
                        return 'output';
@@ -322,12 +357,13 @@ class WebInstaller_ExistingWiki extends WebInstallerPage {
 
        /**
         * Initiate an upgrade of the existing database
-        * @param $vars Variables from LocalSettings.php and AdminSettings.php
+        * @param $vars array Variables from LocalSettings.php and AdminSettings.php
         * @return Status
         */
        protected function handleExistingUpgrade( $vars ) {
                // Check $wgDBtype
-               if ( !isset( $vars['wgDBtype'] ) || !in_array( $vars['wgDBtype'], Installer::getDBTypes() ) ) {
+               if ( !isset( $vars['wgDBtype'] ) ||
+                        !in_array( $vars['wgDBtype'], Installer::getDBTypes() ) ) {
                        return Status::newFatal( 'config-localsettings-connection-error', '' );
                }
 
@@ -417,7 +453,7 @@ class WebInstaller_DBConnect extends WebInstallerPage {
 
                $dbSupport = '';
                foreach( $this->parent->getDBTypes() as $type ) {
-                       $link = DatabaseBase::newFromType( $type )->getSoftwareLink();
+                       $link = DatabaseBase::factory( $type )->getSoftwareLink();
                        $dbSupport .= wfMsgNoTrans( "config-support-$type", $link ) . "\n";
                }
                $this->addHTML( $this->parent->getInfoBox(
@@ -438,12 +474,13 @@ class WebInstaller_DBConnect extends WebInstallerPage {
                                "</li>\n";
 
                        $settings .=
-                               Html::openElement( 'div', array( 'id' => 'DB_wrapper_' . $type, 'class' => 'dbWrapper' ) ) .
+                               Html::openElement( 'div', array( 'id' => 'DB_wrapper_' . $type,
+                                               'class' => 'dbWrapper' ) ) .
                                Html::element( 'h3', array(), wfMsg( 'config-header-' . $type ) ) .
                                $installer->getConnectForm() .
                                "</div>\n";
                }
-               $types .= "</ul><br clear=\"left\"/>\n";
+               $types .= "</ul><br style=\"clear: left\"/>\n";
 
                $this->addHTML(
                        $this->parent->label( 'config-db-type', false, $types ) .
@@ -467,6 +504,9 @@ class WebInstaller_DBConnect extends WebInstallerPage {
 }
 
 class WebInstaller_Upgrade extends WebInstallerPage {
+       public function isSlow() {
+               return true;
+       }
 
        public function execute() {
                if ( $this->getVar( '_UpgradeDone' ) ) {
@@ -531,7 +571,7 @@ class WebInstaller_Upgrade extends WebInstallerPage {
                $this->addHTML(
                        $this->parent->getInfoBox(
                                wfMsgNoTrans( $msg,
-                                       $GLOBALS['wgServer'] .
+                                       $this->getVar( 'wgServer' ) .
                                                $this->getVar( 'wgScriptPath' ) . '/index' .
                                                $this->getVar( 'wgScriptExtension' )
                                ), 'tick-32.png'
@@ -608,7 +648,8 @@ class WebInstaller_Name extends WebInstallerPage {
                                'label' => 'config-project-namespace',
                                'itemLabelPrefix' => 'config-ns-',
                                'values' => array( 'site-name', 'generic', 'other' ),
-                               'commonAttribs' => array( 'class' => 'enableForOther', 'rel' => 'config_wgMetaNamespace' ),
+                               'commonAttribs' => array( 'class' => 'enableForOther',
+                                       'rel' => 'config_wgMetaNamespace' ),
                                'help' => $this->parent->getHelpBox( 'config-project-namespace-help' )
                        ) ) .
                        $this->parent->getTextBox( array(
@@ -754,7 +795,7 @@ class WebInstaller_Name extends WebInstallerPage {
 
                // Validate e-mail if provided
                $email = $this->getVar( '_AdminEmail' );
-               if( $email && !User::isValidEmailAddr( $email ) ) {
+               if( $email && !Sanitizer::validateEmail( $email ) ) {
                        $this->parent->showError( 'config-admin-error-bademail' );
                        $retVal = false;
                }
@@ -882,12 +923,14 @@ class WebInstaller_Options extends WebInstallerPage {
                        $this->parent->getTextBox( array(
                                'var' => 'wgDeletedDirectory',
                                'label' => 'config-upload-deleted',
+                               'attribs' => array( 'dir' => 'ltr' ),
                                'help' => $this->parent->getHelpBox( 'config-upload-deleted-help' )
                        ) ) .
                        '</div>' .
                        $this->parent->getTextBox( array(
                                'var' => 'wgLogo',
                                'label' => 'config-logo',
+                               'attribs' => array( 'dir' => 'ltr' ),
                                'help' => $this->parent->getHelpBox( 'config-logo-help' )
                        ) )
                );
@@ -906,6 +949,15 @@ class WebInstaller_Options extends WebInstallerPage {
                }
                $caches[] = 'memcached';
 
+               // We'll hide/show this on demand when the value changes, see config.js.
+               $cacheval = $this->getVar( 'wgMainCacheType' );
+               if (!$cacheval) {
+                       // We need to set a default here; but don't hardcode it
+                       // or we lose it every time we reload the page for validation
+                       // or going back!
+                       $cacheval = 'none';
+               }
+               $hidden = ($cacheval == 'memcached') ? '' : 'display: none';
                $this->addHTML(
                        # Advanced settings
                        $this->getFieldSetStart( 'config-advanced-settings' ) .
@@ -915,10 +967,10 @@ class WebInstaller_Options extends WebInstallerPage {
                                'label' => 'config-cache-options',
                                'itemLabelPrefix' => 'config-cache-',
                                'values' => $caches,
-                               'value' => 'none',
+                               'value' => $cacheval,
                        ) ) .
                        $this->parent->getHelpBox( 'config-cache-help' ) .
-                       '<div id="config-memcachewrapper">' .
+                       "<div id=\"config-memcachewrapper\" style=\"$hidden\">" .
                        $this->parent->getTextArea( array(
                                'var' => '_MemCachedServers',
                                'label' => 'config-memcached-servers',
@@ -934,8 +986,8 @@ class WebInstaller_Options extends WebInstallerPage {
         * @return string
         */
        public function getCCPartnerUrl() {
-               global $wgServer;
-               $exitUrl = $wgServer . $this->parent->getUrl( array(
+               $server = $this->getVar( 'wgServer' );
+               $exitUrl = $server . $this->parent->getUrl( array(
                        'page' => 'Options',
                        'SubmitCC' => 'indeed',
                        'config__LicenseCode' => 'cc',
@@ -943,7 +995,7 @@ class WebInstaller_Options extends WebInstallerPage {
                        'config_wgRightsText' => '[license_name]',
                        'config_wgRightsIcon' => '[license_button]',
                ) );
-               $styleUrl = $wgServer . dirname( dirname( $this->parent->getUrl() ) ) .
+               $styleUrl = $server . dirname( dirname( $this->parent->getUrl() ) ) .
                        '/skins/common/config-cc.css';
                $iframeUrl = 'http://creativecommons.org/license/?' .
                        wfArrayToCGI( array(
@@ -1067,8 +1119,10 @@ class WebInstaller_Options extends WebInstallerPage {
                        }
 
                        foreach( $memcServers as $server ) {
-                               $memcParts = explode( ":", $server );
-                               if( !IP::isValid( $memcParts[0] ) ) {
+                               $memcParts = explode( ":", $server, 2 );
+                               if ( !isset( $memcParts[0] )
+                                               || ( !IP::isValid( $memcParts[0] )
+                                                       && ( gethostbyname( $memcParts[0] ) == $memcParts[0] ) ) ) {
                                        $this->parent->showError( 'config-memcache-badip', $memcParts[0] );
                                        return false;
                                } elseif( !isset( $memcParts[1] )  ) {
@@ -1086,6 +1140,9 @@ class WebInstaller_Options extends WebInstallerPage {
 }
 
 class WebInstaller_Install extends WebInstallerPage {
+       public function isSlow() {
+               return true;
+       }
 
        public function execute() {
                if( $this->getVar( '_UpgradeDone' ) ) {
@@ -1147,11 +1204,13 @@ class WebInstaller_Complete extends WebInstallerPage {
        public function execute() {
                // Pop up a dialog box, to make it difficult for the user to forget
                // to download the file
-               $lsUrl = $GLOBALS['wgServer'] . $this->parent->getURL( array( 'localsettings' => 1 ) );
-               if ( isset( $_SERVER['HTTP_USER_AGENT'] ) && strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE' ) !== false ) {
+               $lsUrl = $this->getVar( 'wgServer' ) . $this->parent->getURL( array( 'localsettings' => 1 ) );
+               if ( isset( $_SERVER['HTTP_USER_AGENT'] ) &&
+                        strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE' ) !== false ) {
                        // JS appears the only method that works consistently with IE7+
-                       $this->addHtml( "\n<script type=\"" . $GLOBALS['wgJsMimeType'] . '">jQuery( document ).ready( function() { document.location='
-                               . Xml::encodeJsVar( $lsUrl) . "; } );</script>\n" );
+                       $this->addHtml( "\n<script type=\"" . $GLOBALS['wgJsMimeType'] .
+                               '">jQuery( document ).ready( function() { document.location=' .
+                               Xml::encodeJsVar( $lsUrl) . "; } );</script>\n" );
                } else {
                        $this->parent->request->response()->header( "Refresh: 0;url=$lsUrl" );
                }
@@ -1162,7 +1221,7 @@ class WebInstaller_Complete extends WebInstallerPage {
                        $this->parent->getInfoBox(
                                wfMsgNoTrans( 'config-install-done',
                                        $lsUrl,
-                                       $GLOBALS['wgServer'] .
+                                       $this->getVar( 'wgServer' ) .
                                                $this->getVar( 'wgScriptPath' ) . '/index' .
                                                $this->getVar( 'wgScriptExtension' ),
                                        '<downloadlink/>'
@@ -1207,7 +1266,11 @@ abstract class WebInstaller_Document extends WebInstallerPage {
        }
 
        public function getFileContents() {
-               return file_get_contents( dirname( __FILE__ ) . '/../../' . $this->getFileName() );
+               $file = dirname( __FILE__ ) . '/../../' . $this->getFileName();
+               if( ! file_exists( $file ) ) {
+                       return wfMsgNoTrans( 'config-nofile', $file );
+               }
+               return file_get_contents( $file );
        }
 
 }
@@ -1217,7 +1280,15 @@ class WebInstaller_Readme extends WebInstaller_Document {
 }
 
 class WebInstaller_ReleaseNotes extends WebInstaller_Document {
-       protected function getFileName() { return 'RELEASE-NOTES'; }
+       protected function getFileName() {
+               global $wgVersion;
+
+               if(! preg_match( '/^(\d+)\.(\d+).*/i', $wgVersion, $result ) ) {
+                       throw new MWException('Variable $wgVersion has an invalid value.');
+               }
+
+               return 'RELEASE-NOTES-' . $result[1] . '.' . $result[2];
+       }
 }
 
 class WebInstaller_UpgradeDoc extends WebInstaller_Document {