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' =>
73 'visibility:hidden;overflow:hidden;width:1px;margin:0' ) ) . "\n";
77 $s .= Xml
::submitButton( wfMsg( "config-$back" ),
79 'name' => "submit-$back",
80 'tabindex' => $this->parent
->nextTabIndex()
85 $s .= Xml
::submitButton( wfMsg( "config-$continue" ),
87 'name' => "submit-$continue",
88 'tabindex' => $this->parent
->nextTabIndex(),
92 $s .= "</div></form></div>\n";
96 public function getName() {
97 return str_replace( 'WebInstaller_', '', get_class( $this ) );
100 protected function getId() {
101 return array_search( $this->getName(), $this->parent
->pageSequence
);
104 public function getVar( $var ) {
105 return $this->parent
->getVar( $var );
108 public function setVar( $name, $value ) {
109 $this->parent
->setVar( $name, $value );
113 * Get the starting tags of a fieldset.
115 * @param $legend String: message name
119 protected function getFieldsetStart( $legend ) {
120 return "\n<fieldset><legend>" . wfMsgHtml( $legend ) . "</legend>\n";
124 * Get the end tag of a fieldset.
128 protected function getFieldsetEnd() {
129 return "</fieldset>\n";
133 * Opens a textarea used to display the progress of a long operation
135 protected function startLiveBox() {
137 '<div id="config-spinner" style="display:none;">' .
138 '<img src="../skins/common/images/ajax-loader.gif" /></div>' .
139 '<script>jQuery( "#config-spinner" ).show();</script>' .
140 '<div id="config-live-log">' .
141 '<textarea name="LiveLog" rows="10" cols="30" readonly="readonly">'
143 $this->parent
->output
->flush();
147 * Opposite to startLiveBox()
149 protected function endLiveBox() {
150 $this->addHTML( '</textarea></div>
151 <script>jQuery( "#config-spinner" ).hide()</script>' );
152 $this->parent
->output
->flush();
156 class WebInstaller_Language
extends WebInstallerPage
{
158 public function execute() {
160 $r = $this->parent
->request
;
161 $userLang = $r->getVal( 'userlang' );
162 $contLang = $r->getVal( 'ContLang' );
164 $lifetime = intval( ini_get( 'session.gc_maxlifetime' ) );
166 $lifetime = 1440; // PHP default
169 if ( $r->wasPosted() ) {
171 if ( $this->parent
->getSession( 'test' ) === null ) {
172 $requestTime = $r->getVal( 'LanguageRequestTime' );
173 if ( !$requestTime ) {
174 // The most likely explanation is that the user was knocked back
175 // from another page on POST due to session expiry
176 $msg = 'config-session-expired';
177 } elseif ( time() - $requestTime > $lifetime ) {
178 $msg = 'config-session-expired';
180 $msg = 'config-no-session';
182 $this->parent
->showError( $msg, $wgLang->formatTimePeriod( $lifetime ) );
184 $languages = Language
::getLanguageNames();
185 if ( isset( $languages[$userLang] ) ) {
186 $this->setVar( '_UserLang', $userLang );
188 if ( isset( $languages[$contLang] ) ) {
189 $this->setVar( 'wgLanguageCode', $contLang );
193 } elseif ( $this->parent
->showSessionWarning
) {
194 # The user was knocked back from another page to the start
195 # This probably indicates a session expiry
196 $this->parent
->showError( 'config-session-expired',
197 $wgLang->formatTimePeriod( $lifetime ) );
200 $this->parent
->setSession( 'test', true );
202 if ( !isset( $languages[$userLang] ) ) {
203 $userLang = $this->getVar( '_UserLang', 'en' );
205 if ( !isset( $languages[$contLang] ) ) {
206 $contLang = $this->getVar( 'wgLanguageCode', 'en' );
209 $s = Html
::hidden( 'LanguageRequestTime', time() ) .
210 $this->getLanguageSelector( 'userlang', 'config-your-language', $userLang,
211 $this->parent
->getHelpBox( 'config-your-language-help' ) ) .
212 $this->getLanguageSelector( 'ContLang', 'config-wiki-language', $contLang,
213 $this->parent
->getHelpBox( 'config-wiki-language-help' ) );
214 $this->addHTML( $s );
215 $this->endForm( 'continue', false );
219 * Get a <select> for selecting languages.
223 * @param $selectedCode
224 * @param $helpHtml string
227 public function getLanguageSelector( $name, $label, $selectedCode, $helpHtml = '' ) {
228 global $wgDummyLanguageCodes;
232 $s .= Html
::openElement( 'select', array( 'id' => $name, 'name' => $name,
233 'tabindex' => $this->parent
->nextTabIndex() ) ) . "\n";
235 $languages = Language
::getLanguageNames();
237 foreach ( $languages as $code => $lang ) {
238 if ( isset( $wgDummyLanguageCodes[$code] ) ) continue;
239 $s .= "\n" . Xml
::option( "$code - $lang", $code, $code == $selectedCode );
241 $s .= "\n</select>\n";
242 return $this->parent
->label( $label, $name, $s );
247 class WebInstaller_ExistingWiki
extends WebInstallerPage
{
248 public function execute() {
249 // If there is no LocalSettings.php, continue to the installer welcome page
250 $vars = Installer
::getExistingLocalSettings();
255 // Check if the upgrade key supplied to the user has appeared in LocalSettings.php
256 if ( $vars['wgUpgradeKey'] !== false
257 && $this->getVar( '_UpgradeKeySupplied' )
258 && $this->getVar( 'wgUpgradeKey' ) === $vars['wgUpgradeKey'] )
260 // It's there, so the user is authorized
261 $status = $this->handleExistingUpgrade( $vars );
262 if ( $status->isOK() ) {
266 $this->parent
->showStatusBox( $status );
267 $this->endForm( 'continue' );
272 // If there is no $wgUpgradeKey, tell the user to add one to LocalSettings.php
273 if ( $vars['wgUpgradeKey'] === false ) {
274 if ( $this->getVar( 'wgUpgradeKey', false ) === false ) {
275 $secretKey = $this->getVar( 'wgSecretKey' ); // preserve $wgSecretKey
276 $this->parent
->generateKeys();
277 $this->setVar( 'wgSecretKey', $secretKey );
278 $this->setVar( '_UpgradeKeySupplied', true );
281 $this->addHTML( $this->parent
->getInfoBox(
282 wfMsgNoTrans( 'config-upgrade-key-missing',
283 "<pre>\$wgUpgradeKey = '" . $this->getVar( 'wgUpgradeKey' ) . "';</pre>" )
285 $this->endForm( 'continue' );
289 // If there is an upgrade key, but it wasn't supplied, prompt the user to enter it
291 $r = $this->parent
->request
;
292 if ( $r->wasPosted() ) {
293 $key = $r->getText( 'config_wgUpgradeKey' );
294 if( !$key ||
$key !== $vars['wgUpgradeKey'] ) {
295 $this->parent
->showError( 'config-localsettings-badkey' );
296 $this->showKeyForm();
300 $status = $this->handleExistingUpgrade( $vars );
301 if ( $status->isOK() ) {
304 $this->parent
->showStatusBox( $status );
305 $this->showKeyForm();
309 $this->showKeyForm();
315 * Show the "enter key" form
317 protected function showKeyForm() {
320 $this->parent
->getInfoBox( wfMsgNoTrans( 'config-localsettings-upgrade' ) ).
322 $this->parent
->getTextBox( array(
323 'var' => 'wgUpgradeKey',
324 'label' => 'config-localsettings-key',
325 'attribs' => array( 'autocomplete' => 'off' ),
328 $this->endForm( 'continue' );
331 protected function importVariables( $names, $vars ) {
332 $status = Status
::newGood();
333 foreach ( $names as $name ) {
334 if ( !isset( $vars[$name] ) ) {
335 $status->fatal( 'config-localsettings-incomplete', $name );
337 $this->setVar( $name, $vars[$name] );
343 * Initiate an upgrade of the existing database
344 * @param $vars Variables from LocalSettings.php and AdminSettings.php
347 protected function handleExistingUpgrade( $vars ) {
349 if ( !isset( $vars['wgDBtype'] ) ||
350 !in_array( $vars['wgDBtype'], Installer
::getDBTypes() ) ) {
351 return Status
::newFatal( 'config-localsettings-connection-error', '' );
354 // Set the relevant variables from LocalSettings.php
355 $requiredVars = array( 'wgDBtype' );
356 $status = $this->importVariables( $requiredVars , $vars );
357 $installer = $this->parent
->getDBInstaller();
358 $status->merge( $this->importVariables( $installer->getGlobalNames(), $vars ) );
359 if ( !$status->isOK() ) {
363 if ( isset( $vars['wgDBadminuser'] ) ) {
364 $this->setVar( '_InstallUser', $vars['wgDBadminuser'] );
366 $this->setVar( '_InstallUser', $vars['wgDBuser'] );
368 if ( isset( $vars['wgDBadminpassword'] ) ) {
369 $this->setVar( '_InstallPassword', $vars['wgDBadminpassword'] );
371 $this->setVar( '_InstallPassword', $vars['wgDBpassword'] );
374 // Test the database connection
375 $status = $installer->getConnection();
376 if ( !$status->isOK() ) {
377 // Adjust the error message to explain things correctly
378 $status->replaceMessage( 'config-connection-error',
379 'config-localsettings-connection-error' );
384 $this->setVar( '_ExistingDBSettings', true );
389 class WebInstaller_Welcome
extends WebInstallerPage
{
391 public function execute() {
392 if ( $this->parent
->request
->wasPosted() ) {
393 if ( $this->getVar( '_Environment' ) ) {
397 $this->parent
->output
->addWikiText( wfMsgNoTrans( 'config-welcome' ) );
398 $status = $this->parent
->doEnvironmentChecks();
399 if ( $status->isGood() ) {
400 $this->parent
->output
->addHTML( '<span class="success-message">' .
401 wfMsgHtml( 'config-env-good' ) . '</span>' );
402 $this->parent
->output
->addWikiText( wfMsgNoTrans( 'config-copyright',
403 SpecialVersion
::getCopyrightAndAuthorList() ) );
407 $this->parent
->showStatusMessage( $status );
413 class WebInstaller_DBConnect
extends WebInstallerPage
{
415 public function execute() {
416 if ( $this->getVar( '_ExistingDBSettings' ) ) {
420 $r = $this->parent
->request
;
421 if ( $r->wasPosted() ) {
422 $status = $this->submit();
424 if ( $status->isGood() ) {
425 $this->setVar( '_UpgradeDone', false );
428 $this->parent
->showStatusBox( $status );
434 $types = "<ul class=\"config-settings-block\">\n";
436 $defaultType = $this->getVar( 'wgDBtype' );
439 foreach( $this->parent
->getDBTypes() as $type ) {
440 $link = DatabaseBase
::factory( $type )->getSoftwareLink();
441 $dbSupport .= wfMsgNoTrans( "config-support-$type", $link ) . "\n";
443 $this->addHTML( $this->parent
->getInfoBox(
444 wfMsg( 'config-support-info', $dbSupport ) ) );
446 foreach ( $this->parent
->getVar( '_CompiledDBs' ) as $type ) {
447 $installer = $this->parent
->getDBInstaller( $type );
451 $installer->getReadableName(),
455 $type == $defaultType,
456 array( 'class' => 'dbRadio', 'rel' => "DB_wrapper_$type" )
461 Html
::openElement( 'div', array( 'id' => 'DB_wrapper_' . $type,
462 'class' => 'dbWrapper' ) ) .
463 Html
::element( 'h3', array(), wfMsg( 'config-header-' . $type ) ) .
464 $installer->getConnectForm() .
467 $types .= "</ul><br style=\"clear: left\"/>\n";
470 $this->parent
->label( 'config-db-type', false, $types ) .
477 public function submit() {
478 $r = $this->parent
->request
;
479 $type = $r->getVal( 'DBType' );
480 $this->setVar( 'wgDBtype', $type );
481 $installer = $this->parent
->getDBInstaller( $type );
483 return Status
::newFatal( 'config-invalid-db-type' );
485 return $installer->submitConnectForm();
490 class WebInstaller_Upgrade
extends WebInstallerPage
{
491 public function isSlow() {
495 public function execute() {
496 if ( $this->getVar( '_UpgradeDone' ) ) {
497 // Allow regeneration of LocalSettings.php, unless we are working
498 // from a pre-existing LocalSettings.php file and we want to avoid
499 // leaking its contents
500 if ( $this->parent
->request
->wasPosted() && !$this->getVar( '_ExistingDBSettings' ) ) {
501 // Done message acknowledged
505 // Show the done message again
506 // Make them click back again if they want to do the upgrade again
507 $this->showDoneMessage();
512 // wgDBtype is generally valid here because otherwise the previous page
513 // (connect) wouldn't have declared its happiness
514 $type = $this->getVar( 'wgDBtype' );
515 $installer = $this->parent
->getDBInstaller( $type );
517 if ( !$installer->needsUpgrade() ) {
521 if ( $this->parent
->request
->wasPosted() ) {
522 $installer->preUpgrade();
524 $this->startLiveBox();
525 $result = $installer->doUpgrade();
529 // If they're going to possibly regenerate LocalSettings, we
530 // need to create the upgrade/secret keys. Bug 26481
531 if( !$this->getVar( '_ExistingDBSettings' ) ) {
532 $this->parent
->generateKeys();
534 $this->setVar( '_UpgradeDone', true );
535 $this->showDoneMessage();
541 $this->addHTML( $this->parent
->getInfoBox(
542 wfMsgNoTrans( 'config-can-upgrade', $GLOBALS['wgVersion'] ) ) );
546 public function showDoneMessage() {
548 $regenerate = !$this->getVar( '_ExistingDBSettings' );
550 $msg = 'config-upgrade-done';
552 $msg = 'config-upgrade-done-no-regenerate';
554 $this->parent
->disableLinkPopups();
556 $this->parent
->getInfoBox(
558 $this->getVar( 'wgServer' ) .
559 $this->getVar( 'wgScriptPath' ) . '/index' .
560 $this->getVar( 'wgScriptExtension' )
564 $this->parent
->restoreLinkPopups();
565 $this->endForm( $regenerate ?
'regenerate' : false, false );
570 class WebInstaller_DBSettings
extends WebInstallerPage
{
572 public function execute() {
573 $installer = $this->parent
->getDBInstaller( $this->getVar( 'wgDBtype' ) );
575 $r = $this->parent
->request
;
576 if ( $r->wasPosted() ) {
577 $status = $installer->submitSettingsForm();
578 if ( $status === false ) {
580 } elseif ( $status->isGood() ) {
583 $this->parent
->showStatusBox( $status );
587 $form = $installer->getSettingsForm();
588 if ( $form === false ) {
593 $this->addHTML( $form );
599 class WebInstaller_Name
extends WebInstallerPage
{
601 public function execute() {
602 $r = $this->parent
->request
;
603 if ( $r->wasPosted() ) {
604 if ( $this->submit() ) {
611 // Encourage people to not name their site 'MediaWiki' by blanking the
612 // field. I think that was the intent with the original $GLOBALS['wgSitename']
613 // but these two always were the same so had the effect of making the
614 // installer forget $wgSitename when navigating back to this page.
615 if ( $this->getVar( 'wgSitename' ) == 'MediaWiki' ) {
616 $this->setVar( 'wgSitename', '' );
619 // Set wgMetaNamespace to something valid before we show the form.
620 // $wgMetaNamespace defaults to $wgSiteName which is 'MediaWiki'
621 $metaNS = $this->getVar( 'wgMetaNamespace' );
622 $this->setVar( 'wgMetaNamespace', wfMsgForContent( 'config-ns-other-default' ) );
625 $this->parent
->getTextBox( array(
626 'var' => 'wgSitename',
627 'label' => 'config-site-name',
628 'help' => $this->parent
->getHelpBox( 'config-site-name-help' )
630 $this->parent
->getRadioSet( array(
631 'var' => '_NamespaceType',
632 'label' => 'config-project-namespace',
633 'itemLabelPrefix' => 'config-ns-',
634 'values' => array( 'site-name', 'generic', 'other' ),
635 'commonAttribs' => array( 'class' => 'enableForOther',
636 'rel' => 'config_wgMetaNamespace' ),
637 'help' => $this->parent
->getHelpBox( 'config-project-namespace-help' )
639 $this->parent
->getTextBox( array(
640 'var' => 'wgMetaNamespace',
641 'label' => '', //TODO: Needs a label?
642 'attribs' => array( 'readonly' => 'readonly', 'class' => 'enabledByOther' ),
645 $this->getFieldSetStart( 'config-admin-box' ) .
646 $this->parent
->getTextBox( array(
647 'var' => '_AdminName',
648 'label' => 'config-admin-name',
649 'help' => $this->parent
->getHelpBox( 'config-admin-help' )
651 $this->parent
->getPasswordBox( array(
652 'var' => '_AdminPassword',
653 'label' => 'config-admin-password',
655 $this->parent
->getPasswordBox( array(
656 'var' => '_AdminPassword2',
657 'label' => 'config-admin-password-confirm'
659 $this->parent
->getTextBox( array(
660 'var' => '_AdminEmail',
661 'label' => 'config-admin-email',
662 'help' => $this->parent
->getHelpBox( 'config-admin-email-help' )
664 $this->parent
->getCheckBox( array(
665 'var' => '_Subscribe',
666 'label' => 'config-subscribe',
667 'help' => $this->parent
->getHelpBox( 'config-subscribe-help' )
669 $this->getFieldSetEnd() .
670 $this->parent
->getInfoBox( wfMsg( 'config-almost-done' ) ) .
671 $this->parent
->getRadioSet( array(
672 'var' => '_SkipOptional',
673 'itemLabelPrefix' => 'config-optional-',
674 'values' => array( 'continue', 'skip' )
678 // Restore the default value
679 $this->setVar( 'wgMetaNamespace', $metaNS );
685 public function submit() {
687 $this->parent
->setVarsFromRequest( array( 'wgSitename', '_NamespaceType',
688 '_AdminName', '_AdminPassword', '_AdminPassword2', '_AdminEmail',
689 '_Subscribe', '_SkipOptional', 'wgMetaNamespace' ) );
691 // Validate site name
692 if ( strval( $this->getVar( 'wgSitename' ) ) === '' ) {
693 $this->parent
->showError( 'config-site-name-blank' );
698 $nsType = $this->getVar( '_NamespaceType' );
699 if ( $nsType == 'site-name' ) {
700 $name = $this->getVar( 'wgSitename' );
701 // Sanitize for namespace
702 // This algorithm should match the JS one in WebInstallerOutput.php
703 $name = preg_replace( '/[\[\]\{\}|#<>%+? ]/', '_', $name );
704 $name = str_replace( '&', '&', $name );
705 $name = preg_replace( '/__+/', '_', $name );
706 $name = ucfirst( trim( $name, '_' ) );
707 } elseif ( $nsType == 'generic' ) {
708 $name = wfMsg( 'config-ns-generic' );
710 $name = $this->getVar( 'wgMetaNamespace' );
713 // Validate namespace
714 if ( strpos( $name, ':' ) !== false ) {
717 // Title-style validation
718 $title = Title
::newFromText( $name );
720 $good = $nsType == 'site-name';
722 $name = $title->getDBkey();
727 $this->parent
->showError( 'config-ns-invalid', $name );
731 // Make sure it won't conflict with any existing namespaces
733 $nsIndex = $wgContLang->getNsIndex( $name );
734 if( $nsIndex !== false && $nsIndex !== NS_PROJECT
) {
735 $this->parent
->showError( 'config-ns-conflict', $name );
739 $this->setVar( 'wgMetaNamespace', $name );
741 // Validate username for creation
742 $name = $this->getVar( '_AdminName' );
743 if ( strval( $name ) === '' ) {
744 $this->parent
->showError( 'config-admin-name-blank' );
748 $cname = User
::getCanonicalName( $name, 'creatable' );
749 if ( $cname === false ) {
750 $this->parent
->showError( 'config-admin-name-invalid', $name );
753 $this->setVar( '_AdminName', $cname );
759 $pwd = $this->getVar( '_AdminPassword' );
760 $user = User
::newFromName( $cname );
761 $valid = $user && $user->getPasswordValidity( $pwd );
762 if ( strval( $pwd ) === '' ) {
763 # $user->getPasswordValidity just checks for $wgMinimalPasswordLength.
764 # This message is more specific and helpful.
765 $msg = 'config-admin-password-blank';
766 } elseif ( $pwd !== $this->getVar( '_AdminPassword2' ) ) {
767 $msg = 'config-admin-password-mismatch';
768 } elseif ( $valid !== true ) {
769 # As of writing this will only catch the username being e.g. 'FOO' and
773 if ( $msg !== false ) {
774 call_user_func_array( array( $this->parent
, 'showError' ), (array)$msg );
775 $this->setVar( '_AdminPassword', '' );
776 $this->setVar( '_AdminPassword2', '' );
780 // Validate e-mail if provided
781 $email = $this->getVar( '_AdminEmail' );
782 if( $email && !Sanitizer
::validateEmail( $email ) ) {
783 $this->parent
->showError( 'config-admin-error-bademail' );
786 // If they asked to subscribe to mediawiki-announce but didn't give
787 // an e-mail, show an error. Bug 29332
788 if( !$email && $this->getVar( '_Subscribe' ) ) {
789 $this->parent
->showError( 'config-subscribe-noemail' );
798 class WebInstaller_Options
extends WebInstallerPage
{
800 public function execute() {
801 if ( $this->getVar( '_SkipOptional' ) == 'skip' ) {
804 if ( $this->parent
->request
->wasPosted() ) {
805 if ( $this->submit() ) {
810 $emailwrapperStyle = $this->getVar( 'wgEnableEmail' ) ?
'' : 'display: none';
814 $this->parent
->getRadioSet( array(
815 'var' => '_RightsProfile',
816 'label' => 'config-profile',
817 'itemLabelPrefix' => 'config-profile-',
818 'values' => array_keys( $this->parent
->rightsProfiles
),
820 $this->parent
->getInfoBox( wfMsgNoTrans( 'config-profile-help' ) ) .
823 $this->parent
->getRadioSet( array(
824 'var' => '_LicenseCode',
825 'label' => 'config-license',
826 'itemLabelPrefix' => 'config-license-',
827 'values' => array_keys( $this->parent
->licenses
),
828 'commonAttribs' => array( 'class' => 'licenseRadio' ),
830 $this->getCCChooser() .
831 $this->parent
->getHelpBox( 'config-license-help' ) .
834 $this->getFieldSetStart( 'config-email-settings' ) .
835 $this->parent
->getCheckBox( array(
836 'var' => 'wgEnableEmail',
837 'label' => 'config-enable-email',
838 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'emailwrapper' ),
840 $this->parent
->getHelpBox( 'config-enable-email-help' ) .
841 "<div id=\"emailwrapper\" style=\"$emailwrapperStyle\">" .
842 $this->parent
->getTextBox( array(
843 'var' => 'wgPasswordSender',
844 'label' => 'config-email-sender'
846 $this->parent
->getHelpBox( 'config-email-sender-help' ) .
847 $this->parent
->getCheckBox( array(
848 'var' => 'wgEnableUserEmail',
849 'label' => 'config-email-user',
851 $this->parent
->getHelpBox( 'config-email-user-help' ) .
852 $this->parent
->getCheckBox( array(
853 'var' => 'wgEnotifUserTalk',
854 'label' => 'config-email-usertalk',
856 $this->parent
->getHelpBox( 'config-email-usertalk-help' ) .
857 $this->parent
->getCheckBox( array(
858 'var' => 'wgEnotifWatchlist',
859 'label' => 'config-email-watchlist',
861 $this->parent
->getHelpBox( 'config-email-watchlist-help' ) .
862 $this->parent
->getCheckBox( array(
863 'var' => 'wgEmailAuthentication',
864 'label' => 'config-email-auth',
866 $this->parent
->getHelpBox( 'config-email-auth-help' ) .
868 $this->getFieldSetEnd()
871 $extensions = $this->parent
->findExtensions();
874 $extHtml = $this->getFieldSetStart( 'config-extensions' );
876 foreach( $extensions as $ext ) {
877 $extHtml .= $this->parent
->getCheckBox( array(
883 $extHtml .= $this->parent
->getHelpBox( 'config-extensions-help' ) .
884 $this->getFieldSetEnd();
885 $this->addHTML( $extHtml );
888 // Having / in paths in Windows looks funny :)
889 $this->setVar( 'wgDeletedDirectory',
891 '/', DIRECTORY_SEPARATOR
,
892 $this->getVar( 'wgDeletedDirectory' )
896 $uploadwrapperStyle = $this->getVar( 'wgEnableUploads' ) ?
'' : 'display: none';
899 $this->getFieldSetStart( 'config-upload-settings' ) .
900 $this->parent
->getCheckBox( array(
901 'var' => 'wgEnableUploads',
902 'label' => 'config-upload-enable',
903 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'uploadwrapper' ),
904 'help' => $this->parent
->getHelpBox( 'config-upload-help' )
906 '<div id="uploadwrapper" style="' . $uploadwrapperStyle . '">' .
907 $this->parent
->getTextBox( array(
908 'var' => 'wgDeletedDirectory',
909 'label' => 'config-upload-deleted',
910 'attribs' => array( 'dir' => 'ltr' ),
911 'help' => $this->parent
->getHelpBox( 'config-upload-deleted-help' )
914 $this->parent
->getTextBox( array(
916 'label' => 'config-logo',
917 'attribs' => array( 'dir' => 'ltr' ),
918 'help' => $this->parent
->getHelpBox( 'config-logo-help' )
922 $this->parent
->getCheckBox( array(
923 'var' => 'wgUseInstantCommons',
924 'label' => 'config-instantcommons',
925 'help' => $this->parent
->getHelpBox( 'config-instantcommons-help' )
927 $this->getFieldSetEnd()
930 $caches = array( 'none' );
931 if( count( $this->getVar( '_Caches' ) ) ) {
934 $caches[] = 'memcached';
936 // We'll hide/show this on demand when the value changes, see config.js.
937 $cacheval = $this->getVar( 'wgMainCacheType' );
939 // We need to set a default here; but don't hardcode it
940 // or we lose it every time we reload the page for validation
944 $hidden = ($cacheval == 'memcached') ?
'' : 'display: none';
947 $this->getFieldSetStart( 'config-advanced-settings' ) .
948 # Object cache settings
949 $this->parent
->getRadioSet( array(
950 'var' => 'wgMainCacheType',
951 'label' => 'config-cache-options',
952 'itemLabelPrefix' => 'config-cache-',
954 'value' => $cacheval,
956 $this->parent
->getHelpBox( 'config-cache-help' ) .
957 "<div id=\"config-memcachewrapper\" style=\"$hidden\">" .
958 $this->parent
->getTextArea( array(
959 'var' => '_MemCachedServers',
960 'label' => 'config-memcached-servers',
961 'help' => $this->parent
->getHelpBox( 'config-memcached-help' )
964 $this->getFieldSetEnd()
972 public function getCCPartnerUrl() {
973 $server = $this->getVar( 'wgServer' );
974 $exitUrl = $server . $this->parent
->getUrl( array(
976 'SubmitCC' => 'indeed',
977 'config__LicenseCode' => 'cc',
978 'config_wgRightsUrl' => '[license_url]',
979 'config_wgRightsText' => '[license_name]',
980 'config_wgRightsIcon' => '[license_button]',
982 $styleUrl = $server . dirname( dirname( $this->parent
->getUrl() ) ) .
983 '/skins/common/config-cc.css';
984 $iframeUrl = 'http://creativecommons.org/license/?' .
986 'partner' => 'MediaWiki',
987 'exit_url' => $exitUrl,
988 'lang' => $this->getVar( '_UserLang' ),
989 'stylesheet' => $styleUrl,
994 public function getCCChooser() {
995 $iframeAttribs = array(
996 'class' => 'config-cc-iframe',
997 'name' => 'config-cc-iframe',
998 'id' => 'config-cc-iframe',
1003 if ( $this->getVar( '_CCDone' ) ) {
1004 $iframeAttribs['src'] = $this->parent
->getUrl( array( 'ShowCC' => 'yes' ) );
1006 $iframeAttribs['src'] = $this->getCCPartnerUrl();
1008 $wrapperStyle = ($this->getVar('_LicenseCode') == 'cc-choose') ?
'' : 'display: none';
1011 "<div class=\"config-cc-wrapper\" id=\"config-cc-wrapper\" style=\"$wrapperStyle\">\n" .
1012 Html
::element( 'iframe', $iframeAttribs, '', false /* not short */ ) .
1016 public function getCCDoneBox() {
1017 $js = "parent.document.getElementById('config-cc-wrapper').style.height = '$1';";
1018 // If you change this height, also change it in config.css
1019 $expandJs = str_replace( '$1', '54em', $js );
1020 $reduceJs = str_replace( '$1', '70px', $js );
1023 Html
::element( 'img', array( 'src' => $this->getVar( 'wgRightsIcon' ) ) ) .
1025 htmlspecialchars( $this->getVar( 'wgRightsText' ) ) .
1027 "<p style=\"text-align: center\">" .
1030 'href' => $this->getCCPartnerUrl(),
1031 'onclick' => $expandJs,
1033 wfMsg( 'config-cc-again' )
1036 "<script type=\"text/javascript\">\n" .
1037 # Reduce the wrapper div height
1038 htmlspecialchars( $reduceJs ) .
1043 public function submitCC() {
1044 $newValues = $this->parent
->setVarsFromRequest(
1045 array( 'wgRightsUrl', 'wgRightsText', 'wgRightsIcon' ) );
1046 if ( count( $newValues ) != 3 ) {
1047 $this->parent
->showError( 'config-cc-error' );
1050 $this->setVar( '_CCDone', true );
1051 $this->addHTML( $this->getCCDoneBox() );
1054 public function submit() {
1055 $this->parent
->setVarsFromRequest( array( '_RightsProfile', '_LicenseCode',
1056 'wgEnableEmail', 'wgPasswordSender', 'wgEnableUploads', 'wgLogo',
1057 'wgEnableUserEmail', 'wgEnotifUserTalk', 'wgEnotifWatchlist',
1058 'wgEmailAuthentication', 'wgMainCacheType', '_MemCachedServers',
1059 'wgUseInstantCommons' ) );
1061 if ( !in_array( $this->getVar( '_RightsProfile' ),
1062 array_keys( $this->parent
->rightsProfiles
) ) )
1064 reset( $this->parent
->rightsProfiles
);
1065 $this->setVar( '_RightsProfile', key( $this->parent
->rightsProfiles
) );
1068 $code = $this->getVar( '_LicenseCode' );
1069 if ( $code == 'cc-choose' ) {
1070 if ( !$this->getVar( '_CCDone' ) ) {
1071 $this->parent
->showError( 'config-cc-not-chosen' );
1074 } elseif ( in_array( $code, array_keys( $this->parent
->licenses
) ) ) {
1075 $entry = $this->parent
->licenses
[$code];
1076 if ( isset( $entry['text'] ) ) {
1077 $this->setVar( 'wgRightsText', $entry['text'] );
1079 $this->setVar( 'wgRightsText', wfMsg( 'config-license-' . $code ) );
1081 $this->setVar( 'wgRightsUrl', $entry['url'] );
1082 $this->setVar( 'wgRightsIcon', $entry['icon'] );
1084 $this->setVar( 'wgRightsText', '' );
1085 $this->setVar( 'wgRightsUrl', '' );
1086 $this->setVar( 'wgRightsIcon', '' );
1089 $extsAvailable = $this->parent
->findExtensions();
1090 $extsToInstall = array();
1091 foreach( $extsAvailable as $ext ) {
1092 if( $this->parent
->request
->getCheck( 'config_ext-' . $ext ) ) {
1093 $extsToInstall[] = $ext;
1096 $this->parent
->setVar( '_Extensions', $extsToInstall );
1098 if( $this->getVar( 'wgMainCacheType' ) == 'memcached' ) {
1099 $memcServers = explode( "\n", $this->getVar( '_MemCachedServers' ) );
1100 if( !$memcServers ) {
1101 $this->parent
->showError( 'config-memcache-needservers' );
1105 foreach( $memcServers as $server ) {
1106 $memcParts = explode( ":", $server, 2 );
1107 if ( !isset( $memcParts[0] )
1108 ||
( !IP
::isValid( $memcParts[0] )
1109 && ( gethostbyname( $memcParts[0] ) == $memcParts[0] ) ) ) {
1110 $this->parent
->showError( 'config-memcache-badip', $memcParts[0] );
1112 } elseif( !isset( $memcParts[1] ) ) {
1113 $this->parent
->showError( 'config-memcache-noport', $memcParts[0] );
1115 } elseif( $memcParts[1] < 1 ||
$memcParts[1] > 65535 ) {
1116 $this->parent
->showError( 'config-memcache-badport', 1, 65535 );
1126 class WebInstaller_Install
extends WebInstallerPage
{
1127 public function isSlow() {
1131 public function execute() {
1132 if( $this->getVar( '_UpgradeDone' ) ) {
1134 } elseif( $this->getVar( '_InstallDone' ) ) {
1136 } elseif( $this->parent
->request
->wasPosted() ) {
1138 $this->addHTML("<ul>");
1139 $results = $this->parent
->performInstallation(
1140 array( $this, 'startStage'),
1141 array( $this, 'endStage' )
1143 $this->addHTML("</ul>");
1144 // PerformInstallation bails on a fatal, so make sure the last item
1145 // completed before giving 'next.' Likewise, only provide back on failure
1146 $lastStep = end( $results );
1147 $continue = $lastStep->isOK() ?
'continue' : false;
1148 $back = $lastStep->isOK() ?
false : 'back';
1149 $this->endForm( $continue, $back );
1152 $this->addHTML( $this->parent
->getInfoBox( wfMsgNoTrans( 'config-install-begin' ) ) );
1158 public function startStage( $step ) {
1159 $this->addHTML( "<li>" . wfMsgHtml( "config-install-$step" ) . wfMsg( 'ellipsis') );
1160 if ( $step == 'extension-tables' ) {
1161 $this->startLiveBox();
1167 * @param $status Status
1169 public function endStage( $step, $status ) {
1170 if ( $step == 'extension-tables' ) {
1171 $this->endLiveBox();
1173 $msg = $status->isOk() ?
'config-install-step-done' : 'config-install-step-failed';
1174 $html = wfMsgHtml( 'word-separator' ) . wfMsgHtml( $msg );
1175 if ( !$status->isOk() ) {
1176 $html = "<span class=\"error\">$html</span>";
1178 $this->addHTML( $html . "</li>\n" );
1179 if( !$status->isGood() ) {
1180 $this->parent
->showStatusBox( $status );
1186 class WebInstaller_Complete
extends WebInstallerPage
{
1188 public function execute() {
1189 // Pop up a dialog box, to make it difficult for the user to forget
1190 // to download the file
1191 $lsUrl = $this->getVar( 'wgServer' ) . $this->parent
->getURL( array( 'localsettings' => 1 ) );
1192 if ( isset( $_SERVER['HTTP_USER_AGENT'] ) &&
1193 strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE' ) !== false ) {
1194 // JS appears the only method that works consistently with IE7+
1195 $this->addHtml( "\n<script type=\"" . $GLOBALS['wgJsMimeType'] .
1196 '">jQuery( document ).ready( function() { document.location=' .
1197 Xml
::encodeJsVar( $lsUrl) . "; } );</script>\n" );
1199 $this->parent
->request
->response()->header( "Refresh: 0;url=$lsUrl" );
1203 $this->parent
->disableLinkPopups();
1205 $this->parent
->getInfoBox(
1206 wfMsgNoTrans( 'config-install-done',
1208 $this->getVar( 'wgServer' ) .
1209 $this->getVar( 'wgScriptPath' ) . '/index' .
1210 $this->getVar( 'wgScriptExtension' ),
1215 $this->parent
->restoreLinkPopups();
1216 $this->endForm( false, false );
1220 class WebInstaller_Restart
extends WebInstallerPage
{
1222 public function execute() {
1223 $r = $this->parent
->request
;
1224 if ( $r->wasPosted() ) {
1225 $really = $r->getVal( 'submit-restart' );
1227 $this->parent
->reset();
1233 $s = $this->parent
->getWarningBox( wfMsgNoTrans( 'config-help-restart' ) );
1234 $this->addHTML( $s );
1235 $this->endForm( 'restart' );
1240 abstract class WebInstaller_Document
extends WebInstallerPage
{
1242 protected abstract function getFileName();
1244 public function execute() {
1245 $text = $this->getFileContents();
1246 $text = InstallDocFormatter
::format( $text );
1247 $this->parent
->output
->addWikiText( $text );
1249 $this->endForm( false );
1252 public function getFileContents() {
1253 return file_get_contents( dirname( __FILE__
) . '/../../' . $this->getFileName() );
1258 class WebInstaller_Readme
extends WebInstaller_Document
{
1259 protected function getFileName() { return 'README'; }
1262 class WebInstaller_ReleaseNotes
extends WebInstaller_Document
{
1263 protected function getFileName() { return 'RELEASE-NOTES'; }
1266 class WebInstaller_UpgradeDoc
extends WebInstaller_Document
{
1267 protected function getFileName() { return 'UPGRADE'; }
1270 class WebInstaller_Copying
extends WebInstaller_Document
{
1271 protected function getFileName() { return 'COPYING'; }