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 .= Html
::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 );
104 * Get the starting tags of a fieldset.
106 * @param $legend String: message name
108 protected function getFieldsetStart( $legend ) {
109 return "\n<fieldset><legend>" . wfMsgHtml( $legend ) . "</legend>\n";
113 * Get the end tag of a fieldset.
115 protected function getFieldsetEnd() {
116 return "</fieldset>\n";
120 class WebInstaller_Locked
extends WebInstallerPage
{
122 // The status of Installer::getLocalSettingsStatus()
125 public function setLocalSettingsStatus( Status
$s ) {
129 public function execute() {
130 $r = $this->parent
->request
;
131 if( !$r->wasPosted() ||
!$this->status
->isOK() ) {
135 $key = $r->getText( 'config_wpUpgradeKey' );
136 if( !$key ||
$key !== $this->getVar( '_UpgradeKey' ) ) {
137 $this->parent
->showError( 'config-localsettings-badkey' );
141 $this->setVar( '_LocalSettingsLocked', false );
148 * Display stuff to the end user
150 private function display() {
152 $this->parent
->showStatusBox( $this->status
);
153 if( $this->status
->isOK() && !$this->status
->isGood() ) {
154 $this->addHTML( "<br />" .
155 $this->parent
->getTextBox( array(
156 'var' => 'wpUpgradeKey',
157 'label' => 'config-localsettings-key',
165 class WebInstaller_Language
extends WebInstallerPage
{
167 public function execute() {
169 $r = $this->parent
->request
;
170 $userLang = $r->getVal( 'UserLang' );
171 $contLang = $r->getVal( 'ContLang' );
173 $lifetime = intval( ini_get( 'session.gc_maxlifetime' ) );
175 $lifetime = 1440; // PHP default
178 if ( $r->wasPosted() ) {
180 if ( $this->parent
->getSession( 'test' ) === null ) {
181 $requestTime = $r->getVal( 'LanguageRequestTime' );
182 if ( !$requestTime ) {
183 // The most likely explanation is that the user was knocked back
184 // from another page on POST due to session expiry
185 $msg = 'config-session-expired';
186 } elseif ( time() - $requestTime > $lifetime ) {
187 $msg = 'config-session-expired';
189 $msg = 'config-no-session';
191 $this->parent
->showError( $msg, $wgLang->formatTimePeriod( $lifetime ) );
193 $languages = Language
::getLanguageNames();
194 if ( isset( $languages[$userLang] ) ) {
195 $this->setVar( '_UserLang', $userLang );
197 if ( isset( $languages[$contLang] ) ) {
198 $this->setVar( 'wgLanguageCode', $contLang );
202 } elseif ( $this->parent
->showSessionWarning
) {
203 # The user was knocked back from another page to the start
204 # This probably indicates a session expiry
205 $this->parent
->showError( 'config-session-expired', $wgLang->formatTimePeriod( $lifetime ) );
208 $this->parent
->setSession( 'test', true );
210 if ( !isset( $languages[$userLang] ) ) {
211 $userLang = $this->getVar( '_UserLang', 'en' );
213 if ( !isset( $languages[$contLang] ) ) {
214 $contLang = $this->getVar( 'wgLanguageCode', 'en' );
217 $s = Html
::hidden( 'LanguageRequestTime', time() ) .
218 $this->getLanguageSelector( 'UserLang', 'config-your-language', $userLang ) .
219 $this->parent
->getHelpBox( 'config-your-language-help' ) .
220 $this->getLanguageSelector( 'ContLang', 'config-wiki-language', $contLang ) .
221 $this->parent
->getHelpBox( 'config-wiki-language-help' );
224 $this->addHTML( $s );
229 * Get a <select> for selecting languages.
231 public function getLanguageSelector( $name, $label, $selectedCode ) {
232 global $wgDummyLanguageCodes;
233 $s = Xml
::openElement( 'select', array( 'id' => $name, 'name' => $name ) ) . "\n";
235 $languages = Language
::getLanguageNames();
237 $dummies = array_flip( $wgDummyLanguageCodes );
238 foreach ( $languages as $code => $lang ) {
239 if ( isset( $dummies[$code] ) ) continue;
240 $s .= "\n" . Xml
::option( "$code - $lang", $code, $code == $selectedCode );
242 $s .= "\n</select>\n";
243 return $this->parent
->label( $label, $name, $s );
248 class WebInstaller_Welcome
extends WebInstallerPage
{
250 public function execute() {
251 if ( $this->parent
->request
->wasPosted() ) {
252 if ( $this->getVar( '_Environment' ) ) {
256 $this->parent
->output
->addWikiText( wfMsgNoTrans( 'config-welcome' ) );
257 $status = $this->parent
->doEnvironmentChecks();
259 $this->parent
->output
->addWikiText( wfMsgNoTrans( 'config-copyright',
260 SpecialVersion
::getCopyrightAndAuthorList() ) );
268 class WebInstaller_DBConnect
extends WebInstallerPage
{
270 public function execute() {
271 $r = $this->parent
->request
;
272 if ( $r->wasPosted() ) {
273 $status = $this->submit();
274 if ( $status->isGood() ) {
275 $this->setVar( '_UpgradeDone', false );
278 $this->parent
->showStatusBox( $status );
284 $types = "<ul class=\"config-settings-block\">\n";
286 $defaultType = $this->getVar( 'wgDBtype' );
289 foreach( $this->parent
->getDBTypes() as $type ) {
290 $db = 'Database' . ucfirst( $type );
291 $dbSupport .= wfMsgNoTrans( "config-support-$type",
292 call_user_func( array( $db, 'getSoftwareLink' ) ) ) . "\n";
294 $this->addHTML( $this->parent
->getInfoBox(
295 wfMsg( 'config-support-info', $dbSupport ) ) );
297 foreach ( $this->parent
->getVar( '_CompiledDBs' ) as $type ) {
298 $installer = $this->parent
->getDBInstaller( $type );
302 $installer->getReadableName(),
306 $type == $defaultType,
307 array( 'class' => 'dbRadio', 'rel' => "DB_wrapper_$type" )
312 Xml
::openElement( 'div', array( 'id' => 'DB_wrapper_' . $type, 'class' => 'dbWrapper' ) ) .
313 Xml
::element( 'h3', array(), wfMsg( 'config-header-' . $type ) ) .
314 $installer->getConnectForm() .
317 $types .= "</ul><br clear=\"left\"/>\n";
320 $this->parent
->label( 'config-db-type', false, $types ) .
327 public function submit() {
328 $r = $this->parent
->request
;
329 $type = $r->getVal( 'DBType' );
330 $this->setVar( 'wgDBtype', $type );
331 $installer = $this->parent
->getDBInstaller( $type );
333 return Status
::newFatal( 'config-invalid-db-type' );
335 return $installer->submitConnectForm();
340 class WebInstaller_Upgrade
extends WebInstallerPage
{
342 public function execute() {
343 if ( $this->getVar( '_UpgradeDone' ) ) {
344 if ( $this->parent
->request
->wasPosted() ) {
345 // Done message acknowledged
349 // Show the done message again
350 // Make them click back again if they want to do the upgrade again
351 $this->showDoneMessage();
356 // wgDBtype is generally valid here because otherwise the previous page
357 // (connect) wouldn't have declared its happiness
358 $type = $this->getVar( 'wgDBtype' );
359 $installer = $this->parent
->getDBInstaller( $type );
361 if ( !$installer->needsUpgrade() ) {
365 if ( $this->parent
->request
->wasPosted() ) {
366 $installer->preUpgrade();
368 '<div id="config-spinner" style="display:none;"><img src="../skins/common/images/ajax-loader.gif" /></div>' .
369 '<script>jQuery( "#config-spinner" )[0].style.display = "block";</script>' .
370 '<textarea id="config-update-log" name="UpdateLog" rows="10" readonly="readonly">'
372 $this->parent
->output
->flush();
373 $result = $installer->doUpgrade();
374 $this->addHTML( '</textarea>
375 <script>jQuery( "#config-spinner" )[0].style.display = "none";</script>' );
376 $this->parent
->output
->flush();
378 $this->setVar( '_UpgradeDone', true );
379 $this->showDoneMessage();
385 $this->addHTML( $this->parent
->getInfoBox(
386 wfMsgNoTrans( 'config-can-upgrade', $GLOBALS['wgVersion'] ) ) );
390 public function showDoneMessage() {
393 $this->parent
->getInfoBox(
394 wfMsgNoTrans( 'config-upgrade-done',
395 $GLOBALS['wgServer'] .
396 $this->getVar( 'wgScriptPath' ) . '/index' .
397 $this->getVar( 'wgScriptExtension' )
401 $this->endForm( 'regenerate' );
406 class WebInstaller_DBSettings
extends WebInstallerPage
{
408 public function execute() {
409 $installer = $this->parent
->getDBInstaller( $this->getVar( 'wgDBtype' ) );
411 $r = $this->parent
->request
;
412 if ( $r->wasPosted() ) {
413 $status = $installer->submitSettingsForm();
414 if ( $status === false ) {
416 } elseif ( $status->isGood() ) {
419 $this->parent
->showStatusBox( $status );
423 $form = $installer->getSettingsForm();
424 if ( $form === false ) {
429 $this->addHTML( $form );
435 class WebInstaller_Name
extends WebInstallerPage
{
437 public function execute() {
438 $r = $this->parent
->request
;
439 if ( $r->wasPosted() ) {
440 if ( $this->submit() ) {
447 if ( $this->getVar( 'wgSitename' ) == $GLOBALS['wgSitename'] ) {
448 $this->setVar( 'wgSitename', '' );
451 // Set wgMetaNamespace to something valid before we show the form.
452 // $wgMetaNamespace defaults to $wgSiteName which is 'MediaWiki'
453 $metaNS = $this->getVar( 'wgMetaNamespace' );
454 $this->setVar( 'wgMetaNamespace', wfMsgForContent( 'config-ns-other-default' ) );
457 $this->parent
->getTextBox( array(
458 'var' => 'wgSitename',
459 'label' => 'config-site-name',
461 $this->parent
->getHelpBox( 'config-site-name-help' ) .
462 $this->parent
->getRadioSet( array(
463 'var' => '_NamespaceType',
464 'label' => 'config-project-namespace',
465 'itemLabelPrefix' => 'config-ns-',
466 'values' => array( 'site-name', 'generic', 'other' ),
467 'commonAttribs' => array( 'class' => 'enableForOther', 'rel' => 'config_wgMetaNamespace' ),
469 $this->parent
->getTextBox( array(
470 'var' => 'wgMetaNamespace',
472 'attribs' => array( 'disabled' => '' ),
474 $this->parent
->getHelpBox( 'config-project-namespace-help' ) .
475 $this->getFieldSetStart( 'config-admin-box' ) .
476 $this->parent
->getTextBox( array(
477 'var' => '_AdminName',
478 'label' => 'config-admin-name'
480 $this->parent
->getPasswordBox( array(
481 'var' => '_AdminPassword',
482 'label' => 'config-admin-password',
484 $this->parent
->getPasswordBox( array(
485 'var' => '_AdminPassword2',
486 'label' => 'config-admin-password-confirm'
488 $this->parent
->getHelpBox( 'config-admin-help' ) .
489 $this->parent
->getTextBox( array(
490 'var' => '_AdminEmail',
491 'label' => 'config-admin-email'
493 $this->parent
->getHelpBox( 'config-admin-email-help' ) .
494 $this->parent
->getCheckBox( array(
495 'var' => '_Subscribe',
496 'label' => 'config-subscribe'
498 $this->parent
->getHelpBox( 'config-subscribe-help' ) .
499 $this->getFieldSetEnd() .
500 $this->parent
->getInfoBox( wfMsg( 'config-almost-done' ) ) .
501 $this->parent
->getRadioSet( array(
502 'var' => '_SkipOptional',
503 'itemLabelPrefix' => 'config-optional-',
504 'values' => array( 'continue', 'skip' )
508 // Restore the default value
509 $this->setVar( 'wgMetaNamespace', $metaNS );
515 public function submit() {
517 $this->parent
->setVarsFromRequest( array( 'wgSitename', '_NamespaceType',
518 '_AdminName', '_AdminPassword', '_AdminPassword2', '_AdminEmail',
519 '_Subscribe', '_SkipOptional' ) );
521 // Validate site name
522 if ( strval( $this->getVar( 'wgSitename' ) ) === '' ) {
523 $this->parent
->showError( 'config-site-name-blank' );
528 $nsType = $this->getVar( '_NamespaceType' );
529 if ( $nsType == 'site-name' ) {
530 $name = $this->getVar( 'wgSitename' );
531 // Sanitize for namespace
532 // This algorithm should match the JS one in WebInstallerOutput.php
533 $name = preg_replace( '/[\[\]\{\}|#<>%+? ]/', '_', $name );
534 $name = str_replace( '&', '&', $name );
535 $name = preg_replace( '/__+/', '_', $name );
536 $name = ucfirst( trim( $name, '_' ) );
537 } elseif ( $nsType == 'generic' ) {
538 $name = wfMsg( 'config-ns-generic' );
540 $name = $this->getVar( 'wgMetaNamespace' );
543 // Validate namespace
544 if ( strpos( $name, ':' ) !== false ) {
547 // Title-style validation
548 $title = Title
::newFromText( $name );
550 $good = $nsType == 'site-name';
552 $name = $title->getDBkey();
557 $this->parent
->showError( 'config-ns-invalid', $name );
560 $this->setVar( 'wgMetaNamespace', $name );
562 // Validate username for creation
563 $name = $this->getVar( '_AdminName' );
564 if ( strval( $name ) === '' ) {
565 $this->parent
->showError( 'config-admin-name-blank' );
569 $cname = User
::getCanonicalName( $name, 'creatable' );
570 if ( $cname === false ) {
571 $this->parent
->showError( 'config-admin-name-invalid', $name );
574 $this->setVar( '_AdminName', $cname );
580 $pwd = $this->getVar( '_AdminPassword' );
581 $user = User
::newFromName( $cname );
582 $valid = $user->getPasswordValidity( $pwd );
583 if ( strval( $pwd ) === '' ) {
584 # $user->getPasswordValidity just checks for $wgMinimalPasswordLength.
585 # This message is more specific and helpful.
586 $msg = 'config-admin-password-blank';
587 } elseif ( $pwd !== $this->getVar( '_AdminPassword2' ) ) {
588 $msg = 'config-admin-password-mismatch';
589 } elseif ( $valid !== true ) {
590 # As of writing this will only catch the username being e.g. 'FOO' and
594 if ( $msg !== false ) {
595 $this->parent
->showError( $msg );
596 $this->setVar( '_AdminPassword', '' );
597 $this->setVar( '_AdminPassword2', '' );
605 class WebInstaller_Options
extends WebInstallerPage
{
607 public function execute() {
608 if ( $this->getVar( '_SkipOptional' ) == 'skip' ) {
611 if ( $this->parent
->request
->wasPosted() ) {
612 if ( $this->submit() ) {
620 $this->parent
->getRadioSet( array(
621 'var' => '_RightsProfile',
622 'label' => 'config-profile',
623 'itemLabelPrefix' => 'config-profile-',
624 'values' => array_keys( $this->parent
->rightsProfiles
),
626 $this->parent
->getHelpBox( 'config-profile-help' ) .
629 $this->parent
->getRadioSet( array(
630 'var' => '_LicenseCode',
631 'label' => 'config-license',
632 'itemLabelPrefix' => 'config-license-',
633 'values' => array_keys( $this->parent
->licenses
),
634 'commonAttribs' => array( 'class' => 'licenseRadio' ),
636 $this->getCCChooser() .
637 $this->parent
->getHelpBox( 'config-license-help' ) .
640 $this->getFieldSetStart( 'config-email-settings' ) .
641 $this->parent
->getCheckBox( array(
642 'var' => 'wgEnableEmail',
643 'label' => 'config-enable-email',
644 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'emailwrapper' ),
646 $this->parent
->getHelpBox( 'config-enable-email-help' ) .
647 "<div id=\"emailwrapper\">" .
648 $this->parent
->getTextBox( array(
649 'var' => 'wgPasswordSender',
650 'label' => 'config-email-sender'
652 $this->parent
->getHelpBox( 'config-email-sender-help' ) .
653 $this->parent
->getCheckBox( array(
654 'var' => 'wgEnableUserEmail',
655 'label' => 'config-email-user',
657 $this->parent
->getHelpBox( 'config-email-user-help' ) .
658 $this->parent
->getCheckBox( array(
659 'var' => 'wgEnotifUserTalk',
660 'label' => 'config-email-usertalk',
662 $this->parent
->getHelpBox( 'config-email-usertalk-help' ) .
663 $this->parent
->getCheckBox( array(
664 'var' => 'wgEnotifWatchlist',
665 'label' => 'config-email-watchlist',
667 $this->parent
->getHelpBox( 'config-email-watchlist-help' ) .
668 $this->parent
->getCheckBox( array(
669 'var' => 'wgEmailAuthentication',
670 'label' => 'config-email-auth',
672 $this->parent
->getHelpBox( 'config-email-auth-help' ) .
674 $this->getFieldSetEnd()
677 $extensions = $this->parent
->findExtensions();
680 $extHtml = $this->getFieldSetStart( 'config-extensions' );
682 foreach( $extensions as $ext ) {
683 $extHtml .= $this->parent
->getCheckBox( array(
689 $extHtml .= $this->parent
->getHelpBox( 'config-extensions-help' ) .
690 $this->getFieldSetEnd();
691 $this->addHTML( $extHtml );
696 $this->getFieldSetStart( 'config-upload-settings' ) .
697 $this->parent
->getCheckBox( array(
698 'var' => 'wgEnableUploads',
699 'label' => 'config-upload-enable',
700 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'uploadwrapper' ),
702 $this->parent
->getHelpBox( 'config-upload-help' ) .
703 '<div id="uploadwrapper" style="display: none;">' .
704 $this->parent
->getTextBox( array(
705 'var' => 'wgDeletedDirectory',
706 'label' => 'config-upload-deleted',
708 $this->parent
->getHelpBox( 'config-upload-deleted-help' ) .
710 $this->parent
->getTextBox( array(
712 'label' => 'config-logo'
714 $this->parent
->getHelpBox( 'config-logo-help' )
716 $canUse = $this->getVar( '_ExternalHTTP' ) ?
717 'config-instantcommons-good' : 'config-instantcommons-bad';
719 $this->parent
->getCheckBox( array(
720 'var' => 'wgUseInstantCommons',
721 'label' => 'config-instantcommons',
723 $this->parent
->getHelpBox( 'config-instantcommons-help', wfMsgNoTrans( $canUse ) ) .
724 $this->getFieldSetEnd()
727 $caches = array( 'none' );
728 if( count( $this->getVar( '_Caches' ) ) ) {
731 $caches[] = 'memcached';
735 $this->getFieldSetStart( 'config-advanced-settings' ) .
736 # Object cache settings
737 $this->parent
->getRadioSet( array(
738 'var' => 'wgMainCacheType',
739 'label' => 'config-cache-options',
740 'itemLabelPrefix' => 'config-cache-',
744 $this->parent
->getHelpBox( 'config-cache-help' ) .
745 '<div id="config-memcachewrapper">' .
746 $this->parent
->getTextBox( array(
747 'var' => '_MemCachedServers',
748 'label' => 'config-memcached-servers',
750 $this->parent
->getHelpBox( 'config-memcached-help' ) . '</div>' .
751 $this->getFieldSetEnd()
756 public function getCCPartnerUrl() {
758 $exitUrl = $wgServer . $this->parent
->getUrl( array(
760 'SubmitCC' => 'indeed',
761 'config__LicenseCode' => 'cc',
762 'config_wgRightsUrl' => '[license_url]',
763 'config_wgRightsText' => '[license_name]',
764 'config_wgRightsIcon' => '[license_button]',
766 $styleUrl = $wgServer . dirname( dirname( $this->parent
->getUrl() ) ) .
767 '/skins/common/config-cc.css';
768 $iframeUrl = 'http://creativecommons.org/license/?' .
770 'partner' => 'MediaWiki',
771 'exit_url' => $exitUrl,
772 'lang' => $this->getVar( '_UserLang' ),
773 'stylesheet' => $styleUrl,
778 public function getCCChooser() {
779 $iframeAttribs = array(
780 'class' => 'config-cc-iframe',
781 'name' => 'config-cc-iframe',
782 'id' => 'config-cc-iframe',
787 if ( $this->getVar( '_CCDone' ) ) {
788 $iframeAttribs['src'] = $this->parent
->getUrl( array( 'ShowCC' => 'yes' ) );
790 $iframeAttribs['src'] = $this->getCCPartnerUrl();
794 "<div class=\"config-cc-wrapper\" id=\"config-cc-wrapper\" style=\"display: none;\">\n" .
795 Xml
::element( 'iframe', $iframeAttribs, '', false /* not short */ ) .
799 public function getCCDoneBox() {
800 $js = "parent.document.getElementById('config-cc-wrapper').style.height = '$1';";
801 // If you change this height, also change it in config.css
802 $expandJs = str_replace( '$1', '54em', $js );
803 $reduceJs = str_replace( '$1', '70px', $js );
806 Xml
::element( 'img', array( 'src' => $this->getVar( 'wgRightsIcon' ) ) ) .
808 htmlspecialchars( $this->getVar( 'wgRightsText' ) ) .
810 "<p style=\"text-align: center\">" .
813 'href' => $this->getCCPartnerUrl(),
814 'onclick' => $expandJs,
816 wfMsg( 'config-cc-again' )
819 "<script type=\"text/javascript\">\n" .
820 # Reduce the wrapper div height
821 htmlspecialchars( $reduceJs ) .
826 public function submitCC() {
827 $newValues = $this->parent
->setVarsFromRequest(
828 array( 'wgRightsUrl', 'wgRightsText', 'wgRightsIcon' ) );
829 if ( count( $newValues ) != 3 ) {
830 $this->parent
->showError( 'config-cc-error' );
833 $this->setVar( '_CCDone', true );
834 $this->addHTML( $this->getCCDoneBox() );
837 public function submit() {
838 $this->parent
->setVarsFromRequest( array( '_RightsProfile', '_LicenseCode',
839 'wgEnableEmail', 'wgPasswordSender', 'wgEnableUploads', 'wgLogo',
840 'wgEnableUserEmail', 'wgEnotifUserTalk', 'wgEnotifWatchlist',
841 'wgEmailAuthentication', 'wgMainCacheType', '_MemCachedServers',
842 'wgUseInstantCommons' ) );
844 if ( !in_array( $this->getVar( '_RightsProfile' ),
845 array_keys( $this->parent
->rightsProfiles
) ) )
847 reset( $this->parent
->rightsProfiles
);
848 $this->setVar( '_RightsProfile', key( $this->parent
->rightsProfiles
) );
851 $code = $this->getVar( '_LicenseCode' );
852 if ( $code == 'cc-choose' ) {
853 if ( !$this->getVar( '_CCDone' ) ) {
854 $this->parent
->showError( 'config-cc-not-chosen' );
857 } elseif ( in_array( $code, array_keys( $this->parent
->licenses
) ) ) {
858 $entry = $this->parent
->licenses
[$code];
859 if ( isset( $entry['text'] ) ) {
860 $this->setVar( 'wgRightsText', $entry['text'] );
862 $this->setVar( 'wgRightsText', wfMsg( 'config-license-' . $code ) );
864 $this->setVar( 'wgRightsUrl', $entry['url'] );
865 $this->setVar( 'wgRightsIcon', $entry['icon'] );
867 $this->setVar( 'wgRightsText', '' );
868 $this->setVar( 'wgRightsUrl', '' );
869 $this->setVar( 'wgRightsIcon', '' );
872 $extsAvailable = $this->parent
->findExtensions();
873 $extsToInstall = array();
874 foreach( $extsAvailable as $ext ) {
875 if( $this->parent
->request
->getCheck( 'config_ext-' . $ext ) ) {
876 $extsToInstall[] = $ext;
879 $this->parent
->setVar( '_Extensions', $extsToInstall );
885 class WebInstaller_Install
extends WebInstallerPage
{
887 public function execute() {
888 if( $this->parent
->request
->wasPosted() ) {
890 } elseif( $this->getVar( '_InstallDone' ) ) {
892 $status = new Status();
893 $status->warning( 'config-install-alreadydone' );
894 $this->parent
->showStatusBox( $status );
895 } elseif( $this->getVar( '_UpgradeDone' ) ) {
899 $this->addHTML("<ul>");
900 $this->parent
->performInstallation(
901 array( $this, 'startStage'),
902 array( $this, 'endStage' )
904 $this->addHTML("</ul>");
910 public function startStage( $step ) {
911 $this->addHTML( "<li>" . wfMsgHtml( "config-install-$step" ) . wfMsg( 'ellipsis') );
914 public function endStage( $step, $status ) {
915 $msg = $status->isOk() ?
'config-install-step-done' : 'config-install-step-failed';
916 $html = wfMsgHtml( 'word-separator' ) . wfMsgHtml( $msg );
917 if ( !$status->isOk() ) {
918 $html = "<span class=\"error\">$html</span>";
920 $this->addHTML( $html . "</li>\n" );
921 if( !$status->isGood() ) {
922 $this->parent
->showStatusBox( $status );
928 class WebInstaller_Complete
extends WebInstallerPage
{
930 public function execute() {
933 $this->parent
->getInfoBox(
934 wfMsgNoTrans( 'config-install-done',
935 $GLOBALS['wgServer'] . $this->parent
->getURL( array( 'localsettings' => 1 ) ),
936 $GLOBALS['wgServer'] .
937 $this->getVar( 'wgScriptPath' ) . '/index' .
938 $this->getVar( 'wgScriptExtension' )
942 $this->endForm( false );
946 class WebInstaller_Restart
extends WebInstallerPage
{
948 public function execute() {
949 $r = $this->parent
->request
;
950 if ( $r->wasPosted() ) {
951 $really = $r->getVal( 'submit-restart' );
953 $this->parent
->session
= array();
954 $this->parent
->happyPages
= array();
955 $this->parent
->settings
= array();
961 $s = $this->parent
->getWarningBox( wfMsgNoTrans( 'config-help-restart' ) );
962 $this->addHTML( $s );
963 $this->endForm( 'restart' );
968 abstract class WebInstaller_Document
extends WebInstallerPage
{
970 protected abstract function getFileName();
972 public function execute() {
973 $text = $this->getFileContents();
974 $this->parent
->output
->addWikiText( $text );
976 $this->endForm( false );
979 public function getFileContents() {
980 return file_get_contents( dirname( __FILE__
) . '/../../' . $this->getFileName() );
983 protected function formatTextFile( $text ) {
984 $text = str_replace( array( '<', '{{', '[[' ),
985 array( '<', '{{', '[[' ), $text );
986 // replace numbering with [1], [2], etc with MW-style numbering
987 $text = preg_replace( "/\r?\n(\r?\n)?\\[\\d+\\]/m", "\\1#", $text );
988 // join word-wrapped lines into one
991 $text = preg_replace( "/\n([\\*#])([^\r\n]*?)\r?\n([^\r\n#\\*:]+)/", "\n\\1\\2 \\3", $text );
992 } while ( $text != $prev );
993 // turn (bug nnnn) into links
994 $text = preg_replace_callback('/bug (\d+)/', array( $this, 'replaceBugLinks' ), $text );
995 // add links to manual to every global variable mentioned
996 $text = preg_replace_callback('/(\$wg[a-z0-9_]+)/i', array( $this, 'replaceConfigLinks' ), $text );
997 // special case for <pre> - formatted links
1000 $text = preg_replace( '/^([^\\s].*?)\r?\n[\\s]+(https?:\/\/)/m', "\\1\n:\\2", $text );
1001 } while ( $text != $prev );
1005 private function replaceBugLinks( $matches ) {
1006 return '<span class="config-plainlink">[https://bugzilla.wikimedia.org/' .
1007 $matches[1] . ' bug ' . $matches[1] . ']</span>';
1010 private function replaceConfigLinks( $matches ) {
1011 return '<span class="config-plainlink">[http://www.mediawiki.org/wiki/Manual:' .
1012 $matches[1] . ' ' . $matches[1] . ']</span>';
1017 class WebInstaller_Readme
extends WebInstaller_Document
{
1019 protected function getFileName() { return 'README'; }
1021 public function getFileContents() {
1022 return $this->formatTextFile( parent
::getFileContents() );
1027 class WebInstaller_ReleaseNotes
extends WebInstaller_Document
{
1029 protected function getFileName() { return 'RELEASE-NOTES'; }
1031 public function getFileContents() {
1032 return $this->formatTextFile( parent
::getFileContents() );
1037 class WebInstaller_UpgradeDoc
extends WebInstaller_Document
{
1039 protected function getFileName() { return 'UPGRADE'; }
1041 public function getFileContents() {
1042 return $this->formatTextFile( parent
::getFileContents() );
1047 class WebInstaller_Copying
extends WebInstaller_Document
{
1049 protected function getFileName() { return 'COPYING'; }
1051 public function getFileContents() {
1052 $text = parent
::getFileContents();
1053 $text = str_replace( "\x0C", '', $text );
1054 $text = preg_replace_callback( '/\n[ \t]+/m', array( 'WebInstaller_Copying', 'replaceLeadingSpaces' ), $text );
1055 $text = '<tt>' . nl2br( $text ) . '</tt>';
1059 private static function replaceLeadingSpaces( $matches ) {
1060 return "\n" . str_repeat( ' ', strlen( $matches[0] ) );