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 public 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
{
121 // The status of Installer::getLocalSettingsStatus()
124 public function setLocalSettingsStatus( Status
$s ) {
128 public function execute() {
129 $r = $this->parent
->request
;
130 if( !$r->wasPosted() ||
!$this->status
->isOK() ) {
134 $key = $r->getText( 'config_wpUpgradeKey' );
135 if( !$key ||
$key !== $this->getVar( '_UpgradeKey' ) ) {
136 $this->parent
->showError( 'config-localsettings-badkey' );
140 $this->setVar( '_LocalSettingsLocked', false );
147 * Display stuff to the end user
149 private function display() {
151 $this->parent
->showStatusBox( $this->status
);
152 if( $this->status
->isOK() && !$this->status
->isGood() ) {
153 $this->addHTML( "<br />" .
154 $this->parent
->getTextBox( array(
155 'var' => 'wpUpgradeKey',
156 'label' => 'config-localsettings-key',
164 class WebInstaller_Language
extends WebInstallerPage
{
166 public function execute() {
168 $r = $this->parent
->request
;
169 $userLang = $r->getVal( 'UserLang' );
170 $contLang = $r->getVal( 'ContLang' );
172 $lifetime = intval( ini_get( 'session.gc_maxlifetime' ) );
174 $lifetime = 1440; // PHP default
177 if ( $r->wasPosted() ) {
179 if ( $this->parent
->getSession( 'test' ) === null ) {
180 $requestTime = $r->getVal( 'LanguageRequestTime' );
181 if ( !$requestTime ) {
182 // The most likely explanation is that the user was knocked back
183 // from another page on POST due to session expiry
184 $msg = 'config-session-expired';
185 } elseif ( time() - $requestTime > $lifetime ) {
186 $msg = 'config-session-expired';
188 $msg = 'config-no-session';
190 $this->parent
->showError( $msg, $wgLang->formatTimePeriod( $lifetime ) );
192 $languages = Language
::getLanguageNames();
193 if ( isset( $languages[$userLang] ) ) {
194 $this->setVar( '_UserLang', $userLang );
196 if ( isset( $languages[$contLang] ) ) {
197 $this->setVar( 'wgLanguageCode', $contLang );
199 $this->setVar( '_ExternalHTTP', $r->getBool( 'config__ExternalHTTP' ) );
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, $this->parent
->getHelpBox( 'config-your-language-help' ) ) .
219 $this->getLanguageSelector( 'ContLang', 'config-wiki-language', $contLang, $this->parent
->getHelpBox( 'config-wiki-language-help' ) ) .
220 $this->parent
->getCheckBox(
222 'var' => '_ExternalHTTP',
223 'label' => 'config-allow-requests',
224 'help' => $this->parent
->getHelpBox( 'config-allow-requests-help' )
228 $this->addHTML( $s );
233 * Get a <select> for selecting languages.
235 public function getLanguageSelector( $name, $label, $selectedCode ) {
236 global $wgDummyLanguageCodes;
237 $s = Html
::openElement( 'select', array( 'id' => $name, 'name' => $name ) ) . "\n";
239 $languages = Language
::getLanguageNames();
241 $dummies = array_flip( $wgDummyLanguageCodes );
242 foreach ( $languages as $code => $lang ) {
243 if ( isset( $dummies[$code] ) ) continue;
244 $s .= "\n" . Xml
::option( "$code - $lang", $code, $code == $selectedCode );
246 $s .= "\n</select>\n";
247 return $this->parent
->label( $label, $name, $s );
252 class WebInstaller_Welcome
extends WebInstallerPage
{
254 public function execute() {
255 if ( $this->parent
->request
->wasPosted() ) {
256 if ( $this->getVar( '_Environment' ) ) {
260 $this->parent
->output
->addWikiText( wfMsgNoTrans( 'config-welcome' ) );
261 $status = $this->parent
->doEnvironmentChecks();
263 $this->parent
->output
->addWikiText( wfMsgNoTrans( 'config-copyright',
264 SpecialVersion
::getCopyrightAndAuthorList() ) );
272 class WebInstaller_DBConnect
extends WebInstallerPage
{
274 public function execute() {
275 $r = $this->parent
->request
;
276 if ( $r->wasPosted() ) {
277 $status = $this->submit();
278 if ( $status->isGood() ) {
279 $this->setVar( '_UpgradeDone', false );
282 $this->parent
->showStatusBox( $status );
288 $types = "<ul class=\"config-settings-block\">\n";
290 $defaultType = $this->getVar( 'wgDBtype' );
293 foreach( $this->parent
->getDBTypes() as $type ) {
294 $db = 'Database' . ucfirst( $type );
295 $dbSupport .= wfMsgNoTrans( "config-support-$type",
296 call_user_func( array( $db, 'getSoftwareLink' ) ) ) . "\n";
298 $this->addHTML( $this->parent
->getInfoBox(
299 wfMsg( 'config-support-info', $dbSupport ) ) );
301 foreach ( $this->parent
->getVar( '_CompiledDBs' ) as $type ) {
302 $installer = $this->parent
->getDBInstaller( $type );
306 $installer->getReadableName(),
310 $type == $defaultType,
311 array( 'class' => 'dbRadio', 'rel' => "DB_wrapper_$type" )
316 Html
::openElement( 'div', array( 'id' => 'DB_wrapper_' . $type, 'class' => 'dbWrapper' ) ) .
317 Html
::element( 'h3', array(), wfMsg( 'config-header-' . $type ) ) .
318 $installer->getConnectForm() .
321 $types .= "</ul><br clear=\"left\"/>\n";
324 $this->parent
->label( 'config-db-type', false, $types ) .
331 public function submit() {
332 $r = $this->parent
->request
;
333 $type = $r->getVal( 'DBType' );
334 $this->setVar( 'wgDBtype', $type );
335 $installer = $this->parent
->getDBInstaller( $type );
337 return Status
::newFatal( 'config-invalid-db-type' );
339 return $installer->submitConnectForm();
344 class WebInstaller_Upgrade
extends WebInstallerPage
{
346 public function execute() {
347 if ( $this->getVar( '_UpgradeDone' ) ) {
348 if ( $this->parent
->request
->wasPosted() ) {
349 // Done message acknowledged
353 // Show the done message again
354 // Make them click back again if they want to do the upgrade again
355 $this->showDoneMessage();
360 // wgDBtype is generally valid here because otherwise the previous page
361 // (connect) wouldn't have declared its happiness
362 $type = $this->getVar( 'wgDBtype' );
363 $installer = $this->parent
->getDBInstaller( $type );
365 if ( !$installer->needsUpgrade() ) {
369 if ( $this->parent
->request
->wasPosted() ) {
370 $installer->preUpgrade();
372 '<div id="config-spinner" style="display:none;"><img src="../skins/common/images/ajax-loader.gif" /></div>' .
373 '<script>jQuery( "#config-spinner" )[0].style.display = "block";</script>' .
374 '<textarea id="config-update-log" name="UpdateLog" rows="10" readonly="readonly">'
376 $this->parent
->output
->flush();
377 $result = $installer->doUpgrade();
378 $this->addHTML( '</textarea>
379 <script>jQuery( "#config-spinner" )[0].style.display = "none";</script>' );
380 $this->parent
->output
->flush();
382 $this->setVar( '_UpgradeDone', true );
383 $this->showDoneMessage();
389 $this->addHTML( $this->parent
->getInfoBox(
390 wfMsgNoTrans( 'config-can-upgrade', $GLOBALS['wgVersion'] ) ) );
394 public function showDoneMessage() {
397 $this->parent
->getInfoBox(
398 wfMsgNoTrans( 'config-upgrade-done',
399 $GLOBALS['wgServer'] .
400 $this->getVar( 'wgScriptPath' ) . '/index' .
401 $this->getVar( 'wgScriptExtension' )
405 $this->endForm( 'regenerate' );
410 class WebInstaller_DBSettings
extends WebInstallerPage
{
412 public function execute() {
413 $installer = $this->parent
->getDBInstaller( $this->getVar( 'wgDBtype' ) );
415 $r = $this->parent
->request
;
416 if ( $r->wasPosted() ) {
417 $status = $installer->submitSettingsForm();
418 if ( $status === false ) {
420 } elseif ( $status->isGood() ) {
423 $this->parent
->showStatusBox( $status );
427 $form = $installer->getSettingsForm();
428 if ( $form === false ) {
433 $this->addHTML( $form );
439 class WebInstaller_Name
extends WebInstallerPage
{
441 public function execute() {
442 $r = $this->parent
->request
;
443 if ( $r->wasPosted() ) {
444 if ( $this->submit() ) {
451 if ( $this->getVar( 'wgSitename' ) == $GLOBALS['wgSitename'] ) {
452 $this->setVar( 'wgSitename', '' );
455 // Set wgMetaNamespace to something valid before we show the form.
456 // $wgMetaNamespace defaults to $wgSiteName which is 'MediaWiki'
457 $metaNS = $this->getVar( 'wgMetaNamespace' );
458 $this->setVar( 'wgMetaNamespace', wfMsgForContent( 'config-ns-other-default' ) );
461 $this->parent
->getTextBox( array(
462 'var' => 'wgSitename',
463 'label' => 'config-site-name',
464 'help' => $this->parent
->getHelpBox( 'config-site-name-help' )
466 $this->parent
->getRadioSet( array(
467 'var' => '_NamespaceType',
468 'label' => 'config-project-namespace',
469 'itemLabelPrefix' => 'config-ns-',
470 'values' => array( 'site-name', 'generic', 'other' ),
471 'commonAttribs' => array( 'class' => 'enableForOther', 'rel' => 'config_wgMetaNamespace' ),
472 'help' => $this->parent
->getHelpBox( 'config-project-namespace-help' )
474 $this->parent
->getTextBox( array(
475 'var' => 'wgMetaNamespace',
477 'attribs' => array( 'disabled' => '' ),
480 $this->getFieldSetStart( 'config-admin-box' ) .
481 $this->parent
->getTextBox( array(
482 'var' => '_AdminName',
483 'label' => 'config-admin-name'
485 $this->parent
->getPasswordBox( array(
486 'var' => '_AdminPassword',
487 'label' => 'config-admin-password',
488 'help' => $this->parent
->getHelpBox( 'config-admin-help' )
490 $this->parent
->getPasswordBox( array(
491 'var' => '_AdminPassword2',
492 'label' => 'config-admin-password-confirm'
494 $this->parent
->getTextBox( array(
495 'var' => '_AdminEmail',
496 'label' => 'config-admin-email',
497 'help' => $this->parent
->getHelpBox( 'config-admin-email-help' )
499 $this->parent
->getCheckBox( array(
500 'var' => '_Subscribe',
501 'label' => 'config-subscribe',
502 'help' => $this->parent
->getHelpBox( 'config-subscribe-help' )
504 $this->getFieldSetEnd() .
505 $this->parent
->getInfoBox( wfMsg( 'config-almost-done' ) ) .
506 $this->parent
->getRadioSet( array(
507 'var' => '_SkipOptional',
508 'itemLabelPrefix' => 'config-optional-',
509 'values' => array( 'continue', 'skip' )
513 // Restore the default value
514 $this->setVar( 'wgMetaNamespace', $metaNS );
520 public function submit() {
522 $this->parent
->setVarsFromRequest( array( 'wgSitename', '_NamespaceType',
523 '_AdminName', '_AdminPassword', '_AdminPassword2', '_AdminEmail',
524 '_Subscribe', '_SkipOptional' ) );
526 // Validate site name
527 if ( strval( $this->getVar( 'wgSitename' ) ) === '' ) {
528 $this->parent
->showError( 'config-site-name-blank' );
533 $nsType = $this->getVar( '_NamespaceType' );
534 if ( $nsType == 'site-name' ) {
535 $name = $this->getVar( 'wgSitename' );
536 // Sanitize for namespace
537 // This algorithm should match the JS one in WebInstallerOutput.php
538 $name = preg_replace( '/[\[\]\{\}|#<>%+? ]/', '_', $name );
539 $name = str_replace( '&', '&', $name );
540 $name = preg_replace( '/__+/', '_', $name );
541 $name = ucfirst( trim( $name, '_' ) );
542 } elseif ( $nsType == 'generic' ) {
543 $name = wfMsg( 'config-ns-generic' );
545 $name = $this->getVar( 'wgMetaNamespace' );
548 // Validate namespace
549 if ( strpos( $name, ':' ) !== false ) {
552 // Title-style validation
553 $title = Title
::newFromText( $name );
555 $good = $nsType == 'site-name';
557 $name = $title->getDBkey();
562 $this->parent
->showError( 'config-ns-invalid', $name );
565 $this->setVar( 'wgMetaNamespace', $name );
567 // Validate username for creation
568 $name = $this->getVar( '_AdminName' );
569 if ( strval( $name ) === '' ) {
570 $this->parent
->showError( 'config-admin-name-blank' );
574 $cname = User
::getCanonicalName( $name, 'creatable' );
575 if ( $cname === false ) {
576 $this->parent
->showError( 'config-admin-name-invalid', $name );
579 $this->setVar( '_AdminName', $cname );
586 $pwd = $this->getVar( '_AdminPassword' );
587 $user = User
::newFromName( $cname );
588 if ( ( isset ( $pwd ) ) && ( $user != null ) ) {
589 $valid = $user->getPasswordValidity( $pwd );
591 if ( strval( $pwd ) === '' ) {
592 # $user->getPasswordValidity just checks for $wgMinimalPasswordLength.
593 # This message is more specific and helpful.
594 $msg = 'config-admin-password-blank';
595 } elseif ( $pwd !== $this->getVar( '_AdminPassword2' ) ) {
596 $msg = 'config-admin-password-mismatch';
597 } elseif ( $valid !== true ) {
598 # As of writing this will only catch the username being e.g. 'FOO' and
602 if ( $msg !== false ) {
603 $this->parent
->showError( $msg );
604 $this->setVar( '_AdminPassword', '' );
605 $this->setVar( '_AdminPassword2', '' );
613 class WebInstaller_Options
extends WebInstallerPage
{
615 public function execute() {
616 if ( $this->getVar( '_SkipOptional' ) == 'skip' ) {
619 if ( $this->parent
->request
->wasPosted() ) {
620 if ( $this->submit() ) {
628 $this->parent
->getRadioSet( array(
629 'var' => '_RightsProfile',
630 'label' => 'config-profile',
631 'itemLabelPrefix' => 'config-profile-',
632 'values' => array_keys( $this->parent
->rightsProfiles
),
634 $this->parent
->getHelpBox( 'config-profile-help' ) .
637 $this->parent
->getRadioSet( array(
638 'var' => '_LicenseCode',
639 'label' => 'config-license',
640 'itemLabelPrefix' => 'config-license-',
641 'values' => array_keys( $this->parent
->licenses
),
642 'commonAttribs' => array( 'class' => 'licenseRadio' ),
644 $this->getCCChooser() .
645 $this->parent
->getHelpBox( 'config-license-help' ) .
648 $this->getFieldSetStart( 'config-email-settings' ) .
649 $this->parent
->getCheckBox( array(
650 'var' => 'wgEnableEmail',
651 'label' => 'config-enable-email',
652 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'emailwrapper' ),
654 $this->parent
->getHelpBox( 'config-enable-email-help' ) .
655 "<div id=\"emailwrapper\">" .
656 $this->parent
->getTextBox( array(
657 'var' => 'wgPasswordSender',
658 'label' => 'config-email-sender'
660 $this->parent
->getHelpBox( 'config-email-sender-help' ) .
661 $this->parent
->getCheckBox( array(
662 'var' => 'wgEnableUserEmail',
663 'label' => 'config-email-user',
665 $this->parent
->getHelpBox( 'config-email-user-help' ) .
666 $this->parent
->getCheckBox( array(
667 'var' => 'wgEnotifUserTalk',
668 'label' => 'config-email-usertalk',
670 $this->parent
->getHelpBox( 'config-email-usertalk-help' ) .
671 $this->parent
->getCheckBox( array(
672 'var' => 'wgEnotifWatchlist',
673 'label' => 'config-email-watchlist',
675 $this->parent
->getHelpBox( 'config-email-watchlist-help' ) .
676 $this->parent
->getCheckBox( array(
677 'var' => 'wgEmailAuthentication',
678 'label' => 'config-email-auth',
680 $this->parent
->getHelpBox( 'config-email-auth-help' ) .
682 $this->getFieldSetEnd()
685 $extensions = $this->parent
->findExtensions();
688 $extHtml = $this->getFieldSetStart( 'config-extensions' );
690 foreach( $extensions as $ext ) {
691 $extHtml .= $this->parent
->getCheckBox( array(
697 $extHtml .= $this->parent
->getHelpBox( 'config-extensions-help' ) .
698 $this->getFieldSetEnd();
699 $this->addHTML( $extHtml );
704 $this->getFieldSetStart( 'config-upload-settings' ) .
705 $this->parent
->getCheckBox( array(
706 'var' => 'wgEnableUploads',
707 'label' => 'config-upload-enable',
708 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'uploadwrapper' ),
709 'help' => $this->parent
->getHelpBox( 'config-upload-help' )
711 '<div id="uploadwrapper" style="display: none;">' .
712 $this->parent
->getTextBox( array(
713 'var' => 'wgDeletedDirectory',
714 'label' => 'config-upload-deleted',
715 'help' => $this->parent
->getHelpBox( 'config-upload-deleted-help' )
718 $this->parent
->getTextBox( array(
720 'label' => 'config-logo',
721 'help' => $this->parent
->getHelpBox( 'config-logo-help' )
724 $canUse = $this->getVar( '_ExternalHTTP' ) ?
725 'config-instantcommons-good' : 'config-instantcommons-bad';
727 $this->parent
->getCheckBox( array(
728 'var' => 'wgUseInstantCommons',
729 'label' => 'config-instantcommons',
730 'help' => $this->parent
->getHelpBox( 'config-instantcommons-help', wfMsgNoTrans( $canUse ) )
732 $this->getFieldSetEnd()
735 $caches = array( 'none' );
736 if( count( $this->getVar( '_Caches' ) ) ) {
739 $caches[] = 'memcached';
743 $this->getFieldSetStart( 'config-advanced-settings' ) .
744 # Object cache settings
745 $this->parent
->getRadioSet( array(
746 'var' => 'wgMainCacheType',
747 'label' => 'config-cache-options',
748 'itemLabelPrefix' => 'config-cache-',
752 $this->parent
->getHelpBox( 'config-cache-help' ) .
753 '<div id="config-memcachewrapper">' .
754 $this->parent
->getTextBox( array(
755 'var' => '_MemCachedServers',
756 'label' => 'config-memcached-servers',
757 'help' => $this->parent
->getHelpBox( 'config-memcached-help' )
760 $this->getFieldSetEnd()
765 public function getCCPartnerUrl() {
767 $exitUrl = $wgServer . $this->parent
->getUrl( array(
769 'SubmitCC' => 'indeed',
770 'config__LicenseCode' => 'cc',
771 'config_wgRightsUrl' => '[license_url]',
772 'config_wgRightsText' => '[license_name]',
773 'config_wgRightsIcon' => '[license_button]',
775 $styleUrl = $wgServer . dirname( dirname( $this->parent
->getUrl() ) ) .
776 '/skins/common/config-cc.css';
777 $iframeUrl = 'http://creativecommons.org/license/?' .
779 'partner' => 'MediaWiki',
780 'exit_url' => $exitUrl,
781 'lang' => $this->getVar( '_UserLang' ),
782 'stylesheet' => $styleUrl,
787 public function getCCChooser() {
788 $iframeAttribs = array(
789 'class' => 'config-cc-iframe',
790 'name' => 'config-cc-iframe',
791 'id' => 'config-cc-iframe',
796 if ( $this->getVar( '_CCDone' ) ) {
797 $iframeAttribs['src'] = $this->parent
->getUrl( array( 'ShowCC' => 'yes' ) );
799 $iframeAttribs['src'] = $this->getCCPartnerUrl();
803 "<div class=\"config-cc-wrapper\" id=\"config-cc-wrapper\" style=\"display: none;\">\n" .
804 Html
::element( 'iframe', $iframeAttribs, '', false /* not short */ ) .
808 public function getCCDoneBox() {
809 $js = "parent.document.getElementById('config-cc-wrapper').style.height = '$1';";
810 // If you change this height, also change it in config.css
811 $expandJs = str_replace( '$1', '54em', $js );
812 $reduceJs = str_replace( '$1', '70px', $js );
815 Html
::element( 'img', array( 'src' => $this->getVar( 'wgRightsIcon' ) ) ) .
817 htmlspecialchars( $this->getVar( 'wgRightsText' ) ) .
819 "<p style=\"text-align: center\">" .
822 'href' => $this->getCCPartnerUrl(),
823 'onclick' => $expandJs,
825 wfMsg( 'config-cc-again' )
828 "<script type=\"text/javascript\">\n" .
829 # Reduce the wrapper div height
830 htmlspecialchars( $reduceJs ) .
835 public function submitCC() {
836 $newValues = $this->parent
->setVarsFromRequest(
837 array( 'wgRightsUrl', 'wgRightsText', 'wgRightsIcon' ) );
838 if ( count( $newValues ) != 3 ) {
839 $this->parent
->showError( 'config-cc-error' );
842 $this->setVar( '_CCDone', true );
843 $this->addHTML( $this->getCCDoneBox() );
846 public function submit() {
847 $this->parent
->setVarsFromRequest( array( '_RightsProfile', '_LicenseCode',
848 'wgEnableEmail', 'wgPasswordSender', 'wgEnableUploads', 'wgLogo',
849 'wgEnableUserEmail', 'wgEnotifUserTalk', 'wgEnotifWatchlist',
850 'wgEmailAuthentication', 'wgMainCacheType', '_MemCachedServers',
851 'wgUseInstantCommons' ) );
853 if ( !in_array( $this->getVar( '_RightsProfile' ),
854 array_keys( $this->parent
->rightsProfiles
) ) )
856 reset( $this->parent
->rightsProfiles
);
857 $this->setVar( '_RightsProfile', key( $this->parent
->rightsProfiles
) );
860 $code = $this->getVar( '_LicenseCode' );
861 if ( $code == 'cc-choose' ) {
862 if ( !$this->getVar( '_CCDone' ) ) {
863 $this->parent
->showError( 'config-cc-not-chosen' );
866 } elseif ( in_array( $code, array_keys( $this->parent
->licenses
) ) ) {
867 $entry = $this->parent
->licenses
[$code];
868 if ( isset( $entry['text'] ) ) {
869 $this->setVar( 'wgRightsText', $entry['text'] );
871 $this->setVar( 'wgRightsText', wfMsg( 'config-license-' . $code ) );
873 $this->setVar( 'wgRightsUrl', $entry['url'] );
874 $this->setVar( 'wgRightsIcon', $entry['icon'] );
876 $this->setVar( 'wgRightsText', '' );
877 $this->setVar( 'wgRightsUrl', '' );
878 $this->setVar( 'wgRightsIcon', '' );
881 $extsAvailable = $this->parent
->findExtensions();
882 $extsToInstall = array();
883 foreach( $extsAvailable as $ext ) {
884 if( $this->parent
->request
->getCheck( 'config_ext-' . $ext ) ) {
885 $extsToInstall[] = $ext;
888 $this->parent
->setVar( '_Extensions', $extsToInstall );
894 class WebInstaller_Install
extends WebInstallerPage
{
896 public function execute() {
897 if( $this->parent
->request
->wasPosted() ) {
899 } elseif( $this->getVar( '_InstallDone' ) ) {
901 $status = new Status();
902 $status->warning( 'config-install-alreadydone' );
903 $this->parent
->showStatusBox( $status );
904 } elseif( $this->getVar( '_UpgradeDone' ) ) {
908 $this->addHTML("<ul>");
909 $this->parent
->performInstallation(
910 array( $this, 'startStage'),
911 array( $this, 'endStage' )
913 $this->addHTML("</ul>");
919 public function startStage( $step ) {
920 $this->addHTML( "<li>" . wfMsgHtml( "config-install-$step" ) . wfMsg( 'ellipsis') );
923 public function endStage( $step, $status ) {
924 $msg = $status->isOk() ?
'config-install-step-done' : 'config-install-step-failed';
925 $html = wfMsgHtml( 'word-separator' ) . wfMsgHtml( $msg );
926 if ( !$status->isOk() ) {
927 $html = "<span class=\"error\">$html</span>";
929 $this->addHTML( $html . "</li>\n" );
930 if( !$status->isGood() ) {
931 $this->parent
->showStatusBox( $status );
937 class WebInstaller_Complete
extends WebInstallerPage
{
939 public function execute() {
942 $this->parent
->getInfoBox(
943 wfMsgNoTrans( 'config-install-done',
944 $GLOBALS['wgServer'] . $this->parent
->getURL( array( 'localsettings' => 1 ) ),
945 $GLOBALS['wgServer'] .
946 $this->getVar( 'wgScriptPath' ) . '/index' .
947 $this->getVar( 'wgScriptExtension' )
951 $this->endForm( false );
955 class WebInstaller_Restart
extends WebInstallerPage
{
957 public function execute() {
958 $r = $this->parent
->request
;
959 if ( $r->wasPosted() ) {
960 $really = $r->getVal( 'submit-restart' );
962 $this->parent
->session
= array();
963 $this->parent
->happyPages
= array();
964 $this->parent
->settings
= array();
970 $s = $this->parent
->getWarningBox( wfMsgNoTrans( 'config-help-restart' ) );
971 $this->addHTML( $s );
972 $this->endForm( 'restart' );
977 abstract class WebInstaller_Document
extends WebInstallerPage
{
979 protected abstract function getFileName();
981 public function execute() {
982 $text = $this->getFileContents();
983 $this->parent
->output
->addWikiText( $text );
985 $this->endForm( false );
988 public function getFileContents() {
989 return file_get_contents( dirname( __FILE__
) . '/../../' . $this->getFileName() );
992 protected function formatTextFile( $text ) {
993 $text = str_replace( array( '<', '{{', '[[' ),
994 array( '<', '{{', '[[' ), $text );
995 // replace numbering with [1], [2], etc with MW-style numbering
996 $text = preg_replace( "/\r?\n(\r?\n)?\\[\\d+\\]/m", "\\1#", $text );
997 // join word-wrapped lines into one
1000 $text = preg_replace( "/\n([\\*#])([^\r\n]*?)\r?\n([^\r\n#\\*:]+)/", "\n\\1\\2 \\3", $text );
1001 } while ( $text != $prev );
1002 // turn (bug nnnn) into links
1003 $text = preg_replace_callback('/bug (\d+)/', array( $this, 'replaceBugLinks' ), $text );
1004 // add links to manual to every global variable mentioned
1005 $text = preg_replace_callback('/(\$wg[a-z0-9_]+)/i', array( $this, 'replaceConfigLinks' ), $text );
1006 // special case for <pre> - formatted links
1009 $text = preg_replace( '/^([^\\s].*?)\r?\n[\\s]+(https?:\/\/)/m', "\\1\n:\\2", $text );
1010 } while ( $text != $prev );
1014 private function replaceBugLinks( $matches ) {
1015 return '<span class="config-plainlink">[https://bugzilla.wikimedia.org/' .
1016 $matches[1] . ' bug ' . $matches[1] . ']</span>';
1019 private function replaceConfigLinks( $matches ) {
1020 return '<span class="config-plainlink">[http://www.mediawiki.org/wiki/Manual:' .
1021 $matches[1] . ' ' . $matches[1] . ']</span>';
1026 class WebInstaller_Readme
extends WebInstaller_Document
{
1028 protected function getFileName() { return 'README'; }
1030 public function getFileContents() {
1031 return $this->formatTextFile( parent
::getFileContents() );
1036 class WebInstaller_ReleaseNotes
extends WebInstaller_Document
{
1038 protected function getFileName() { return 'RELEASE-NOTES'; }
1040 public function getFileContents() {
1041 return $this->formatTextFile( parent
::getFileContents() );
1046 class WebInstaller_UpgradeDoc
extends WebInstaller_Document
{
1048 protected function getFileName() { return 'UPGRADE'; }
1050 public function getFileContents() {
1051 return $this->formatTextFile( parent
::getFileContents() );
1056 class WebInstaller_Copying
extends WebInstaller_Document
{
1058 protected function getFileName() { return 'COPYING'; }
1060 public function getFileContents() {
1061 $text = parent
::getFileContents();
1062 $text = str_replace( "\x0C", '', $text );
1063 $text = preg_replace_callback( '/\n[ \t]+/m', array( 'WebInstaller_Copying', 'replaceLeadingSpaces' ), $text );
1064 $text = '<tt>' . nl2br( $text ) . '</tt>';
1068 private static function replaceLeadingSpaces( $matches ) {
1069 return "\n" . str_repeat( ' ', strlen( $matches[0] ) );