* Installer for Oracle fixes
[mediawiki.git] / includes / installer / WebInstallerPage.php
blobb3738f6bfb00f6d531a8a3695d76b5921b0854bb
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',
201 SpecialVersion::getCopyrightAndAuthorList() ) );
202 $this->startForm();
203 $this->endForm();
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 );
217 return 'continue';
218 } else {
219 $this->parent->showStatusBox( $status );
223 $this->startForm();
225 $types = "<ul class=\"config-settings-block\">\n";
226 $settings = '';
227 $defaultType = $this->getVar( 'wgDBtype' );
229 $dbSupport = '';
230 foreach( $this->parent->getDBTypes() as $type ) {
231 $db = 'Database' . ucfirst( $type );
232 $dbSupport .= wfMsgNoTrans( "config-support-$type",
233 call_user_func( array( $db, 'getSoftwareLink' ) ) ) . "\n";
235 $this->addHTML( $this->parent->getInfoBox(
236 wfMsg( 'config-support-info', $dbSupport ) ) );
238 foreach ( $this->parent->getVar( '_CompiledDBs' ) as $type ) {
239 $installer = $this->parent->getDBInstaller( $type );
240 $types .=
241 '<li>' .
242 Xml::radioLabel(
243 $installer->getReadableName(),
244 'DBType',
245 $type,
246 "DBType_$type",
247 $type == $defaultType,
248 array( 'class' => 'dbRadio', 'rel' => "DB_wrapper_$type" )
250 "</li>\n";
252 $settings .=
253 Xml::openElement( 'div', array( 'id' => 'DB_wrapper_' . $type, 'class' => 'dbWrapper' ) ) .
254 Xml::element( 'h3', array(), wfMsg( 'config-header-' . $type ) ) .
255 $installer->getConnectForm() .
256 "</div>\n";
258 $types .= "</ul><br clear=\"left\"/>\n";
260 $this->addHTML(
261 $this->parent->label( 'config-db-type', false, $types ) .
262 $settings
265 $this->endForm();
268 public function submit() {
269 $r = $this->parent->request;
270 $type = $r->getVal( 'DBType' );
271 $this->setVar( 'wgDBtype', $type );
272 $installer = $this->parent->getDBInstaller( $type );
273 if ( !$installer ) {
274 return Status::newFatal( 'config-invalid-db-type' );
276 return $installer->submitConnectForm();
281 class WebInstaller_Upgrade extends WebInstallerPage {
283 public function execute() {
284 if ( $this->getVar( '_UpgradeDone' ) ) {
285 if ( $this->parent->request->wasPosted() ) {
286 // Done message acknowledged
287 return 'continue';
288 } else {
289 // Back button click
290 // Show the done message again
291 // Make them click back again if they want to do the upgrade again
292 $this->showDoneMessage();
293 return 'output';
297 // wgDBtype is generally valid here because otherwise the previous page
298 // (connect) wouldn't have declared its happiness
299 $type = $this->getVar( 'wgDBtype' );
300 $installer = $this->parent->getDBInstaller( $type );
302 if ( !$installer->needsUpgrade() ) {
303 return 'skip';
306 if ( $this->parent->request->wasPosted() ) {
307 $installer->preUpgrade();
308 $this->addHTML(
309 '<div id="config-spinner" style="display:none;"><img src="../skins/common/images/ajax-loader.gif" /></div>' .
310 '<script>jQuery( "#config-spinner" )[0].style.display = "block";</script>' .
311 '<textarea id="config-update-log" name="UpdateLog" rows="10" readonly="readonly">'
313 $this->parent->output->flush();
314 $result = $installer->doUpgrade();
315 $this->addHTML( '</textarea>
316 <script>jQuery( "#config-spinner" )[0].style.display = "none";</script>' );
317 $this->parent->output->flush();
318 if ( $result ) {
319 $this->setVar( '_UpgradeDone', true );
320 $this->showDoneMessage();
321 return 'output';
325 $this->startForm();
326 $this->addHTML( $this->parent->getInfoBox(
327 wfMsgNoTrans( 'config-can-upgrade', $GLOBALS['wgVersion'] ) ) );
328 $this->endForm();
331 public function showDoneMessage() {
332 $this->startForm();
333 $this->addHTML(
334 $this->parent->getInfoBox(
335 wfMsgNoTrans( 'config-upgrade-done',
336 $GLOBALS['wgServer'] .
337 $this->getVar( 'wgScriptPath' ) . '/index' .
338 $this->getVar( 'wgScriptExtension' )
339 ), 'tick-32.png'
342 $this->endForm( 'regenerate' );
347 class WebInstaller_DBSettings extends WebInstallerPage {
349 public function execute() {
350 $installer = $this->parent->getDBInstaller( $this->getVar( 'wgDBtype' ) );
352 $r = $this->parent->request;
353 if ( $r->wasPosted() ) {
354 $status = $installer->submitSettingsForm();
355 if ( $status === false ) {
356 return 'skip';
357 } elseif ( $status->isGood() ) {
358 return 'continue';
359 } else {
360 $this->parent->showStatusBox( $status );
364 $form = $installer->getSettingsForm();
365 if ( $form === false ) {
366 return 'skip';
369 $this->startForm();
370 $this->addHTML( $form );
371 $this->endForm();
376 class WebInstaller_Name extends WebInstallerPage {
378 public function execute() {
379 $r = $this->parent->request;
380 if ( $r->wasPosted() ) {
381 if ( $this->submit() ) {
382 return 'continue';
386 $this->startForm();
388 if ( $this->getVar( 'wgSitename' ) == $GLOBALS['wgSitename'] ) {
389 $this->setVar( 'wgSitename', '' );
392 // Set wgMetaNamespace to something valid before we show the form.
393 // $wgMetaNamespace defaults to $wgSiteName which is 'MediaWiki'
394 $metaNS = $this->getVar( 'wgMetaNamespace' );
395 $this->setVar( 'wgMetaNamespace', wfMsgForContent( 'config-ns-other-default' ) );
397 $this->addHTML(
398 $this->parent->getTextBox( array(
399 'var' => 'wgSitename',
400 'label' => 'config-site-name',
401 ) ) .
402 $this->parent->getHelpBox( 'config-site-name-help' ) .
403 $this->parent->getRadioSet( array(
404 'var' => '_NamespaceType',
405 'label' => 'config-project-namespace',
406 'itemLabelPrefix' => 'config-ns-',
407 'values' => array( 'site-name', 'generic', 'other' ),
408 'commonAttribs' => array( 'class' => 'enableForOther', 'rel' => 'config_wgMetaNamespace' ),
409 ) ) .
410 $this->parent->getTextBox( array(
411 'var' => 'wgMetaNamespace',
412 'label' => '',
413 'attribs' => array( 'disabled' => '' ),
414 ) ) .
415 $this->parent->getHelpBox( 'config-project-namespace-help' ) .
416 $this->parent->getFieldsetStart( 'config-admin-box' ) .
417 $this->parent->getTextBox( array(
418 'var' => '_AdminName',
419 'label' => 'config-admin-name'
420 ) ) .
421 $this->parent->getPasswordBox( array(
422 'var' => '_AdminPassword',
423 'label' => 'config-admin-password',
424 ) ) .
425 $this->parent->getPasswordBox( array(
426 'var' => '_AdminPassword2',
427 'label' => 'config-admin-password-confirm'
428 ) ) .
429 $this->parent->getHelpBox( 'config-admin-help' ) .
430 $this->parent->getTextBox( array(
431 'var' => '_AdminEmail',
432 'label' => 'config-admin-email'
433 ) ) .
434 $this->parent->getHelpBox( 'config-admin-email-help' ) .
435 $this->parent->getCheckBox( array(
436 'var' => '_Subscribe',
437 'label' => 'config-subscribe'
438 ) ) .
439 $this->parent->getHelpBox( 'config-subscribe-help' ) .
440 $this->parent->getFieldsetEnd() .
441 $this->parent->getInfoBox( wfMsg( 'config-almost-done' ) ) .
442 $this->parent->getRadioSet( array(
443 'var' => '_SkipOptional',
444 'itemLabelPrefix' => 'config-optional-',
445 'values' => array( 'continue', 'skip' )
449 // Restore the default value
450 $this->setVar( 'wgMetaNamespace', $metaNS );
452 $this->endForm();
453 return 'output';
456 public function submit() {
457 $retVal = true;
458 $this->parent->setVarsFromRequest( array( 'wgSitename', '_NamespaceType',
459 '_AdminName', '_AdminPassword', '_AdminPassword2', '_AdminEmail',
460 '_Subscribe', '_SkipOptional' ) );
462 // Validate site name
463 if ( strval( $this->getVar( 'wgSitename' ) ) === '' ) {
464 $this->parent->showError( 'config-site-name-blank' );
465 $retVal = false;
468 // Fetch namespace
469 $nsType = $this->getVar( '_NamespaceType' );
470 if ( $nsType == 'site-name' ) {
471 $name = $this->getVar( 'wgSitename' );
472 // Sanitize for namespace
473 // This algorithm should match the JS one in WebInstallerOutput.php
474 $name = preg_replace( '/[\[\]\{\}|#<>%+? ]/', '_', $name );
475 $name = str_replace( '&', '&amp;', $name );
476 $name = preg_replace( '/__+/', '_', $name );
477 $name = ucfirst( trim( $name, '_' ) );
478 } elseif ( $nsType == 'generic' ) {
479 $name = wfMsg( 'config-ns-generic' );
480 } else { // other
481 $name = $this->getVar( 'wgMetaNamespace' );
484 // Validate namespace
485 if ( strpos( $name, ':' ) !== false ) {
486 $good = false;
487 } else {
488 // Title-style validation
489 $title = Title::newFromText( $name );
490 if ( !$title ) {
491 $good = $nsType == 'site-name';
492 } else {
493 $name = $title->getDBkey();
494 $good = true;
497 if ( !$good ) {
498 $this->parent->showError( 'config-ns-invalid', $name );
499 $retVal = false;
501 $this->setVar( 'wgMetaNamespace', $name );
503 // Validate username for creation
504 $name = $this->getVar( '_AdminName' );
505 if ( strval( $name ) === '' ) {
506 $this->parent->showError( 'config-admin-name-blank' );
507 $cname = $name;
508 $retVal = false;
509 } else {
510 $cname = User::getCanonicalName( $name, 'creatable' );
511 if ( $cname === false ) {
512 $this->parent->showError( 'config-admin-name-invalid', $name );
513 $retVal = false;
514 } else {
515 $this->setVar( '_AdminName', $cname );
519 // Validate password
520 $msg = false;
521 $pwd = $this->getVar( '_AdminPassword' );
522 $user = User::newFromName( $cname );
523 $valid = $user->getPasswordValidity( $pwd );
524 if ( strval( $pwd ) === '' ) {
525 # $user->getPasswordValidity just checks for $wgMinimalPasswordLength.
526 # This message is more specific and helpful.
527 $msg = 'config-admin-password-blank';
528 } elseif ( $pwd !== $this->getVar( '_AdminPassword2' ) ) {
529 $msg = 'config-admin-password-mismatch';
530 } elseif ( $valid !== true ) {
531 # As of writing this will only catch the username being e.g. 'FOO' and
532 # the password 'foo'
533 $msg = $valid;
535 if ( $msg !== false ) {
536 $this->parent->showError( $msg );
537 $this->setVar( '_AdminPassword', '' );
538 $this->setVar( '_AdminPassword2', '' );
539 $retVal = false;
541 return $retVal;
546 class WebInstaller_Options extends WebInstallerPage {
548 public function execute() {
549 if ( $this->getVar( '_SkipOptional' ) == 'skip' ) {
550 return 'skip';
552 if ( $this->parent->request->wasPosted() ) {
553 if ( $this->submit() ) {
554 return 'continue';
558 $this->startForm();
559 $this->addHTML(
560 # User Rights
561 $this->parent->getRadioSet( array(
562 'var' => '_RightsProfile',
563 'label' => 'config-profile',
564 'itemLabelPrefix' => 'config-profile-',
565 'values' => array_keys( $this->parent->rightsProfiles ),
566 ) ) .
567 $this->parent->getHelpBox( 'config-profile-help' ) .
569 # Licensing
570 $this->parent->getRadioSet( array(
571 'var' => '_LicenseCode',
572 'label' => 'config-license',
573 'itemLabelPrefix' => 'config-license-',
574 'values' => array_keys( $this->parent->licenses ),
575 'commonAttribs' => array( 'class' => 'licenseRadio' ),
576 ) ) .
577 $this->getCCChooser() .
578 $this->parent->getHelpBox( 'config-license-help' ) .
580 # E-mail
581 $this->parent->getFieldsetStart( 'config-email-settings' ) .
582 $this->parent->getCheckBox( array(
583 'var' => 'wgEnableEmail',
584 'label' => 'config-enable-email',
585 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'emailwrapper' ),
586 ) ) .
587 $this->parent->getHelpBox( 'config-enable-email-help' ) .
588 "<div id=\"emailwrapper\">" .
589 $this->parent->getTextBox( array(
590 'var' => 'wgPasswordSender',
591 'label' => 'config-email-sender'
592 ) ) .
593 $this->parent->getHelpBox( 'config-email-sender-help' ) .
594 $this->parent->getCheckBox( array(
595 'var' => 'wgEnableUserEmail',
596 'label' => 'config-email-user',
597 ) ) .
598 $this->parent->getHelpBox( 'config-email-user-help' ) .
599 $this->parent->getCheckBox( array(
600 'var' => 'wgEnotifUserTalk',
601 'label' => 'config-email-usertalk',
602 ) ) .
603 $this->parent->getHelpBox( 'config-email-usertalk-help' ) .
604 $this->parent->getCheckBox( array(
605 'var' => 'wgEnotifWatchlist',
606 'label' => 'config-email-watchlist',
607 ) ) .
608 $this->parent->getHelpBox( 'config-email-watchlist-help' ) .
609 $this->parent->getCheckBox( array(
610 'var' => 'wgEmailAuthentication',
611 'label' => 'config-email-auth',
612 ) ) .
613 $this->parent->getHelpBox( 'config-email-auth-help' ) .
614 "</div>" .
615 $this->parent->getFieldsetEnd()
618 $extensions = $this->parent->findExtensions();
620 if( $extensions ) {
621 $extHtml = $this->parent->getFieldsetStart( 'config-extensions' );
623 foreach( $extensions as $ext ) {
624 $extHtml .= $this->parent->getCheckBox( array(
625 'var' => "ext-$ext",
626 'rawtext' => $ext,
627 ) );
630 $extHtml .= $this->parent->getHelpBox( 'config-extensions-help' ) .
631 $this->parent->getFieldsetEnd();
632 $this->addHTML( $extHtml );
635 $this->addHTML(
636 # Uploading
637 $this->parent->getFieldsetStart( 'config-upload-settings' ) .
638 $this->parent->getCheckBox( array(
639 'var' => 'wgEnableUploads',
640 'label' => 'config-upload-enable',
641 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'uploadwrapper' ),
642 ) ) .
643 $this->parent->getHelpBox( 'config-upload-help' ) .
644 '<div id="uploadwrapper" style="display: none;">' .
645 $this->parent->getTextBox( array(
646 'var' => 'wgDeletedDirectory',
647 'label' => 'config-upload-deleted',
648 ) ) .
649 $this->parent->getHelpBox( 'config-upload-deleted-help' ) .
650 '</div>' .
651 $this->parent->getTextBox( array(
652 'var' => 'wgLogo',
653 'label' => 'config-logo'
654 ) ) .
655 $this->parent->getHelpBox( 'config-logo-help' )
657 $canUse = $this->getVar( '_ExternalHTTP' ) ?
658 'config-instantcommons-good' : 'config-instantcommons-bad';
659 $this->addHTML(
660 $this->parent->getCheckBox( array(
661 'var' => 'wgUseInstantCommons',
662 'label' => 'config-instantcommons',
663 ) ) .
664 $this->parent->getHelpBox( 'config-instantcommons-help', wfMsgNoTrans( $canUse ) ) .
665 $this->parent->getFieldsetEnd()
668 $caches = array( 'none' );
669 if( count( $this->getVar( '_Caches' ) ) ) {
670 $caches[] = 'accel';
672 $caches[] = 'memcached';
674 $this->addHTML(
675 # Advanced settings
676 $this->parent->getFieldsetStart( 'config-advanced-settings' ) .
677 # Object cache settings
678 $this->parent->getRadioSet( array(
679 'var' => 'wgMainCacheType',
680 'label' => 'config-cache-options',
681 'itemLabelPrefix' => 'config-cache-',
682 'values' => $caches,
683 'value' => 'none',
684 ) ) .
685 $this->parent->getHelpBox( 'config-cache-help' ) .
686 '<div id="config-memcachewrapper">' .
687 $this->parent->getTextBox( array(
688 'var' => '_MemCachedServers',
689 'label' => 'config-memcached-servers',
690 ) ) .
691 $this->parent->getHelpBox( 'config-memcached-help' ) . '</div>' .
692 $this->parent->getFieldsetEnd()
694 $this->endForm();
697 public function getCCPartnerUrl() {
698 global $wgServer;
699 $exitUrl = $wgServer . $this->parent->getUrl( array(
700 'page' => 'Options',
701 'SubmitCC' => 'indeed',
702 'config__LicenseCode' => 'cc',
703 'config_wgRightsUrl' => '[license_url]',
704 'config_wgRightsText' => '[license_name]',
705 'config_wgRightsIcon' => '[license_button]',
706 ) );
707 $styleUrl = $wgServer . dirname( dirname( $this->parent->getUrl() ) ) .
708 '/skins/common/config-cc.css';
709 $iframeUrl = 'http://creativecommons.org/license/?' .
710 wfArrayToCGI( array(
711 'partner' => 'MediaWiki',
712 'exit_url' => $exitUrl,
713 'lang' => $this->getVar( '_UserLang' ),
714 'stylesheet' => $styleUrl,
715 ) );
716 return $iframeUrl;
719 public function getCCChooser() {
720 $iframeAttribs = array(
721 'class' => 'config-cc-iframe',
722 'name' => 'config-cc-iframe',
723 'id' => 'config-cc-iframe',
724 'frameborder' => 0,
725 'width' => '100%',
726 'height' => '100%',
728 if ( $this->getVar( '_CCDone' ) ) {
729 $iframeAttribs['src'] = $this->parent->getUrl( array( 'ShowCC' => 'yes' ) );
730 } else {
731 $iframeAttribs['src'] = $this->getCCPartnerUrl();
734 return
735 "<div class=\"config-cc-wrapper\" id=\"config-cc-wrapper\" style=\"display: none;\">\n" .
736 Xml::element( 'iframe', $iframeAttribs, '', false /* not short */ ) .
737 "</div>\n";
740 public function getCCDoneBox() {
741 $js = "parent.document.getElementById('config-cc-wrapper').style.height = '$1';";
742 // If you change this height, also change it in config.css
743 $expandJs = str_replace( '$1', '54em', $js );
744 $reduceJs = str_replace( '$1', '70px', $js );
745 return
746 '<p>'.
747 Xml::element( 'img', array( 'src' => $this->getVar( 'wgRightsIcon' ) ) ) .
748 '&#160;&#160;' .
749 htmlspecialchars( $this->getVar( 'wgRightsText' ) ) .
750 "</p>\n" .
751 "<p style=\"text-align: center\">" .
752 Xml::element( 'a',
753 array(
754 'href' => $this->getCCPartnerUrl(),
755 'onclick' => $expandJs,
757 wfMsg( 'config-cc-again' )
759 "</p>\n" .
760 "<script type=\"text/javascript\">\n" .
761 # Reduce the wrapper div height
762 htmlspecialchars( $reduceJs ) .
763 "\n" .
764 "</script>\n";
767 public function submitCC() {
768 $newValues = $this->parent->setVarsFromRequest(
769 array( 'wgRightsUrl', 'wgRightsText', 'wgRightsIcon' ) );
770 if ( count( $newValues ) != 3 ) {
771 $this->parent->showError( 'config-cc-error' );
772 return;
774 $this->setVar( '_CCDone', true );
775 $this->addHTML( $this->getCCDoneBox() );
778 public function submit() {
779 $this->parent->setVarsFromRequest( array( '_RightsProfile', '_LicenseCode',
780 'wgEnableEmail', 'wgPasswordSender', 'wgEnableUploads', 'wgLogo',
781 'wgEnableUserEmail', 'wgEnotifUserTalk', 'wgEnotifWatchlist',
782 'wgEmailAuthentication', 'wgMainCacheType', '_MemCachedServers',
783 'wgUseInstantCommons' ) );
785 if ( !in_array( $this->getVar( '_RightsProfile' ),
786 array_keys( $this->parent->rightsProfiles ) ) )
788 reset( $this->parent->rightsProfiles );
789 $this->setVar( '_RightsProfile', key( $this->parent->rightsProfiles ) );
792 $code = $this->getVar( '_LicenseCode' );
793 if ( $code == 'cc-choose' ) {
794 if ( !$this->getVar( '_CCDone' ) ) {
795 $this->parent->showError( 'config-cc-not-chosen' );
796 return false;
798 } elseif ( in_array( $code, array_keys( $this->parent->licenses ) ) ) {
799 $entry = $this->parent->licenses[$code];
800 if ( isset( $entry['text'] ) ) {
801 $this->setVar( 'wgRightsText', $entry['text'] );
802 } else {
803 $this->setVar( 'wgRightsText', wfMsg( 'config-license-' . $code ) );
805 $this->setVar( 'wgRightsUrl', $entry['url'] );
806 $this->setVar( 'wgRightsIcon', $entry['icon'] );
807 } else {
808 $this->setVar( 'wgRightsText', '' );
809 $this->setVar( 'wgRightsUrl', '' );
810 $this->setVar( 'wgRightsIcon', '' );
813 $extsAvailable = $this->parent->findExtensions();
814 $extsToInstall = array();
815 foreach( $extsAvailable as $ext ) {
816 if( $this->parent->request->getCheck( 'config_ext-' . $ext ) ) {
817 $extsToInstall[] = $ext;
820 $this->parent->setVar( '_Extensions', $extsToInstall );
821 return true;
826 class WebInstaller_Install extends WebInstallerPage {
828 public function execute() {
829 if( $this->parent->request->wasPosted() ) {
830 return 'continue';
831 } elseif( $this->getVar( '_InstallDone' ) ) {
832 $this->startForm();
833 $status = new Status();
834 $status->warning( 'config-install-alreadydone' );
835 $this->parent->showStatusBox( $status );
836 } elseif( $this->getVar( '_UpgradeDone' ) ) {
837 return 'skip';
838 } else {
839 $this->startForm();
840 $this->addHTML("<ul>");
841 $this->parent->performInstallation(
842 array( $this, 'startStage'),
843 array( $this, 'endStage' )
845 $this->addHTML("</ul>");
847 $this->endForm();
848 return true;
851 public function startStage( $step ) {
852 $this->addHTML( "<li>" . wfMsgHtml( "config-install-$step" ) . wfMsg( 'ellipsis') );
855 public function endStage( $step, $status ) {
856 $msg = $status->isOk() ? 'config-install-step-done' : 'config-install-step-failed';
857 $html = wfMsgHtml( 'word-separator' ) . wfMsgHtml( $msg );
858 if ( !$status->isOk() ) {
859 $html = "<span class=\"error\">$html</span>";
861 $this->addHTML( $html . "</li>\n" );
862 if( !$status->isGood() ) {
863 $this->parent->showStatusBox( $status );
869 class WebInstaller_Complete extends WebInstallerPage {
871 public function execute() {
872 $this->startForm();
873 $this->addHTML(
874 $this->parent->getInfoBox(
875 wfMsgNoTrans( 'config-install-done',
876 $GLOBALS['wgServer'] . $this->parent->getURL( array( 'localsettings' => 1 ) ),
877 $GLOBALS['wgServer'] .
878 $this->getVar( 'wgScriptPath' ) . '/index' .
879 $this->getVar( 'wgScriptExtension' )
880 ), 'tick-32.png'
883 $this->endForm( false );
887 class WebInstaller_Restart extends WebInstallerPage {
889 public function execute() {
890 $r = $this->parent->request;
891 if ( $r->wasPosted() ) {
892 $really = $r->getVal( 'submit-restart' );
893 if ( $really ) {
894 $this->parent->session = array();
895 $this->parent->happyPages = array();
896 $this->parent->settings = array();
898 return 'continue';
901 $this->startForm();
902 $s = $this->parent->getWarningBox( wfMsgNoTrans( 'config-help-restart' ) );
903 $this->addHTML( $s );
904 $this->endForm( 'restart' );
909 abstract class WebInstaller_Document extends WebInstallerPage {
911 protected abstract function getFileName();
913 public function execute() {
914 $text = $this->getFileContents();
915 $this->parent->output->addWikiText( $text );
916 $this->startForm();
917 $this->endForm( false );
920 public function getFileContents() {
921 return file_get_contents( dirname( __FILE__ ) . '/../../' . $this->getFileName() );
924 protected function formatTextFile( $text ) {
925 $text = str_replace( array( '<', '{{', '[[' ),
926 array( '&lt;', '&#123;&#123;', '&#91;&#91;' ), $text );
927 // replace numbering with [1], [2], etc with MW-style numbering
928 $text = preg_replace( "/\r?\n(\r?\n)?\\[\\d+\\]/m", "\\1#", $text );
929 // join word-wrapped lines into one
930 do {
931 $prev = $text;
932 $text = preg_replace( "/\n([\\*#])([^\r\n]*?)\r?\n([^\r\n#\\*:]+)/", "\n\\1\\2 \\3", $text );
933 } while ( $text != $prev );
934 // turn (bug nnnn) into links
935 $text = preg_replace_callback('/bug (\d+)/', array( $this, 'replaceBugLinks' ), $text );
936 // add links to manual to every global variable mentioned
937 $text = preg_replace_callback('/(\$wg[a-z0-9_]+)/i', array( $this, 'replaceConfigLinks' ), $text );
938 // special case for <pre> - formatted links
939 do {
940 $prev = $text;
941 $text = preg_replace( '/^([^\\s].*?)\r?\n[\\s]+(https?:\/\/)/m', "\\1\n:\\2", $text );
942 } while ( $text != $prev );
943 return $text;
946 private function replaceBugLinks( $matches ) {
947 return '<span class="config-plainlink">[https://bugzilla.wikimedia.org/' .
948 $matches[1] . ' bug ' . $matches[1] . ']</span>';
951 private function replaceConfigLinks( $matches ) {
952 return '<span class="config-plainlink">[http://www.mediawiki.org/wiki/Manual:' .
953 $matches[1] . ' ' . $matches[1] . ']</span>';
958 class WebInstaller_Readme extends WebInstaller_Document {
960 protected function getFileName() { return 'README'; }
962 public function getFileContents() {
963 return $this->formatTextFile( parent::getFileContents() );
968 class WebInstaller_ReleaseNotes extends WebInstaller_Document {
970 protected function getFileName() { return 'RELEASE-NOTES'; }
972 public function getFileContents() {
973 return $this->formatTextFile( parent::getFileContents() );
978 class WebInstaller_UpgradeDoc extends WebInstaller_Document {
980 protected function getFileName() { return 'UPGRADE'; }
982 public function getFileContents() {
983 return $this->formatTextFile( parent::getFileContents() );
988 class WebInstaller_Copying extends WebInstaller_Document {
990 protected function getFileName() { return 'COPYING'; }
992 public function getFileContents() {
993 $text = parent::getFileContents();
994 $text = str_replace( "\x0C", '', $text );
995 $text = preg_replace_callback( '/\n[ \t]+/m', array( 'WebInstaller_Copying', 'replaceLeadingSpaces' ), $text );
996 $text = '<tt>' . nl2br( $text ) . '</tt>';
997 return $text;
1000 private static function replaceLeadingSpaces( $matches ) {
1001 return "\n" . str_repeat( '&#160;', strlen( $matches[0] ) );