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 $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
62 $s .= Xml
::submitButton( wfMsg( "config-$continue" ),
63 array( 'name' => "enter-$continue", 'style' => 'display:none' ) ) . "\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_Locked
extends WebInstallerPage
{
120 // The status of Installer::getLocalSettingsStatus()
123 public function setLocalSettingsStatus( Status
$s ) {
127 protected function getId() {
131 public function execute() {
132 $r = $this->parent
->request
;
133 if( !$r->wasPosted() ||
!$this->status
->isOK() ) {
137 $key = $r->getText( 'config_wpUpgradeKey' );
138 if( !$key ||
$key !== $this->getVar( '_UpgradeKey' ) ) {
139 $this->parent
->showError( 'config-localsettings-badkey' );
143 $this->setVar( '_LocalSettingsLocked', false );
150 * Display stuff to the end user
152 private function display() {
154 $this->parent
->showStatusBox( $this->status
);
156 if( $this->status
->isOK() && !$this->status
->isGood() ) {
157 $this->addHTML( "<br />" .
158 $this->parent
->getTextBox( array(
159 'var' => 'wpUpgradeKey',
160 'label' => 'config-localsettings-key',
163 $continue = 'continue';
165 $this->endForm( $continue );
169 class WebInstaller_Language
extends WebInstallerPage
{
171 public function execute() {
173 $r = $this->parent
->request
;
174 $userLang = $r->getVal( 'UserLang' );
175 $contLang = $r->getVal( 'ContLang' );
177 $lifetime = intval( ini_get( 'session.gc_maxlifetime' ) );
179 $lifetime = 1440; // PHP default
182 if ( $r->wasPosted() ) {
184 if ( $this->parent
->getSession( 'test' ) === null ) {
185 $requestTime = $r->getVal( 'LanguageRequestTime' );
186 if ( !$requestTime ) {
187 // The most likely explanation is that the user was knocked back
188 // from another page on POST due to session expiry
189 $msg = 'config-session-expired';
190 } elseif ( time() - $requestTime > $lifetime ) {
191 $msg = 'config-session-expired';
193 $msg = 'config-no-session';
195 $this->parent
->showError( $msg, $wgLang->formatTimePeriod( $lifetime ) );
197 $languages = Language
::getLanguageNames();
198 if ( isset( $languages[$userLang] ) ) {
199 $this->setVar( '_UserLang', $userLang );
201 if ( isset( $languages[$contLang] ) ) {
202 $this->setVar( 'wgLanguageCode', $contLang );
204 $this->setVar( '_ExternalHTTP', $r->getBool( 'config__ExternalHTTP' ) );
207 } elseif ( $this->parent
->showSessionWarning
) {
208 # The user was knocked back from another page to the start
209 # This probably indicates a session expiry
210 $this->parent
->showError( 'config-session-expired', $wgLang->formatTimePeriod( $lifetime ) );
213 $this->parent
->setSession( 'test', true );
215 if ( !isset( $languages[$userLang] ) ) {
216 $userLang = $this->getVar( '_UserLang', 'en' );
218 if ( !isset( $languages[$contLang] ) ) {
219 $contLang = $this->getVar( 'wgLanguageCode', 'en' );
222 $s = Html
::hidden( 'LanguageRequestTime', time() ) .
223 $this->getLanguageSelector( 'UserLang', 'config-your-language', $userLang, $this->parent
->getHelpBox( 'config-your-language-help' ) ) .
224 $this->getLanguageSelector( 'ContLang', 'config-wiki-language', $contLang, $this->parent
->getHelpBox( 'config-wiki-language-help' ) ) .
225 $this->parent
->getCheckBox(
227 'var' => '_ExternalHTTP',
228 'label' => 'config-allow-requests',
229 'help' => $this->parent
->getHelpBox( 'config-allow-requests-help' )
233 $this->addHTML( $s );
238 * Get a <select> for selecting languages.
240 public function getLanguageSelector( $name, $label, $selectedCode ) {
241 global $wgDummyLanguageCodes;
242 $s = Html
::openElement( 'select', array( 'id' => $name, 'name' => $name ) ) . "\n";
244 $languages = Language
::getLanguageNames();
246 $dummies = array_flip( $wgDummyLanguageCodes );
247 foreach ( $languages as $code => $lang ) {
248 if ( isset( $dummies[$code] ) ) continue;
249 $s .= "\n" . Xml
::option( "$code - $lang", $code, $code == $selectedCode );
251 $s .= "\n</select>\n";
252 return $this->parent
->label( $label, $name, $s );
257 class WebInstaller_Welcome
extends WebInstallerPage
{
259 public function execute() {
260 if ( $this->parent
->request
->wasPosted() ) {
261 if ( $this->getVar( '_Environment' ) ) {
265 $this->parent
->output
->addWikiText( wfMsgNoTrans( 'config-welcome' ) );
266 $status = $this->parent
->doEnvironmentChecks();
268 $this->parent
->output
->addWikiText( wfMsgNoTrans( 'config-copyright',
269 SpecialVersion
::getCopyrightAndAuthorList() ) );
277 class WebInstaller_DBConnect
extends WebInstallerPage
{
279 public function execute() {
280 $r = $this->parent
->request
;
281 if ( $r->wasPosted() ) {
282 $status = $this->submit();
283 if ( $status->isGood() ) {
284 $this->setVar( '_UpgradeDone', false );
287 $this->parent
->showStatusBox( $status );
293 $types = "<ul class=\"config-settings-block\">\n";
295 $defaultType = $this->getVar( 'wgDBtype' );
298 foreach( $this->parent
->getDBTypes() as $type ) {
299 $db = 'Database' . ucfirst( $type );
300 $dbSupport .= wfMsgNoTrans( "config-support-$type",
301 call_user_func( array( $db, 'getSoftwareLink' ) ) ) . "\n";
303 $this->addHTML( $this->parent
->getInfoBox(
304 wfMsg( 'config-support-info', $dbSupport ) ) );
306 foreach ( $this->parent
->getVar( '_CompiledDBs' ) as $type ) {
307 $installer = $this->parent
->getDBInstaller( $type );
311 $installer->getReadableName(),
315 $type == $defaultType,
316 array( 'class' => 'dbRadio', 'rel' => "DB_wrapper_$type" )
321 Html
::openElement( 'div', array( 'id' => 'DB_wrapper_' . $type, 'class' => 'dbWrapper' ) ) .
322 Html
::element( 'h3', array(), wfMsg( 'config-header-' . $type ) ) .
323 $installer->getConnectForm() .
326 $types .= "</ul><br clear=\"left\"/>\n";
329 $this->parent
->label( 'config-db-type', false, $types ) .
336 public function submit() {
337 $r = $this->parent
->request
;
338 $type = $r->getVal( 'DBType' );
339 $this->setVar( 'wgDBtype', $type );
340 $installer = $this->parent
->getDBInstaller( $type );
342 return Status
::newFatal( 'config-invalid-db-type' );
344 return $installer->submitConnectForm();
349 class WebInstaller_Upgrade
extends WebInstallerPage
{
351 public function execute() {
352 if ( $this->getVar( '_UpgradeDone' ) ) {
353 if ( $this->parent
->request
->wasPosted() ) {
354 // Done message acknowledged
358 // Show the done message again
359 // Make them click back again if they want to do the upgrade again
360 $this->showDoneMessage();
365 // wgDBtype is generally valid here because otherwise the previous page
366 // (connect) wouldn't have declared its happiness
367 $type = $this->getVar( 'wgDBtype' );
368 $installer = $this->parent
->getDBInstaller( $type );
370 if ( !$installer->needsUpgrade() ) {
374 if ( $this->parent
->request
->wasPosted() ) {
375 $installer->preUpgrade();
377 '<div id="config-spinner" style="display:none;"><img src="../skins/common/images/ajax-loader.gif" /></div>' .
378 '<script>jQuery( "#config-spinner" )[0].style.display = "block";</script>' .
379 '<textarea id="config-update-log" name="UpdateLog" rows="10" readonly="readonly">'
381 $this->parent
->output
->flush();
382 $result = $installer->doUpgrade();
383 $this->addHTML( '</textarea>
384 <script>jQuery( "#config-spinner" )[0].style.display = "none";</script>' );
385 $this->parent
->output
->flush();
387 $this->setVar( '_UpgradeDone', true );
388 $this->showDoneMessage();
394 $this->addHTML( $this->parent
->getInfoBox(
395 wfMsgNoTrans( 'config-can-upgrade', $GLOBALS['wgVersion'] ) ) );
399 public function showDoneMessage() {
402 $this->parent
->getInfoBox(
403 wfMsgNoTrans( 'config-upgrade-done',
404 $GLOBALS['wgServer'] .
405 $this->getVar( 'wgScriptPath' ) . '/index' .
406 $this->getVar( 'wgScriptExtension' )
410 $this->endForm( 'regenerate' );
415 class WebInstaller_DBSettings
extends WebInstallerPage
{
417 public function execute() {
418 $installer = $this->parent
->getDBInstaller( $this->getVar( 'wgDBtype' ) );
420 $r = $this->parent
->request
;
421 if ( $r->wasPosted() ) {
422 $status = $installer->submitSettingsForm();
423 if ( $status === false ) {
425 } elseif ( $status->isGood() ) {
428 $this->parent
->showStatusBox( $status );
432 $form = $installer->getSettingsForm();
433 if ( $form === false ) {
438 $this->addHTML( $form );
444 class WebInstaller_Name
extends WebInstallerPage
{
446 public function execute() {
447 $r = $this->parent
->request
;
448 if ( $r->wasPosted() ) {
449 if ( $this->submit() ) {
456 if ( $this->getVar( 'wgSitename' ) == $GLOBALS['wgSitename'] ) {
457 $this->setVar( 'wgSitename', '' );
460 // Set wgMetaNamespace to something valid before we show the form.
461 // $wgMetaNamespace defaults to $wgSiteName which is 'MediaWiki'
462 $metaNS = $this->getVar( 'wgMetaNamespace' );
463 $this->setVar( 'wgMetaNamespace', wfMsgForContent( 'config-ns-other-default' ) );
466 $this->parent
->getTextBox( array(
467 'var' => 'wgSitename',
468 'label' => 'config-site-name',
469 'help' => $this->parent
->getHelpBox( 'config-site-name-help' )
471 $this->parent
->getRadioSet( array(
472 'var' => '_NamespaceType',
473 'label' => 'config-project-namespace',
474 'itemLabelPrefix' => 'config-ns-',
475 'values' => array( 'site-name', 'generic', 'other' ),
476 'commonAttribs' => array( 'class' => 'enableForOther', 'rel' => 'config_wgMetaNamespace' ),
477 'help' => $this->parent
->getHelpBox( 'config-project-namespace-help' )
479 $this->parent
->getTextBox( array(
480 'var' => 'wgMetaNamespace',
482 'attribs' => array( 'disabled' => '' ),
485 $this->getFieldSetStart( 'config-admin-box' ) .
486 $this->parent
->getTextBox( array(
487 'var' => '_AdminName',
488 'label' => 'config-admin-name',
489 'help' => $this->parent
->getHelpBox( 'config-admin-help' )
491 $this->parent
->getPasswordBox( array(
492 'var' => '_AdminPassword',
493 'label' => 'config-admin-password',
495 $this->parent
->getPasswordBox( array(
496 'var' => '_AdminPassword2',
497 'label' => 'config-admin-password-confirm'
499 $this->parent
->getTextBox( array(
500 'var' => '_AdminEmail',
501 'label' => 'config-admin-email',
502 'help' => $this->parent
->getHelpBox( 'config-admin-email-help' )
504 $this->parent
->getCheckBox( array(
505 'var' => '_Subscribe',
506 'label' => 'config-subscribe',
507 'help' => $this->parent
->getHelpBox( 'config-subscribe-help' )
509 $this->getFieldSetEnd() .
510 $this->parent
->getInfoBox( wfMsg( 'config-almost-done' ) ) .
511 $this->parent
->getRadioSet( array(
512 'var' => '_SkipOptional',
513 'itemLabelPrefix' => 'config-optional-',
514 'values' => array( 'continue', 'skip' )
518 // Restore the default value
519 $this->setVar( 'wgMetaNamespace', $metaNS );
525 public function submit() {
527 $this->parent
->setVarsFromRequest( array( 'wgSitename', '_NamespaceType',
528 '_AdminName', '_AdminPassword', '_AdminPassword2', '_AdminEmail',
529 '_Subscribe', '_SkipOptional' ) );
531 // Validate site name
532 if ( strval( $this->getVar( 'wgSitename' ) ) === '' ) {
533 $this->parent
->showError( 'config-site-name-blank' );
538 $nsType = $this->getVar( '_NamespaceType' );
539 if ( $nsType == 'site-name' ) {
540 $name = $this->getVar( 'wgSitename' );
541 // Sanitize for namespace
542 // This algorithm should match the JS one in WebInstallerOutput.php
543 $name = preg_replace( '/[\[\]\{\}|#<>%+? ]/', '_', $name );
544 $name = str_replace( '&', '&', $name );
545 $name = preg_replace( '/__+/', '_', $name );
546 $name = ucfirst( trim( $name, '_' ) );
547 } elseif ( $nsType == 'generic' ) {
548 $name = wfMsg( 'config-ns-generic' );
550 $name = $this->getVar( 'wgMetaNamespace' );
553 // Validate namespace
554 if ( strpos( $name, ':' ) !== false ) {
557 // Title-style validation
558 $title = Title
::newFromText( $name );
560 $good = $nsType == 'site-name';
562 $name = $title->getDBkey();
567 $this->parent
->showError( 'config-ns-invalid', $name );
570 $this->setVar( 'wgMetaNamespace', $name );
572 // Validate username for creation
573 $name = $this->getVar( '_AdminName' );
574 if ( strval( $name ) === '' ) {
575 $this->parent
->showError( 'config-admin-name-blank' );
579 $cname = User
::getCanonicalName( $name, 'creatable' );
580 if ( $cname === false ) {
581 $this->parent
->showError( 'config-admin-name-invalid', $name );
584 $this->setVar( '_AdminName', $cname );
591 $pwd = $this->getVar( '_AdminPassword' );
592 $user = User
::newFromName( $cname );
593 if ( ( isset ( $pwd ) ) && ( $user != null ) ) {
594 $valid = $user->getPasswordValidity( $pwd );
596 if ( strval( $pwd ) === '' ) {
597 # $user->getPasswordValidity just checks for $wgMinimalPasswordLength.
598 # This message is more specific and helpful.
599 $msg = 'config-admin-password-blank';
600 } elseif ( $pwd !== $this->getVar( '_AdminPassword2' ) ) {
601 $msg = 'config-admin-password-mismatch';
602 } elseif ( $valid !== true ) {
603 # As of writing this will only catch the username being e.g. 'FOO' and
607 if ( $msg !== false ) {
608 $this->parent
->showError( $msg );
609 $this->setVar( '_AdminPassword', '' );
610 $this->setVar( '_AdminPassword2', '' );
618 class WebInstaller_Options
extends WebInstallerPage
{
620 public function execute() {
621 if ( $this->getVar( '_SkipOptional' ) == 'skip' ) {
624 if ( $this->parent
->request
->wasPosted() ) {
625 if ( $this->submit() ) {
633 $this->parent
->getRadioSet( array(
634 'var' => '_RightsProfile',
635 'label' => 'config-profile',
636 'itemLabelPrefix' => 'config-profile-',
637 'values' => array_keys( $this->parent
->rightsProfiles
),
639 $this->parent
->getHelpBox( 'config-profile-help' ) .
642 $this->parent
->getRadioSet( array(
643 'var' => '_LicenseCode',
644 'label' => 'config-license',
645 'itemLabelPrefix' => 'config-license-',
646 'values' => array_keys( $this->parent
->licenses
),
647 'commonAttribs' => array( 'class' => 'licenseRadio' ),
649 $this->getCCChooser() .
650 $this->parent
->getHelpBox( 'config-license-help' ) .
653 $this->getFieldSetStart( 'config-email-settings' ) .
654 $this->parent
->getCheckBox( array(
655 'var' => 'wgEnableEmail',
656 'label' => 'config-enable-email',
657 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'emailwrapper' ),
659 $this->parent
->getHelpBox( 'config-enable-email-help' ) .
660 "<div id=\"emailwrapper\">" .
661 $this->parent
->getTextBox( array(
662 'var' => 'wgPasswordSender',
663 'label' => 'config-email-sender'
665 $this->parent
->getHelpBox( 'config-email-sender-help' ) .
666 $this->parent
->getCheckBox( array(
667 'var' => 'wgEnableUserEmail',
668 'label' => 'config-email-user',
670 $this->parent
->getHelpBox( 'config-email-user-help' ) .
671 $this->parent
->getCheckBox( array(
672 'var' => 'wgEnotifUserTalk',
673 'label' => 'config-email-usertalk',
675 $this->parent
->getHelpBox( 'config-email-usertalk-help' ) .
676 $this->parent
->getCheckBox( array(
677 'var' => 'wgEnotifWatchlist',
678 'label' => 'config-email-watchlist',
680 $this->parent
->getHelpBox( 'config-email-watchlist-help' ) .
681 $this->parent
->getCheckBox( array(
682 'var' => 'wgEmailAuthentication',
683 'label' => 'config-email-auth',
685 $this->parent
->getHelpBox( 'config-email-auth-help' ) .
687 $this->getFieldSetEnd()
690 $extensions = $this->parent
->findExtensions();
693 $extHtml = $this->getFieldSetStart( 'config-extensions' );
695 foreach( $extensions as $ext ) {
696 $extHtml .= $this->parent
->getCheckBox( array(
702 $extHtml .= $this->parent
->getHelpBox( 'config-extensions-help' ) .
703 $this->getFieldSetEnd();
704 $this->addHTML( $extHtml );
709 $this->getFieldSetStart( 'config-upload-settings' ) .
710 $this->parent
->getCheckBox( array(
711 'var' => 'wgEnableUploads',
712 'label' => 'config-upload-enable',
713 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'uploadwrapper' ),
714 'help' => $this->parent
->getHelpBox( 'config-upload-help' )
716 '<div id="uploadwrapper" style="display: none;">' .
717 $this->parent
->getTextBox( array(
718 'var' => 'wgDeletedDirectory',
719 'label' => 'config-upload-deleted',
720 'help' => $this->parent
->getHelpBox( 'config-upload-deleted-help' )
723 $this->parent
->getTextBox( array(
725 'label' => 'config-logo',
726 'help' => $this->parent
->getHelpBox( 'config-logo-help' )
729 $canUse = $this->getVar( '_ExternalHTTP' ) ?
730 'config-instantcommons-good' : 'config-instantcommons-bad';
732 $this->parent
->getCheckBox( array(
733 'var' => 'wgUseInstantCommons',
734 'label' => 'config-instantcommons',
735 'help' => $this->parent
->getHelpBox( 'config-instantcommons-help', wfMsgNoTrans( $canUse ) )
737 $this->getFieldSetEnd()
740 $caches = array( 'none' );
741 if( count( $this->getVar( '_Caches' ) ) ) {
744 $caches[] = 'memcached';
748 $this->getFieldSetStart( 'config-advanced-settings' ) .
749 # Object cache settings
750 $this->parent
->getRadioSet( array(
751 'var' => 'wgMainCacheType',
752 'label' => 'config-cache-options',
753 'itemLabelPrefix' => 'config-cache-',
757 $this->parent
->getHelpBox( 'config-cache-help' ) .
758 '<div id="config-memcachewrapper">' .
759 $this->parent
->getTextBox( array(
760 'var' => '_MemCachedServers',
761 'label' => 'config-memcached-servers',
762 'help' => $this->parent
->getHelpBox( 'config-memcached-help' )
765 $this->getFieldSetEnd()
770 public function getCCPartnerUrl() {
772 $exitUrl = $wgServer . $this->parent
->getUrl( array(
774 'SubmitCC' => 'indeed',
775 'config__LicenseCode' => 'cc',
776 'config_wgRightsUrl' => '[license_url]',
777 'config_wgRightsText' => '[license_name]',
778 'config_wgRightsIcon' => '[license_button]',
780 $styleUrl = $wgServer . dirname( dirname( $this->parent
->getUrl() ) ) .
781 '/skins/common/config-cc.css';
782 $iframeUrl = 'http://creativecommons.org/license/?' .
784 'partner' => 'MediaWiki',
785 'exit_url' => $exitUrl,
786 'lang' => $this->getVar( '_UserLang' ),
787 'stylesheet' => $styleUrl,
792 public function getCCChooser() {
793 $iframeAttribs = array(
794 'class' => 'config-cc-iframe',
795 'name' => 'config-cc-iframe',
796 'id' => 'config-cc-iframe',
801 if ( $this->getVar( '_CCDone' ) ) {
802 $iframeAttribs['src'] = $this->parent
->getUrl( array( 'ShowCC' => 'yes' ) );
804 $iframeAttribs['src'] = $this->getCCPartnerUrl();
808 "<div class=\"config-cc-wrapper\" id=\"config-cc-wrapper\" style=\"display: none;\">\n" .
809 Html
::element( 'iframe', $iframeAttribs, '', false /* not short */ ) .
813 public function getCCDoneBox() {
814 $js = "parent.document.getElementById('config-cc-wrapper').style.height = '$1';";
815 // If you change this height, also change it in config.css
816 $expandJs = str_replace( '$1', '54em', $js );
817 $reduceJs = str_replace( '$1', '70px', $js );
820 Html
::element( 'img', array( 'src' => $this->getVar( 'wgRightsIcon' ) ) ) .
822 htmlspecialchars( $this->getVar( 'wgRightsText' ) ) .
824 "<p style=\"text-align: center\">" .
827 'href' => $this->getCCPartnerUrl(),
828 'onclick' => $expandJs,
830 wfMsg( 'config-cc-again' )
833 "<script type=\"text/javascript\">\n" .
834 # Reduce the wrapper div height
835 htmlspecialchars( $reduceJs ) .
840 public function submitCC() {
841 $newValues = $this->parent
->setVarsFromRequest(
842 array( 'wgRightsUrl', 'wgRightsText', 'wgRightsIcon' ) );
843 if ( count( $newValues ) != 3 ) {
844 $this->parent
->showError( 'config-cc-error' );
847 $this->setVar( '_CCDone', true );
848 $this->addHTML( $this->getCCDoneBox() );
851 public function submit() {
852 $this->parent
->setVarsFromRequest( array( '_RightsProfile', '_LicenseCode',
853 'wgEnableEmail', 'wgPasswordSender', 'wgEnableUploads', 'wgLogo',
854 'wgEnableUserEmail', 'wgEnotifUserTalk', 'wgEnotifWatchlist',
855 'wgEmailAuthentication', 'wgMainCacheType', '_MemCachedServers',
856 'wgUseInstantCommons' ) );
858 if ( !in_array( $this->getVar( '_RightsProfile' ),
859 array_keys( $this->parent
->rightsProfiles
) ) )
861 reset( $this->parent
->rightsProfiles
);
862 $this->setVar( '_RightsProfile', key( $this->parent
->rightsProfiles
) );
865 $code = $this->getVar( '_LicenseCode' );
866 if ( $code == 'cc-choose' ) {
867 if ( !$this->getVar( '_CCDone' ) ) {
868 $this->parent
->showError( 'config-cc-not-chosen' );
871 } elseif ( in_array( $code, array_keys( $this->parent
->licenses
) ) ) {
872 $entry = $this->parent
->licenses
[$code];
873 if ( isset( $entry['text'] ) ) {
874 $this->setVar( 'wgRightsText', $entry['text'] );
876 $this->setVar( 'wgRightsText', wfMsg( 'config-license-' . $code ) );
878 $this->setVar( 'wgRightsUrl', $entry['url'] );
879 $this->setVar( 'wgRightsIcon', $entry['icon'] );
881 $this->setVar( 'wgRightsText', '' );
882 $this->setVar( 'wgRightsUrl', '' );
883 $this->setVar( 'wgRightsIcon', '' );
886 $extsAvailable = $this->parent
->findExtensions();
887 $extsToInstall = array();
888 foreach( $extsAvailable as $ext ) {
889 if( $this->parent
->request
->getCheck( 'config_ext-' . $ext ) ) {
890 $extsToInstall[] = $ext;
893 $this->parent
->setVar( '_Extensions', $extsToInstall );
899 class WebInstaller_Install
extends WebInstallerPage
{
901 public function execute() {
902 if( $this->parent
->request
->wasPosted() ) {
904 } elseif( $this->getVar( '_InstallDone' ) ) {
906 $status = new Status();
907 $status->warning( 'config-install-alreadydone' );
908 $this->parent
->showStatusBox( $status );
909 } elseif( $this->getVar( '_UpgradeDone' ) ) {
913 $this->addHTML("<ul>");
914 $this->parent
->performInstallation(
915 array( $this, 'startStage'),
916 array( $this, 'endStage' )
918 $this->addHTML("</ul>");
924 public function startStage( $step ) {
925 $this->addHTML( "<li>" . wfMsgHtml( "config-install-$step" ) . wfMsg( 'ellipsis') );
928 public function endStage( $step, $status ) {
929 $msg = $status->isOk() ?
'config-install-step-done' : 'config-install-step-failed';
930 $html = wfMsgHtml( 'word-separator' ) . wfMsgHtml( $msg );
931 if ( !$status->isOk() ) {
932 $html = "<span class=\"error\">$html</span>";
934 $this->addHTML( $html . "</li>\n" );
935 if( !$status->isGood() ) {
936 $this->parent
->showStatusBox( $status );
942 class WebInstaller_Complete
extends WebInstallerPage
{
944 public function execute() {
947 $this->parent
->getInfoBox(
948 wfMsgNoTrans( 'config-install-done',
949 $GLOBALS['wgServer'] . $this->parent
->getURL( array( 'localsettings' => 1 ) ),
950 $GLOBALS['wgServer'] .
951 $this->getVar( 'wgScriptPath' ) . '/index' .
952 $this->getVar( 'wgScriptExtension' )
956 $this->endForm( false );
960 class WebInstaller_Restart
extends WebInstallerPage
{
962 public function execute() {
963 $r = $this->parent
->request
;
964 if ( $r->wasPosted() ) {
965 $really = $r->getVal( 'submit-restart' );
967 $this->parent
->session
= array();
968 $this->parent
->happyPages
= array();
969 $this->parent
->settings
= array();
975 $s = $this->parent
->getWarningBox( wfMsgNoTrans( 'config-help-restart' ) );
976 $this->addHTML( $s );
977 $this->endForm( 'restart' );
982 abstract class WebInstaller_Document
extends WebInstallerPage
{
984 protected abstract function getFileName();
986 public function execute() {
987 $text = $this->getFileContents();
988 $this->parent
->output
->addWikiText( $text );
990 $this->endForm( false );
993 public function getFileContents() {
994 return file_get_contents( dirname( __FILE__
) . '/../../' . $this->getFileName() );
997 protected function formatTextFile( $text ) {
998 $text = str_replace( array( '<', '{{', '[[' ),
999 array( '<', '{{', '[[' ), $text );
1000 // replace numbering with [1], [2], etc with MW-style numbering
1001 $text = preg_replace( "/\r?\n(\r?\n)?\\[\\d+\\]/m", "\\1#", $text );
1002 // join word-wrapped lines into one
1005 $text = preg_replace( "/\n([\\*#])([^\r\n]*?)\r?\n([^\r\n#\\*:]+)/", "\n\\1\\2 \\3", $text );
1006 } while ( $text != $prev );
1007 // turn (bug nnnn) into links
1008 $text = preg_replace_callback('/bug (\d+)/', array( $this, 'replaceBugLinks' ), $text );
1009 // add links to manual to every global variable mentioned
1010 $text = preg_replace_callback('/(\$wg[a-z0-9_]+)/i', array( $this, 'replaceConfigLinks' ), $text );
1011 // special case for <pre> - formatted links
1014 $text = preg_replace( '/^([^\\s].*?)\r?\n[\\s]+(https?:\/\/)/m', "\\1\n:\\2", $text );
1015 } while ( $text != $prev );
1019 private function replaceBugLinks( $matches ) {
1020 return '<span class="config-plainlink">[https://bugzilla.wikimedia.org/' .
1021 $matches[1] . ' bug ' . $matches[1] . ']</span>';
1024 private function replaceConfigLinks( $matches ) {
1025 return '<span class="config-plainlink">[http://www.mediawiki.org/wiki/Manual:' .
1026 $matches[1] . ' ' . $matches[1] . ']</span>';
1031 class WebInstaller_Readme
extends WebInstaller_Document
{
1033 protected function getFileName() { return 'README'; }
1035 public function getFileContents() {
1036 return $this->formatTextFile( parent
::getFileContents() );
1041 class WebInstaller_ReleaseNotes
extends WebInstaller_Document
{
1043 protected function getFileName() { return 'RELEASE-NOTES'; }
1045 public function getFileContents() {
1046 return $this->formatTextFile( parent
::getFileContents() );
1051 class WebInstaller_UpgradeDoc
extends WebInstaller_Document
{
1053 protected function getFileName() { return 'UPGRADE'; }
1055 public function getFileContents() {
1056 return $this->formatTextFile( parent
::getFileContents() );
1061 class WebInstaller_Copying
extends WebInstaller_Document
{
1063 protected function getFileName() { return 'COPYING'; }
1065 public function getFileContents() {
1066 $text = parent
::getFileContents();
1067 $text = str_replace( "\x0C", '', $text );
1068 $text = preg_replace_callback( '/\n[ \t]+/m', array( 'WebInstaller_Copying', 'replaceLeadingSpaces' ), $text );
1069 $text = '<tt>' . nl2br( $text ) . '</tt>';
1073 private static function replaceLeadingSpaces( $matches ) {
1074 return "\n" . str_repeat( ' ', strlen( $matches[0] ) );