Merge "Installer: properly override default $wgLogo value"
[lhc/web/wiklou.git] / includes / installer / WebInstallerPage.php
index 4bc6cad..e1ee836 100644 (file)
@@ -36,12 +36,13 @@ abstract class WebInstallerPage {
         */
        public $parent;
 
+       /**
+        * @return string
+        */
        abstract public function execute();
 
        /**
-        * Constructor.
-        *
-        * @param $parent WebInstaller
+        * @param WebInstaller $parent
         */
        public function __construct( WebInstaller $parent ) {
                $this->parent = $parent;
@@ -51,12 +52,16 @@ abstract class WebInstallerPage {
         * 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
+        *
+        * @return bool Always false in this default implementation.
         */
        public function isSlow() {
                return false;
        }
 
+       /**
+        * @param string $html
+        */
        public function addHTML( $html ) {
                $this->parent->output->addHTML( $html );
        }
@@ -124,18 +129,33 @@ abstract class WebInstallerPage {
                $this->addHTML( $s );
        }
 
+       /**
+        * @return string
+        */
        public function getName() {
                return str_replace( 'WebInstaller_', '', get_class( $this ) );
        }
 
+       /**
+        * @return string
+        */
        protected function getId() {
                return array_search( $this->getName(), $this->parent->pageSequence );
        }
 
+       /**
+        * @param string $var
+        *
+        * @return mixed
+        */
        public function getVar( $var ) {
                return $this->parent->getVar( $var );
        }
 
+       /**
+        * @param string $name
+        * @param mixed $value
+        */
        public function setVar( $name, $value ) {
                $this->parent->setVar( $name, $value );
        }
@@ -175,16 +195,21 @@ abstract class WebInstallerPage {
        }
 
        /**
-        * Opposite to startLiveBox()
+        * Opposite to WebInstallerPage::startLiveBox
         */
        protected function endLiveBox() {
                $this->addHTML( '</textarea></div>
 <script>jQuery( "#config-spinner" ).hide()</script>' );
                $this->parent->output->flush();
        }
+
 }
 
 class WebInstaller_Language extends WebInstallerPage {
+
+       /**
+        * @return string|null
+        */
        public function execute() {
                global $wgLang;
                $r = $this->parent->request;
@@ -244,15 +269,18 @@ class WebInstaller_Language extends WebInstallerPage {
                                $this->parent->getHelpBox( 'config-wiki-language-help' ) );
                $this->addHTML( $s );
                $this->endForm( 'continue', false );
+
+               return null;
        }
 
        /**
         * Get a "<select>" for selecting languages.
         *
-        * @param $name
-        * @param $label
-        * @param $selectedCode
-        * @param $helpHtml string
+        * @param string $name
+        * @param string $label
+        * @param string $selectedCode
+        * @param string $helpHtml
+        *
         * @return string
         */
        public function getLanguageSelector( $name, $label, $selectedCode, $helpHtml = '' ) {
@@ -275,9 +303,14 @@ class WebInstaller_Language extends WebInstallerPage {
 
                return $this->parent->label( $label, $name, $s );
        }
+
 }
 
 class WebInstaller_ExistingWiki extends WebInstallerPage {
+
+       /**
+        * @return string
+        */
        public function execute() {
                // If there is no LocalSettings.php, continue to the installer welcome page
                $vars = Installer::getExistingLocalSettings();
@@ -366,6 +399,12 @@ class WebInstaller_ExistingWiki extends WebInstallerPage {
                $this->endForm( 'continue' );
        }
 
+       /**
+        * @param string[] $names
+        * @param mixed[] $vars
+        *
+        * @return Status
+        */
        protected function importVariables( $names, $vars ) {
                $status = Status::newGood();
                foreach ( $names as $name ) {
@@ -380,7 +419,9 @@ class WebInstaller_ExistingWiki extends WebInstallerPage {
 
        /**
         * Initiate an upgrade of the existing database
-        * @param array $vars Variables from LocalSettings.php
+        *
+        * @param mixed[] $vars Variables from LocalSettings.php
+        *
         * @return Status
         */
        protected function handleExistingUpgrade( $vars ) {
@@ -426,10 +467,14 @@ class WebInstaller_ExistingWiki extends WebInstallerPage {
 
                return $status;
        }
+
 }
 
 class WebInstaller_Welcome extends WebInstallerPage {
 
+       /**
+        * @return string
+        */
        public function execute() {
                if ( $this->parent->request->wasPosted() ) {
                        if ( $this->getVar( '_Environment' ) ) {
@@ -451,11 +496,13 @@ class WebInstaller_Welcome extends WebInstallerPage {
 
                return '';
        }
+
 }
 
 class WebInstaller_DBConnect extends WebInstallerPage {
+
        /**
-        * @return string|void When string, "skip" or "continue"
+        * @return string|null When string, "skip" or "continue"
         */
        public function execute() {
                if ( $this->getVar( '_ExistingDBSettings' ) ) {
@@ -529,8 +576,13 @@ class WebInstaller_DBConnect extends WebInstallerPage {
 
                $this->addHTML( $this->parent->label( 'config-db-type', false, $types ) . $settings );
                $this->endForm();
+
+               return null;
        }
 
+       /**
+        * @return Status
+        */
        public function submit() {
                $r = $this->parent->request;
                $type = $r->getVal( 'DBType' );
@@ -545,13 +597,21 @@ class WebInstaller_DBConnect extends WebInstallerPage {
 
                return $installer->submitConnectForm();
        }
+
 }
 
 class WebInstaller_Upgrade extends WebInstallerPage {
+
+       /**
+        * @return bool Always true.
+        */
        public function isSlow() {
                return true;
        }
 
+       /**
+        * @return string|null
+        */
        public function execute() {
                if ( $this->getVar( '_UpgradeDone' ) ) {
                        // Allow regeneration of LocalSettings.php, unless we are working
@@ -603,6 +663,8 @@ class WebInstaller_Upgrade extends WebInstallerPage {
                $this->addHTML( $this->parent->getInfoBox(
                        wfMessage( 'config-can-upgrade', $GLOBALS['wgVersion'] )->plain() ) );
                $this->endForm();
+
+               return null;
        }
 
        public function showDoneMessage() {
@@ -626,10 +688,14 @@ class WebInstaller_Upgrade extends WebInstallerPage {
                $this->parent->restoreLinkPopups();
                $this->endForm( $regenerate ? 'regenerate' : false, false );
        }
+
 }
 
 class WebInstaller_DBSettings extends WebInstallerPage {
 
+       /**
+        * @return string|null
+        */
        public function execute() {
                $installer = $this->parent->getDBInstaller( $this->getVar( 'wgDBtype' ) );
 
@@ -653,11 +719,17 @@ class WebInstaller_DBSettings extends WebInstallerPage {
                $this->startForm();
                $this->addHTML( $form );
                $this->endForm();
+
+               return null;
        }
+
 }
 
 class WebInstaller_Name extends WebInstallerPage {
 
+       /**
+        * @return string
+        */
        public function execute() {
                $r = $this->parent->request;
                if ( $r->wasPosted() ) {
@@ -718,7 +790,7 @@ class WebInstaller_Name extends WebInstallerPage {
                                'label' => 'config-admin-password',
                        ) ) .
                        $this->parent->getPasswordBox( array(
-                               'var' => '_AdminPassword2',
+                               'var' => '_AdminPasswordConfirm',
                                'label' => 'config-admin-password-confirm'
                        ) ) .
                        $this->parent->getTextBox( array(
@@ -751,10 +823,13 @@ class WebInstaller_Name extends WebInstallerPage {
                return 'output';
        }
 
+       /**
+        * @return bool
+        */
        public function submit() {
                $retVal = true;
                $this->parent->setVarsFromRequest( array( 'wgSitename', '_NamespaceType',
-                       '_AdminName', '_AdminPassword', '_AdminPassword2', '_AdminEmail',
+                       '_AdminName', '_AdminPassword', '_AdminPasswordConfirm', '_AdminEmail',
                        '_Subscribe', '_SkipOptional', 'wgMetaNamespace' ) );
 
                // Validate site name
@@ -836,7 +911,7 @@ class WebInstaller_Name extends WebInstallerPage {
                        # $user->getPasswordValidity just checks for $wgMinimalPasswordLength.
                        # This message is more specific and helpful.
                        $msg = 'config-admin-password-blank';
-               } elseif ( $pwd !== $this->getVar( '_AdminPassword2' ) ) {
+               } elseif ( $pwd !== $this->getVar( '_AdminPasswordConfirm' ) ) {
                        $msg = 'config-admin-password-mismatch';
                } elseif ( $valid !== true ) {
                        $msg = $valid;
@@ -844,7 +919,7 @@ class WebInstaller_Name extends WebInstallerPage {
                if ( $msg !== false ) {
                        call_user_func_array( array( $this->parent, 'showError' ), (array)$msg );
                        $this->setVar( '_AdminPassword', '' );
-                       $this->setVar( '_AdminPassword2', '' );
+                       $this->setVar( '_AdminPasswordConfirm', '' );
                        $retVal = false;
                }
 
@@ -863,9 +938,14 @@ class WebInstaller_Name extends WebInstallerPage {
 
                return $retVal;
        }
+
 }
 
 class WebInstaller_Options extends WebInstallerPage {
+
+       /**
+        * @return string|null
+        */
        public function execute() {
                if ( $this->getVar( '_SkipOptional' ) == 'skip' ) {
                        return 'skip';
@@ -969,10 +1049,6 @@ class WebInstaller_Options extends WebInstallerPage {
                                $this->getVar( 'wgDeletedDirectory' )
                        )
                );
-               // If we're using the default, let the user set it relative to $wgScriptPath
-               $curLogo = $this->getVar( 'wgLogo' );
-               $logoString = ( $curLogo == "/wiki/skins/common/images/wiki.png" ) ?
-                       '$wgStylePath/common/images/wiki.png' : $curLogo;
 
                $uploadwrapperStyle = $this->getVar( 'wgEnableUploads' ) ? '' : 'display: none';
                $this->addHTML(
@@ -994,7 +1070,6 @@ class WebInstaller_Options extends WebInstallerPage {
                        '</div>' .
                        $this->parent->getTextBox( array(
                                'var' => 'wgLogo',
-                               'value' => $logoString,
                                'label' => 'config-logo',
                                'attribs' => array( 'dir' => 'ltr' ),
                                'help' => $this->parent->getHelpBox( 'config-logo-help' )
@@ -1049,6 +1124,8 @@ class WebInstaller_Options extends WebInstallerPage {
                        $this->getFieldSetEnd()
                );
                $this->endForm();
+
+               return null;
        }
 
        /**
@@ -1077,6 +1154,9 @@ class WebInstaller_Options extends WebInstallerPage {
                return $iframeUrl;
        }
 
+       /**
+        * @return string
+        */
        public function getCCChooser() {
                $iframeAttribs = array(
                        'class' => 'config-cc-iframe',
@@ -1098,6 +1178,9 @@ class WebInstaller_Options extends WebInstallerPage {
                        "</div>\n";
        }
 
+       /**
+        * @return string
+        */
        public function getCCDoneBox() {
                $js = "parent.document.getElementById('config-cc-wrapper').style.height = '$1';";
                // If you change this height, also change it in config.css
@@ -1137,6 +1220,9 @@ class WebInstaller_Options extends WebInstallerPage {
                $this->addHTML( $this->getCCDoneBox() );
        }
 
+       /**
+        * @return bool
+        */
        public function submit() {
                $this->parent->setVarsFromRequest( array( '_RightsProfile', '_LicenseCode',
                        'wgEnableEmail', 'wgPasswordSender', 'wgEnableUploads', 'wgLogo',
@@ -1144,8 +1230,7 @@ class WebInstaller_Options extends WebInstallerPage {
                        'wgEmailAuthentication', 'wgMainCacheType', '_MemCachedServers',
                        'wgUseInstantCommons' ) );
 
-               if ( !in_array( $this->getVar( '_RightsProfile' ),
-                       array_keys( $this->parent->rightsProfiles ) )
+               if ( !array_key_exists( $this->getVar( '_RightsProfile' ), $this->parent->rightsProfiles )
                ) {
                        reset( $this->parent->rightsProfiles );
                        $this->setVar( '_RightsProfile', key( $this->parent->rightsProfiles ) );
@@ -1158,7 +1243,7 @@ class WebInstaller_Options extends WebInstallerPage {
 
                                return false;
                        }
-               } elseif ( in_array( $code, array_keys( $this->parent->licenses ) ) ) {
+               } elseif ( array_key_exists( $code, $this->parent->licenses ) ) {
                        // Messages:
                        // config-license-cc-by, config-license-cc-by-sa, config-license-cc-by-nc-sa,
                        // config-license-cc-0, config-license-pd, config-license-gfdl, config-license-none,
@@ -1217,13 +1302,21 @@ class WebInstaller_Options extends WebInstallerPage {
 
                return true;
        }
+
 }
 
 class WebInstaller_Install extends WebInstallerPage {
+
+       /**
+        * @return bool Always true.
+        */
        public function isSlow() {
                return true;
        }
 
+       /**
+        * @return string|bool
+        */
        public function execute() {
                if ( $this->getVar( '_UpgradeDone' ) ) {
                        return 'skip';
@@ -1252,6 +1345,9 @@ class WebInstaller_Install extends WebInstallerPage {
                return true;
        }
 
+       /**
+        * @param string $step
+        */
        public function startStage( $step ) {
                // Messages: config-install-database, config-install-tables, config-install-interwiki,
                // config-install-stats, config-install-keys, config-install-sysop, config-install-mainpage
@@ -1264,8 +1360,8 @@ class WebInstaller_Install extends WebInstallerPage {
        }
 
        /**
-        * @param $step
-        * @param $status Status
+        * @param string $step
+        * @param Status $status
         */
        public function endStage( $step, $status ) {
                if ( $step == 'extension-tables' ) {
@@ -1281,9 +1377,11 @@ class WebInstaller_Install extends WebInstallerPage {
                        $this->parent->showStatusBox( $status );
                }
        }
+
 }
 
 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
@@ -1317,10 +1415,14 @@ class WebInstaller_Complete extends WebInstallerPage {
                $this->parent->restoreLinkPopups();
                $this->endForm( false, false );
        }
+
 }
 
 class WebInstaller_Restart extends WebInstallerPage {
 
+       /**
+        * @return string|null
+        */
        public function execute() {
                $r = $this->parent->request;
                if ( $r->wasPosted() ) {
@@ -1336,11 +1438,17 @@ class WebInstaller_Restart extends WebInstallerPage {
                $s = $this->parent->getWarningBox( wfMessage( 'config-help-restart' )->plain() );
                $this->addHTML( $s );
                $this->endForm( 'restart' );
+
+               return null;
        }
+
 }
 
 abstract class WebInstaller_Document extends WebInstallerPage {
 
+       /**
+        * @return string
+        */
        abstract protected function getFileName();
 
        public function execute() {
@@ -1351,6 +1459,9 @@ abstract class WebInstaller_Document extends WebInstallerPage {
                $this->endForm( false );
        }
 
+       /**
+        * @return string
+        */
        public function getFileContents() {
                $file = __DIR__ . '/../../' . $this->getFileName();
                if ( !file_exists( $file ) ) {
@@ -1359,15 +1470,26 @@ abstract class WebInstaller_Document extends WebInstallerPage {
 
                return file_get_contents( $file );
        }
+
 }
 
 class WebInstaller_Readme extends WebInstaller_Document {
+
+       /**
+        * @return string
+        */
        protected function getFileName() {
                return 'README';
        }
+
 }
 
 class WebInstaller_ReleaseNotes extends WebInstaller_Document {
+
+       /**
+        * @throws MWException
+        * @return string
+        */
        protected function getFileName() {
                global $wgVersion;
 
@@ -1377,16 +1499,27 @@ class WebInstaller_ReleaseNotes extends WebInstaller_Document {
 
                return 'RELEASE-NOTES-' . $result[1] . '.' . $result[2];
        }
+
 }
 
 class WebInstaller_UpgradeDoc extends WebInstaller_Document {
+
+       /**
+        * @return string
+        */
        protected function getFileName() {
                return 'UPGRADE';
        }
+
 }
 
 class WebInstaller_Copying extends WebInstaller_Document {
+
+       /**
+        * @return string
+        */
        protected function getFileName() {
                return 'COPYING';
        }
+
 }