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' ) {
53 $this->parent
->output
->outputWarnings();
54 $s = "<div class=\"config-submit\">\n";
57 if ( $id === false ) {
58 $s .= Xml
::hidden( 'lastPage', $this->parent
->request
->getVal( 'lastPage' ) );
62 // Fake submit button for enter keypress
63 $s .= Xml
::submitButton( wfMsg( "config-$continue" ),
64 array( 'name' => "enter-$continue", 'style' => 'display:none' ) ) . "\n";
68 $s .= Xml
::submitButton( wfMsg( 'config-back' ),
70 'name' => 'submit-back',
71 'tabindex' => $this->parent
->nextTabIndex()
76 $s .= Xml
::submitButton( wfMsg( "config-$continue" ),
78 'name' => "submit-$continue",
79 'tabindex' => $this->parent
->nextTabIndex(),
83 $s .= "</div></form></div>\n";
87 public function getName() {
88 return str_replace( 'WebInstaller_', '', get_class( $this ) );
91 public function getId() {
92 return array_search( $this->getName(), $this->parent
->pageSequence
);
95 public function getVar( $var ) {
96 return $this->parent
->getVar( $var );
99 public function setVar( $name, $value ) {
100 $this->parent
->setVar( $name, $value );
105 class WebInstaller_Language
extends WebInstallerPage
{
107 public function execute() {
109 $r = $this->parent
->request
;
110 $userLang = $r->getVal( 'UserLang' );
111 $contLang = $r->getVal( 'ContLang' );
113 $lifetime = intval( ini_get( 'session.gc_maxlifetime' ) );
115 $lifetime = 1440; // PHP default
118 if ( $r->wasPosted() ) {
120 if ( $this->parent
->getSession( 'test' ) === null ) {
121 $requestTime = $r->getVal( 'LanguageRequestTime' );
122 if ( !$requestTime ) {
123 // The most likely explanation is that the user was knocked back
124 // from another page on POST due to session expiry
125 $msg = 'config-session-expired';
126 } elseif ( time() - $requestTime > $lifetime ) {
127 $msg = 'config-session-expired';
129 $msg = 'config-no-session';
131 $this->parent
->showError( $msg, $wgLang->formatTimePeriod( $lifetime ) );
133 $languages = Language
::getLanguageNames();
134 if ( isset( $languages[$userLang] ) ) {
135 $this->setVar( '_UserLang', $userLang );
137 if ( isset( $languages[$contLang] ) ) {
138 $this->setVar( 'wgLanguageCode', $contLang );
142 } elseif ( $this->parent
->showSessionWarning
) {
143 # The user was knocked back from another page to the start
144 # This probably indicates a session expiry
145 $this->parent
->showError( 'config-session-expired', $wgLang->formatTimePeriod( $lifetime ) );
148 $this->parent
->setSession( 'test', true );
150 if ( !isset( $languages[$userLang] ) ) {
151 $userLang = $this->getVar( '_UserLang', 'en' );
153 if ( !isset( $languages[$contLang] ) ) {
154 $contLang = $this->getVar( 'wgLanguageCode', 'en' );
158 Xml
::hidden( 'LanguageRequestTime', time() ) .
159 $this->getLanguageSelector( 'UserLang', 'config-your-language', $userLang ) .
160 $this->parent
->getHelpBox( 'config-your-language-help' ) .
161 $this->getLanguageSelector( 'ContLang', 'config-wiki-language', $contLang ) .
162 $this->parent
->getHelpBox( 'config-wiki-language-help' );
165 $this->addHTML( $s );
170 * Get a <select> for selecting languages.
172 public function getLanguageSelector( $name, $label, $selectedCode ) {
173 global $wgDummyLanguageCodes;
174 $s = Xml
::openElement( 'select', array( 'id' => $name, 'name' => $name ) ) . "\n";
176 $languages = Language
::getLanguageNames();
178 $dummies = array_flip( $wgDummyLanguageCodes );
179 foreach ( $languages as $code => $lang ) {
180 if ( isset( $dummies[$code] ) ) continue;
181 $s .= "\n" . Xml
::option( "$code - $lang", $code, $code == $selectedCode );
183 $s .= "\n</select>\n";
184 return $this->parent
->label( $label, $name, $s );
189 class WebInstaller_Welcome
extends WebInstallerPage
{
191 public function execute() {
192 if ( $this->parent
->request
->wasPosted() ) {
193 if ( $this->getVar( '_Environment' ) ) {
197 $this->parent
->output
->addWikiText( wfMsgNoTrans( 'config-welcome' ) );
198 $status = $this->parent
->doEnvironmentChecks();
200 $this->parent
->output
->addWikiText( wfMsgNoTrans( 'config-copyright',
201 SpecialVersion
::getCopyrightAndAuthorList() ) );
209 class WebInstaller_DBConnect
extends WebInstallerPage
{
211 public function execute() {
212 $r = $this->parent
->request
;
213 if ( $r->wasPosted() ) {
214 $status = $this->submit();
215 if ( $status->isGood() ) {
216 $this->setVar( '_UpgradeDone', false );
219 $this->parent
->showStatusBox( $status );
225 $types = "<ul class=\"config-settings-block\">\n";
227 $defaultType = $this->getVar( 'wgDBtype' );
230 foreach( $this->parent
->getDBTypes() as $type ) {
231 $db = 'Database' . ucfirst( $type );
232 $dbSupport .= wfMsgNoTrans( "config-support-$type", $db::getSoftwareLink() ) . "\n";
234 $this->addHTML( $this->parent
->getInfoBox(
235 wfMsg( 'config-support-info', $dbSupport ) ) );
237 foreach ( $this->parent
->getVar( '_CompiledDBs' ) as $type ) {
238 $installer = $this->parent
->getDBInstaller( $type );
242 $installer->getReadableName(),
246 $type == $defaultType,
247 array( 'class' => 'dbRadio', 'rel' => "DB_wrapper_$type" )
252 Xml
::openElement( 'div', array( 'id' => 'DB_wrapper_' . $type, 'class' => 'dbWrapper' ) ) .
253 Xml
::element( 'h3', array(), wfMsg( 'config-header-' . $type ) ) .
254 $installer->getConnectForm() .
257 $types .= "</ul><br clear=\"left\"/>\n";
260 $this->parent
->label( 'config-db-type', false, $types ) .
267 public function submit() {
268 $r = $this->parent
->request
;
269 $type = $r->getVal( 'DBType' );
270 $this->setVar( 'wgDBtype', $type );
271 $installer = $this->parent
->getDBInstaller( $type );
273 return Status
::newFatal( 'config-invalid-db-type' );
275 return $installer->submitConnectForm();
280 class WebInstaller_Upgrade
extends WebInstallerPage
{
282 public function execute() {
283 if ( $this->getVar( '_UpgradeDone' ) ) {
284 if ( $this->parent
->request
->wasPosted() ) {
285 // Done message acknowledged
289 // Show the done message again
290 // Make them click back again if they want to do the upgrade again
291 $this->showDoneMessage();
296 // wgDBtype is generally valid here because otherwise the previous page
297 // (connect) wouldn't have declared its happiness
298 $type = $this->getVar( 'wgDBtype' );
299 $installer = $this->parent
->getDBInstaller( $type );
301 if ( !$installer->needsUpgrade() ) {
305 if ( $this->parent
->request
->wasPosted() ) {
306 $installer->preUpgrade();
308 '<div id="config-spinner" style="display:none;"><img src="../skins/common/images/ajax-loader.gif" /></div>' .
309 '<script>jQuery( "#config-spinner" )[0].style.display = "block";</script>' .
310 '<textarea id="config-update-log" name="UpdateLog" rows="10" readonly="readonly">'
312 $this->parent
->output
->flush();
313 $result = $installer->doUpgrade();
314 $this->addHTML( '</textarea>
315 <script>jQuery( "#config-spinner" )[0].style.display = "none";</script>' );
316 $this->parent
->output
->flush();
318 $this->setVar( '_UpgradeDone', true );
319 $this->showDoneMessage();
325 $this->addHTML( $this->parent
->getInfoBox(
326 wfMsgNoTrans( 'config-can-upgrade', $GLOBALS['wgVersion'] ) ) );
330 public function showDoneMessage() {
333 $this->parent
->getInfoBox(
334 wfMsgNoTrans( 'config-upgrade-done',
335 $GLOBALS['wgServer'] .
336 $this->getVar( 'wgScriptPath' ) . '/index' .
337 $this->getVar( 'wgScriptExtension' )
341 $this->endForm( 'regenerate' );
346 class WebInstaller_DBSettings
extends WebInstallerPage
{
348 public function execute() {
349 $installer = $this->parent
->getDBInstaller( $this->getVar( 'wgDBtype' ) );
351 $r = $this->parent
->request
;
352 if ( $r->wasPosted() ) {
353 $status = $installer->submitSettingsForm();
354 if ( $status === false ) {
356 } elseif ( $status->isGood() ) {
359 $this->parent
->showStatusBox( $status );
363 $form = $installer->getSettingsForm();
364 if ( $form === false ) {
369 $this->addHTML( $form );
375 class WebInstaller_Name
extends WebInstallerPage
{
377 public function execute() {
378 $r = $this->parent
->request
;
379 if ( $r->wasPosted() ) {
380 if ( $this->submit() ) {
387 if ( $this->getVar( 'wgSitename' ) == $GLOBALS['wgSitename'] ) {
388 $this->setVar( 'wgSitename', '' );
391 // Set wgMetaNamespace to something valid before we show the form.
392 // $wgMetaNamespace defaults to $wgSiteName which is 'MediaWiki'
393 $metaNS = $this->getVar( 'wgMetaNamespace' );
394 $this->setVar( 'wgMetaNamespace', wfMsgForContent( 'config-ns-other-default' ) );
397 $this->parent
->getTextBox( array(
398 'var' => 'wgSitename',
399 'label' => 'config-site-name',
401 $this->parent
->getHelpBox( 'config-site-name-help' ) .
402 $this->parent
->getRadioSet( array(
403 'var' => '_NamespaceType',
404 'label' => 'config-project-namespace',
405 'itemLabelPrefix' => 'config-ns-',
406 'values' => array( 'site-name', 'generic', 'other' ),
407 'commonAttribs' => array( 'class' => 'enableForOther', 'rel' => 'config_wgMetaNamespace' ),
409 $this->parent
->getTextBox( array(
410 'var' => 'wgMetaNamespace',
412 'attribs' => array( 'disabled' => '' ),
414 $this->parent
->getHelpBox( 'config-project-namespace-help' ) .
415 $this->parent
->getFieldsetStart( 'config-admin-box' ) .
416 $this->parent
->getTextBox( array(
417 'var' => '_AdminName',
418 'label' => 'config-admin-name'
420 $this->parent
->getPasswordBox( array(
421 'var' => '_AdminPassword',
422 'label' => 'config-admin-password',
424 $this->parent
->getPasswordBox( array(
425 'var' => '_AdminPassword2',
426 'label' => 'config-admin-password-confirm'
428 $this->parent
->getHelpBox( 'config-admin-help' ) .
429 $this->parent
->getTextBox( array(
430 'var' => '_AdminEmail',
431 'label' => 'config-admin-email'
433 $this->parent
->getHelpBox( 'config-admin-email-help' ) .
434 $this->parent
->getCheckBox( array(
435 'var' => '_Subscribe',
436 'label' => 'config-subscribe'
438 $this->parent
->getHelpBox( 'config-subscribe-help' ) .
439 $this->parent
->getFieldsetEnd() .
440 $this->parent
->getInfoBox( wfMsg( 'config-almost-done' ) ) .
441 $this->parent
->getRadioSet( array(
442 'var' => '_SkipOptional',
443 'itemLabelPrefix' => 'config-optional-',
444 'values' => array( 'continue', 'skip' )
448 // Restore the default value
449 $this->setVar( 'wgMetaNamespace', $metaNS );
455 public function submit() {
457 $this->parent
->setVarsFromRequest( array( 'wgSitename', '_NamespaceType',
458 '_AdminName', '_AdminPassword', '_AdminPassword2', '_AdminEmail',
459 '_Subscribe', '_SkipOptional' ) );
461 // Validate site name
462 if ( strval( $this->getVar( 'wgSitename' ) ) === '' ) {
463 $this->parent
->showError( 'config-site-name-blank' );
468 $nsType = $this->getVar( '_NamespaceType' );
469 if ( $nsType == 'site-name' ) {
470 $name = $this->getVar( 'wgSitename' );
471 // Sanitize for namespace
472 // This algorithm should match the JS one in WebInstallerOutput.php
473 $name = preg_replace( '/[\[\]\{\}|#<>%+? ]/', '_', $name );
474 $name = str_replace( '&', '&', $name );
475 $name = preg_replace( '/__+/', '_', $name );
476 $name = ucfirst( trim( $name, '_' ) );
477 } elseif ( $nsType == 'generic' ) {
478 $name = wfMsg( 'config-ns-generic' );
480 $name = $this->getVar( 'wgMetaNamespace' );
483 // Validate namespace
484 if ( strpos( $name, ':' ) !== false ) {
487 // Title-style validation
488 $title = Title
::newFromText( $name );
490 $good = $nsType == 'site-name';
492 $name = $title->getDBkey();
497 $this->parent
->showError( 'config-ns-invalid', $name );
500 $this->setVar( 'wgMetaNamespace', $name );
502 // Validate username for creation
503 $name = $this->getVar( '_AdminName' );
504 if ( strval( $name ) === '' ) {
505 $this->parent
->showError( 'config-admin-name-blank' );
509 $cname = User
::getCanonicalName( $name, 'creatable' );
510 if ( $cname === false ) {
511 $this->parent
->showError( 'config-admin-name-invalid', $name );
514 $this->setVar( '_AdminName', $cname );
520 $pwd = $this->getVar( '_AdminPassword' );
521 $user = User
::newFromName( $cname );
522 $valid = $user->getPasswordValidity( $pwd );
523 if ( strval( $pwd ) === '' ) {
524 # $user->getPasswordValidity just checks for $wgMinimalPasswordLength.
525 # This message is more specific and helpful.
526 $msg = 'config-admin-password-blank';
527 } elseif ( $pwd !== $this->getVar( '_AdminPassword2' ) ) {
528 $msg = 'config-admin-password-mismatch';
529 } elseif ( $valid !== true ) {
530 # As of writing this will only catch the username being e.g. 'FOO' and
534 if ( $msg !== false ) {
535 $this->parent
->showError( $msg );
536 $this->setVar( '_AdminPassword', '' );
537 $this->setVar( '_AdminPassword2', '' );
545 class WebInstaller_Options
extends WebInstallerPage
{
547 public function execute() {
548 if ( $this->getVar( '_SkipOptional' ) == 'skip' ) {
551 if ( $this->parent
->request
->wasPosted() ) {
552 if ( $this->submit() ) {
560 $this->parent
->getRadioSet( array(
561 'var' => '_RightsProfile',
562 'label' => 'config-profile',
563 'itemLabelPrefix' => 'config-profile-',
564 'values' => array_keys( $this->parent
->rightsProfiles
),
566 $this->parent
->getHelpBox( 'config-profile-help' ) .
569 $this->parent
->getRadioSet( array(
570 'var' => '_LicenseCode',
571 'label' => 'config-license',
572 'itemLabelPrefix' => 'config-license-',
573 'values' => array_keys( $this->parent
->licenses
),
574 'commonAttribs' => array( 'class' => 'licenseRadio' ),
576 $this->getCCChooser() .
577 $this->parent
->getHelpBox( 'config-license-help' ) .
580 $this->parent
->getFieldsetStart( 'config-email-settings' ) .
581 $this->parent
->getCheckBox( array(
582 'var' => 'wgEnableEmail',
583 'label' => 'config-enable-email',
584 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'emailwrapper' ),
586 $this->parent
->getHelpBox( 'config-enable-email-help' ) .
587 "<div id=\"emailwrapper\">" .
588 $this->parent
->getTextBox( array(
589 'var' => 'wgPasswordSender',
590 'label' => 'config-email-sender'
592 $this->parent
->getHelpBox( 'config-email-sender-help' ) .
593 $this->parent
->getCheckBox( array(
594 'var' => 'wgEnableUserEmail',
595 'label' => 'config-email-user',
597 $this->parent
->getHelpBox( 'config-email-user-help' ) .
598 $this->parent
->getCheckBox( array(
599 'var' => 'wgEnotifUserTalk',
600 'label' => 'config-email-usertalk',
602 $this->parent
->getHelpBox( 'config-email-usertalk-help' ) .
603 $this->parent
->getCheckBox( array(
604 'var' => 'wgEnotifWatchlist',
605 'label' => 'config-email-watchlist',
607 $this->parent
->getHelpBox( 'config-email-watchlist-help' ) .
608 $this->parent
->getCheckBox( array(
609 'var' => 'wgEmailAuthentication',
610 'label' => 'config-email-auth',
612 $this->parent
->getHelpBox( 'config-email-auth-help' ) .
614 $this->parent
->getFieldsetEnd()
617 $extensions = $this->parent
->findExtensions();
620 $extHtml = $this->parent
->getFieldsetStart( 'config-extensions' );
622 foreach( $extensions as $ext ) {
623 $extHtml .= $this->parent
->getCheckBox( array(
629 $extHtml .= $this->parent
->getHelpBox( 'config-extensions-help' ) .
630 $this->parent
->getFieldsetEnd();
631 $this->addHTML( $extHtml );
636 $this->parent
->getFieldsetStart( 'config-upload-settings' ) .
637 $this->parent
->getCheckBox( array(
638 'var' => 'wgEnableUploads',
639 'label' => 'config-upload-enable',
640 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'uploadwrapper' ),
642 $this->parent
->getHelpBox( 'config-upload-help' ) .
643 '<div id="uploadwrapper" style="display: none;">' .
644 $this->parent
->getTextBox( array(
645 'var' => 'wgDeletedDirectory',
646 'label' => 'config-upload-deleted',
648 $this->parent
->getHelpBox( 'config-upload-deleted-help' ) .
650 $this->parent
->getTextBox( array(
652 'label' => 'config-logo'
654 $this->parent
->getHelpBox( 'config-logo-help' )
656 $canUse = $this->getVar( '_ExternalHTTP' ) ?
657 'config-instantcommons-good' : 'config-instantcommons-bad';
659 $this->parent
->getCheckBox( array(
660 'var' => 'wgUseInstantCommons',
661 'label' => 'config-instantcommons',
663 $this->parent
->getHelpBox( 'config-instantcommons-help', wfMsgNoTrans( $canUse ) ) .
664 $this->parent
->getFieldsetEnd()
667 $caches = array( 'none' );
668 if( count( $this->getVar( '_Caches' ) ) ) {
671 $caches[] = 'memcached';
675 $this->parent
->getFieldsetStart( 'config-advanced-settings' ) .
676 # Object cache settings
677 $this->parent
->getRadioSet( array(
678 'var' => 'wgMainCacheType',
679 'label' => 'config-cache-options',
680 'itemLabelPrefix' => 'config-cache-',
684 $this->parent
->getHelpBox( 'config-cache-help' ) .
685 '<div id="config-memcachewrapper">' .
686 $this->parent
->getTextBox( array(
687 'var' => '_MemCachedServers',
688 'label' => 'config-memcached-servers',
690 $this->parent
->getHelpBox( 'config-memcached-help' ) . '</div>' .
691 $this->parent
->getFieldsetEnd()
696 public function getCCPartnerUrl() {
698 $exitUrl = $wgServer . $this->parent
->getUrl( array(
700 'SubmitCC' => 'indeed',
701 'config__LicenseCode' => 'cc',
702 'config_wgRightsUrl' => '[license_url]',
703 'config_wgRightsText' => '[license_name]',
704 'config_wgRightsIcon' => '[license_button]',
706 $styleUrl = $wgServer . dirname( dirname( $this->parent
->getUrl() ) ) .
707 '/skins/common/config-cc.css';
708 $iframeUrl = 'http://creativecommons.org/license/?' .
710 'partner' => 'MediaWiki',
711 'exit_url' => $exitUrl,
712 'lang' => $this->getVar( '_UserLang' ),
713 'stylesheet' => $styleUrl,
718 public function getCCChooser() {
719 $iframeAttribs = array(
720 'class' => 'config-cc-iframe',
721 'name' => 'config-cc-iframe',
722 'id' => 'config-cc-iframe',
727 if ( $this->getVar( '_CCDone' ) ) {
728 $iframeAttribs['src'] = $this->parent
->getUrl( array( 'ShowCC' => 'yes' ) );
730 $iframeAttribs['src'] = $this->getCCPartnerUrl();
734 "<div class=\"config-cc-wrapper\" id=\"config-cc-wrapper\" style=\"display: none;\">\n" .
735 Xml
::element( 'iframe', $iframeAttribs, '', false /* not short */ ) .
739 public function getCCDoneBox() {
740 $js = "parent.document.getElementById('config-cc-wrapper').style.height = '$1';";
741 // If you change this height, also change it in config.css
742 $expandJs = str_replace( '$1', '54em', $js );
743 $reduceJs = str_replace( '$1', '70px', $js );
746 Xml
::element( 'img', array( 'src' => $this->getVar( 'wgRightsIcon' ) ) ) .
748 htmlspecialchars( $this->getVar( 'wgRightsText' ) ) .
750 "<p style=\"text-align: center\">" .
753 'href' => $this->getCCPartnerUrl(),
754 'onclick' => $expandJs,
756 wfMsg( 'config-cc-again' )
759 "<script type=\"text/javascript\">\n" .
760 # Reduce the wrapper div height
761 htmlspecialchars( $reduceJs ) .
766 public function submitCC() {
767 $newValues = $this->parent
->setVarsFromRequest(
768 array( 'wgRightsUrl', 'wgRightsText', 'wgRightsIcon' ) );
769 if ( count( $newValues ) != 3 ) {
770 $this->parent
->showError( 'config-cc-error' );
773 $this->setVar( '_CCDone', true );
774 $this->addHTML( $this->getCCDoneBox() );
777 public function submit() {
778 $this->parent
->setVarsFromRequest( array( '_RightsProfile', '_LicenseCode',
779 'wgEnableEmail', 'wgPasswordSender', 'wgEnableUploads', 'wgLogo',
780 'wgEnableUserEmail', 'wgEnotifUserTalk', 'wgEnotifWatchlist',
781 'wgEmailAuthentication', 'wgMainCacheType', '_MemCachedServers',
782 'wgUseInstantCommons' ) );
784 if ( !in_array( $this->getVar( '_RightsProfile' ),
785 array_keys( $this->parent
->rightsProfiles
) ) )
787 reset( $this->parent
->rightsProfiles
);
788 $this->setVar( '_RightsProfile', key( $this->parent
->rightsProfiles
) );
791 $code = $this->getVar( '_LicenseCode' );
792 if ( $code == 'cc-choose' ) {
793 if ( !$this->getVar( '_CCDone' ) ) {
794 $this->parent
->showError( 'config-cc-not-chosen' );
797 } elseif ( in_array( $code, array_keys( $this->parent
->licenses
) ) ) {
798 $entry = $this->parent
->licenses
[$code];
799 if ( isset( $entry['text'] ) ) {
800 $this->setVar( 'wgRightsText', $entry['text'] );
802 $this->setVar( 'wgRightsText', wfMsg( 'config-license-' . $code ) );
804 $this->setVar( 'wgRightsUrl', $entry['url'] );
805 $this->setVar( 'wgRightsIcon', $entry['icon'] );
807 $this->setVar( 'wgRightsText', '' );
808 $this->setVar( 'wgRightsUrl', '' );
809 $this->setVar( 'wgRightsIcon', '' );
812 $extsAvailable = $this->parent
->findExtensions();
813 $extsToInstall = array();
814 foreach( $extsAvailable as $ext ) {
815 if( $this->parent
->request
->getCheck( 'config_ext-' . $ext ) ) {
816 $extsToInstall[] = $ext;
819 $this->parent
->setVar( '_Extensions', $extsToInstall );
825 class WebInstaller_Install
extends WebInstallerPage
{
827 public function execute() {
828 if( $this->parent
->request
->wasPosted() ) {
830 } elseif( $this->getVar( '_InstallDone' ) ) {
832 $status = new Status();
833 $status->warning( 'config-install-alreadydone' );
834 $this->parent
->showStatusBox( $status );
835 } elseif( $this->getVar( '_UpgradeDone' ) ) {
839 $this->addHTML("<ul>");
840 $this->parent
->performInstallation(
841 array( $this, 'startStage'),
842 array( $this, 'endStage' )
844 $this->addHTML("</ul>");
850 public function startStage( $step ) {
851 $this->addHTML( "<li>" . wfMsgHtml( "config-install-$step" ) . wfMsg( 'ellipsis') );
854 public function endStage( $step, $status ) {
855 $msg = $status->isOk() ?
'config-install-step-done' : 'config-install-step-failed';
856 $html = wfMsgHtml( 'word-separator' ) . wfMsgHtml( $msg );
857 if ( !$status->isOk() ) {
858 $html = "<span class=\"error\">$html</span>";
860 $this->addHTML( $html . "</li>\n" );
861 if( !$status->isGood() ) {
862 $this->parent
->showStatusBox( $status );
868 class WebInstaller_Complete
extends WebInstallerPage
{
870 public function execute() {
873 $this->parent
->getInfoBox(
874 wfMsgNoTrans( 'config-install-done',
875 $GLOBALS['wgServer'] . $this->parent
->getURL( array( 'localsettings' => 1 ) ),
876 $GLOBALS['wgServer'] .
877 $this->getVar( 'wgScriptPath' ) . '/index' .
878 $this->getVar( 'wgScriptExtension' )
882 $this->endForm( false );
886 class WebInstaller_Restart
extends WebInstallerPage
{
888 public function execute() {
889 $r = $this->parent
->request
;
890 if ( $r->wasPosted() ) {
891 $really = $r->getVal( 'submit-restart' );
893 $this->parent
->session
= array();
894 $this->parent
->happyPages
= array();
895 $this->parent
->settings
= array();
901 $s = $this->parent
->getWarningBox( wfMsgNoTrans( 'config-help-restart' ) );
902 $this->addHTML( $s );
903 $this->endForm( 'restart' );
908 abstract class WebInstaller_Document
extends WebInstallerPage
{
910 protected abstract function getFileName();
912 public function execute() {
913 $text = $this->getFileContents();
914 $this->parent
->output
->addWikiText( $text );
916 $this->endForm( false );
919 public function getFileContents() {
920 return file_get_contents( dirname( __FILE__
) . '/../../' . $this->getFileName() );
923 protected function formatTextFile( $text ) {
924 $text = str_replace( array( '<', '{{', '[[' ),
925 array( '<', '{{', '[[' ), $text );
926 // replace numbering with [1], [2], etc with MW-style numbering
927 $text = preg_replace( "/\r?\n(\r?\n)?\\[\\d+\\]/m", "\\1#", $text );
928 // join word-wrapped lines into one
931 $text = preg_replace( "/\n([\\*#])([^\r\n]*?)\r?\n([^\r\n#\\*:]+)/", "\n\\1\\2 \\3", $text );
932 } while ( $text != $prev );
933 // turn (bug nnnn) into links
934 $text = preg_replace_callback('/bug (\d+)/', array( $this, 'replaceBugLinks' ), $text );
935 // add links to manual to every global variable mentioned
936 $text = preg_replace_callback('/(\$wg[a-z0-9_]+)/i', array( $this, 'replaceConfigLinks' ), $text );
937 // special case for <pre> - formatted links
940 $text = preg_replace( '/^([^\\s].*?)\r?\n[\\s]+(https?:\/\/)/m', "\\1\n:\\2", $text );
941 } while ( $text != $prev );
945 private function replaceBugLinks( $matches ) {
946 return '<span class="config-plainlink">[https://bugzilla.wikimedia.org/' .
947 $matches[1] . ' bug ' . $matches[1] . ']</span>';
950 private function replaceConfigLinks( $matches ) {
951 return '<span class="config-plainlink">[http://www.mediawiki.org/wiki/Manual:' .
952 $matches[1] . ' ' . $matches[1] . ']</span>';
957 class WebInstaller_Readme
extends WebInstaller_Document
{
959 protected function getFileName() { return 'README'; }
961 public function getFileContents() {
962 return $this->formatTextFile( parent
::getFileContents() );
967 class WebInstaller_ReleaseNotes
extends WebInstaller_Document
{
969 protected function getFileName() { return 'RELEASE-NOTES'; }
971 public function getFileContents() {
972 return $this->formatTextFile( parent
::getFileContents() );
977 class WebInstaller_UpgradeDoc
extends WebInstaller_Document
{
979 protected function getFileName() { return 'UPGRADE'; }
981 public function getFileContents() {
982 return $this->formatTextFile( parent
::getFileContents() );
987 class WebInstaller_Copying
extends WebInstaller_Document
{
989 protected function getFileName() { return 'COPYING'; }
991 public function getFileContents() {
992 $text = parent
::getFileContents();
993 $text = str_replace( "\x0C", '', $text );
994 $text = preg_replace_callback( '/\n[ \t]+/m', array( 'WebInstaller_Copying', 'replaceLeadingSpaces' ), $text );
995 $text = '<tt>' . nl2br( $text ) . '</tt>';
999 private static function replaceLeadingSpaces( $matches ) {
1000 return "\n" . str_repeat( ' ', strlen( $matches[0] ) );