3 * Base code for web installer pages.
10 * Abstract class to define pages for the web installer.
15 abstract class WebInstallerPage
{
18 * The WebInstaller object this WebInstallerPage belongs to.
24 public abstract function execute();
29 * @param $parent WebInstaller
31 public function __construct( WebInstaller
$parent ) {
32 $this->parent
= $parent;
36 * Is this a slow-running page in the installer? If so, WebInstaller will
37 * set_time_limit(0) before calling execute(). Right now this only applies
38 * to Install and Upgrade pages
40 public function isSlow() {
44 public function addHTML( $html ) {
45 $this->parent
->output
->addHTML( $html );
48 public function startForm() {
50 "<div class=\"config-section\">\n" .
55 'action' => $this->parent
->getUrl( array( 'page' => $this->getName() ) )
61 public function endForm( $continue = 'continue', $back = 'back' ) {
62 $s = "<div class=\"config-submit\">\n";
65 if ( $id === false ) {
66 $s .= Html
::hidden( 'lastPage', $this->parent
->request
->getVal( 'lastPage' ) );
70 // Fake submit button for enter keypress (bug 26267)
71 $s .= Xml
::submitButton( wfMsg( "config-$continue" ),
72 array( 'name' => "enter-$continue", 'style' => 'visibility:hidden;overflow:hidden;width:1px;margin:0' ) ) . "\n";
76 $s .= Xml
::submitButton( wfMsg( "config-$back" ),
78 'name' => "submit-$back",
79 'tabindex' => $this->parent
->nextTabIndex()
84 $s .= Xml
::submitButton( wfMsg( "config-$continue" ),
86 'name' => "submit-$continue",
87 'tabindex' => $this->parent
->nextTabIndex(),
91 $s .= "</div></form></div>\n";
95 public function getName() {
96 return str_replace( 'WebInstaller_', '', get_class( $this ) );
99 protected function getId() {
100 return array_search( $this->getName(), $this->parent
->pageSequence
);
103 public function getVar( $var ) {
104 return $this->parent
->getVar( $var );
107 public function setVar( $name, $value ) {
108 $this->parent
->setVar( $name, $value );
112 * Get the starting tags of a fieldset.
114 * @param $legend String: message name
118 protected function getFieldsetStart( $legend ) {
119 return "\n<fieldset><legend>" . wfMsgHtml( $legend ) . "</legend>\n";
123 * Get the end tag of a fieldset.
127 protected function getFieldsetEnd() {
128 return "</fieldset>\n";
132 * Opens a textarea used to display the progress of a long operation
134 protected function startLiveBox() {
136 '<div id="config-spinner" style="display:none;"><img src="../skins/common/images/ajax-loader.gif" /></div>' .
137 '<script>jQuery( "#config-spinner" ).show();</script>' .
138 '<div id="config-live-log"><textarea name="LiveLog" rows="10" cols="30" readonly="readonly">'
140 $this->parent
->output
->flush();
144 * Opposite to startLiveBox()
146 protected function endLiveBox() {
147 $this->addHTML( '</textarea></div>
148 <script>jQuery( "#config-spinner" ).hide()</script>' );
149 $this->parent
->output
->flush();
153 class WebInstaller_Language
extends WebInstallerPage
{
155 public function execute() {
157 $r = $this->parent
->request
;
158 $userLang = $r->getVal( 'UserLang' );
159 $contLang = $r->getVal( 'ContLang' );
161 $lifetime = intval( ini_get( 'session.gc_maxlifetime' ) );
163 $lifetime = 1440; // PHP default
166 if ( $r->wasPosted() ) {
168 if ( $this->parent
->getSession( 'test' ) === null ) {
169 $requestTime = $r->getVal( 'LanguageRequestTime' );
170 if ( !$requestTime ) {
171 // The most likely explanation is that the user was knocked back
172 // from another page on POST due to session expiry
173 $msg = 'config-session-expired';
174 } elseif ( time() - $requestTime > $lifetime ) {
175 $msg = 'config-session-expired';
177 $msg = 'config-no-session';
179 $this->parent
->showError( $msg, $wgLang->formatTimePeriod( $lifetime ) );
181 $languages = Language
::getLanguageNames();
182 if ( isset( $languages[$userLang] ) ) {
183 $this->setVar( '_UserLang', $userLang );
185 if ( isset( $languages[$contLang] ) ) {
186 $this->setVar( 'wgLanguageCode', $contLang );
190 } elseif ( $this->parent
->showSessionWarning
) {
191 # The user was knocked back from another page to the start
192 # This probably indicates a session expiry
193 $this->parent
->showError( 'config-session-expired', $wgLang->formatTimePeriod( $lifetime ) );
196 $this->parent
->setSession( 'test', true );
198 if ( !isset( $languages[$userLang] ) ) {
199 $userLang = $this->getVar( '_UserLang', 'en' );
201 if ( !isset( $languages[$contLang] ) ) {
202 $contLang = $this->getVar( 'wgLanguageCode', 'en' );
205 $s = Html
::hidden( 'LanguageRequestTime', time() ) .
206 $this->getLanguageSelector( 'UserLang', 'config-your-language', $userLang, $this->parent
->getHelpBox( 'config-your-language-help' ) ) .
207 $this->getLanguageSelector( 'ContLang', 'config-wiki-language', $contLang, $this->parent
->getHelpBox( 'config-wiki-language-help' ) );
208 $this->addHTML( $s );
209 $this->endForm( 'continue', false );
213 * Get a <select> for selecting languages.
217 public function getLanguageSelector( $name, $label, $selectedCode, $helpHtml = '' ) {
218 global $wgDummyLanguageCodes;
222 $s .= Html
::openElement( 'select', array( 'id' => $name, 'name' => $name ) ) . "\n";
224 $languages = Language
::getLanguageNames();
226 $dummies = array_flip( $wgDummyLanguageCodes );
227 foreach ( $languages as $code => $lang ) {
228 if ( isset( $dummies[$code] ) ) continue;
229 $s .= "\n" . Xml
::option( "$code - $lang", $code, $code == $selectedCode );
231 $s .= "\n</select>\n";
232 return $this->parent
->label( $label, $name, $s );
237 class WebInstaller_ExistingWiki
extends WebInstallerPage
{
238 public function execute() {
239 // If there is no LocalSettings.php, continue to the installer welcome page
240 $vars = Installer
::getExistingLocalSettings();
245 // Check if the upgrade key supplied to the user has appeared in LocalSettings.php
246 if ( $vars['wgUpgradeKey'] !== false
247 && $this->getVar( '_UpgradeKeySupplied' )
248 && $this->getVar( 'wgUpgradeKey' ) === $vars['wgUpgradeKey'] )
250 // It's there, so the user is authorized
251 $status = $this->handleExistingUpgrade( $vars );
252 if ( $status->isOK() ) {
256 $this->parent
->showStatusBox( $status );
257 $this->endForm( 'continue' );
262 // If there is no $wgUpgradeKey, tell the user to add one to LocalSettings.php
263 if ( $vars['wgUpgradeKey'] === false ) {
264 if ( $this->getVar( 'wgUpgradeKey', false ) === false ) {
265 $secretKey = $this->getVar( 'wgSecretKey' ); // preserve $wgSecretKey
266 $this->parent
->generateKeys();
267 $this->setVar( 'wgSecretKey', $secretKey );
268 $this->setVar( '_UpgradeKeySupplied', true );
271 $this->addHTML( $this->parent
->getInfoBox(
272 wfMsgNoTrans( 'config-upgrade-key-missing',
273 "<pre>\$wgUpgradeKey = '" . $this->getVar( 'wgUpgradeKey' ) . "';</pre>" )
275 $this->endForm( 'continue' );
279 // If there is an upgrade key, but it wasn't supplied, prompt the user to enter it
281 $r = $this->parent
->request
;
282 if ( $r->wasPosted() ) {
283 $key = $r->getText( 'config_wgUpgradeKey' );
284 if( !$key ||
$key !== $vars['wgUpgradeKey'] ) {
285 $this->parent
->showError( 'config-localsettings-badkey' );
286 $this->showKeyForm();
290 $status = $this->handleExistingUpgrade( $vars );
291 if ( $status->isOK() ) {
294 $this->parent
->showStatusBox( $status );
295 $this->showKeyForm();
299 $this->showKeyForm();
305 * Show the "enter key" form
307 protected function showKeyForm() {
310 $this->parent
->getInfoBox( wfMsgNoTrans( 'config-localsettings-upgrade' ) ).
312 $this->parent
->getTextBox( array(
313 'var' => 'wgUpgradeKey',
314 'label' => 'config-localsettings-key',
315 'attribs' => array( 'autocomplete' => 'off' ),
318 $this->endForm( 'continue' );
321 protected function importVariables( $names, $vars ) {
322 $status = Status
::newGood();
323 foreach ( $names as $name ) {
324 if ( !isset( $vars[$name] ) ) {
325 $status->fatal( 'config-localsettings-incomplete', $name );
327 $this->setVar( $name, $vars[$name] );
333 * Initiate an upgrade of the existing database
334 * @param $vars Variables from LocalSettings.php and AdminSettings.php
337 protected function handleExistingUpgrade( $vars ) {
339 if ( !isset( $vars['wgDBtype'] ) ||
!in_array( $vars['wgDBtype'], Installer
::getDBTypes() ) ) {
340 return Status
::newFatal( 'config-localsettings-connection-error', '' );
343 // Set the relevant variables from LocalSettings.php
344 $requiredVars = array( 'wgDBtype' );
345 $status = $this->importVariables( $requiredVars , $vars );
346 $installer = $this->parent
->getDBInstaller();
347 $status->merge( $this->importVariables( $installer->getGlobalNames(), $vars ) );
348 if ( !$status->isOK() ) {
352 if ( isset( $vars['wgDBadminuser'] ) ) {
353 $this->setVar( '_InstallUser', $vars['wgDBadminuser'] );
355 $this->setVar( '_InstallUser', $vars['wgDBuser'] );
357 if ( isset( $vars['wgDBadminpassword'] ) ) {
358 $this->setVar( '_InstallPassword', $vars['wgDBadminpassword'] );
360 $this->setVar( '_InstallPassword', $vars['wgDBpassword'] );
363 // Test the database connection
364 $status = $installer->getConnection();
365 if ( !$status->isOK() ) {
366 // Adjust the error message to explain things correctly
367 $status->replaceMessage( 'config-connection-error',
368 'config-localsettings-connection-error' );
373 $this->setVar( '_ExistingDBSettings', true );
378 class WebInstaller_Welcome
extends WebInstallerPage
{
380 public function execute() {
381 if ( $this->parent
->request
->wasPosted() ) {
382 if ( $this->getVar( '_Environment' ) ) {
386 $this->parent
->output
->addWikiText( wfMsgNoTrans( 'config-welcome' ) );
387 $status = $this->parent
->doEnvironmentChecks();
388 if ( $status->isGood() ) {
389 $this->parent
->output
->addHTML( '<span class="success-message">' .
390 wfMsgHtml( 'config-env-good' ) . '</span>' );
391 $this->parent
->output
->addWikiText( wfMsgNoTrans( 'config-copyright',
392 SpecialVersion
::getCopyrightAndAuthorList() ) );
396 $this->parent
->showStatusMessage( $status );
402 class WebInstaller_DBConnect
extends WebInstallerPage
{
404 public function execute() {
405 if ( $this->getVar( '_ExistingDBSettings' ) ) {
409 $r = $this->parent
->request
;
410 if ( $r->wasPosted() ) {
411 $status = $this->submit();
413 if ( $status->isGood() ) {
414 $this->setVar( '_UpgradeDone', false );
417 $this->parent
->showStatusBox( $status );
423 $types = "<ul class=\"config-settings-block\">\n";
425 $defaultType = $this->getVar( 'wgDBtype' );
428 foreach( $this->parent
->getDBTypes() as $type ) {
429 $link = DatabaseBase
::factory( $type )->getSoftwareLink();
430 $dbSupport .= wfMsgNoTrans( "config-support-$type", $link ) . "\n";
432 $this->addHTML( $this->parent
->getInfoBox(
433 wfMsg( 'config-support-info', $dbSupport ) ) );
435 foreach ( $this->parent
->getVar( '_CompiledDBs' ) as $type ) {
436 $installer = $this->parent
->getDBInstaller( $type );
440 $installer->getReadableName(),
444 $type == $defaultType,
445 array( 'class' => 'dbRadio', 'rel' => "DB_wrapper_$type" )
450 Html
::openElement( 'div', array( 'id' => 'DB_wrapper_' . $type, 'class' => 'dbWrapper' ) ) .
451 Html
::element( 'h3', array(), wfMsg( 'config-header-' . $type ) ) .
452 $installer->getConnectForm() .
455 $types .= "</ul><br clear=\"left\"/>\n";
458 $this->parent
->label( 'config-db-type', false, $types ) .
465 public function submit() {
466 $r = $this->parent
->request
;
467 $type = $r->getVal( 'DBType' );
468 $this->setVar( 'wgDBtype', $type );
469 $installer = $this->parent
->getDBInstaller( $type );
471 return Status
::newFatal( 'config-invalid-db-type' );
473 return $installer->submitConnectForm();
478 class WebInstaller_Upgrade
extends WebInstallerPage
{
479 public function isSlow() {
483 public function execute() {
484 if ( $this->getVar( '_UpgradeDone' ) ) {
485 // Allow regeneration of LocalSettings.php, unless we are working
486 // from a pre-existing LocalSettings.php file and we want to avoid
487 // leaking its contents
488 if ( $this->parent
->request
->wasPosted() && !$this->getVar( '_ExistingDBSettings' ) ) {
489 // Done message acknowledged
493 // Show the done message again
494 // Make them click back again if they want to do the upgrade again
495 $this->showDoneMessage();
500 // wgDBtype is generally valid here because otherwise the previous page
501 // (connect) wouldn't have declared its happiness
502 $type = $this->getVar( 'wgDBtype' );
503 $installer = $this->parent
->getDBInstaller( $type );
505 if ( !$installer->needsUpgrade() ) {
509 if ( $this->parent
->request
->wasPosted() ) {
510 $installer->preUpgrade();
512 $this->startLiveBox();
513 $result = $installer->doUpgrade();
517 // If they're going to possibly regenerate LocalSettings, we
518 // need to create the upgrade/secret keys. Bug 26481
519 if( !$this->getVar( '_ExistingDBSettings' ) ) {
520 $this->parent
->generateKeys();
522 $this->setVar( '_UpgradeDone', true );
523 $this->showDoneMessage();
529 $this->addHTML( $this->parent
->getInfoBox(
530 wfMsgNoTrans( 'config-can-upgrade', $GLOBALS['wgVersion'] ) ) );
534 public function showDoneMessage() {
536 $regenerate = !$this->getVar( '_ExistingDBSettings' );
538 $msg = 'config-upgrade-done';
540 $msg = 'config-upgrade-done-no-regenerate';
542 $this->parent
->disableLinkPopups();
544 $this->parent
->getInfoBox(
546 $this->getVar( 'wgServer' ) .
547 $this->getVar( 'wgScriptPath' ) . '/index' .
548 $this->getVar( 'wgScriptExtension' )
552 $this->parent
->restoreLinkPopups();
553 $this->endForm( $regenerate ?
'regenerate' : false, false );
558 class WebInstaller_DBSettings
extends WebInstallerPage
{
560 public function execute() {
561 $installer = $this->parent
->getDBInstaller( $this->getVar( 'wgDBtype' ) );
563 $r = $this->parent
->request
;
564 if ( $r->wasPosted() ) {
565 $status = $installer->submitSettingsForm();
566 if ( $status === false ) {
568 } elseif ( $status->isGood() ) {
571 $this->parent
->showStatusBox( $status );
575 $form = $installer->getSettingsForm();
576 if ( $form === false ) {
581 $this->addHTML( $form );
587 class WebInstaller_Name
extends WebInstallerPage
{
589 public function execute() {
590 $r = $this->parent
->request
;
591 if ( $r->wasPosted() ) {
592 if ( $this->submit() ) {
599 // Encourage people to not name their site 'MediaWiki' by blanking the
600 // field. I think that was the intent with the original $GLOBALS['wgSitename']
601 // but these two always were the same so had the effect of making the
602 // installer forget $wgSitename when navigating back to this page.
603 if ( $this->getVar( 'wgSitename' ) == 'MediaWiki' ) {
604 $this->setVar( 'wgSitename', '' );
607 // Set wgMetaNamespace to something valid before we show the form.
608 // $wgMetaNamespace defaults to $wgSiteName which is 'MediaWiki'
609 $metaNS = $this->getVar( 'wgMetaNamespace' );
610 $this->setVar( 'wgMetaNamespace', wfMsgForContent( 'config-ns-other-default' ) );
613 $this->parent
->getTextBox( array(
614 'var' => 'wgSitename',
615 'label' => 'config-site-name',
616 'help' => $this->parent
->getHelpBox( 'config-site-name-help' )
618 $this->parent
->getRadioSet( array(
619 'var' => '_NamespaceType',
620 'label' => 'config-project-namespace',
621 'itemLabelPrefix' => 'config-ns-',
622 'values' => array( 'site-name', 'generic', 'other' ),
623 'commonAttribs' => array( 'class' => 'enableForOther', 'rel' => 'config_wgMetaNamespace' ),
624 'help' => $this->parent
->getHelpBox( 'config-project-namespace-help' )
626 $this->parent
->getTextBox( array(
627 'var' => 'wgMetaNamespace',
628 'label' => '', //TODO: Needs a label?
629 'attribs' => array( 'readonly' => 'readonly', 'class' => 'enabledByOther' ),
632 $this->getFieldSetStart( 'config-admin-box' ) .
633 $this->parent
->getTextBox( array(
634 'var' => '_AdminName',
635 'label' => 'config-admin-name',
636 'help' => $this->parent
->getHelpBox( 'config-admin-help' )
638 $this->parent
->getPasswordBox( array(
639 'var' => '_AdminPassword',
640 'label' => 'config-admin-password',
642 $this->parent
->getPasswordBox( array(
643 'var' => '_AdminPassword2',
644 'label' => 'config-admin-password-confirm'
646 $this->parent
->getTextBox( array(
647 'var' => '_AdminEmail',
648 'label' => 'config-admin-email',
649 'help' => $this->parent
->getHelpBox( 'config-admin-email-help' )
651 $this->parent
->getCheckBox( array(
652 'var' => '_Subscribe',
653 'label' => 'config-subscribe',
654 'help' => $this->parent
->getHelpBox( 'config-subscribe-help' )
656 $this->getFieldSetEnd() .
657 $this->parent
->getInfoBox( wfMsg( 'config-almost-done' ) ) .
658 $this->parent
->getRadioSet( array(
659 'var' => '_SkipOptional',
660 'itemLabelPrefix' => 'config-optional-',
661 'values' => array( 'continue', 'skip' )
665 // Restore the default value
666 $this->setVar( 'wgMetaNamespace', $metaNS );
672 public function submit() {
674 $this->parent
->setVarsFromRequest( array( 'wgSitename', '_NamespaceType',
675 '_AdminName', '_AdminPassword', '_AdminPassword2', '_AdminEmail',
676 '_Subscribe', '_SkipOptional', 'wgMetaNamespace' ) );
678 // Validate site name
679 if ( strval( $this->getVar( 'wgSitename' ) ) === '' ) {
680 $this->parent
->showError( 'config-site-name-blank' );
685 $nsType = $this->getVar( '_NamespaceType' );
686 if ( $nsType == 'site-name' ) {
687 $name = $this->getVar( 'wgSitename' );
688 // Sanitize for namespace
689 // This algorithm should match the JS one in WebInstallerOutput.php
690 $name = preg_replace( '/[\[\]\{\}|#<>%+? ]/', '_', $name );
691 $name = str_replace( '&', '&', $name );
692 $name = preg_replace( '/__+/', '_', $name );
693 $name = ucfirst( trim( $name, '_' ) );
694 } elseif ( $nsType == 'generic' ) {
695 $name = wfMsg( 'config-ns-generic' );
697 $name = $this->getVar( 'wgMetaNamespace' );
700 // Validate namespace
701 if ( strpos( $name, ':' ) !== false ) {
704 // Title-style validation
705 $title = Title
::newFromText( $name );
707 $good = $nsType == 'site-name';
709 $name = $title->getDBkey();
714 $this->parent
->showError( 'config-ns-invalid', $name );
718 // Make sure it won't conflict with any existing namespaces
720 $nsIndex = $wgContLang->getNsIndex( $name );
721 if( $nsIndex !== false && $nsIndex !== NS_PROJECT
) {
722 $this->parent
->showError( 'config-ns-conflict', $name );
726 $this->setVar( 'wgMetaNamespace', $name );
728 // Validate username for creation
729 $name = $this->getVar( '_AdminName' );
730 if ( strval( $name ) === '' ) {
731 $this->parent
->showError( 'config-admin-name-blank' );
735 $cname = User
::getCanonicalName( $name, 'creatable' );
736 if ( $cname === false ) {
737 $this->parent
->showError( 'config-admin-name-invalid', $name );
740 $this->setVar( '_AdminName', $cname );
746 $pwd = $this->getVar( '_AdminPassword' );
747 $user = User
::newFromName( $cname );
748 $valid = $user && $user->getPasswordValidity( $pwd );
749 if ( strval( $pwd ) === '' ) {
750 # $user->getPasswordValidity just checks for $wgMinimalPasswordLength.
751 # This message is more specific and helpful.
752 $msg = 'config-admin-password-blank';
753 } elseif ( $pwd !== $this->getVar( '_AdminPassword2' ) ) {
754 $msg = 'config-admin-password-mismatch';
755 } elseif ( $valid !== true ) {
756 # As of writing this will only catch the username being e.g. 'FOO' and
760 if ( $msg !== false ) {
761 call_user_func_array( array( $this->parent
, 'showError' ), (array)$msg );
762 $this->setVar( '_AdminPassword', '' );
763 $this->setVar( '_AdminPassword2', '' );
767 // Validate e-mail if provided
768 $email = $this->getVar( '_AdminEmail' );
769 if( $email && !Sanitizer
::validateEmail( $email ) ) {
770 $this->parent
->showError( 'config-admin-error-bademail' );
773 // If they asked to subscribe to mediawiki-announce but didn't give
774 // an e-mail, show an error. Bug 29332
775 if( !$email && $this->getVar( '_Subscribe' ) ) {
776 $this->parent
->showError( 'config-subscribe-noemail' );
785 class WebInstaller_Options
extends WebInstallerPage
{
787 public function execute() {
788 if ( $this->getVar( '_SkipOptional' ) == 'skip' ) {
791 if ( $this->parent
->request
->wasPosted() ) {
792 if ( $this->submit() ) {
797 $emailwrapperStyle = $this->getVar( 'wgEnableEmail' ) ?
'' : 'display: none';
801 $this->parent
->getRadioSet( array(
802 'var' => '_RightsProfile',
803 'label' => 'config-profile',
804 'itemLabelPrefix' => 'config-profile-',
805 'values' => array_keys( $this->parent
->rightsProfiles
),
807 $this->parent
->getInfoBox( wfMsgNoTrans( 'config-profile-help' ) ) .
810 $this->parent
->getRadioSet( array(
811 'var' => '_LicenseCode',
812 'label' => 'config-license',
813 'itemLabelPrefix' => 'config-license-',
814 'values' => array_keys( $this->parent
->licenses
),
815 'commonAttribs' => array( 'class' => 'licenseRadio' ),
817 $this->getCCChooser() .
818 $this->parent
->getHelpBox( 'config-license-help' ) .
821 $this->getFieldSetStart( 'config-email-settings' ) .
822 $this->parent
->getCheckBox( array(
823 'var' => 'wgEnableEmail',
824 'label' => 'config-enable-email',
825 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'emailwrapper' ),
827 $this->parent
->getHelpBox( 'config-enable-email-help' ) .
828 "<div id=\"emailwrapper\" style=\"$emailwrapperStyle\">" .
829 $this->parent
->getTextBox( array(
830 'var' => 'wgPasswordSender',
831 'label' => 'config-email-sender'
833 $this->parent
->getHelpBox( 'config-email-sender-help' ) .
834 $this->parent
->getCheckBox( array(
835 'var' => 'wgEnableUserEmail',
836 'label' => 'config-email-user',
838 $this->parent
->getHelpBox( 'config-email-user-help' ) .
839 $this->parent
->getCheckBox( array(
840 'var' => 'wgEnotifUserTalk',
841 'label' => 'config-email-usertalk',
843 $this->parent
->getHelpBox( 'config-email-usertalk-help' ) .
844 $this->parent
->getCheckBox( array(
845 'var' => 'wgEnotifWatchlist',
846 'label' => 'config-email-watchlist',
848 $this->parent
->getHelpBox( 'config-email-watchlist-help' ) .
849 $this->parent
->getCheckBox( array(
850 'var' => 'wgEmailAuthentication',
851 'label' => 'config-email-auth',
853 $this->parent
->getHelpBox( 'config-email-auth-help' ) .
855 $this->getFieldSetEnd()
858 $extensions = $this->parent
->findExtensions();
861 $extHtml = $this->getFieldSetStart( 'config-extensions' );
863 foreach( $extensions as $ext ) {
864 $extHtml .= $this->parent
->getCheckBox( array(
870 $extHtml .= $this->parent
->getHelpBox( 'config-extensions-help' ) .
871 $this->getFieldSetEnd();
872 $this->addHTML( $extHtml );
875 // Having / in paths in Windows looks funny :)
876 $this->setVar( 'wgDeletedDirectory',
878 '/', DIRECTORY_SEPARATOR
,
879 $this->getVar( 'wgDeletedDirectory' )
883 $uploadwrapperStyle = $this->getVar( 'wgEnableUploads' ) ?
'' : 'display: none';
886 $this->getFieldSetStart( 'config-upload-settings' ) .
887 $this->parent
->getCheckBox( array(
888 'var' => 'wgEnableUploads',
889 'label' => 'config-upload-enable',
890 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'uploadwrapper' ),
891 'help' => $this->parent
->getHelpBox( 'config-upload-help' )
893 '<div id="uploadwrapper" style="' . $uploadwrapperStyle . '">' .
894 $this->parent
->getTextBox( array(
895 'var' => 'wgDeletedDirectory',
896 'label' => 'config-upload-deleted',
897 'attribs' => array( 'dir' => 'ltr' ),
898 'help' => $this->parent
->getHelpBox( 'config-upload-deleted-help' )
901 $this->parent
->getTextBox( array(
903 'label' => 'config-logo',
904 'attribs' => array( 'dir' => 'ltr' ),
905 'help' => $this->parent
->getHelpBox( 'config-logo-help' )
909 $this->parent
->getCheckBox( array(
910 'var' => 'wgUseInstantCommons',
911 'label' => 'config-instantcommons',
912 'help' => $this->parent
->getHelpBox( 'config-instantcommons-help' )
914 $this->getFieldSetEnd()
917 $caches = array( 'none' );
918 if( count( $this->getVar( '_Caches' ) ) ) {
921 $caches[] = 'memcached';
923 // We'll hide/show this on demand when the value changes, see config.js.
924 $cacheval = $this->getVar( 'wgMainCacheType' );
926 // We need to set a default here; but don't hardcode it
927 // or we lose it every time we reload the page for validation
931 $hidden = ($cacheval == 'memcached') ?
'' : 'display: none';
934 $this->getFieldSetStart( 'config-advanced-settings' ) .
935 # Object cache settings
936 $this->parent
->getRadioSet( array(
937 'var' => 'wgMainCacheType',
938 'label' => 'config-cache-options',
939 'itemLabelPrefix' => 'config-cache-',
941 'value' => $cacheval,
943 $this->parent
->getHelpBox( 'config-cache-help' ) .
944 "<div id=\"config-memcachewrapper\" style=\"$hidden\">" .
945 $this->parent
->getTextArea( array(
946 'var' => '_MemCachedServers',
947 'label' => 'config-memcached-servers',
948 'help' => $this->parent
->getHelpBox( 'config-memcached-help' )
951 $this->getFieldSetEnd()
959 public function getCCPartnerUrl() {
960 $server = $this->getVar( 'wgServer' );
961 $exitUrl = $server . $this->parent
->getUrl( array(
963 'SubmitCC' => 'indeed',
964 'config__LicenseCode' => 'cc',
965 'config_wgRightsUrl' => '[license_url]',
966 'config_wgRightsText' => '[license_name]',
967 'config_wgRightsIcon' => '[license_button]',
969 $styleUrl = $server . dirname( dirname( $this->parent
->getUrl() ) ) .
970 '/skins/common/config-cc.css';
971 $iframeUrl = 'http://creativecommons.org/license/?' .
973 'partner' => 'MediaWiki',
974 'exit_url' => $exitUrl,
975 'lang' => $this->getVar( '_UserLang' ),
976 'stylesheet' => $styleUrl,
981 public function getCCChooser() {
982 $iframeAttribs = array(
983 'class' => 'config-cc-iframe',
984 'name' => 'config-cc-iframe',
985 'id' => 'config-cc-iframe',
990 if ( $this->getVar( '_CCDone' ) ) {
991 $iframeAttribs['src'] = $this->parent
->getUrl( array( 'ShowCC' => 'yes' ) );
993 $iframeAttribs['src'] = $this->getCCPartnerUrl();
995 $wrapperStyle = ($this->getVar('_LicenseCode') == 'cc-choose') ?
'' : 'display: none';
998 "<div class=\"config-cc-wrapper\" id=\"config-cc-wrapper\" style=\"$wrapperStyle\">\n" .
999 Html
::element( 'iframe', $iframeAttribs, '', false /* not short */ ) .
1003 public function getCCDoneBox() {
1004 $js = "parent.document.getElementById('config-cc-wrapper').style.height = '$1';";
1005 // If you change this height, also change it in config.css
1006 $expandJs = str_replace( '$1', '54em', $js );
1007 $reduceJs = str_replace( '$1', '70px', $js );
1010 Html
::element( 'img', array( 'src' => $this->getVar( 'wgRightsIcon' ) ) ) .
1012 htmlspecialchars( $this->getVar( 'wgRightsText' ) ) .
1014 "<p style=\"text-align: center\">" .
1017 'href' => $this->getCCPartnerUrl(),
1018 'onclick' => $expandJs,
1020 wfMsg( 'config-cc-again' )
1023 "<script type=\"text/javascript\">\n" .
1024 # Reduce the wrapper div height
1025 htmlspecialchars( $reduceJs ) .
1030 public function submitCC() {
1031 $newValues = $this->parent
->setVarsFromRequest(
1032 array( 'wgRightsUrl', 'wgRightsText', 'wgRightsIcon' ) );
1033 if ( count( $newValues ) != 3 ) {
1034 $this->parent
->showError( 'config-cc-error' );
1037 $this->setVar( '_CCDone', true );
1038 $this->addHTML( $this->getCCDoneBox() );
1041 public function submit() {
1042 $this->parent
->setVarsFromRequest( array( '_RightsProfile', '_LicenseCode',
1043 'wgEnableEmail', 'wgPasswordSender', 'wgEnableUploads', 'wgLogo',
1044 'wgEnableUserEmail', 'wgEnotifUserTalk', 'wgEnotifWatchlist',
1045 'wgEmailAuthentication', 'wgMainCacheType', '_MemCachedServers',
1046 'wgUseInstantCommons' ) );
1048 if ( !in_array( $this->getVar( '_RightsProfile' ),
1049 array_keys( $this->parent
->rightsProfiles
) ) )
1051 reset( $this->parent
->rightsProfiles
);
1052 $this->setVar( '_RightsProfile', key( $this->parent
->rightsProfiles
) );
1055 $code = $this->getVar( '_LicenseCode' );
1056 if ( $code == 'cc-choose' ) {
1057 if ( !$this->getVar( '_CCDone' ) ) {
1058 $this->parent
->showError( 'config-cc-not-chosen' );
1061 } elseif ( in_array( $code, array_keys( $this->parent
->licenses
) ) ) {
1062 $entry = $this->parent
->licenses
[$code];
1063 if ( isset( $entry['text'] ) ) {
1064 $this->setVar( 'wgRightsText', $entry['text'] );
1066 $this->setVar( 'wgRightsText', wfMsg( 'config-license-' . $code ) );
1068 $this->setVar( 'wgRightsUrl', $entry['url'] );
1069 $this->setVar( 'wgRightsIcon', $entry['icon'] );
1071 $this->setVar( 'wgRightsText', '' );
1072 $this->setVar( 'wgRightsUrl', '' );
1073 $this->setVar( 'wgRightsIcon', '' );
1076 $extsAvailable = $this->parent
->findExtensions();
1077 $extsToInstall = array();
1078 foreach( $extsAvailable as $ext ) {
1079 if( $this->parent
->request
->getCheck( 'config_ext-' . $ext ) ) {
1080 $extsToInstall[] = $ext;
1083 $this->parent
->setVar( '_Extensions', $extsToInstall );
1085 if( $this->getVar( 'wgMainCacheType' ) == 'memcached' ) {
1086 $memcServers = explode( "\n", $this->getVar( '_MemCachedServers' ) );
1087 if( !$memcServers ) {
1088 $this->parent
->showError( 'config-memcache-needservers' );
1092 foreach( $memcServers as $server ) {
1093 $memcParts = explode( ":", $server, 2 );
1094 if ( !isset( $memcParts[0] )
1095 ||
( !IP
::isValid( $memcParts[0] )
1096 && ( gethostbyname( $memcParts[0] ) == $memcParts[0] ) ) ) {
1097 $this->parent
->showError( 'config-memcache-badip', $memcParts[0] );
1099 } elseif( !isset( $memcParts[1] ) ) {
1100 $this->parent
->showError( 'config-memcache-noport', $memcParts[0] );
1102 } elseif( $memcParts[1] < 1 ||
$memcParts[1] > 65535 ) {
1103 $this->parent
->showError( 'config-memcache-badport', 1, 65535 );
1113 class WebInstaller_Install
extends WebInstallerPage
{
1114 public function isSlow() {
1118 public function execute() {
1119 if( $this->getVar( '_UpgradeDone' ) ) {
1121 } elseif( $this->getVar( '_InstallDone' ) ) {
1123 } elseif( $this->parent
->request
->wasPosted() ) {
1125 $this->addHTML("<ul>");
1126 $results = $this->parent
->performInstallation(
1127 array( $this, 'startStage'),
1128 array( $this, 'endStage' )
1130 $this->addHTML("</ul>");
1131 // PerformInstallation bails on a fatal, so make sure the last item
1132 // completed before giving 'next.' Likewise, only provide back on failure
1133 $lastStep = end( $results );
1134 $continue = $lastStep->isOK() ?
'continue' : false;
1135 $back = $lastStep->isOK() ?
false : 'back';
1136 $this->endForm( $continue, $back );
1139 $this->addHTML( $this->parent
->getInfoBox( wfMsgNoTrans( 'config-install-begin' ) ) );
1145 public function startStage( $step ) {
1146 $this->addHTML( "<li>" . wfMsgHtml( "config-install-$step" ) . wfMsg( 'ellipsis') );
1147 if ( $step == 'extension-tables' ) {
1148 $this->startLiveBox();
1154 * @param $status Status
1156 public function endStage( $step, $status ) {
1157 if ( $step == 'extension-tables' ) {
1158 $this->endLiveBox();
1160 $msg = $status->isOk() ?
'config-install-step-done' : 'config-install-step-failed';
1161 $html = wfMsgHtml( 'word-separator' ) . wfMsgHtml( $msg );
1162 if ( !$status->isOk() ) {
1163 $html = "<span class=\"error\">$html</span>";
1165 $this->addHTML( $html . "</li>\n" );
1166 if( !$status->isGood() ) {
1167 $this->parent
->showStatusBox( $status );
1173 class WebInstaller_Complete
extends WebInstallerPage
{
1175 public function execute() {
1176 // Pop up a dialog box, to make it difficult for the user to forget
1177 // to download the file
1178 $lsUrl = $this->getVar( 'wgServer' ) . $this->parent
->getURL( array( 'localsettings' => 1 ) );
1179 if ( isset( $_SERVER['HTTP_USER_AGENT'] ) && strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE' ) !== false ) {
1180 // JS appears the only method that works consistently with IE7+
1181 $this->addHtml( "\n<script type=\"" . $GLOBALS['wgJsMimeType'] . '">jQuery( document ).ready( function() { document.location='
1182 . Xml
::encodeJsVar( $lsUrl) . "; } );</script>\n" );
1184 $this->parent
->request
->response()->header( "Refresh: 0;url=$lsUrl" );
1188 $this->parent
->disableLinkPopups();
1190 $this->parent
->getInfoBox(
1191 wfMsgNoTrans( 'config-install-done',
1193 $this->getVar( 'wgServer' ) .
1194 $this->getVar( 'wgScriptPath' ) . '/index' .
1195 $this->getVar( 'wgScriptExtension' ),
1200 $this->parent
->restoreLinkPopups();
1201 $this->endForm( false, false );
1205 class WebInstaller_Restart
extends WebInstallerPage
{
1207 public function execute() {
1208 $r = $this->parent
->request
;
1209 if ( $r->wasPosted() ) {
1210 $really = $r->getVal( 'submit-restart' );
1212 $this->parent
->reset();
1218 $s = $this->parent
->getWarningBox( wfMsgNoTrans( 'config-help-restart' ) );
1219 $this->addHTML( $s );
1220 $this->endForm( 'restart' );
1225 abstract class WebInstaller_Document
extends WebInstallerPage
{
1227 protected abstract function getFileName();
1229 public function execute() {
1230 $text = $this->getFileContents();
1231 $text = InstallDocFormatter
::format( $text );
1232 $this->parent
->output
->addWikiText( $text );
1234 $this->endForm( false );
1237 public function getFileContents() {
1238 return file_get_contents( dirname( __FILE__
) . '/../../' . $this->getFileName() );
1243 class WebInstaller_Readme
extends WebInstaller_Document
{
1244 protected function getFileName() { return 'README'; }
1247 class WebInstaller_ReleaseNotes
extends WebInstaller_Document
{
1248 protected function getFileName() { return 'RELEASE-NOTES'; }
1251 class WebInstaller_UpgradeDoc
extends WebInstaller_Document
{
1252 protected function getFileName() { return 'UPGRADE'; }
1255 class WebInstaller_Copying
extends WebInstaller_Document
{
1256 protected function getFileName() { return 'COPYING'; }