Skip install entirely if we did an upgrade
[mediawiki.git] / includes / installer / WebInstallerPage.php
blob9d93f9511ba62ff539927fd534699ff12981c9c4
1 <?php
2 /**
3 * Base code for web installer pages.
5 * @file
6 * @ingroup Deployment
7 */
9 /**
10 * Abstract class to define pages for the web installer.
12 * @ingroup Deployment
13 * @since 1.17
15 abstract class WebInstallerPage {
17 /**
18 * The WebInstaller object this WebInstallerPage belongs to.
20 * @var WebInstaller
22 public $parent;
24 public abstract function execute();
26 /**
27 * Constructor.
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() {
40 $this->addHTML(
41 "<div class=\"config-section\">\n" .
42 Xml::openElement(
43 'form',
44 array(
45 'method' => 'post',
46 'action' => $this->parent->getUrl( array( 'page' => $this->getName() ) )
48 ) . "\n"
52 public function endForm( $continue = 'continue' ) {
53 $this->parent->output->outputWarnings();
54 $s = "<div class=\"config-submit\">\n";
55 $id = $this->getId();
57 if ( $id === false ) {
58 $s .= Xml::hidden( 'lastPage', $this->parent->request->getVal( 'lastPage' ) );
61 if ( $continue ) {
62 // Fake submit button for enter keypress
63 $s .= Xml::submitButton( wfMsg( "config-$continue" ),
64 array( 'name' => "enter-$continue", 'style' => 'display:none' ) ) . "\n";
67 if ( $id !== 0 ) {
68 $s .= Xml::submitButton( wfMsg( 'config-back' ),
69 array(
70 'name' => 'submit-back',
71 'tabindex' => $this->parent->nextTabIndex()
72 ) ) . "\n";
75 if ( $continue ) {
76 $s .= Xml::submitButton( wfMsg( "config-$continue" ),
77 array(
78 'name' => "submit-$continue",
79 'tabindex' => $this->parent->nextTabIndex(),
80 ) ) . "\n";
83 $s .= "</div></form></div>\n";
84 $this->addHTML( $s );
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() {
108 global $wgLang;
109 $r = $this->parent->request;
110 $userLang = $r->getVal( 'UserLang' );
111 $contLang = $r->getVal( 'ContLang' );
113 $lifetime = intval( ini_get( 'session.gc_maxlifetime' ) );
114 if ( !$lifetime ) {
115 $lifetime = 1440; // PHP default
118 if ( $r->wasPosted() ) {
119 # Do session test
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';
128 } else {
129 $msg = 'config-no-session';
131 $this->parent->showError( $msg, $wgLang->formatTimePeriod( $lifetime ) );
132 } else {
133 $languages = Language::getLanguageNames();
134 if ( isset( $languages[$userLang] ) ) {
135 $this->setVar( '_UserLang', $userLang );
137 if ( isset( $languages[$contLang] ) ) {
138 $this->setVar( 'wgLanguageCode', $contLang );
140 return 'continue';
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' );
156 $this->startForm();
157 $s =
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 );
166 $this->endForm();
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();
177 ksort( $languages );
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' ) ) {
194 return 'continue';
197 $this->parent->output->addWikiText( wfMsgNoTrans( 'config-welcome' ) );
198 $status = $this->parent->doEnvironmentChecks();
199 if ( $status ) {
200 $this->parent->output->addWikiText( wfMsgNoTrans( 'config-copyright', wfMsg( 'config-authors' ) ) );
201 $this->startForm();
202 $this->endForm();
208 class WebInstaller_DBConnect extends WebInstallerPage {
210 public function execute() {
211 $r = $this->parent->request;
212 if ( $r->wasPosted() ) {
213 $status = $this->submit();
214 if ( $status->isGood() ) {
215 $this->setVar( '_UpgradeDone', false );
216 return 'continue';
217 } else {
218 $this->parent->showStatusBox( $status );
222 $this->startForm();
224 $types = "<ul class=\"config-settings-block\">\n";
225 $settings = '';
226 $defaultType = $this->getVar( 'wgDBtype' );
228 $dbSupport = '';
229 foreach( $this->parent->getDBTypes() as $type ) {
230 $db = 'Database' . ucfirst( $type );
231 $dbSupport .= wfMsgNoTrans( "config-support-$type", $db::getSoftwareLink() ) . "\n";
233 $this->addHTML( $this->parent->getInfoBox(
234 wfMsg( 'config-support-info', $dbSupport ) ) );
236 foreach ( $this->parent->getVar( '_CompiledDBs' ) as $type ) {
237 $installer = $this->parent->getDBInstaller( $type );
238 $types .=
239 '<li>' .
240 Xml::radioLabel(
241 $installer->getReadableName(),
242 'DBType',
243 $type,
244 "DBType_$type",
245 $type == $defaultType,
246 array( 'class' => 'dbRadio', 'rel' => "DB_wrapper_$type" )
248 "</li>\n";
250 $settings .=
251 Xml::openElement( 'div', array( 'id' => 'DB_wrapper_' . $type, 'class' => 'dbWrapper' ) ) .
252 Xml::element( 'h3', array(), wfMsg( 'config-header-' . $type ) ) .
253 $installer->getConnectForm() .
254 "</div>\n";
256 $types .= "</ul><br clear=\"left\"/>\n";
258 $this->addHTML(
259 $this->parent->label( 'config-db-type', false, $types ) .
260 $settings
263 $this->endForm();
266 public function submit() {
267 $r = $this->parent->request;
268 $type = $r->getVal( 'DBType' );
269 $this->setVar( 'wgDBtype', $type );
270 $installer = $this->parent->getDBInstaller( $type );
271 if ( !$installer ) {
272 return Status::newFatal( 'config-invalid-db-type' );
274 return $installer->submitConnectForm();
279 class WebInstaller_Upgrade extends WebInstallerPage {
281 public function execute() {
282 if ( $this->getVar( '_UpgradeDone' ) ) {
283 if ( $this->parent->request->wasPosted() ) {
284 // Done message acknowledged
285 return 'continue';
286 } else {
287 // Back button click
288 // Show the done message again
289 // Make them click back again if they want to do the upgrade again
290 $this->showDoneMessage();
291 return 'output';
295 // wgDBtype is generally valid here because otherwise the previous page
296 // (connect) wouldn't have declared its happiness
297 $type = $this->getVar( 'wgDBtype' );
298 $installer = $this->parent->getDBInstaller( $type );
300 if ( !$installer->needsUpgrade() ) {
301 return 'skip';
304 if ( $this->parent->request->wasPosted() ) {
305 $installer->preUpgrade();
306 $this->addHTML(
307 '<div id="config-spinner" style="display:none;"><img src="../skins/common/images/ajax-loader.gif" /></div>' .
308 '<script>jQuery( "#config-spinner" )[0].style.display = "block";</script>' .
309 '<textarea id="config-update-log" name="UpdateLog" rows="10" readonly="readonly">'
311 $this->parent->output->flush();
312 $result = $installer->doUpgrade();
313 $this->addHTML( '</textarea>
314 <script>jQuery( "#config-spinner" )[0].style.display = "none";</script>' );
315 $this->parent->output->flush();
316 if ( $result ) {
317 $this->setVar( '_UpgradeDone', true );
318 $this->showDoneMessage();
319 return 'output';
323 $this->startForm();
324 $this->addHTML( $this->parent->getInfoBox(
325 wfMsgNoTrans( 'config-can-upgrade', $GLOBALS['wgVersion'] ) ) );
326 $this->endForm();
329 public function showDoneMessage() {
330 $this->startForm();
331 $this->addHTML(
332 $this->parent->getInfoBox(
333 wfMsgNoTrans( 'config-upgrade-done',
334 $GLOBALS['wgServer'] .
335 $this->getVar( 'wgScriptPath' ) . '/index' .
336 $this->getVar( 'wgScriptExtension' )
337 ), 'tick-32.png'
340 $this->endForm( 'regenerate' );
345 class WebInstaller_DBSettings extends WebInstallerPage {
347 public function execute() {
348 $installer = $this->parent->getDBInstaller( $this->getVar( 'wgDBtype' ) );
350 $r = $this->parent->request;
351 if ( $r->wasPosted() ) {
352 $status = $installer->submitSettingsForm();
353 if ( $status === false ) {
354 return 'skip';
355 } elseif ( $status->isGood() ) {
356 return 'continue';
357 } else {
358 $this->parent->showStatusBox( $status );
362 $form = $installer->getSettingsForm();
363 if ( $form === false ) {
364 return 'skip';
367 $this->startForm();
368 $this->addHTML( $form );
369 $this->endForm();
374 class WebInstaller_Name extends WebInstallerPage {
376 public function execute() {
377 $r = $this->parent->request;
378 if ( $r->wasPosted() ) {
379 if ( $this->submit() ) {
380 return 'continue';
384 $this->startForm();
386 if ( $this->getVar( 'wgSitename' ) == $GLOBALS['wgSitename'] ) {
387 $this->setVar( 'wgSitename', '' );
390 // Set wgMetaNamespace to something valid before we show the form.
391 // $wgMetaNamespace defaults to $wgSiteName which is 'MediaWiki'
392 $metaNS = $this->getVar( 'wgMetaNamespace' );
393 $this->setVar( 'wgMetaNamespace', wfMsgForContent( 'config-ns-other-default' ) );
395 $this->addHTML(
396 $this->parent->getTextBox( array(
397 'var' => 'wgSitename',
398 'label' => 'config-site-name',
399 ) ) .
400 $this->parent->getHelpBox( 'config-site-name-help' ) .
401 $this->parent->getRadioSet( array(
402 'var' => '_NamespaceType',
403 'label' => 'config-project-namespace',
404 'itemLabelPrefix' => 'config-ns-',
405 'values' => array( 'site-name', 'generic', 'other' ),
406 'commonAttribs' => array( 'class' => 'enableForOther', 'rel' => 'config_wgMetaNamespace' ),
407 ) ) .
408 $this->parent->getTextBox( array(
409 'var' => 'wgMetaNamespace',
410 'label' => '',
411 'attribs' => array( 'disabled' => '' ),
412 ) ) .
413 $this->parent->getHelpBox( 'config-project-namespace-help' ) .
414 $this->parent->getFieldsetStart( 'config-admin-box' ) .
415 $this->parent->getTextBox( array(
416 'var' => '_AdminName',
417 'label' => 'config-admin-name'
418 ) ) .
419 $this->parent->getPasswordBox( array(
420 'var' => '_AdminPassword',
421 'label' => 'config-admin-password',
422 ) ) .
423 $this->parent->getPasswordBox( array(
424 'var' => '_AdminPassword2',
425 'label' => 'config-admin-password-confirm'
426 ) ) .
427 $this->parent->getHelpBox( 'config-admin-help' ) .
428 $this->parent->getTextBox( array(
429 'var' => '_AdminEmail',
430 'label' => 'config-admin-email'
431 ) ) .
432 $this->parent->getHelpBox( 'config-admin-email-help' ) .
433 $this->parent->getCheckBox( array(
434 'var' => '_Subscribe',
435 'label' => 'config-subscribe'
436 ) ) .
437 $this->parent->getHelpBox( 'config-subscribe-help' ) .
438 $this->parent->getFieldsetEnd() .
439 $this->parent->getInfoBox( wfMsg( 'config-almost-done' ) ) .
440 $this->parent->getRadioSet( array(
441 'var' => '_SkipOptional',
442 'itemLabelPrefix' => 'config-optional-',
443 'values' => array( 'continue', 'skip' )
447 // Restore the default value
448 $this->setVar( 'wgMetaNamespace', $metaNS );
450 $this->endForm();
451 return 'output';
454 public function submit() {
455 $retVal = true;
456 $this->parent->setVarsFromRequest( array( 'wgSitename', '_NamespaceType',
457 '_AdminName', '_AdminPassword', '_AdminPassword2', '_AdminEmail',
458 '_Subscribe', '_SkipOptional' ) );
460 // Validate site name
461 if ( strval( $this->getVar( 'wgSitename' ) ) === '' ) {
462 $this->parent->showError( 'config-site-name-blank' );
463 $retVal = false;
466 // Fetch namespace
467 $nsType = $this->getVar( '_NamespaceType' );
468 if ( $nsType == 'site-name' ) {
469 $name = $this->getVar( 'wgSitename' );
470 // Sanitize for namespace
471 // This algorithm should match the JS one in WebInstallerOutput.php
472 $name = preg_replace( '/[\[\]\{\}|#<>%+? ]/', '_', $name );
473 $name = str_replace( '&', '&amp;', $name );
474 $name = preg_replace( '/__+/', '_', $name );
475 $name = ucfirst( trim( $name, '_' ) );
476 } elseif ( $nsType == 'generic' ) {
477 $name = wfMsg( 'config-ns-generic' );
478 } else { // other
479 $name = $this->getVar( 'wgMetaNamespace' );
482 // Validate namespace
483 if ( strpos( $name, ':' ) !== false ) {
484 $good = false;
485 } else {
486 // Title-style validation
487 $title = Title::newFromText( $name );
488 if ( !$title ) {
489 $good = $nsType == 'site-name' ? true : false;
490 } else {
491 $name = $title->getDBkey();
492 $good = true;
495 if ( !$good ) {
496 $this->parent->showError( 'config-ns-invalid', $name );
497 $retVal = false;
499 $this->setVar( 'wgMetaNamespace', $name );
501 // Validate username for creation
502 $name = $this->getVar( '_AdminName' );
503 if ( strval( $name ) === '' ) {
504 $this->parent->showError( 'config-admin-name-blank' );
505 $cname = $name;
506 $retVal = false;
507 } else {
508 $cname = User::getCanonicalName( $name, 'creatable' );
509 if ( $cname === false ) {
510 $this->parent->showError( 'config-admin-name-invalid', $name );
511 $retVal = false;
512 } else {
513 $this->setVar( '_AdminName', $cname );
517 // Validate password
518 $msg = false;
519 $pwd = $this->getVar( '_AdminPassword' );
520 $user = User::newFromName( $cname );
521 $valid = $user->getPasswordValidity( $pwd );
522 if ( strval( $pwd ) === '' ) {
523 # $user->getPasswordValidity just checks for $wgMinimalPasswordLength.
524 # This message is more specific and helpful.
525 $msg = 'config-admin-password-blank';
526 } elseif ( $pwd !== $this->getVar( '_AdminPassword2' ) ) {
527 $msg = 'config-admin-password-mismatch';
528 } elseif ( $valid !== true ) {
529 # As of writing this will only catch the username being e.g. 'FOO' and
530 # the password 'foo'
531 $msg = $valid;
533 if ( $msg !== false ) {
534 $this->parent->showError( $msg );
535 $this->setVar( '_AdminPassword', '' );
536 $this->setVar( '_AdminPassword2', '' );
537 $retVal = false;
539 return $retVal;
544 class WebInstaller_Options extends WebInstallerPage {
546 public function execute() {
547 if ( $this->getVar( '_SkipOptional' ) == 'skip' ) {
548 return 'skip';
550 if ( $this->parent->request->wasPosted() ) {
551 if ( $this->submit() ) {
552 return 'continue';
556 $this->startForm();
557 $this->addHTML(
558 # User Rights
559 $this->parent->getRadioSet( array(
560 'var' => '_RightsProfile',
561 'label' => 'config-profile',
562 'itemLabelPrefix' => 'config-profile-',
563 'values' => array_keys( $this->parent->rightsProfiles ),
564 ) ) .
565 $this->parent->getHelpBox( 'config-profile-help' ) .
567 # Licensing
568 $this->parent->getRadioSet( array(
569 'var' => '_LicenseCode',
570 'label' => 'config-license',
571 'itemLabelPrefix' => 'config-license-',
572 'values' => array_keys( $this->parent->licenses ),
573 'commonAttribs' => array( 'class' => 'licenseRadio' ),
574 ) ) .
575 $this->getCCChooser() .
576 $this->parent->getHelpBox( 'config-license-help' ) .
578 # E-mail
579 $this->parent->getFieldsetStart( 'config-email-settings' ) .
580 $this->parent->getCheckBox( array(
581 'var' => 'wgEnableEmail',
582 'label' => 'config-enable-email',
583 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'emailwrapper' ),
584 ) ) .
585 $this->parent->getHelpBox( 'config-enable-email-help' ) .
586 "<div id=\"emailwrapper\">" .
587 $this->parent->getTextBox( array(
588 'var' => 'wgPasswordSender',
589 'label' => 'config-email-sender'
590 ) ) .
591 $this->parent->getHelpBox( 'config-email-sender-help' ) .
592 $this->parent->getCheckBox( array(
593 'var' => 'wgEnableUserEmail',
594 'label' => 'config-email-user',
595 ) ) .
596 $this->parent->getHelpBox( 'config-email-user-help' ) .
597 $this->parent->getCheckBox( array(
598 'var' => 'wgEnotifUserTalk',
599 'label' => 'config-email-usertalk',
600 ) ) .
601 $this->parent->getHelpBox( 'config-email-usertalk-help' ) .
602 $this->parent->getCheckBox( array(
603 'var' => 'wgEnotifWatchlist',
604 'label' => 'config-email-watchlist',
605 ) ) .
606 $this->parent->getHelpBox( 'config-email-watchlist-help' ) .
607 $this->parent->getCheckBox( array(
608 'var' => 'wgEmailAuthentication',
609 'label' => 'config-email-auth',
610 ) ) .
611 $this->parent->getHelpBox( 'config-email-auth-help' ) .
612 "</div>" .
613 $this->parent->getFieldsetEnd()
616 $extensions = $this->parent->findExtensions();
618 if( $extensions ) {
619 $extHtml = $this->parent->getFieldsetStart( 'config-extensions' );
621 foreach( $extensions as $ext ) {
622 $extHtml .= $this->parent->getCheckBox( array(
623 'var' => "ext-$ext",
624 'rawtext' => $ext,
625 ) );
628 $extHtml .= $this->parent->getHelpBox( 'config-extensions-help' ) .
629 $this->parent->getFieldsetEnd();
630 $this->addHTML( $extHtml );
633 $this->addHTML(
634 # Uploading
635 $this->parent->getFieldsetStart( 'config-upload-settings' ) .
636 $this->parent->getCheckBox( array(
637 'var' => 'wgEnableUploads',
638 'label' => 'config-upload-enable',
639 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'uploadwrapper' ),
640 ) ) .
641 $this->parent->getHelpBox( 'config-upload-help' ) .
642 '<div id="uploadwrapper" style="display: none;">' .
643 $this->parent->getTextBox( array(
644 'var' => 'wgDeletedDirectory',
645 'label' => 'config-upload-deleted',
646 ) ) .
647 $this->parent->getHelpBox( 'config-upload-deleted-help' ) .
648 '</div>' .
649 $this->parent->getTextBox( array(
650 'var' => 'wgLogo',
651 'label' => 'config-logo'
652 ) ) .
653 $this->parent->getHelpBox( 'config-logo-help' )
655 $canUse = $this->getVar( '_ExternalHTTP' ) ?
656 'config-instantcommons-good' : 'config-instantcommons-bad';
657 $this->addHTML(
658 $this->parent->getCheckBox( array(
659 'var' => 'wgUseInstantCommons',
660 'label' => 'config-instantcommons',
661 ) ) .
662 $this->parent->getHelpBox( 'config-instantcommons-help', wfMsgNoTrans( $canUse ) ) .
663 $this->parent->getFieldsetEnd()
666 $caches = array( 'none' );
667 if( count( $this->getVar( '_Caches' ) ) ) {
668 $caches[] = 'accel';
670 $caches[] = 'memcached';
672 $this->addHTML(
673 # Advanced settings
674 $this->parent->getFieldsetStart( 'config-advanced-settings' ) .
675 # Object cache settings
676 $this->parent->getRadioSet( array(
677 'var' => 'wgMainCacheType',
678 'label' => 'config-cache-options',
679 'itemLabelPrefix' => 'config-cache-',
680 'values' => $caches,
681 'value' => 'none',
682 ) ) .
683 $this->parent->getHelpBox( 'config-cache-help' ) .
684 '<div id="config-memcachewrapper">' .
685 $this->parent->getTextBox( array(
686 'var' => '_MemCachedServers',
687 'label' => 'config-memcached-servers',
688 ) ) .
689 $this->parent->getHelpBox( 'config-memcached-help' ) . '</div>' .
690 $this->parent->getFieldsetEnd()
692 $this->endForm();
695 public function getCCPartnerUrl() {
696 global $wgServer;
697 $exitUrl = $wgServer . $this->parent->getUrl( array(
698 'page' => 'Options',
699 'SubmitCC' => 'indeed',
700 'config__LicenseCode' => 'cc',
701 'config_wgRightsUrl' => '[license_url]',
702 'config_wgRightsText' => '[license_name]',
703 'config_wgRightsIcon' => '[license_button]',
704 ) );
705 $styleUrl = $wgServer . dirname( dirname( $this->parent->getUrl() ) ) .
706 '/skins/common/config-cc.css';
707 $iframeUrl = 'http://creativecommons.org/license/?' .
708 wfArrayToCGI( array(
709 'partner' => 'MediaWiki',
710 'exit_url' => $exitUrl,
711 'lang' => $this->getVar( '_UserLang' ),
712 'stylesheet' => $styleUrl,
713 ) );
714 return $iframeUrl;
717 public function getCCChooser() {
718 $iframeAttribs = array(
719 'class' => 'config-cc-iframe',
720 'name' => 'config-cc-iframe',
721 'id' => 'config-cc-iframe',
722 'frameborder' => 0,
723 'width' => '100%',
724 'height' => '100%',
726 if ( $this->getVar( '_CCDone' ) ) {
727 $iframeAttribs['src'] = $this->parent->getUrl( array( 'ShowCC' => 'yes' ) );
728 } else {
729 $iframeAttribs['src'] = $this->getCCPartnerUrl();
732 return
733 "<div class=\"config-cc-wrapper\" id=\"config-cc-wrapper\" style=\"display: none;\">\n" .
734 Xml::element( 'iframe', $iframeAttribs, '', false /* not short */ ) .
735 "</div>\n";
738 public function getCCDoneBox() {
739 $js = "parent.document.getElementById('config-cc-wrapper').style.height = '$1';";
740 // If you change this height, also change it in config.css
741 $expandJs = str_replace( '$1', '54em', $js );
742 $reduceJs = str_replace( '$1', '70px', $js );
743 return
744 '<p>'.
745 Xml::element( 'img', array( 'src' => $this->getVar( 'wgRightsIcon' ) ) ) .
746 '&#160;&#160;' .
747 htmlspecialchars( $this->getVar( 'wgRightsText' ) ) .
748 "</p>\n" .
749 "<p style=\"text-align: center\">" .
750 Xml::element( 'a',
751 array(
752 'href' => $this->getCCPartnerUrl(),
753 'onclick' => $expandJs,
755 wfMsg( 'config-cc-again' )
757 "</p>\n" .
758 "<script type=\"text/javascript\">\n" .
759 # Reduce the wrapper div height
760 htmlspecialchars( $reduceJs ) .
761 "\n" .
762 "</script>\n";
765 public function submitCC() {
766 $newValues = $this->parent->setVarsFromRequest(
767 array( 'wgRightsUrl', 'wgRightsText', 'wgRightsIcon' ) );
768 if ( count( $newValues ) != 3 ) {
769 $this->parent->showError( 'config-cc-error' );
770 return;
772 $this->setVar( '_CCDone', true );
773 $this->addHTML( $this->getCCDoneBox() );
776 public function submit() {
777 $this->parent->setVarsFromRequest( array( '_RightsProfile', '_LicenseCode',
778 'wgEnableEmail', 'wgPasswordSender', 'wgEnableUploads', 'wgLogo',
779 'wgEnableUserEmail', 'wgEnotifUserTalk', 'wgEnotifWatchlist',
780 'wgEmailAuthentication', 'wgMainCacheType', '_MemCachedServers',
781 'wgUseInstantCommons' ) );
783 if ( !in_array( $this->getVar( '_RightsProfile' ),
784 array_keys( $this->parent->rightsProfiles ) ) )
786 reset( $this->parent->rightsProfiles );
787 $this->setVar( '_RightsProfile', key( $this->parent->rightsProfiles ) );
790 $code = $this->getVar( '_LicenseCode' );
791 if ( $code == 'cc-choose' ) {
792 if ( !$this->getVar( '_CCDone' ) ) {
793 $this->parent->showError( 'config-cc-not-chosen' );
794 return false;
796 } elseif ( in_array( $code, array_keys( $this->parent->licenses ) ) ) {
797 $entry = $this->parent->licenses[$code];
798 if ( isset( $entry['text'] ) ) {
799 $this->setVar( 'wgRightsText', $entry['text'] );
800 } else {
801 $this->setVar( 'wgRightsText', wfMsg( 'config-license-' . $code ) );
803 $this->setVar( 'wgRightsUrl', $entry['url'] );
804 $this->setVar( 'wgRightsIcon', $entry['icon'] );
805 } else {
806 $this->setVar( 'wgRightsText', '' );
807 $this->setVar( 'wgRightsUrl', '' );
808 $this->setVar( 'wgRightsIcon', '' );
811 $extsAvailable = $this->parent->findExtensions();
812 $extsToInstall = array();
813 foreach( $extsAvailable as $ext ) {
814 if( $this->parent->request->getCheck( 'config_ext-' . $ext ) ) {
815 $extsToInstall[] = $ext;
818 $this->parent->setVar( '_Extensions', $extsToInstall );
819 return true;
824 class WebInstaller_Install extends WebInstallerPage {
826 public function execute() {
827 if( $this->parent->request->wasPosted() ) {
828 return 'continue';
829 } elseif( $this->getVar( '_InstallDone' ) ) {
830 $this->startForm();
831 $status = new Status();
832 $status->warning( 'config-install-alreadydone' );
833 $this->parent->showStatusBox( $status );
834 } elseif( $this->getVar( '_UpgradeDone' ) ) {
835 return 'skip';
836 } else {
837 $this->startForm();
838 $this->addHTML("<ul>");
839 $this->parent->performInstallation(
840 array( $this, 'startStage'),
841 array( $this, 'endStage' )
843 $this->addHTML("</ul>");
845 $this->endForm();
846 return true;
849 public function startStage( $step ) {
850 $this->addHTML( "<li>" . wfMsgHtml( "config-install-$step" ) . wfMsg( 'ellipsis') );
853 public function endStage( $step, $status ) {
854 $msg = $status->isOk() ? 'config-install-step-done' : 'config-install-step-failed';
855 $html = wfMsgHtml( 'word-separator' ) . wfMsgHtml( $msg );
856 if ( !$status->isOk() ) {
857 $html = "<span class=\"error\">$html</span>";
859 $this->addHTML( $html . "</li>\n" );
860 if( !$status->isGood() ) {
861 $this->parent->showStatusBox( $status );
867 class WebInstaller_Complete extends WebInstallerPage {
869 public function execute() {
870 $this->startForm();
871 $this->addHTML(
872 $this->parent->getInfoBox(
873 wfMsgNoTrans( 'config-install-done',
874 $GLOBALS['wgServer'] . $this->parent->getURL( array( 'localsettings' => 1 ) ),
875 $GLOBALS['wgServer'] .
876 $this->getVar( 'wgScriptPath' ) . '/index' .
877 $this->getVar( 'wgScriptExtension' )
878 ), 'tick-32.png'
881 $this->endForm( false );
885 class WebInstaller_Restart extends WebInstallerPage {
887 public function execute() {
888 $r = $this->parent->request;
889 if ( $r->wasPosted() ) {
890 $really = $r->getVal( 'submit-restart' );
891 if ( $really ) {
892 $this->parent->session = array();
893 $this->parent->happyPages = array();
894 $this->parent->settings = array();
896 return 'continue';
899 $this->startForm();
900 $s = $this->parent->getWarningBox( wfMsgNoTrans( 'config-help-restart' ) );
901 $this->addHTML( $s );
902 $this->endForm( 'restart' );
907 abstract class WebInstaller_Document extends WebInstallerPage {
909 protected abstract function getFileName();
911 public function execute() {
912 $text = $this->getFileContents();
913 $this->parent->output->addWikiText( $text );
914 $this->startForm();
915 $this->endForm( false );
918 public function getFileContents() {
919 return file_get_contents( dirname( __FILE__ ) . '/../../' . $this->getFileName() );
922 protected function formatTextFile( $text ) {
923 $text = str_replace( array( '<', '{{', '[[' ),
924 array( '&lt;', '&#123;&#123;', '&#91;&#91;' ), $text );
925 // replace numbering with [1], [2], etc with MW-style numbering
926 $text = preg_replace( "/\r?\n(\r?\n)?\\[\\d+\\]/m", "\\1#", $text );
927 // join word-wrapped lines into one
928 do {
929 $prev = $text;
930 $text = preg_replace( "/\n([\\*#])([^\r\n]*?)\r?\n([^\r\n#\\*:]+)/", "\n\\1\\2 \\3", $text );
931 } while ( $text != $prev );
932 // turn (bug nnnn) into links
933 $text = preg_replace_callback('/bug (\d+)/', array( $this, 'replaceBugLinks' ), $text );
934 // add links to manual to every global variable mentioned
935 $text = preg_replace_callback('/(\$wg[a-z0-9_]+)/i', array( $this, 'replaceConfigLinks' ), $text );
936 // special case for <pre> - formatted links
937 do {
938 $prev = $text;
939 $text = preg_replace( '/^([^\\s].*?)\r?\n[\\s]+(https?:\/\/)/m', "\\1\n:\\2", $text );
940 } while ( $text != $prev );
941 return $text;
944 private function replaceBugLinks( $matches ) {
945 return '<span class="config-plainlink">[https://bugzilla.wikimedia.org/' .
946 $matches[1] . ' bug ' . $matches[1] . ']</span>';
949 private function replaceConfigLinks( $matches ) {
950 return '<span class="config-plainlink">[http://www.mediawiki.org/wiki/Manual:' .
951 $matches[1] . ' ' . $matches[1] . ']</span>';
956 class WebInstaller_Readme extends WebInstaller_Document {
958 protected function getFileName() { return 'README'; }
960 public function getFileContents() {
961 return $this->formatTextFile( parent::getFileContents() );
966 class WebInstaller_ReleaseNotes extends WebInstaller_Document {
968 protected function getFileName() { return 'RELEASE-NOTES'; }
970 public function getFileContents() {
971 return $this->formatTextFile( parent::getFileContents() );
976 class WebInstaller_UpgradeDoc extends WebInstaller_Document {
978 protected function getFileName() { return 'UPGRADE'; }
980 public function getFileContents() {
981 return $this->formatTextFile( parent::getFileContents() );
986 class WebInstaller_Copying extends WebInstaller_Document {
988 protected function getFileName() { return 'COPYING'; }
990 public function getFileContents() {
991 $text = parent::getFileContents();
992 $text = str_replace( "\x0C", '', $text );
993 $text = preg_replace_callback( '/\n[ \t]+/m', array( 'WebInstaller_Copying', 'replaceLeadingSpaces' ), $text );
994 $text = '<tt>' . nl2br( $text ) . '</tt>';
995 return $text;
998 private static function replaceLeadingSpaces( $matches ) {
999 return "\n" . str_repeat( '&#160;', strlen( $matches[0] ) );