3 * Base code for web installer pages.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
25 * Abstract class to define pages for the web installer.
30 abstract class WebInstallerPage
{
33 * The WebInstaller object this WebInstallerPage belongs to.
39 abstract public function execute();
44 * @param $parent WebInstaller
46 public function __construct( WebInstaller
$parent ) {
47 $this->parent
= $parent;
51 * Is this a slow-running page in the installer? If so, WebInstaller will
52 * set_time_limit(0) before calling execute(). Right now this only applies
53 * to Install and Upgrade pages
56 public function isSlow() {
60 public function addHTML( $html ) {
61 $this->parent
->output
->addHTML( $html );
64 public function startForm() {
66 "<div class=\"config-section\">\n" .
71 'action' => $this->parent
->getUrl( array( 'page' => $this->getName() ) )
78 * @param string|bool $continue
79 * @param string|bool $back
81 public function endForm( $continue = 'continue', $back = 'back' ) {
82 $s = "<div class=\"config-submit\">\n";
85 if ( $id === false ) {
86 $s .= Html
::hidden( 'lastPage', $this->parent
->request
->getVal( 'lastPage' ) );
90 // Fake submit button for enter keypress (bug 26267)
91 // Messages: config-continue, config-restart, config-regenerate
92 $s .= Xml
::submitButton( wfMessage( "config-$continue" )->text(),
93 array( 'name' => "enter-$continue", 'style' =>
94 'visibility:hidden;overflow:hidden;width:1px;margin:0' ) ) . "\n";
98 // Message: config-back
99 $s .= Xml
::submitButton( wfMessage( "config-$back" )->text(),
101 'name' => "submit-$back",
102 'tabindex' => $this->parent
->nextTabIndex()
107 // Messages: config-continue, config-restart, config-regenerate
108 $s .= Xml
::submitButton( wfMessage( "config-$continue" )->text(),
110 'name' => "submit-$continue",
111 'tabindex' => $this->parent
->nextTabIndex(),
115 $s .= "</div></form></div>\n";
116 $this->addHTML( $s );
119 public function getName() {
120 return str_replace( 'WebInstaller_', '', get_class( $this ) );
123 protected function getId() {
124 return array_search( $this->getName(), $this->parent
->pageSequence
);
127 public function getVar( $var ) {
128 return $this->parent
->getVar( $var );
131 public function setVar( $name, $value ) {
132 $this->parent
->setVar( $name, $value );
136 * Get the starting tags of a fieldset.
138 * @param string $legend message name
142 protected function getFieldsetStart( $legend ) {
143 return "\n<fieldset><legend>" . wfMessage( $legend )->escaped() . "</legend>\n";
147 * Get the end tag of a fieldset.
151 protected function getFieldsetEnd() {
152 return "</fieldset>\n";
156 * Opens a textarea used to display the progress of a long operation
158 protected function startLiveBox() {
160 '<div id="config-spinner" style="display:none;">' .
161 '<img src="../skins/common/images/ajax-loader.gif" /></div>' .
162 '<script>jQuery( "#config-spinner" ).show();</script>' .
163 '<div id="config-live-log">' .
164 '<textarea name="LiveLog" rows="10" cols="30" readonly="readonly">'
166 $this->parent
->output
->flush();
170 * Opposite to startLiveBox()
172 protected function endLiveBox() {
173 $this->addHTML( '</textarea></div>
174 <script>jQuery( "#config-spinner" ).hide()</script>' );
175 $this->parent
->output
->flush();
179 class WebInstaller_Language
extends WebInstallerPage
{
181 public function execute() {
183 $r = $this->parent
->request
;
184 $userLang = $r->getVal( 'uselang' );
185 $contLang = $r->getVal( 'ContLang' );
187 $languages = Language
::fetchLanguageNames();
188 $lifetime = intval( ini_get( 'session.gc_maxlifetime' ) );
190 $lifetime = 1440; // PHP default
193 if ( $r->wasPosted() ) {
195 if ( $this->parent
->getSession( 'test' ) === null ) {
196 $requestTime = $r->getVal( 'LanguageRequestTime' );
197 if ( !$requestTime ) {
198 // The most likely explanation is that the user was knocked back
199 // from another page on POST due to session expiry
200 $msg = 'config-session-expired';
201 } elseif ( time() - $requestTime > $lifetime ) {
202 $msg = 'config-session-expired';
204 $msg = 'config-no-session';
206 $this->parent
->showError( $msg, $wgLang->formatTimePeriod( $lifetime ) );
208 if ( isset( $languages[$userLang] ) ) {
209 $this->setVar( '_UserLang', $userLang );
211 if ( isset( $languages[$contLang] ) ) {
212 $this->setVar( 'wgLanguageCode', $contLang );
216 } elseif ( $this->parent
->showSessionWarning
) {
217 # The user was knocked back from another page to the start
218 # This probably indicates a session expiry
219 $this->parent
->showError( 'config-session-expired',
220 $wgLang->formatTimePeriod( $lifetime ) );
223 $this->parent
->setSession( 'test', true );
225 if ( !isset( $languages[$userLang] ) ) {
226 $userLang = $this->getVar( '_UserLang', 'en' );
228 if ( !isset( $languages[$contLang] ) ) {
229 $contLang = $this->getVar( 'wgLanguageCode', 'en' );
232 $s = Html
::hidden( 'LanguageRequestTime', time() ) .
233 $this->getLanguageSelector( 'uselang', 'config-your-language', $userLang,
234 $this->parent
->getHelpBox( 'config-your-language-help' ) ) .
235 $this->getLanguageSelector( 'ContLang', 'config-wiki-language', $contLang,
236 $this->parent
->getHelpBox( 'config-wiki-language-help' ) );
237 $this->addHTML( $s );
238 $this->endForm( 'continue', false );
242 * Get a "<select>" for selecting languages.
246 * @param $selectedCode
247 * @param $helpHtml string
250 public function getLanguageSelector( $name, $label, $selectedCode, $helpHtml = '' ) {
251 global $wgDummyLanguageCodes;
255 $s .= Html
::openElement( 'select', array( 'id' => $name, 'name' => $name,
256 'tabindex' => $this->parent
->nextTabIndex() ) ) . "\n";
258 $languages = Language
::fetchLanguageNames();
260 foreach ( $languages as $code => $lang ) {
261 if ( isset( $wgDummyLanguageCodes[$code] ) ) {
264 $s .= "\n" . Xml
::option( "$code - $lang", $code, $code == $selectedCode );
266 $s .= "\n</select>\n";
267 return $this->parent
->label( $label, $name, $s );
272 class WebInstaller_ExistingWiki
extends WebInstallerPage
{
273 public function execute() {
274 // If there is no LocalSettings.php, continue to the installer welcome page
275 $vars = Installer
::getExistingLocalSettings();
280 // Check if the upgrade key supplied to the user has appeared in LocalSettings.php
281 if ( $vars['wgUpgradeKey'] !== false
282 && $this->getVar( '_UpgradeKeySupplied' )
283 && $this->getVar( 'wgUpgradeKey' ) === $vars['wgUpgradeKey'] )
285 // It's there, so the user is authorized
286 $status = $this->handleExistingUpgrade( $vars );
287 if ( $status->isOK() ) {
291 $this->parent
->showStatusBox( $status );
292 $this->endForm( 'continue' );
297 // If there is no $wgUpgradeKey, tell the user to add one to LocalSettings.php
298 if ( $vars['wgUpgradeKey'] === false ) {
299 if ( $this->getVar( 'wgUpgradeKey', false ) === false ) {
300 $secretKey = $this->getVar( 'wgSecretKey' ); // preserve $wgSecretKey
301 $this->parent
->generateKeys();
302 $this->setVar( 'wgSecretKey', $secretKey );
303 $this->setVar( '_UpgradeKeySupplied', true );
306 $this->addHTML( $this->parent
->getInfoBox(
307 wfMessage( 'config-upgrade-key-missing', "<pre dir=\"ltr\">\$wgUpgradeKey = '" .
308 $this->getVar( 'wgUpgradeKey' ) . "';</pre>" )->plain()
310 $this->endForm( 'continue' );
314 // If there is an upgrade key, but it wasn't supplied, prompt the user to enter it
316 $r = $this->parent
->request
;
317 if ( $r->wasPosted() ) {
318 $key = $r->getText( 'config_wgUpgradeKey' );
319 if ( !$key ||
$key !== $vars['wgUpgradeKey'] ) {
320 $this->parent
->showError( 'config-localsettings-badkey' );
321 $this->showKeyForm();
325 $status = $this->handleExistingUpgrade( $vars );
326 if ( $status->isOK() ) {
329 $this->parent
->showStatusBox( $status );
330 $this->showKeyForm();
334 $this->showKeyForm();
340 * Show the "enter key" form
342 protected function showKeyForm() {
345 $this->parent
->getInfoBox( wfMessage( 'config-localsettings-upgrade' )->plain() ) .
347 $this->parent
->getTextBox( array(
348 'var' => 'wgUpgradeKey',
349 'label' => 'config-localsettings-key',
350 'attribs' => array( 'autocomplete' => 'off' ),
353 $this->endForm( 'continue' );
356 protected function importVariables( $names, $vars ) {
357 $status = Status
::newGood();
358 foreach ( $names as $name ) {
359 if ( !isset( $vars[$name] ) ) {
360 $status->fatal( 'config-localsettings-incomplete', $name );
362 $this->setVar( $name, $vars[$name] );
368 * Initiate an upgrade of the existing database
369 * @param array $vars Variables from LocalSettings.php and AdminSettings.php
372 protected function handleExistingUpgrade( $vars ) {
374 if ( !isset( $vars['wgDBtype'] ) ||
375 !in_array( $vars['wgDBtype'], Installer
::getDBTypes() ) ) {
376 return Status
::newFatal( 'config-localsettings-connection-error', '' );
379 // Set the relevant variables from LocalSettings.php
380 $requiredVars = array( 'wgDBtype' );
381 $status = $this->importVariables( $requiredVars, $vars );
382 $installer = $this->parent
->getDBInstaller();
383 $status->merge( $this->importVariables( $installer->getGlobalNames(), $vars ) );
384 if ( !$status->isOK() ) {
388 if ( isset( $vars['wgDBadminuser'] ) ) {
389 $this->setVar( '_InstallUser', $vars['wgDBadminuser'] );
391 $this->setVar( '_InstallUser', $vars['wgDBuser'] );
393 if ( isset( $vars['wgDBadminpassword'] ) ) {
394 $this->setVar( '_InstallPassword', $vars['wgDBadminpassword'] );
396 $this->setVar( '_InstallPassword', $vars['wgDBpassword'] );
399 // Test the database connection
400 $status = $installer->getConnection();
401 if ( !$status->isOK() ) {
402 // Adjust the error message to explain things correctly
403 $status->replaceMessage( 'config-connection-error',
404 'config-localsettings-connection-error' );
409 $this->setVar( '_ExistingDBSettings', true );
414 class WebInstaller_Welcome
extends WebInstallerPage
{
416 public function execute() {
417 if ( $this->parent
->request
->wasPosted() ) {
418 if ( $this->getVar( '_Environment' ) ) {
422 $this->parent
->output
->addWikiText( wfMessage( 'config-welcome' )->plain() );
423 $status = $this->parent
->doEnvironmentChecks();
424 if ( $status->isGood() ) {
425 $this->parent
->output
->addHTML( '<span class="success-message">' .
426 wfMessage( 'config-env-good' )->escaped() . '</span>' );
427 $this->parent
->output
->addWikiText( wfMessage( 'config-copyright',
428 SpecialVersion
::getCopyrightAndAuthorList() )->plain() );
432 $this->parent
->showStatusMessage( $status );
439 class WebInstaller_DBConnect
extends WebInstallerPage
{
441 public function execute() {
442 if ( $this->getVar( '_ExistingDBSettings' ) ) {
446 $r = $this->parent
->request
;
447 if ( $r->wasPosted() ) {
448 $status = $this->submit();
450 if ( $status->isGood() ) {
451 $this->setVar( '_UpgradeDone', false );
454 $this->parent
->showStatusBox( $status );
460 $types = "<ul class=\"config-settings-block\">\n";
462 $defaultType = $this->getVar( 'wgDBtype' );
464 // Messages: config-support-mysql, config-support-postgres, config-support-oracle,
465 // config-support-sqlite
467 foreach ( $this->parent
->getDBTypes() as $type ) {
468 $link = DatabaseBase
::factory( $type )->getSoftwareLink();
469 $dbSupport .= wfMessage( "config-support-$type", $link )->plain() . "\n";
471 $this->addHTML( $this->parent
->getInfoBox(
472 wfMessage( 'config-support-info', trim( $dbSupport ) )->text() ) );
474 // It's possible that the library for the default DB type is not compiled in.
475 // In that case, instead select the first supported DB type in the list.
476 $compiledDBs = $this->parent
->getCompiledDBs();
477 if ( !in_array( $defaultType, $compiledDBs ) ) {
478 $defaultType = $compiledDBs[0];
481 foreach ( $compiledDBs as $type ) {
482 $installer = $this->parent
->getDBInstaller( $type );
486 $installer->getReadableName(),
490 $type == $defaultType,
491 array( 'class' => 'dbRadio', 'rel' => "DB_wrapper_$type" )
495 // Messages: config-header-mysql, config-header-postgres, config-header-oracle,
496 // config-header-sqlite
498 Html
::openElement( 'div', array( 'id' => 'DB_wrapper_' . $type,
499 'class' => 'dbWrapper' ) ) .
500 Html
::element( 'h3', array(), wfMessage( 'config-header-' . $type )->text() ) .
501 $installer->getConnectForm() .
504 $types .= "</ul><br style=\"clear: left\"/>\n";
507 $this->parent
->label( 'config-db-type', false, $types ) .
514 public function submit() {
515 $r = $this->parent
->request
;
516 $type = $r->getVal( 'DBType' );
518 return Status
::newFatal( 'config-invalid-db-type' );
520 $this->setVar( 'wgDBtype', $type );
521 $installer = $this->parent
->getDBInstaller( $type );
523 return Status
::newFatal( 'config-invalid-db-type' );
525 return $installer->submitConnectForm();
530 class WebInstaller_Upgrade
extends WebInstallerPage
{
531 public function isSlow() {
535 public function execute() {
536 if ( $this->getVar( '_UpgradeDone' ) ) {
537 // Allow regeneration of LocalSettings.php, unless we are working
538 // from a pre-existing LocalSettings.php file and we want to avoid
539 // leaking its contents
540 if ( $this->parent
->request
->wasPosted() && !$this->getVar( '_ExistingDBSettings' ) ) {
541 // Done message acknowledged
545 // Show the done message again
546 // Make them click back again if they want to do the upgrade again
547 $this->showDoneMessage();
552 // wgDBtype is generally valid here because otherwise the previous page
553 // (connect) wouldn't have declared its happiness
554 $type = $this->getVar( 'wgDBtype' );
555 $installer = $this->parent
->getDBInstaller( $type );
557 if ( !$installer->needsUpgrade() ) {
561 if ( $this->parent
->request
->wasPosted() ) {
562 $installer->preUpgrade();
564 $this->startLiveBox();
565 $result = $installer->doUpgrade();
569 // If they're going to possibly regenerate LocalSettings, we
570 // need to create the upgrade/secret keys. Bug 26481
571 if ( !$this->getVar( '_ExistingDBSettings' ) ) {
572 $this->parent
->generateKeys();
574 $this->setVar( '_UpgradeDone', true );
575 $this->showDoneMessage();
581 $this->addHTML( $this->parent
->getInfoBox(
582 wfMessage( 'config-can-upgrade', $GLOBALS['wgVersion'] )->plain() ) );
586 public function showDoneMessage() {
588 $regenerate = !$this->getVar( '_ExistingDBSettings' );
590 $msg = 'config-upgrade-done';
592 $msg = 'config-upgrade-done-no-regenerate';
594 $this->parent
->disableLinkPopups();
596 $this->parent
->getInfoBox(
598 $this->getVar( 'wgServer' ) .
599 $this->getVar( 'wgScriptPath' ) . '/index' .
600 $this->getVar( 'wgScriptExtension' )
601 )->plain(), 'tick-32.png'
604 $this->parent
->restoreLinkPopups();
605 $this->endForm( $regenerate ?
'regenerate' : false, false );
610 class WebInstaller_DBSettings
extends WebInstallerPage
{
612 public function execute() {
613 $installer = $this->parent
->getDBInstaller( $this->getVar( 'wgDBtype' ) );
615 $r = $this->parent
->request
;
616 if ( $r->wasPosted() ) {
617 $status = $installer->submitSettingsForm();
618 if ( $status === false ) {
620 } elseif ( $status->isGood() ) {
623 $this->parent
->showStatusBox( $status );
627 $form = $installer->getSettingsForm();
628 if ( $form === false ) {
633 $this->addHTML( $form );
639 class WebInstaller_Name
extends WebInstallerPage
{
641 public function execute() {
642 $r = $this->parent
->request
;
643 if ( $r->wasPosted() ) {
644 if ( $this->submit() ) {
651 // Encourage people to not name their site 'MediaWiki' by blanking the
652 // field. I think that was the intent with the original $GLOBALS['wgSitename']
653 // but these two always were the same so had the effect of making the
654 // installer forget $wgSitename when navigating back to this page.
655 if ( $this->getVar( 'wgSitename' ) == 'MediaWiki' ) {
656 $this->setVar( 'wgSitename', '' );
659 // Set wgMetaNamespace to something valid before we show the form.
660 // $wgMetaNamespace defaults to $wgSiteName which is 'MediaWiki'
661 $metaNS = $this->getVar( 'wgMetaNamespace' );
664 wfMessage( 'config-ns-other-default' )->inContentLanguage()->text()
668 $this->parent
->getTextBox( array(
669 'var' => 'wgSitename',
670 'label' => 'config-site-name',
671 'help' => $this->parent
->getHelpBox( 'config-site-name-help' )
673 // getRadioSet() builds a set of labeled radio buttons.
674 // For grep: The following messages are used as the item labels:
675 // config-ns-site-name, config-ns-generic, config-ns-other
676 $this->parent
->getRadioSet( array(
677 'var' => '_NamespaceType',
678 'label' => 'config-project-namespace',
679 'itemLabelPrefix' => 'config-ns-',
680 'values' => array( 'site-name', 'generic', 'other' ),
681 'commonAttribs' => array( 'class' => 'enableForOther',
682 'rel' => 'config_wgMetaNamespace' ),
683 'help' => $this->parent
->getHelpBox( 'config-project-namespace-help' )
685 $this->parent
->getTextBox( array(
686 'var' => 'wgMetaNamespace',
687 'label' => '', //TODO: Needs a label?
688 'attribs' => array( 'readonly' => 'readonly', 'class' => 'enabledByOther' ),
691 $this->getFieldSetStart( 'config-admin-box' ) .
692 $this->parent
->getTextBox( array(
693 'var' => '_AdminName',
694 'label' => 'config-admin-name',
695 'help' => $this->parent
->getHelpBox( 'config-admin-help' )
697 $this->parent
->getPasswordBox( array(
698 'var' => '_AdminPassword',
699 'label' => 'config-admin-password',
701 $this->parent
->getPasswordBox( array(
702 'var' => '_AdminPassword2',
703 'label' => 'config-admin-password-confirm'
705 $this->parent
->getTextBox( array(
706 'var' => '_AdminEmail',
707 'label' => 'config-admin-email',
708 'help' => $this->parent
->getHelpBox( 'config-admin-email-help' )
710 $this->parent
->getCheckBox( array(
711 'var' => '_Subscribe',
712 'label' => 'config-subscribe',
713 'help' => $this->parent
->getHelpBox( 'config-subscribe-help' )
715 $this->getFieldSetEnd() .
716 $this->parent
->getInfoBox( wfMessage( 'config-almost-done' )->text() ) .
717 // getRadioSet() builds a set of labeled radio buttons.
718 // For grep: The following messages are used as the item labels:
719 // config-optional-continue, config-optional-skip
720 $this->parent
->getRadioSet( array(
721 'var' => '_SkipOptional',
722 'itemLabelPrefix' => 'config-optional-',
723 'values' => array( 'continue', 'skip' )
727 // Restore the default value
728 $this->setVar( 'wgMetaNamespace', $metaNS );
734 public function submit() {
736 $this->parent
->setVarsFromRequest( array( 'wgSitename', '_NamespaceType',
737 '_AdminName', '_AdminPassword', '_AdminPassword2', '_AdminEmail',
738 '_Subscribe', '_SkipOptional', 'wgMetaNamespace' ) );
740 // Validate site name
741 if ( strval( $this->getVar( 'wgSitename' ) ) === '' ) {
742 $this->parent
->showError( 'config-site-name-blank' );
747 $nsType = $this->getVar( '_NamespaceType' );
748 if ( $nsType == 'site-name' ) {
749 $name = $this->getVar( 'wgSitename' );
750 // Sanitize for namespace
751 // This algorithm should match the JS one in WebInstallerOutput.php
752 $name = preg_replace( '/[\[\]\{\}|#<>%+? ]/', '_', $name );
753 $name = str_replace( '&', '&', $name );
754 $name = preg_replace( '/__+/', '_', $name );
755 $name = ucfirst( trim( $name, '_' ) );
756 } elseif ( $nsType == 'generic' ) {
757 $name = wfMessage( 'config-ns-generic' )->text();
759 $name = $this->getVar( 'wgMetaNamespace' );
762 // Validate namespace
763 if ( strpos( $name, ':' ) !== false ) {
766 // Title-style validation
767 $title = Title
::newFromText( $name );
769 $good = $nsType == 'site-name';
771 $name = $title->getDBkey();
776 $this->parent
->showError( 'config-ns-invalid', $name );
780 // Make sure it won't conflict with any existing namespaces
782 $nsIndex = $wgContLang->getNsIndex( $name );
783 if ( $nsIndex !== false && $nsIndex !== NS_PROJECT
) {
784 $this->parent
->showError( 'config-ns-conflict', $name );
788 $this->setVar( 'wgMetaNamespace', $name );
790 // Validate username for creation
791 $name = $this->getVar( '_AdminName' );
792 if ( strval( $name ) === '' ) {
793 $this->parent
->showError( 'config-admin-name-blank' );
797 $cname = User
::getCanonicalName( $name, 'creatable' );
798 if ( $cname === false ) {
799 $this->parent
->showError( 'config-admin-name-invalid', $name );
802 $this->setVar( '_AdminName', $cname );
808 $pwd = $this->getVar( '_AdminPassword' );
809 $user = User
::newFromName( $cname );
810 $valid = $user && $user->getPasswordValidity( $pwd );
811 if ( strval( $pwd ) === '' ) {
812 # $user->getPasswordValidity just checks for $wgMinimalPasswordLength.
813 # This message is more specific and helpful.
814 $msg = 'config-admin-password-blank';
815 } elseif ( $pwd !== $this->getVar( '_AdminPassword2' ) ) {
816 $msg = 'config-admin-password-mismatch';
817 } elseif ( $valid !== true ) {
818 # As of writing this will only catch the username being e.g. 'FOO' and
822 if ( $msg !== false ) {
823 call_user_func_array( array( $this->parent
, 'showError' ), (array)$msg );
824 $this->setVar( '_AdminPassword', '' );
825 $this->setVar( '_AdminPassword2', '' );
829 // Validate e-mail if provided
830 $email = $this->getVar( '_AdminEmail' );
831 if ( $email && !Sanitizer
::validateEmail( $email ) ) {
832 $this->parent
->showError( 'config-admin-error-bademail' );
835 // If they asked to subscribe to mediawiki-announce but didn't give
836 // an e-mail, show an error. Bug 29332
837 if ( !$email && $this->getVar( '_Subscribe' ) ) {
838 $this->parent
->showError( 'config-subscribe-noemail' );
847 class WebInstaller_Options
extends WebInstallerPage
{
849 public function execute() {
850 if ( $this->getVar( '_SkipOptional' ) == 'skip' ) {
853 if ( $this->parent
->request
->wasPosted() ) {
854 if ( $this->submit() ) {
859 $emailwrapperStyle = $this->getVar( 'wgEnableEmail' ) ?
'' : 'display: none';
863 // getRadioSet() builds a set of labeled radio buttons.
864 // For grep: The following messages are used as the item labels:
865 // config-profile-wiki, config-profile-no-anon, config-profile-fishbowl, config-profile-private
866 $this->parent
->getRadioSet( array(
867 'var' => '_RightsProfile',
868 'label' => 'config-profile',
869 'itemLabelPrefix' => 'config-profile-',
870 'values' => array_keys( $this->parent
->rightsProfiles
),
872 $this->parent
->getInfoBox( wfMessage( 'config-profile-help' )->plain() ) .
875 // getRadioSet() builds a set of labeled radio buttons.
876 // For grep: The following messages are used as the item labels:
877 // config-license-cc-by, config-license-cc-by-sa, config-license-cc-by-nc-sa,
878 // config-license-cc-0, config-license-pd, config-license-gfdl,
879 // config-license-none, config-license-cc-choose
880 $this->parent
->getRadioSet( array(
881 'var' => '_LicenseCode',
882 'label' => 'config-license',
883 'itemLabelPrefix' => 'config-license-',
884 'values' => array_keys( $this->parent
->licenses
),
885 'commonAttribs' => array( 'class' => 'licenseRadio' ),
887 $this->getCCChooser() .
888 $this->parent
->getHelpBox( 'config-license-help' ) .
891 $this->getFieldSetStart( 'config-email-settings' ) .
892 $this->parent
->getCheckBox( array(
893 'var' => 'wgEnableEmail',
894 'label' => 'config-enable-email',
895 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'emailwrapper' ),
897 $this->parent
->getHelpBox( 'config-enable-email-help' ) .
898 "<div id=\"emailwrapper\" style=\"$emailwrapperStyle\">" .
899 $this->parent
->getTextBox( array(
900 'var' => 'wgPasswordSender',
901 'label' => 'config-email-sender'
903 $this->parent
->getHelpBox( 'config-email-sender-help' ) .
904 $this->parent
->getCheckBox( array(
905 'var' => 'wgEnableUserEmail',
906 'label' => 'config-email-user',
908 $this->parent
->getHelpBox( 'config-email-user-help' ) .
909 $this->parent
->getCheckBox( array(
910 'var' => 'wgEnotifUserTalk',
911 'label' => 'config-email-usertalk',
913 $this->parent
->getHelpBox( 'config-email-usertalk-help' ) .
914 $this->parent
->getCheckBox( array(
915 'var' => 'wgEnotifWatchlist',
916 'label' => 'config-email-watchlist',
918 $this->parent
->getHelpBox( 'config-email-watchlist-help' ) .
919 $this->parent
->getCheckBox( array(
920 'var' => 'wgEmailAuthentication',
921 'label' => 'config-email-auth',
923 $this->parent
->getHelpBox( 'config-email-auth-help' ) .
925 $this->getFieldSetEnd()
928 $extensions = $this->parent
->findExtensions();
931 $extHtml = $this->getFieldSetStart( 'config-extensions' );
933 foreach ( $extensions as $ext ) {
934 $extHtml .= $this->parent
->getCheckBox( array(
940 $extHtml .= $this->parent
->getHelpBox( 'config-extensions-help' ) .
941 $this->getFieldSetEnd();
942 $this->addHTML( $extHtml );
945 // Having / in paths in Windows looks funny :)
946 $this->setVar( 'wgDeletedDirectory',
948 '/', DIRECTORY_SEPARATOR
,
949 $this->getVar( 'wgDeletedDirectory' )
952 // If we're using the default, let the user set it relative to $wgScriptPath
953 $curLogo = $this->getVar( 'wgLogo' );
954 $logoString = ( $curLogo == "/wiki/skins/common/images/wiki.png" ) ?
955 '$wgStylePath/common/images/wiki.png' : $curLogo;
957 $uploadwrapperStyle = $this->getVar( 'wgEnableUploads' ) ?
'' : 'display: none';
960 $this->getFieldSetStart( 'config-upload-settings' ) .
961 $this->parent
->getCheckBox( array(
962 'var' => 'wgEnableUploads',
963 'label' => 'config-upload-enable',
964 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'uploadwrapper' ),
965 'help' => $this->parent
->getHelpBox( 'config-upload-help' )
967 '<div id="uploadwrapper" style="' . $uploadwrapperStyle . '">' .
968 $this->parent
->getTextBox( array(
969 'var' => 'wgDeletedDirectory',
970 'label' => 'config-upload-deleted',
971 'attribs' => array( 'dir' => 'ltr' ),
972 'help' => $this->parent
->getHelpBox( 'config-upload-deleted-help' )
975 $this->parent
->getTextBox( array(
977 'value' => $logoString,
978 'label' => 'config-logo',
979 'attribs' => array( 'dir' => 'ltr' ),
980 'help' => $this->parent
->getHelpBox( 'config-logo-help' )
984 $this->parent
->getCheckBox( array(
985 'var' => 'wgUseInstantCommons',
986 'label' => 'config-instantcommons',
987 'help' => $this->parent
->getHelpBox( 'config-instantcommons-help' )
989 $this->getFieldSetEnd()
992 $caches = array( 'none' );
993 if ( count( $this->getVar( '_Caches' ) ) ) {
996 $caches[] = 'memcached';
998 // We'll hide/show this on demand when the value changes, see config.js.
999 $cacheval = $this->getVar( 'wgMainCacheType' );
1001 // We need to set a default here; but don't hardcode it
1002 // or we lose it every time we reload the page for validation
1006 $hidden = ( $cacheval == 'memcached' ) ?
'' : 'display: none';
1009 $this->getFieldSetStart( 'config-advanced-settings' ) .
1010 # Object cache settings
1011 // getRadioSet() builds a set of labeled radio buttons.
1012 // For grep: The following messages are used as the item labels:
1013 // config-cache-none, config-cache-accel, config-cache-memcached
1014 $this->parent
->getRadioSet( array(
1015 'var' => 'wgMainCacheType',
1016 'label' => 'config-cache-options',
1017 'itemLabelPrefix' => 'config-cache-',
1018 'values' => $caches,
1019 'value' => $cacheval,
1021 $this->parent
->getHelpBox( 'config-cache-help' ) .
1022 "<div id=\"config-memcachewrapper\" style=\"$hidden\">" .
1023 $this->parent
->getTextArea( array(
1024 'var' => '_MemCachedServers',
1025 'label' => 'config-memcached-servers',
1026 'help' => $this->parent
->getHelpBox( 'config-memcached-help' )
1029 $this->getFieldSetEnd()
1037 public function getCCPartnerUrl() {
1038 $server = $this->getVar( 'wgServer' );
1039 $exitUrl = $server . $this->parent
->getUrl( array(
1040 'page' => 'Options',
1041 'SubmitCC' => 'indeed',
1042 'config__LicenseCode' => 'cc',
1043 'config_wgRightsUrl' => '[license_url]',
1044 'config_wgRightsText' => '[license_name]',
1045 'config_wgRightsIcon' => '[license_button]',
1047 $styleUrl = $server . dirname( dirname( $this->parent
->getUrl() ) ) .
1048 '/skins/common/config-cc.css';
1049 $iframeUrl = 'http://creativecommons.org/license/?' .
1050 wfArrayToCgi( array(
1051 'partner' => 'MediaWiki',
1052 'exit_url' => $exitUrl,
1053 'lang' => $this->getVar( '_UserLang' ),
1054 'stylesheet' => $styleUrl,
1059 public function getCCChooser() {
1060 $iframeAttribs = array(
1061 'class' => 'config-cc-iframe',
1062 'name' => 'config-cc-iframe',
1063 'id' => 'config-cc-iframe',
1068 if ( $this->getVar( '_CCDone' ) ) {
1069 $iframeAttribs['src'] = $this->parent
->getUrl( array( 'ShowCC' => 'yes' ) );
1071 $iframeAttribs['src'] = $this->getCCPartnerUrl();
1073 $wrapperStyle = ( $this->getVar( '_LicenseCode' ) == 'cc-choose' ) ?
'' : 'display: none';
1075 return "<div class=\"config-cc-wrapper\" id=\"config-cc-wrapper\" style=\"$wrapperStyle\">\n" .
1076 Html
::element( 'iframe', $iframeAttribs, '', false /* not short */ ) .
1080 public function getCCDoneBox() {
1081 $js = "parent.document.getElementById('config-cc-wrapper').style.height = '$1';";
1082 // If you change this height, also change it in config.css
1083 $expandJs = str_replace( '$1', '54em', $js );
1084 $reduceJs = str_replace( '$1', '70px', $js );
1086 Html
::element( 'img', array( 'src' => $this->getVar( 'wgRightsIcon' ) ) ) .
1088 htmlspecialchars( $this->getVar( 'wgRightsText' ) ) .
1090 "<p style=\"text-align: center;\">" .
1093 'href' => $this->getCCPartnerUrl(),
1094 'onclick' => $expandJs,
1096 wfMessage( 'config-cc-again' )->text()
1100 # Reduce the wrapper div height
1101 htmlspecialchars( $reduceJs ) .
1106 public function submitCC() {
1107 $newValues = $this->parent
->setVarsFromRequest(
1108 array( 'wgRightsUrl', 'wgRightsText', 'wgRightsIcon' ) );
1109 if ( count( $newValues ) != 3 ) {
1110 $this->parent
->showError( 'config-cc-error' );
1113 $this->setVar( '_CCDone', true );
1114 $this->addHTML( $this->getCCDoneBox() );
1117 public function submit() {
1118 $this->parent
->setVarsFromRequest( array( '_RightsProfile', '_LicenseCode',
1119 'wgEnableEmail', 'wgPasswordSender', 'wgEnableUploads', 'wgLogo',
1120 'wgEnableUserEmail', 'wgEnotifUserTalk', 'wgEnotifWatchlist',
1121 'wgEmailAuthentication', 'wgMainCacheType', '_MemCachedServers',
1122 'wgUseInstantCommons' ) );
1124 if ( !in_array( $this->getVar( '_RightsProfile' ),
1125 array_keys( $this->parent
->rightsProfiles
) ) )
1127 reset( $this->parent
->rightsProfiles
);
1128 $this->setVar( '_RightsProfile', key( $this->parent
->rightsProfiles
) );
1131 $code = $this->getVar( '_LicenseCode' );
1132 if ( $code == 'cc-choose' ) {
1133 if ( !$this->getVar( '_CCDone' ) ) {
1134 $this->parent
->showError( 'config-cc-not-chosen' );
1137 } elseif ( in_array( $code, array_keys( $this->parent
->licenses
) ) ) {
1139 // config-license-cc-by, config-license-cc-by-sa, config-license-cc-by-nc-sa,
1140 // config-license-cc-0, config-license-pd, config-license-gfdl, config-license-none,
1141 // config-license-cc-choose
1142 $entry = $this->parent
->licenses
[$code];
1143 if ( isset( $entry['text'] ) ) {
1144 $this->setVar( 'wgRightsText', $entry['text'] );
1146 $this->setVar( 'wgRightsText', wfMessage( 'config-license-' . $code )->text() );
1148 $this->setVar( 'wgRightsUrl', $entry['url'] );
1149 $this->setVar( 'wgRightsIcon', $entry['icon'] );
1151 $this->setVar( 'wgRightsText', '' );
1152 $this->setVar( 'wgRightsUrl', '' );
1153 $this->setVar( 'wgRightsIcon', '' );
1156 $extsAvailable = $this->parent
->findExtensions();
1157 $extsToInstall = array();
1158 foreach ( $extsAvailable as $ext ) {
1159 if ( $this->parent
->request
->getCheck( 'config_ext-' . $ext ) ) {
1160 $extsToInstall[] = $ext;
1163 $this->parent
->setVar( '_Extensions', $extsToInstall );
1165 if ( $this->getVar( 'wgMainCacheType' ) == 'memcached' ) {
1166 $memcServers = explode( "\n", $this->getVar( '_MemCachedServers' ) );
1167 if ( !$memcServers ) {
1168 $this->parent
->showError( 'config-memcache-needservers' );
1172 foreach ( $memcServers as $server ) {
1173 $memcParts = explode( ":", $server, 2 );
1174 if ( !isset( $memcParts[0] )
1175 ||
( !IP
::isValid( $memcParts[0] )
1176 && ( gethostbyname( $memcParts[0] ) == $memcParts[0] ) ) ) {
1177 $this->parent
->showError( 'config-memcache-badip', $memcParts[0] );
1179 } elseif ( !isset( $memcParts[1] ) ) {
1180 $this->parent
->showError( 'config-memcache-noport', $memcParts[0] );
1182 } elseif ( $memcParts[1] < 1 ||
$memcParts[1] > 65535 ) {
1183 $this->parent
->showError( 'config-memcache-badport', 1, 65535 );
1193 class WebInstaller_Install
extends WebInstallerPage
{
1194 public function isSlow() {
1198 public function execute() {
1199 if ( $this->getVar( '_UpgradeDone' ) ) {
1201 } elseif ( $this->getVar( '_InstallDone' ) ) {
1203 } elseif ( $this->parent
->request
->wasPosted() ) {
1205 $this->addHTML( "<ul>" );
1206 $results = $this->parent
->performInstallation(
1207 array( $this, 'startStage' ),
1208 array( $this, 'endStage' )
1210 $this->addHTML( "</ul>" );
1211 // PerformInstallation bails on a fatal, so make sure the last item
1212 // completed before giving 'next.' Likewise, only provide back on failure
1213 $lastStep = end( $results );
1214 $continue = $lastStep->isOK() ?
'continue' : false;
1215 $back = $lastStep->isOK() ?
false : 'back';
1216 $this->endForm( $continue, $back );
1219 $this->addHTML( $this->parent
->getInfoBox( wfMessage( 'config-install-begin' )->plain() ) );
1225 public function startStage( $step ) {
1226 // Messages: config-install-database, config-install-tables, config-install-interwiki,
1227 // config-install-stats, config-install-keys, config-install-sysop, config-install-mainpage
1228 $this->addHTML( "<li>" . wfMessage( "config-install-$step" )->escaped() . wfMessage( 'ellipsis' )->escaped() );
1229 if ( $step == 'extension-tables' ) {
1230 $this->startLiveBox();
1236 * @param $status Status
1238 public function endStage( $step, $status ) {
1239 if ( $step == 'extension-tables' ) {
1240 $this->endLiveBox();
1242 $msg = $status->isOk() ?
'config-install-step-done' : 'config-install-step-failed';
1243 $html = wfMessage( 'word-separator' )->escaped() . wfMessage( $msg )->escaped();
1244 if ( !$status->isOk() ) {
1245 $html = "<span class=\"error\">$html</span>";
1247 $this->addHTML( $html . "</li>\n" );
1248 if ( !$status->isGood() ) {
1249 $this->parent
->showStatusBox( $status );
1255 class WebInstaller_Complete
extends WebInstallerPage
{
1257 public function execute() {
1258 // Pop up a dialog box, to make it difficult for the user to forget
1259 // to download the file
1260 $lsUrl = $this->getVar( 'wgServer' ) . $this->parent
->getURL( array( 'localsettings' => 1 ) );
1261 if ( isset( $_SERVER['HTTP_USER_AGENT'] ) &&
1262 strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE' ) !== false ) {
1263 // JS appears to be the only method that works consistently with IE7+
1264 $this->addHtml( "\n<script>jQuery( function () { document.location = " .
1265 Xml
::encodeJsVar( $lsUrl ) . "; } );</script>\n" );
1267 $this->parent
->request
->response()->header( "Refresh: 0;url=$lsUrl" );
1271 $this->parent
->disableLinkPopups();
1273 $this->parent
->getInfoBox(
1274 wfMessage( 'config-install-done',
1276 $this->getVar( 'wgServer' ) .
1277 $this->getVar( 'wgScriptPath' ) . '/index' .
1278 $this->getVar( 'wgScriptExtension' ),
1280 )->plain(), 'tick-32.png'
1283 $this->addHTML( $this->parent
->getInfoBox(
1284 wfMessage( 'config-extension-link' )->text() ) );
1286 $this->parent
->restoreLinkPopups();
1287 $this->endForm( false, false );
1291 class WebInstaller_Restart
extends WebInstallerPage
{
1293 public function execute() {
1294 $r = $this->parent
->request
;
1295 if ( $r->wasPosted() ) {
1296 $really = $r->getVal( 'submit-restart' );
1298 $this->parent
->reset();
1304 $s = $this->parent
->getWarningBox( wfMessage( 'config-help-restart' )->plain() );
1305 $this->addHTML( $s );
1306 $this->endForm( 'restart' );
1311 abstract class WebInstaller_Document
extends WebInstallerPage
{
1313 abstract protected function getFileName();
1315 public function execute() {
1316 $text = $this->getFileContents();
1317 $text = InstallDocFormatter
::format( $text );
1318 $this->parent
->output
->addWikiText( $text );
1320 $this->endForm( false );
1323 public function getFileContents() {
1324 $file = __DIR__
. '/../../' . $this->getFileName();
1325 if ( ! file_exists( $file ) ) {
1326 return wfMessage( 'config-nofile', $file )->plain();
1328 return file_get_contents( $file );
1333 class WebInstaller_Readme
extends WebInstaller_Document
{
1334 protected function getFileName() {
1339 class WebInstaller_ReleaseNotes
extends WebInstaller_Document
{
1340 protected function getFileName() {
1343 if ( !preg_match( '/^(\d+)\.(\d+).*/i', $wgVersion, $result ) ) {
1344 throw new MWException( 'Variable $wgVersion has an invalid value.' );
1347 return 'RELEASE-NOTES-' . $result[1] . '.' . $result[2];
1351 class WebInstaller_UpgradeDoc
extends WebInstaller_Document
{
1352 protected function getFileName() {
1357 class WebInstaller_Copying
extends WebInstaller_Document
{
1358 protected function getFileName() {