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;
35 public function addHTML( $html ) {
36 $this->parent
->output
->addHTML( $html );
39 public function startForm() {
41 "<div class=\"config-section\">\n" .
46 'action' => $this->parent
->getUrl( array( 'page' => $this->getName() ) )
52 public function endForm( $continue = 'continue', $back = 'back' ) {
53 $s = "<div class=\"config-submit\">\n";
56 if ( $id === false ) {
57 $s .= Html
::hidden( 'lastPage', $this->parent
->request
->getVal( 'lastPage' ) );
61 // Fake submit button for enter keypress (bug 26267)
62 $s .= Xml
::submitButton( wfMsg( "config-$continue" ),
63 array( 'name' => "enter-$continue", 'style' => 'visibility:hidden;overflow:hidden;width:1px;margin:0' ) ) . "\n";
67 $s .= Xml
::submitButton( wfMsg( "config-$back" ),
69 'name' => "submit-$back",
70 'tabindex' => $this->parent
->nextTabIndex()
75 $s .= Xml
::submitButton( wfMsg( "config-$continue" ),
77 'name' => "submit-$continue",
78 'tabindex' => $this->parent
->nextTabIndex(),
82 $s .= "</div></form></div>\n";
86 public function getName() {
87 return str_replace( 'WebInstaller_', '', get_class( $this ) );
90 protected function getId() {
91 return array_search( $this->getName(), $this->parent
->pageSequence
);
94 public function getVar( $var ) {
95 return $this->parent
->getVar( $var );
98 public function setVar( $name, $value ) {
99 $this->parent
->setVar( $name, $value );
103 * Get the starting tags of a fieldset.
105 * @param $legend String: message name
107 protected function getFieldsetStart( $legend ) {
108 return "\n<fieldset><legend>" . wfMsgHtml( $legend ) . "</legend>\n";
112 * Get the end tag of a fieldset.
114 protected function getFieldsetEnd() {
115 return "</fieldset>\n";
119 class WebInstaller_Language
extends WebInstallerPage
{
121 public function execute() {
123 $r = $this->parent
->request
;
124 $userLang = $r->getVal( 'UserLang' );
125 $contLang = $r->getVal( 'ContLang' );
127 $lifetime = intval( ini_get( 'session.gc_maxlifetime' ) );
129 $lifetime = 1440; // PHP default
132 if ( $r->wasPosted() ) {
134 if ( $this->parent
->getSession( 'test' ) === null ) {
135 $requestTime = $r->getVal( 'LanguageRequestTime' );
136 if ( !$requestTime ) {
137 // The most likely explanation is that the user was knocked back
138 // from another page on POST due to session expiry
139 $msg = 'config-session-expired';
140 } elseif ( time() - $requestTime > $lifetime ) {
141 $msg = 'config-session-expired';
143 $msg = 'config-no-session';
145 $this->parent
->showError( $msg, $wgLang->formatTimePeriod( $lifetime ) );
147 $languages = Language
::getLanguageNames();
148 if ( isset( $languages[$userLang] ) ) {
149 $this->setVar( '_UserLang', $userLang );
151 if ( isset( $languages[$contLang] ) ) {
152 $this->setVar( 'wgLanguageCode', $contLang );
156 } elseif ( $this->parent
->showSessionWarning
) {
157 # The user was knocked back from another page to the start
158 # This probably indicates a session expiry
159 $this->parent
->showError( 'config-session-expired', $wgLang->formatTimePeriod( $lifetime ) );
162 $this->parent
->setSession( 'test', true );
164 if ( !isset( $languages[$userLang] ) ) {
165 $userLang = $this->getVar( '_UserLang', 'en' );
167 if ( !isset( $languages[$contLang] ) ) {
168 $contLang = $this->getVar( 'wgLanguageCode', 'en' );
171 $s = Html
::hidden( 'LanguageRequestTime', time() ) .
172 $this->getLanguageSelector( 'UserLang', 'config-your-language', $userLang, $this->parent
->getHelpBox( 'config-your-language-help' ) ) .
173 $this->getLanguageSelector( 'ContLang', 'config-wiki-language', $contLang, $this->parent
->getHelpBox( 'config-wiki-language-help' ) );
174 $this->addHTML( $s );
175 $this->endForm( 'continue', false );
179 * Get a <select> for selecting languages.
181 public function getLanguageSelector( $name, $label, $selectedCode ) {
182 global $wgDummyLanguageCodes;
183 $s = Html
::openElement( 'select', array( 'id' => $name, 'name' => $name ) ) . "\n";
185 $languages = Language
::getLanguageNames();
187 $dummies = array_flip( $wgDummyLanguageCodes );
188 foreach ( $languages as $code => $lang ) {
189 if ( isset( $dummies[$code] ) ) continue;
190 $s .= "\n" . Xml
::option( "$code - $lang", $code, $code == $selectedCode );
192 $s .= "\n</select>\n";
193 return $this->parent
->label( $label, $name, $s );
198 class WebInstaller_ExistingWiki
extends WebInstallerPage
{
199 public function execute() {
200 // If there is no LocalSettings.php, continue to the installer welcome page
201 $vars = $this->parent
->getExistingLocalSettings();
206 // Check if the upgrade key supplied to the user has appeared in LocalSettings.php
207 if ( $vars['wgUpgradeKey'] !== false
208 && $this->getVar( '_UpgradeKeySupplied' )
209 && $this->getVar( 'wgUpgradeKey' ) === $vars['wgUpgradeKey'] )
211 // It's there, so the user is authorized
212 $status = $this->handleExistingUpgrade( $vars );
213 if ( $status->isOK() ) {
217 $this->parent
->showStatusBox( $status );
218 $this->endForm( 'continue' );
221 return $this->handleExistingUpgrade( $vars );
224 // If there is no $wgUpgradeKey, tell the user to add one to LocalSettings.php
225 if ( $vars['wgUpgradeKey'] === false ) {
226 if ( $this->getVar( 'wgUpgradeKey', false ) === false ) {
227 $this->parent
->generateUpgradeKey();
228 $this->setVar( '_UpgradeKeySupplied', true );
231 $this->addHTML( $this->parent
->getInfoBox(
232 wfMsgNoTrans( 'config-upgrade-key-missing',
233 "<pre>\$wgUpgradeKey = '" . $this->getVar( 'wgUpgradeKey' ) . "';</pre>" )
235 $this->endForm( 'continue' );
239 // If there is an upgrade key, but it wasn't supplied, prompt the user to enter it
241 $r = $this->parent
->request
;
242 if ( $r->wasPosted() ) {
243 $key = $r->getText( 'config_wgUpgradeKey' );
244 if( !$key ||
$key !== $vars['wgUpgradeKey'] ) {
245 $this->parent
->showError( 'config-localsettings-badkey' );
246 $this->showKeyForm();
250 $status = $this->handleExistingUpgrade( $vars );
251 if ( $status->isOK() ) {
254 $this->parent
->showStatusBox( $status );
255 $this->showKeyForm();
259 $this->showKeyForm();
265 * Show the "enter key" form
267 protected function showKeyForm() {
270 $this->parent
->getInfoBox( wfMsgNoTrans( 'config-localsettings-upgrade' ) ).
272 $this->parent
->getTextBox( array(
273 'var' => 'wgUpgradeKey',
274 'label' => 'config-localsettings-key',
275 'attribs' => array( 'autocomplete' => 'off' ),
278 $this->endForm( 'continue' );
281 protected function importVariables( $names, $vars ) {
282 $status = Status
::newGood();
283 foreach ( $names as $name ) {
284 if ( !isset( $vars[$name] ) ) {
285 $status->fatal( 'config-localsettings-incomplete', $name );
287 $this->setVar( $name, $vars[$name] );
293 * Initiate an upgrade of the existing database
294 * @param $vars Variables from LocalSettings.php and AdminSettings.php
297 protected function handleExistingUpgrade( $vars ) {
299 if ( !isset( $vars['wgDBtype'] ) ||
!in_array( $vars['wgDBtype'], Installer
::getDBTypes() ) ) {
300 return Status
::newFatal( 'config-localsettings-connection-error', '' );
303 // Set the relevant variables from LocalSettings.php
304 $requiredVars = array( 'wgDBtype', 'wgDBuser', 'wgDBpassword' );
305 $status = $this->importVariables( $requiredVars , $vars );
306 $installer = $this->parent
->getDBInstaller();
307 $status->merge( $this->importVariables( $installer->getGlobalNames(), $vars ) );
308 if ( !$status->isOK() ) {
312 if ( isset( $vars['wgDBadminuser'] ) ) {
313 $this->setVar( '_InstallUser', $vars['wgDBadminuser'] );
315 $this->setVar( '_InstallUser', $vars['wgDBuser'] );
317 if ( isset( $vars['wgDBadminpassword'] ) ) {
318 $this->setVar( '_InstallPassword', $vars['wgDBadminpassword'] );
320 $this->setVar( '_InstallPassword', $vars['wgDBpassword'] );
323 // Test the database connection
324 $status = $installer->getConnection();
325 if ( !$status->isOK() ) {
326 // Adjust the error message to explain things correctly
327 $status->replaceMessage( 'config-connection-error',
328 'config-localsettings-connection-error' );
333 $this->setVar( '_ExistingDBSettings', true );
338 class WebInstaller_Welcome
extends WebInstallerPage
{
340 public function execute() {
341 if ( $this->parent
->request
->wasPosted() ) {
342 if ( $this->getVar( '_Environment' ) ) {
346 $this->parent
->output
->addWikiText( wfMsgNoTrans( 'config-welcome' ) );
347 $status = $this->parent
->doEnvironmentChecks();
349 $this->parent
->output
->addWikiText( wfMsgNoTrans( 'config-copyright',
350 SpecialVersion
::getCopyrightAndAuthorList() ) );
358 class WebInstaller_DBConnect
extends WebInstallerPage
{
360 public function execute() {
361 if ( $this->getVar( '_ExistingDBSettings' ) ) {
365 $r = $this->parent
->request
;
366 if ( $r->wasPosted() ) {
367 $status = $this->submit();
368 if ( $status->isGood() ) {
369 $this->setVar( '_UpgradeDone', false );
372 $this->parent
->showStatusBox( $status );
378 $types = "<ul class=\"config-settings-block\">\n";
380 $defaultType = $this->getVar( 'wgDBtype' );
383 foreach( $this->parent
->getDBTypes() as $type ) {
384 $db = 'Database' . ucfirst( $type );
385 $dbSupport .= wfMsgNoTrans( "config-support-$type",
386 call_user_func( array( $db, 'getSoftwareLink' ) ) ) . "\n";
388 $this->addHTML( $this->parent
->getInfoBox(
389 wfMsg( 'config-support-info', $dbSupport ) ) );
391 foreach ( $this->parent
->getVar( '_CompiledDBs' ) as $type ) {
392 $installer = $this->parent
->getDBInstaller( $type );
396 $installer->getReadableName(),
400 $type == $defaultType,
401 array( 'class' => 'dbRadio', 'rel' => "DB_wrapper_$type" )
406 Html
::openElement( 'div', array( 'id' => 'DB_wrapper_' . $type, 'class' => 'dbWrapper' ) ) .
407 Html
::element( 'h3', array(), wfMsg( 'config-header-' . $type ) ) .
408 $installer->getConnectForm() .
411 $types .= "</ul><br clear=\"left\"/>\n";
414 $this->parent
->label( 'config-db-type', false, $types ) .
421 public function submit() {
422 $r = $this->parent
->request
;
423 $type = $r->getVal( 'DBType' );
424 $this->setVar( 'wgDBtype', $type );
425 $installer = $this->parent
->getDBInstaller( $type );
427 return Status
::newFatal( 'config-invalid-db-type' );
429 return $installer->submitConnectForm();
434 class WebInstaller_Upgrade
extends WebInstallerPage
{
436 public function execute() {
437 if ( $this->getVar( '_UpgradeDone' ) ) {
438 // Allow regeneration of LocalSettings.php, unless we are working
439 // from a pre-existing LocalSettings.php file and we want to avoid
440 // leaking its contents
441 if ( $this->parent
->request
->wasPosted() && !$this->getVar( '_ExistingDBSettings' ) ) {
442 // Done message acknowledged
446 // Show the done message again
447 // Make them click back again if they want to do the upgrade again
448 $this->showDoneMessage();
453 // wgDBtype is generally valid here because otherwise the previous page
454 // (connect) wouldn't have declared its happiness
455 $type = $this->getVar( 'wgDBtype' );
456 $installer = $this->parent
->getDBInstaller( $type );
458 if ( !$installer->needsUpgrade() ) {
462 if ( $this->parent
->request
->wasPosted() ) {
463 $installer->preUpgrade();
465 '<div id="config-spinner" style="display:none;"><img src="../skins/common/images/ajax-loader.gif" /></div>' .
466 '<script>jQuery( "#config-spinner" )[0].style.display = "block";</script>' .
467 '<textarea id="config-update-log" name="UpdateLog" rows="10" readonly="readonly">'
469 $this->parent
->output
->flush();
470 $result = $installer->doUpgrade();
471 $this->addHTML( '</textarea>
472 <script>jQuery( "#config-spinner" )[0].style.display = "none";</script>' );
473 $this->parent
->output
->flush();
475 $this->setVar( '_UpgradeDone', true );
476 $this->showDoneMessage();
482 $this->addHTML( $this->parent
->getInfoBox(
483 wfMsgNoTrans( 'config-can-upgrade', $GLOBALS['wgVersion'] ) ) );
487 public function showDoneMessage() {
489 $regenerate = !$this->getVar( '_ExistingDBSettings' );
491 $msg = 'config-upgrade-done';
493 $msg = 'config-upgrade-done-no-regenerate';
495 $this->parent
->disableLinkPopups();
497 $this->parent
->getInfoBox(
499 $GLOBALS['wgServer'] .
500 $this->getVar( 'wgScriptPath' ) . '/index' .
501 $this->getVar( 'wgScriptExtension' )
505 $this->parent
->restoreLinkPopups();
506 $this->endForm( $regenerate ?
'regenerate' : false, false );
511 class WebInstaller_DBSettings
extends WebInstallerPage
{
513 public function execute() {
514 $installer = $this->parent
->getDBInstaller( $this->getVar( 'wgDBtype' ) );
516 $r = $this->parent
->request
;
517 if ( $r->wasPosted() ) {
518 $status = $installer->submitSettingsForm();
519 if ( $status === false ) {
521 } elseif ( $status->isGood() ) {
524 $this->parent
->showStatusBox( $status );
528 $form = $installer->getSettingsForm();
529 if ( $form === false ) {
534 $this->addHTML( $form );
540 class WebInstaller_Name
extends WebInstallerPage
{
542 public function execute() {
543 $r = $this->parent
->request
;
544 if ( $r->wasPosted() ) {
545 if ( $this->submit() ) {
552 if ( $this->getVar( 'wgSitename' ) == $GLOBALS['wgSitename'] ) {
553 $this->setVar( 'wgSitename', '' );
556 // Set wgMetaNamespace to something valid before we show the form.
557 // $wgMetaNamespace defaults to $wgSiteName which is 'MediaWiki'
558 $metaNS = $this->getVar( 'wgMetaNamespace' );
559 $this->setVar( 'wgMetaNamespace', wfMsgForContent( 'config-ns-other-default' ) );
562 $this->parent
->getTextBox( array(
563 'var' => 'wgSitename',
564 'label' => 'config-site-name',
565 'help' => $this->parent
->getHelpBox( 'config-site-name-help' )
567 $this->parent
->getRadioSet( array(
568 'var' => '_NamespaceType',
569 'label' => 'config-project-namespace',
570 'itemLabelPrefix' => 'config-ns-',
571 'values' => array( 'site-name', 'generic', 'other' ),
572 'commonAttribs' => array( 'class' => 'enableForOther', 'rel' => 'config_wgMetaNamespace' ),
573 'help' => $this->parent
->getHelpBox( 'config-project-namespace-help' )
575 $this->parent
->getTextBox( array(
576 'var' => 'wgMetaNamespace',
577 'label' => '', //TODO: Needs a label?
578 'attribs' => array( 'readonly' => 'readonly', 'class' => 'enabledByOther' ),
581 $this->getFieldSetStart( 'config-admin-box' ) .
582 $this->parent
->getTextBox( array(
583 'var' => '_AdminName',
584 'label' => 'config-admin-name',
585 'help' => $this->parent
->getHelpBox( 'config-admin-help' )
587 $this->parent
->getPasswordBox( array(
588 'var' => '_AdminPassword',
589 'label' => 'config-admin-password',
591 $this->parent
->getPasswordBox( array(
592 'var' => '_AdminPassword2',
593 'label' => 'config-admin-password-confirm'
595 $this->parent
->getTextBox( array(
596 'var' => '_AdminEmail',
597 'label' => 'config-admin-email',
598 'help' => $this->parent
->getHelpBox( 'config-admin-email-help' )
600 $this->parent
->getCheckBox( array(
601 'var' => '_Subscribe',
602 'label' => 'config-subscribe',
603 'help' => $this->parent
->getHelpBox( 'config-subscribe-help' )
605 $this->getFieldSetEnd() .
606 $this->parent
->getInfoBox( wfMsg( 'config-almost-done' ) ) .
607 $this->parent
->getRadioSet( array(
608 'var' => '_SkipOptional',
609 'itemLabelPrefix' => 'config-optional-',
610 'values' => array( 'continue', 'skip' )
614 // Restore the default value
615 $this->setVar( 'wgMetaNamespace', $metaNS );
621 public function submit() {
623 $this->parent
->setVarsFromRequest( array( 'wgSitename', '_NamespaceType',
624 '_AdminName', '_AdminPassword', '_AdminPassword2', '_AdminEmail',
625 '_Subscribe', '_SkipOptional' ) );
627 // Validate site name
628 if ( strval( $this->getVar( 'wgSitename' ) ) === '' ) {
629 $this->parent
->showError( 'config-site-name-blank' );
634 $nsType = $this->getVar( '_NamespaceType' );
635 if ( $nsType == 'site-name' ) {
636 $name = $this->getVar( 'wgSitename' );
637 // Sanitize for namespace
638 // This algorithm should match the JS one in WebInstallerOutput.php
639 $name = preg_replace( '/[\[\]\{\}|#<>%+? ]/', '_', $name );
640 $name = str_replace( '&', '&', $name );
641 $name = preg_replace( '/__+/', '_', $name );
642 $name = ucfirst( trim( $name, '_' ) );
643 } elseif ( $nsType == 'generic' ) {
644 $name = wfMsg( 'config-ns-generic' );
646 $name = $this->getVar( 'wgMetaNamespace' );
649 // Validate namespace
650 if ( strpos( $name, ':' ) !== false ) {
653 // Title-style validation
654 $title = Title
::newFromText( $name );
656 $good = $nsType == 'site-name';
658 $name = $title->getDBkey();
663 $this->parent
->showError( 'config-ns-invalid', $name );
666 $this->setVar( 'wgMetaNamespace', $name );
668 // Validate username for creation
669 $name = $this->getVar( '_AdminName' );
670 if ( strval( $name ) === '' ) {
671 $this->parent
->showError( 'config-admin-name-blank' );
675 $cname = User
::getCanonicalName( $name, 'creatable' );
676 if ( $cname === false ) {
677 $this->parent
->showError( 'config-admin-name-invalid', $name );
680 $this->setVar( '_AdminName', $cname );
687 $pwd = $this->getVar( '_AdminPassword' );
688 $user = User
::newFromName( $cname );
689 $valid = $user && $user->getPasswordValidity( $pwd );
690 if ( strval( $pwd ) === '' ) {
691 # $user->getPasswordValidity just checks for $wgMinimalPasswordLength.
692 # This message is more specific and helpful.
693 $msg = 'config-admin-password-blank';
694 } elseif ( $pwd !== $this->getVar( '_AdminPassword2' ) ) {
695 $msg = 'config-admin-password-mismatch';
696 } elseif ( $valid !== true ) {
697 # As of writing this will only catch the username being e.g. 'FOO' and
701 if ( $msg !== false ) {
702 $this->parent
->showError( $msg );
703 $this->setVar( '_AdminPassword', '' );
704 $this->setVar( '_AdminPassword2', '' );
712 class WebInstaller_Options
extends WebInstallerPage
{
714 public function execute() {
715 if ( $this->getVar( '_SkipOptional' ) == 'skip' ) {
718 if ( $this->parent
->request
->wasPosted() ) {
719 if ( $this->submit() ) {
727 $this->parent
->getRadioSet( array(
728 'var' => '_RightsProfile',
729 'label' => 'config-profile',
730 'itemLabelPrefix' => 'config-profile-',
731 'values' => array_keys( $this->parent
->rightsProfiles
),
733 $this->parent
->getHelpBox( 'config-profile-help' ) .
736 $this->parent
->getRadioSet( array(
737 'var' => '_LicenseCode',
738 'label' => 'config-license',
739 'itemLabelPrefix' => 'config-license-',
740 'values' => array_keys( $this->parent
->licenses
),
741 'commonAttribs' => array( 'class' => 'licenseRadio' ),
743 $this->getCCChooser() .
744 $this->parent
->getHelpBox( 'config-license-help' ) .
747 $this->getFieldSetStart( 'config-email-settings' ) .
748 $this->parent
->getCheckBox( array(
749 'var' => 'wgEnableEmail',
750 'label' => 'config-enable-email',
751 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'emailwrapper' ),
753 $this->parent
->getHelpBox( 'config-enable-email-help' ) .
754 "<div id=\"emailwrapper\">" .
755 $this->parent
->getTextBox( array(
756 'var' => 'wgPasswordSender',
757 'label' => 'config-email-sender'
759 $this->parent
->getHelpBox( 'config-email-sender-help' ) .
760 $this->parent
->getCheckBox( array(
761 'var' => 'wgEnableUserEmail',
762 'label' => 'config-email-user',
764 $this->parent
->getHelpBox( 'config-email-user-help' ) .
765 $this->parent
->getCheckBox( array(
766 'var' => 'wgEnotifUserTalk',
767 'label' => 'config-email-usertalk',
769 $this->parent
->getHelpBox( 'config-email-usertalk-help' ) .
770 $this->parent
->getCheckBox( array(
771 'var' => 'wgEnotifWatchlist',
772 'label' => 'config-email-watchlist',
774 $this->parent
->getHelpBox( 'config-email-watchlist-help' ) .
775 $this->parent
->getCheckBox( array(
776 'var' => 'wgEmailAuthentication',
777 'label' => 'config-email-auth',
779 $this->parent
->getHelpBox( 'config-email-auth-help' ) .
781 $this->getFieldSetEnd()
784 $extensions = $this->parent
->findExtensions();
787 $extHtml = $this->getFieldSetStart( 'config-extensions' );
789 foreach( $extensions as $ext ) {
790 $extHtml .= $this->parent
->getCheckBox( array(
796 $extHtml .= $this->parent
->getHelpBox( 'config-extensions-help' ) .
797 $this->getFieldSetEnd();
798 $this->addHTML( $extHtml );
803 $this->getFieldSetStart( 'config-upload-settings' ) .
804 $this->parent
->getCheckBox( array(
805 'var' => 'wgEnableUploads',
806 'label' => 'config-upload-enable',
807 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'uploadwrapper' ),
808 'help' => $this->parent
->getHelpBox( 'config-upload-help' )
810 '<div id="uploadwrapper" style="display: none;">' .
811 $this->parent
->getTextBox( array(
812 'var' => 'wgDeletedDirectory',
813 'label' => 'config-upload-deleted',
814 'help' => $this->parent
->getHelpBox( 'config-upload-deleted-help' )
817 $this->parent
->getTextBox( array(
819 'label' => 'config-logo',
820 'help' => $this->parent
->getHelpBox( 'config-logo-help' )
824 $this->parent
->getCheckBox( array(
825 'var' => 'wgUseInstantCommons',
826 'label' => 'config-instantcommons',
827 'help' => $this->parent
->getHelpBox( 'config-instantcommons-help' )
829 $this->getFieldSetEnd()
832 $caches = array( 'none' );
833 if( count( $this->getVar( '_Caches' ) ) ) {
836 $caches[] = 'memcached';
840 $this->getFieldSetStart( 'config-advanced-settings' ) .
841 # Object cache settings
842 $this->parent
->getRadioSet( array(
843 'var' => 'wgMainCacheType',
844 'label' => 'config-cache-options',
845 'itemLabelPrefix' => 'config-cache-',
849 $this->parent
->getHelpBox( 'config-cache-help' ) .
850 '<div id="config-memcachewrapper">' .
851 $this->parent
->getTextBox( array(
852 'var' => '_MemCachedServers',
853 'label' => 'config-memcached-servers',
854 'help' => $this->parent
->getHelpBox( 'config-memcached-help' )
857 $this->getFieldSetEnd()
862 public function getCCPartnerUrl() {
864 $exitUrl = $wgServer . $this->parent
->getUrl( array(
866 'SubmitCC' => 'indeed',
867 'config__LicenseCode' => 'cc',
868 'config_wgRightsUrl' => '[license_url]',
869 'config_wgRightsText' => '[license_name]',
870 'config_wgRightsIcon' => '[license_button]',
872 $styleUrl = $wgServer . dirname( dirname( $this->parent
->getUrl() ) ) .
873 '/skins/common/config-cc.css';
874 $iframeUrl = 'http://creativecommons.org/license/?' .
876 'partner' => 'MediaWiki',
877 'exit_url' => $exitUrl,
878 'lang' => $this->getVar( '_UserLang' ),
879 'stylesheet' => $styleUrl,
884 public function getCCChooser() {
885 $iframeAttribs = array(
886 'class' => 'config-cc-iframe',
887 'name' => 'config-cc-iframe',
888 'id' => 'config-cc-iframe',
893 if ( $this->getVar( '_CCDone' ) ) {
894 $iframeAttribs['src'] = $this->parent
->getUrl( array( 'ShowCC' => 'yes' ) );
896 $iframeAttribs['src'] = $this->getCCPartnerUrl();
900 "<div class=\"config-cc-wrapper\" id=\"config-cc-wrapper\" style=\"display: none;\">\n" .
901 Html
::element( 'iframe', $iframeAttribs, '', false /* not short */ ) .
905 public function getCCDoneBox() {
906 $js = "parent.document.getElementById('config-cc-wrapper').style.height = '$1';";
907 // If you change this height, also change it in config.css
908 $expandJs = str_replace( '$1', '54em', $js );
909 $reduceJs = str_replace( '$1', '70px', $js );
912 Html
::element( 'img', array( 'src' => $this->getVar( 'wgRightsIcon' ) ) ) .
914 htmlspecialchars( $this->getVar( 'wgRightsText' ) ) .
916 "<p style=\"text-align: center\">" .
919 'href' => $this->getCCPartnerUrl(),
920 'onclick' => $expandJs,
922 wfMsg( 'config-cc-again' )
925 "<script type=\"text/javascript\">\n" .
926 # Reduce the wrapper div height
927 htmlspecialchars( $reduceJs ) .
932 public function submitCC() {
933 $newValues = $this->parent
->setVarsFromRequest(
934 array( 'wgRightsUrl', 'wgRightsText', 'wgRightsIcon' ) );
935 if ( count( $newValues ) != 3 ) {
936 $this->parent
->showError( 'config-cc-error' );
939 $this->setVar( '_CCDone', true );
940 $this->addHTML( $this->getCCDoneBox() );
943 public function submit() {
944 $this->parent
->setVarsFromRequest( array( '_RightsProfile', '_LicenseCode',
945 'wgEnableEmail', 'wgPasswordSender', 'wgEnableUploads', 'wgLogo',
946 'wgEnableUserEmail', 'wgEnotifUserTalk', 'wgEnotifWatchlist',
947 'wgEmailAuthentication', 'wgMainCacheType', '_MemCachedServers',
948 'wgUseInstantCommons' ) );
950 if ( !in_array( $this->getVar( '_RightsProfile' ),
951 array_keys( $this->parent
->rightsProfiles
) ) )
953 reset( $this->parent
->rightsProfiles
);
954 $this->setVar( '_RightsProfile', key( $this->parent
->rightsProfiles
) );
957 $code = $this->getVar( '_LicenseCode' );
958 if ( $code == 'cc-choose' ) {
959 if ( !$this->getVar( '_CCDone' ) ) {
960 $this->parent
->showError( 'config-cc-not-chosen' );
963 } elseif ( in_array( $code, array_keys( $this->parent
->licenses
) ) ) {
964 $entry = $this->parent
->licenses
[$code];
965 if ( isset( $entry['text'] ) ) {
966 $this->setVar( 'wgRightsText', $entry['text'] );
968 $this->setVar( 'wgRightsText', wfMsg( 'config-license-' . $code ) );
970 $this->setVar( 'wgRightsUrl', $entry['url'] );
971 $this->setVar( 'wgRightsIcon', $entry['icon'] );
973 $this->setVar( 'wgRightsText', '' );
974 $this->setVar( 'wgRightsUrl', '' );
975 $this->setVar( 'wgRightsIcon', '' );
978 $extsAvailable = $this->parent
->findExtensions();
979 $extsToInstall = array();
980 foreach( $extsAvailable as $ext ) {
981 if( $this->parent
->request
->getCheck( 'config_ext-' . $ext ) ) {
982 $extsToInstall[] = $ext;
985 $this->parent
->setVar( '_Extensions', $extsToInstall );
991 class WebInstaller_Install
extends WebInstallerPage
{
993 public function execute() {
994 if( $this->parent
->request
->wasPosted() ) {
996 } elseif( $this->getVar( '_InstallDone' ) ) {
998 $status = new Status();
999 $status->warning( 'config-install-alreadydone' );
1000 $this->parent
->showStatusBox( $status );
1001 } elseif( $this->getVar( '_UpgradeDone' ) ) {
1005 $this->addHTML("<ul>");
1006 $this->parent
->performInstallation(
1007 array( $this, 'startStage'),
1008 array( $this, 'endStage' )
1010 $this->addHTML("</ul>");
1016 public function startStage( $step ) {
1017 $this->addHTML( "<li>" . wfMsgHtml( "config-install-$step" ) . wfMsg( 'ellipsis') );
1020 public function endStage( $step, $status ) {
1021 $msg = $status->isOk() ?
'config-install-step-done' : 'config-install-step-failed';
1022 $html = wfMsgHtml( 'word-separator' ) . wfMsgHtml( $msg );
1023 if ( !$status->isOk() ) {
1024 $html = "<span class=\"error\">$html</span>";
1026 $this->addHTML( $html . "</li>\n" );
1027 if( !$status->isGood() ) {
1028 $this->parent
->showStatusBox( $status );
1034 class WebInstaller_Complete
extends WebInstallerPage
{
1036 public function execute() {
1037 // Pop up a dialog box, to make it difficult for the user to forget
1038 // to download the file
1039 $lsUrl = $GLOBALS['wgServer'] . $this->parent
->getURL( array( 'localsettings' => 1 ) );
1040 $this->parent
->request
->response()->header( "Refresh: 0;$lsUrl" );
1043 $this->parent
->disableLinkPopups();
1045 $this->parent
->getInfoBox(
1046 wfMsgNoTrans( 'config-install-done',
1048 $GLOBALS['wgServer'] .
1049 $this->getVar( 'wgScriptPath' ) . '/index' .
1050 $this->getVar( 'wgScriptExtension' ),
1055 $this->parent
->restoreLinkPopups();
1056 $this->endForm( false, false );
1060 class WebInstaller_Restart
extends WebInstallerPage
{
1062 public function execute() {
1063 $r = $this->parent
->request
;
1064 if ( $r->wasPosted() ) {
1065 $really = $r->getVal( 'submit-restart' );
1067 $this->parent
->session
= array();
1068 $this->parent
->happyPages
= array();
1069 $this->parent
->settings
= array();
1075 $s = $this->parent
->getWarningBox( wfMsgNoTrans( 'config-help-restart' ) );
1076 $this->addHTML( $s );
1077 $this->endForm( 'restart' );
1082 abstract class WebInstaller_Document
extends WebInstallerPage
{
1084 protected abstract function getFileName();
1086 public function execute() {
1087 $text = $this->getFileContents();
1088 $text = $this->formatTextFile( $text );
1089 $this->parent
->output
->addWikiText( $text );
1091 $this->endForm( false );
1094 public function getFileContents() {
1095 return file_get_contents( dirname( __FILE__
) . '/../../' . $this->getFileName() );
1098 protected function formatTextFile( $text ) {
1099 // Use Unix line endings, escape some wikitext stuff
1100 $text = str_replace( array( '<', '{{', '[[', "\r" ),
1101 array( '<', '{{', '[[', '' ), $text );
1102 // join word-wrapped lines into one
1105 $text = preg_replace( "/\n([\\*#\t])([^\n]*?)\n([^\n#\\*:]+)/", "\n\\1\\2 \\3", $text );
1106 } while ( $text != $prev );
1107 // Replace tab indents with colons
1108 $text = preg_replace( '/^\t\t/m', '::', $text );
1109 $text = preg_replace( '/^\t/m', ':', $text );
1110 // turn (bug nnnn) into links
1111 $text = preg_replace_callback('/bug (\d+)/', array( $this, 'replaceBugLinks' ), $text );
1112 // add links to manual to every global variable mentioned
1113 $text = preg_replace_callback('/(\$wg[a-z0-9_]+)/i', array( $this, 'replaceConfigLinks' ), $text );
1117 private function replaceBugLinks( $matches ) {
1118 return '<span class="config-plainlink">[https://bugzilla.wikimedia.org/' .
1119 $matches[1] . ' bug ' . $matches[1] . ']</span>';
1122 private function replaceConfigLinks( $matches ) {
1123 return '<span class="config-plainlink">[http://www.mediawiki.org/wiki/Manual:' .
1124 $matches[1] . ' ' . $matches[1] . ']</span>';
1129 class WebInstaller_Readme
extends WebInstaller_Document
{
1130 protected function getFileName() { return 'README'; }
1133 class WebInstaller_ReleaseNotes
extends WebInstaller_Document
{
1134 protected function getFileName() { return 'RELEASE-NOTES'; }
1137 class WebInstaller_UpgradeDoc
extends WebInstaller_Document
{
1138 protected function getFileName() { return 'UPGRADE'; }
1141 class WebInstaller_Copying
extends WebInstaller_Document
{
1142 protected function getFileName() { return 'COPYING'; }