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 (bug 26267)
62 $s .= Xml
::submitButton( wfMsg( "config-$continue" ),
63 array( 'name' => "enter-$continue", 'style' => 'visibility:hidden;overflow:hidden;width:1px;margin:0' ) ) . "\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_Language
extends WebInstallerPage
{
121 public function execute() {
123 $r = $this->parent
->request
;
124 $userLang = $r->getVal( 'UserLang' );
125 $contLang = $r->getVal( 'ContLang' );
127 $lifetime = intval( ini_get( 'session.gc_maxlifetime' ) );
129 $lifetime = 1440; // PHP default
132 if ( $r->wasPosted() ) {
134 if ( $this->parent
->getSession( 'test' ) === null ) {
135 $requestTime = $r->getVal( 'LanguageRequestTime' );
136 if ( !$requestTime ) {
137 // The most likely explanation is that the user was knocked back
138 // from another page on POST due to session expiry
139 $msg = 'config-session-expired';
140 } elseif ( time() - $requestTime > $lifetime ) {
141 $msg = 'config-session-expired';
143 $msg = 'config-no-session';
145 $this->parent
->showError( $msg, $wgLang->formatTimePeriod( $lifetime ) );
147 $languages = Language
::getLanguageNames();
148 if ( isset( $languages[$userLang] ) ) {
149 $this->setVar( '_UserLang', $userLang );
151 if ( isset( $languages[$contLang] ) ) {
152 $this->setVar( 'wgLanguageCode', $contLang );
156 } elseif ( $this->parent
->showSessionWarning
) {
157 # The user was knocked back from another page to the start
158 # This probably indicates a session expiry
159 $this->parent
->showError( 'config-session-expired', $wgLang->formatTimePeriod( $lifetime ) );
162 $this->parent
->setSession( 'test', true );
164 if ( !isset( $languages[$userLang] ) ) {
165 $userLang = $this->getVar( '_UserLang', 'en' );
167 if ( !isset( $languages[$contLang] ) ) {
168 $contLang = $this->getVar( 'wgLanguageCode', 'en' );
171 $s = Html
::hidden( 'LanguageRequestTime', time() ) .
172 $this->getLanguageSelector( 'UserLang', 'config-your-language', $userLang, $this->parent
->getHelpBox( 'config-your-language-help' ) ) .
173 $this->getLanguageSelector( 'ContLang', 'config-wiki-language', $contLang, $this->parent
->getHelpBox( 'config-wiki-language-help' ) );
174 $this->addHTML( $s );
179 * Get a <select> for selecting languages.
181 public function getLanguageSelector( $name, $label, $selectedCode ) {
182 global $wgDummyLanguageCodes;
183 $s = Html
::openElement( 'select', array( 'id' => $name, 'name' => $name ) ) . "\n";
185 $languages = Language
::getLanguageNames();
187 $dummies = array_flip( $wgDummyLanguageCodes );
188 foreach ( $languages as $code => $lang ) {
189 if ( isset( $dummies[$code] ) ) continue;
190 $s .= "\n" . Xml
::option( "$code - $lang", $code, $code == $selectedCode );
192 $s .= "\n</select>\n";
193 return $this->parent
->label( $label, $name, $s );
198 class WebInstaller_ExistingWiki
extends WebInstallerPage
{
199 public function execute() {
200 // If there is no LocalSettings.php, continue to the installer welcome page
201 $vars = $this->parent
->getExistingLocalSettings();
206 // Check if the upgrade key supplied to the user has appeared in LocalSettings.php
207 if ( $vars['wgUpgradeKey'] !== false
208 && $this->getVar( '_UpgradeKeySupplied' )
209 && $this->getVar( 'wgUpgradeKey' ) === $vars['wgUpgradeKey'] )
211 // It's there, so the user is authorized
212 $status = $this->handleExistingUpgrade( $vars );
213 if ( $status->isOK() ) {
217 $this->parent
->showStatusBox( $status );
218 $this->endForm( 'continue' );
221 return $this->handleExistingUpgrade( $vars );
224 // If there is no $wgUpgradeKey, tell the user to add one to LocalSettings.php
225 if ( $vars['wgUpgradeKey'] === false ) {
226 if ( $this->getVar( 'wgUpgradeKey', false ) === false ) {
227 $this->parent
->generateUpgradeKey();
228 $this->setVar( '_UpgradeKeySupplied', true );
231 $this->addHTML( $this->parent
->getInfoBox(
232 wfMsgNoTrans( 'config-upgrade-key-missing',
233 "<pre>\$wgUpgradeKey = '" . $this->getVar( 'wgUpgradeKey' ) . "';</pre>" )
235 $this->endForm( 'continue' );
239 // If there is an upgrade key, but it wasn't supplied, prompt the user to enter it
241 $r = $this->parent
->request
;
242 if ( $r->wasPosted() ) {
243 $key = $r->getText( 'config_wgUpgradeKey' );
244 if( !$key ||
$key !== $vars['wgUpgradeKey'] ) {
245 $this->parent
->showError( 'config-localsettings-badkey' );
246 $this->showKeyForm();
250 $status = $this->handleExistingUpgrade( $vars );
251 if ( $status->isOK() ) {
254 $this->parent
->showStatusBox( $status );
255 $this->showKeyForm();
259 $this->showKeyForm();
265 * Show the "enter key" form
267 protected function showKeyForm() {
270 $this->parent
->getInfoBox( wfMsgNoTrans( 'config-localsettings-upgrade' ) ).
272 $this->parent
->getTextBox( array(
273 'var' => 'wgUpgradeKey',
274 'label' => 'config-localsettings-key',
275 'attribs' => array( 'autocomplete' => 'off' ),
278 $this->endForm( 'continue' );
281 protected function importVariables( $names, $vars ) {
282 $status = Status
::newGood();
283 foreach ( $names as $name ) {
284 if ( !isset( $vars[$name] ) ) {
285 $status->fatal( 'config-localsettings-incomplete', $name );
287 $this->setVar( $name, $vars[$name] );
293 * Initiate an upgrade of the existing database
294 * @param $vars Variables from LocalSettings.php and AdminSettings.php
297 protected function handleExistingUpgrade( $vars ) {
299 if ( !isset( $vars['wgDBtype'] ) ||
!in_array( $vars['wgDBtype'], Installer
::getDBTypes() ) ) {
300 return Status
::newFatal( 'config-localsettings-connection-error', '' );
303 // Set the relevant variables from LocalSettings.php
304 $requiredVars = array( 'wgDBtype', 'wgDBuser', 'wgDBpassword' );
305 $status = $this->importVariables( $requiredVars , $vars );
306 $installer = $this->parent
->getDBInstaller();
307 $status->merge( $this->importVariables( $installer->getGlobalNames(), $vars ) );
308 if ( !$status->isOK() ) {
312 if ( isset( $vars['wgDBadminuser'] ) ) {
313 $this->setVar( '_InstallUser', $vars['wgDBadminuser'] );
315 $this->setVar( '_InstallUser', $vars['wgDBuser'] );
317 if ( isset( $vars['wgDBadminpassword'] ) ) {
318 $this->setVar( '_InstallPassword', $vars['wgDBadminpassword'] );
320 $this->setVar( '_InstallPassword', $vars['wgDBpassword'] );
323 // Test the database connection
324 $status = $installer->getConnection();
325 if ( !$status->isOK() ) {
326 // Adjust the error message to explain things correctly
327 $status->replaceMessage( 'config-connection-error',
328 'config-localsettings-connection-error' );
333 $this->setVar( '_ExistingDBSettings', true );
338 class WebInstaller_Welcome
extends WebInstallerPage
{
340 public function execute() {
341 if ( $this->parent
->request
->wasPosted() ) {
342 if ( $this->getVar( '_Environment' ) ) {
346 $this->parent
->output
->addWikiText( wfMsgNoTrans( 'config-welcome' ) );
347 $status = $this->parent
->doEnvironmentChecks();
349 $this->parent
->output
->addWikiText( wfMsgNoTrans( 'config-copyright',
350 SpecialVersion
::getCopyrightAndAuthorList() ) );
358 class WebInstaller_DBConnect
extends WebInstallerPage
{
360 public function execute() {
361 if ( $this->getVar( '_ExistingDBSettings' ) ) {
365 $r = $this->parent
->request
;
366 if ( $r->wasPosted() ) {
367 $status = $this->submit();
368 if ( $status->isGood() ) {
369 $this->setVar( '_UpgradeDone', false );
372 $this->parent
->showStatusBox( $status );
378 $types = "<ul class=\"config-settings-block\">\n";
380 $defaultType = $this->getVar( 'wgDBtype' );
383 foreach( $this->parent
->getDBTypes() as $type ) {
384 $db = 'Database' . ucfirst( $type );
385 $dbSupport .= wfMsgNoTrans( "config-support-$type",
386 call_user_func( array( $db, 'getSoftwareLink' ) ) ) . "\n";
388 $this->addHTML( $this->parent
->getInfoBox(
389 wfMsg( 'config-support-info', $dbSupport ) ) );
391 foreach ( $this->parent
->getVar( '_CompiledDBs' ) as $type ) {
392 $installer = $this->parent
->getDBInstaller( $type );
396 $installer->getReadableName(),
400 $type == $defaultType,
401 array( 'class' => 'dbRadio', 'rel' => "DB_wrapper_$type" )
406 Html
::openElement( 'div', array( 'id' => 'DB_wrapper_' . $type, 'class' => 'dbWrapper' ) ) .
407 Html
::element( 'h3', array(), wfMsg( 'config-header-' . $type ) ) .
408 $installer->getConnectForm() .
411 $types .= "</ul><br clear=\"left\"/>\n";
414 $this->parent
->label( 'config-db-type', false, $types ) .
421 public function submit() {
422 $r = $this->parent
->request
;
423 $type = $r->getVal( 'DBType' );
424 $this->setVar( 'wgDBtype', $type );
425 $installer = $this->parent
->getDBInstaller( $type );
427 return Status
::newFatal( 'config-invalid-db-type' );
429 return $installer->submitConnectForm();
434 class WebInstaller_Upgrade
extends WebInstallerPage
{
436 public function execute() {
437 if ( $this->getVar( '_UpgradeDone' ) ) {
438 if ( $this->parent
->request
->wasPosted() ) {
439 // Done message acknowledged
443 // Show the done message again
444 // Make them click back again if they want to do the upgrade again
445 $this->showDoneMessage();
450 // wgDBtype is generally valid here because otherwise the previous page
451 // (connect) wouldn't have declared its happiness
452 $type = $this->getVar( 'wgDBtype' );
453 $installer = $this->parent
->getDBInstaller( $type );
455 if ( !$installer->needsUpgrade() ) {
459 if ( $this->parent
->request
->wasPosted() ) {
460 $installer->preUpgrade();
462 '<div id="config-spinner" style="display:none;"><img src="../skins/common/images/ajax-loader.gif" /></div>' .
463 '<script>jQuery( "#config-spinner" )[0].style.display = "block";</script>' .
464 '<textarea id="config-update-log" name="UpdateLog" rows="10" readonly="readonly">'
466 $this->parent
->output
->flush();
467 $result = $installer->doUpgrade();
468 $this->addHTML( '</textarea>
469 <script>jQuery( "#config-spinner" )[0].style.display = "none";</script>' );
470 $this->parent
->output
->flush();
472 $this->setVar( '_UpgradeDone', true );
473 $this->showDoneMessage();
479 $this->addHTML( $this->parent
->getInfoBox(
480 wfMsgNoTrans( 'config-can-upgrade', $GLOBALS['wgVersion'] ) ) );
484 public function showDoneMessage() {
487 $this->parent
->getInfoBox(
488 wfMsgNoTrans( 'config-upgrade-done',
489 $GLOBALS['wgServer'] .
490 $this->getVar( 'wgScriptPath' ) . '/index' .
491 $this->getVar( 'wgScriptExtension' )
495 $this->endForm( 'regenerate' );
500 class WebInstaller_DBSettings
extends WebInstallerPage
{
502 public function execute() {
503 $installer = $this->parent
->getDBInstaller( $this->getVar( 'wgDBtype' ) );
505 $r = $this->parent
->request
;
506 if ( $r->wasPosted() ) {
507 $status = $installer->submitSettingsForm();
508 if ( $status === false ) {
510 } elseif ( $status->isGood() ) {
513 $this->parent
->showStatusBox( $status );
517 $form = $installer->getSettingsForm();
518 if ( $form === false ) {
523 $this->addHTML( $form );
529 class WebInstaller_Name
extends WebInstallerPage
{
531 public function execute() {
532 $r = $this->parent
->request
;
533 if ( $r->wasPosted() ) {
534 if ( $this->submit() ) {
541 if ( $this->getVar( 'wgSitename' ) == $GLOBALS['wgSitename'] ) {
542 $this->setVar( 'wgSitename', '' );
545 // Set wgMetaNamespace to something valid before we show the form.
546 // $wgMetaNamespace defaults to $wgSiteName which is 'MediaWiki'
547 $metaNS = $this->getVar( 'wgMetaNamespace' );
548 $this->setVar( 'wgMetaNamespace', wfMsgForContent( 'config-ns-other-default' ) );
551 $this->parent
->getTextBox( array(
552 'var' => 'wgSitename',
553 'label' => 'config-site-name',
554 'help' => $this->parent
->getHelpBox( 'config-site-name-help' )
556 $this->parent
->getRadioSet( array(
557 'var' => '_NamespaceType',
558 'label' => 'config-project-namespace',
559 'itemLabelPrefix' => 'config-ns-',
560 'values' => array( 'site-name', 'generic', 'other' ),
561 'commonAttribs' => array( 'class' => 'enableForOther', 'rel' => 'config_wgMetaNamespace' ),
562 'help' => $this->parent
->getHelpBox( 'config-project-namespace-help' )
564 $this->parent
->getTextBox( array(
565 'var' => 'wgMetaNamespace',
566 'label' => '', //TODO: Needs a label?
567 'attribs' => array( 'readonly' => 'readonly', 'class' => 'enabledByOther' ),
570 $this->getFieldSetStart( 'config-admin-box' ) .
571 $this->parent
->getTextBox( array(
572 'var' => '_AdminName',
573 'label' => 'config-admin-name',
574 'help' => $this->parent
->getHelpBox( 'config-admin-help' )
576 $this->parent
->getPasswordBox( array(
577 'var' => '_AdminPassword',
578 'label' => 'config-admin-password',
580 $this->parent
->getPasswordBox( array(
581 'var' => '_AdminPassword2',
582 'label' => 'config-admin-password-confirm'
584 $this->parent
->getTextBox( array(
585 'var' => '_AdminEmail',
586 'label' => 'config-admin-email',
587 'help' => $this->parent
->getHelpBox( 'config-admin-email-help' )
589 $this->parent
->getCheckBox( array(
590 'var' => '_Subscribe',
591 'label' => 'config-subscribe',
592 'help' => $this->parent
->getHelpBox( 'config-subscribe-help' )
594 $this->getFieldSetEnd() .
595 $this->parent
->getInfoBox( wfMsg( 'config-almost-done' ) ) .
596 $this->parent
->getRadioSet( array(
597 'var' => '_SkipOptional',
598 'itemLabelPrefix' => 'config-optional-',
599 'values' => array( 'continue', 'skip' )
603 // Restore the default value
604 $this->setVar( 'wgMetaNamespace', $metaNS );
610 public function submit() {
612 $this->parent
->setVarsFromRequest( array( 'wgSitename', '_NamespaceType',
613 '_AdminName', '_AdminPassword', '_AdminPassword2', '_AdminEmail',
614 '_Subscribe', '_SkipOptional' ) );
616 // Validate site name
617 if ( strval( $this->getVar( 'wgSitename' ) ) === '' ) {
618 $this->parent
->showError( 'config-site-name-blank' );
623 $nsType = $this->getVar( '_NamespaceType' );
624 if ( $nsType == 'site-name' ) {
625 $name = $this->getVar( 'wgSitename' );
626 // Sanitize for namespace
627 // This algorithm should match the JS one in WebInstallerOutput.php
628 $name = preg_replace( '/[\[\]\{\}|#<>%+? ]/', '_', $name );
629 $name = str_replace( '&', '&', $name );
630 $name = preg_replace( '/__+/', '_', $name );
631 $name = ucfirst( trim( $name, '_' ) );
632 } elseif ( $nsType == 'generic' ) {
633 $name = wfMsg( 'config-ns-generic' );
635 $name = $this->getVar( 'wgMetaNamespace' );
638 // Validate namespace
639 if ( strpos( $name, ':' ) !== false ) {
642 // Title-style validation
643 $title = Title
::newFromText( $name );
645 $good = $nsType == 'site-name';
647 $name = $title->getDBkey();
652 $this->parent
->showError( 'config-ns-invalid', $name );
655 $this->setVar( 'wgMetaNamespace', $name );
657 // Validate username for creation
658 $name = $this->getVar( '_AdminName' );
659 if ( strval( $name ) === '' ) {
660 $this->parent
->showError( 'config-admin-name-blank' );
664 $cname = User
::getCanonicalName( $name, 'creatable' );
665 if ( $cname === false ) {
666 $this->parent
->showError( 'config-admin-name-invalid', $name );
669 $this->setVar( '_AdminName', $cname );
676 $pwd = $this->getVar( '_AdminPassword' );
677 $user = User
::newFromName( $cname );
678 $valid = $user && $user->getPasswordValidity( $pwd );
679 if ( strval( $pwd ) === '' ) {
680 # $user->getPasswordValidity just checks for $wgMinimalPasswordLength.
681 # This message is more specific and helpful.
682 $msg = 'config-admin-password-blank';
683 } elseif ( $pwd !== $this->getVar( '_AdminPassword2' ) ) {
684 $msg = 'config-admin-password-mismatch';
685 } elseif ( $valid !== true ) {
686 # As of writing this will only catch the username being e.g. 'FOO' and
690 if ( $msg !== false ) {
691 $this->parent
->showError( $msg );
692 $this->setVar( '_AdminPassword', '' );
693 $this->setVar( '_AdminPassword2', '' );
701 class WebInstaller_Options
extends WebInstallerPage
{
703 public function execute() {
704 if ( $this->getVar( '_SkipOptional' ) == 'skip' ) {
707 if ( $this->parent
->request
->wasPosted() ) {
708 if ( $this->submit() ) {
716 $this->parent
->getRadioSet( array(
717 'var' => '_RightsProfile',
718 'label' => 'config-profile',
719 'itemLabelPrefix' => 'config-profile-',
720 'values' => array_keys( $this->parent
->rightsProfiles
),
722 $this->parent
->getHelpBox( 'config-profile-help' ) .
725 $this->parent
->getRadioSet( array(
726 'var' => '_LicenseCode',
727 'label' => 'config-license',
728 'itemLabelPrefix' => 'config-license-',
729 'values' => array_keys( $this->parent
->licenses
),
730 'commonAttribs' => array( 'class' => 'licenseRadio' ),
732 $this->getCCChooser() .
733 $this->parent
->getHelpBox( 'config-license-help' ) .
736 $this->getFieldSetStart( 'config-email-settings' ) .
737 $this->parent
->getCheckBox( array(
738 'var' => 'wgEnableEmail',
739 'label' => 'config-enable-email',
740 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'emailwrapper' ),
742 $this->parent
->getHelpBox( 'config-enable-email-help' ) .
743 "<div id=\"emailwrapper\">" .
744 $this->parent
->getTextBox( array(
745 'var' => 'wgPasswordSender',
746 'label' => 'config-email-sender'
748 $this->parent
->getHelpBox( 'config-email-sender-help' ) .
749 $this->parent
->getCheckBox( array(
750 'var' => 'wgEnableUserEmail',
751 'label' => 'config-email-user',
753 $this->parent
->getHelpBox( 'config-email-user-help' ) .
754 $this->parent
->getCheckBox( array(
755 'var' => 'wgEnotifUserTalk',
756 'label' => 'config-email-usertalk',
758 $this->parent
->getHelpBox( 'config-email-usertalk-help' ) .
759 $this->parent
->getCheckBox( array(
760 'var' => 'wgEnotifWatchlist',
761 'label' => 'config-email-watchlist',
763 $this->parent
->getHelpBox( 'config-email-watchlist-help' ) .
764 $this->parent
->getCheckBox( array(
765 'var' => 'wgEmailAuthentication',
766 'label' => 'config-email-auth',
768 $this->parent
->getHelpBox( 'config-email-auth-help' ) .
770 $this->getFieldSetEnd()
773 $extensions = $this->parent
->findExtensions();
776 $extHtml = $this->getFieldSetStart( 'config-extensions' );
778 foreach( $extensions as $ext ) {
779 $extHtml .= $this->parent
->getCheckBox( array(
785 $extHtml .= $this->parent
->getHelpBox( 'config-extensions-help' ) .
786 $this->getFieldSetEnd();
787 $this->addHTML( $extHtml );
792 $this->getFieldSetStart( 'config-upload-settings' ) .
793 $this->parent
->getCheckBox( array(
794 'var' => 'wgEnableUploads',
795 'label' => 'config-upload-enable',
796 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'uploadwrapper' ),
797 'help' => $this->parent
->getHelpBox( 'config-upload-help' )
799 '<div id="uploadwrapper" style="display: none;">' .
800 $this->parent
->getTextBox( array(
801 'var' => 'wgDeletedDirectory',
802 'label' => 'config-upload-deleted',
803 'help' => $this->parent
->getHelpBox( 'config-upload-deleted-help' )
806 $this->parent
->getTextBox( array(
808 'label' => 'config-logo',
809 'help' => $this->parent
->getHelpBox( 'config-logo-help' )
813 $this->parent
->getCheckBox( array(
814 'var' => 'wgUseInstantCommons',
815 'label' => 'config-instantcommons',
816 'help' => $this->parent
->getHelpBox( 'config-instantcommons-help' )
818 $this->getFieldSetEnd()
821 $caches = array( 'none' );
822 if( count( $this->getVar( '_Caches' ) ) ) {
825 $caches[] = 'memcached';
829 $this->getFieldSetStart( 'config-advanced-settings' ) .
830 # Object cache settings
831 $this->parent
->getRadioSet( array(
832 'var' => 'wgMainCacheType',
833 'label' => 'config-cache-options',
834 'itemLabelPrefix' => 'config-cache-',
838 $this->parent
->getHelpBox( 'config-cache-help' ) .
839 '<div id="config-memcachewrapper">' .
840 $this->parent
->getTextBox( array(
841 'var' => '_MemCachedServers',
842 'label' => 'config-memcached-servers',
843 'help' => $this->parent
->getHelpBox( 'config-memcached-help' )
846 $this->getFieldSetEnd()
851 public function getCCPartnerUrl() {
853 $exitUrl = $wgServer . $this->parent
->getUrl( array(
855 'SubmitCC' => 'indeed',
856 'config__LicenseCode' => 'cc',
857 'config_wgRightsUrl' => '[license_url]',
858 'config_wgRightsText' => '[license_name]',
859 'config_wgRightsIcon' => '[license_button]',
861 $styleUrl = $wgServer . dirname( dirname( $this->parent
->getUrl() ) ) .
862 '/skins/common/config-cc.css';
863 $iframeUrl = 'http://creativecommons.org/license/?' .
865 'partner' => 'MediaWiki',
866 'exit_url' => $exitUrl,
867 'lang' => $this->getVar( '_UserLang' ),
868 'stylesheet' => $styleUrl,
873 public function getCCChooser() {
874 $iframeAttribs = array(
875 'class' => 'config-cc-iframe',
876 'name' => 'config-cc-iframe',
877 'id' => 'config-cc-iframe',
882 if ( $this->getVar( '_CCDone' ) ) {
883 $iframeAttribs['src'] = $this->parent
->getUrl( array( 'ShowCC' => 'yes' ) );
885 $iframeAttribs['src'] = $this->getCCPartnerUrl();
889 "<div class=\"config-cc-wrapper\" id=\"config-cc-wrapper\" style=\"display: none;\">\n" .
890 Html
::element( 'iframe', $iframeAttribs, '', false /* not short */ ) .
894 public function getCCDoneBox() {
895 $js = "parent.document.getElementById('config-cc-wrapper').style.height = '$1';";
896 // If you change this height, also change it in config.css
897 $expandJs = str_replace( '$1', '54em', $js );
898 $reduceJs = str_replace( '$1', '70px', $js );
901 Html
::element( 'img', array( 'src' => $this->getVar( 'wgRightsIcon' ) ) ) .
903 htmlspecialchars( $this->getVar( 'wgRightsText' ) ) .
905 "<p style=\"text-align: center\">" .
908 'href' => $this->getCCPartnerUrl(),
909 'onclick' => $expandJs,
911 wfMsg( 'config-cc-again' )
914 "<script type=\"text/javascript\">\n" .
915 # Reduce the wrapper div height
916 htmlspecialchars( $reduceJs ) .
921 public function submitCC() {
922 $newValues = $this->parent
->setVarsFromRequest(
923 array( 'wgRightsUrl', 'wgRightsText', 'wgRightsIcon' ) );
924 if ( count( $newValues ) != 3 ) {
925 $this->parent
->showError( 'config-cc-error' );
928 $this->setVar( '_CCDone', true );
929 $this->addHTML( $this->getCCDoneBox() );
932 public function submit() {
933 $this->parent
->setVarsFromRequest( array( '_RightsProfile', '_LicenseCode',
934 'wgEnableEmail', 'wgPasswordSender', 'wgEnableUploads', 'wgLogo',
935 'wgEnableUserEmail', 'wgEnotifUserTalk', 'wgEnotifWatchlist',
936 'wgEmailAuthentication', 'wgMainCacheType', '_MemCachedServers',
937 'wgUseInstantCommons' ) );
939 if ( !in_array( $this->getVar( '_RightsProfile' ),
940 array_keys( $this->parent
->rightsProfiles
) ) )
942 reset( $this->parent
->rightsProfiles
);
943 $this->setVar( '_RightsProfile', key( $this->parent
->rightsProfiles
) );
946 $code = $this->getVar( '_LicenseCode' );
947 if ( $code == 'cc-choose' ) {
948 if ( !$this->getVar( '_CCDone' ) ) {
949 $this->parent
->showError( 'config-cc-not-chosen' );
952 } elseif ( in_array( $code, array_keys( $this->parent
->licenses
) ) ) {
953 $entry = $this->parent
->licenses
[$code];
954 if ( isset( $entry['text'] ) ) {
955 $this->setVar( 'wgRightsText', $entry['text'] );
957 $this->setVar( 'wgRightsText', wfMsg( 'config-license-' . $code ) );
959 $this->setVar( 'wgRightsUrl', $entry['url'] );
960 $this->setVar( 'wgRightsIcon', $entry['icon'] );
962 $this->setVar( 'wgRightsText', '' );
963 $this->setVar( 'wgRightsUrl', '' );
964 $this->setVar( 'wgRightsIcon', '' );
967 $extsAvailable = $this->parent
->findExtensions();
968 $extsToInstall = array();
969 foreach( $extsAvailable as $ext ) {
970 if( $this->parent
->request
->getCheck( 'config_ext-' . $ext ) ) {
971 $extsToInstall[] = $ext;
974 $this->parent
->setVar( '_Extensions', $extsToInstall );
980 class WebInstaller_Install
extends WebInstallerPage
{
982 public function execute() {
983 if( $this->parent
->request
->wasPosted() ) {
985 } elseif( $this->getVar( '_InstallDone' ) ) {
987 $status = new Status();
988 $status->warning( 'config-install-alreadydone' );
989 $this->parent
->showStatusBox( $status );
990 } elseif( $this->getVar( '_UpgradeDone' ) ) {
994 $this->addHTML("<ul>");
995 $this->parent
->performInstallation(
996 array( $this, 'startStage'),
997 array( $this, 'endStage' )
999 $this->addHTML("</ul>");
1005 public function startStage( $step ) {
1006 $this->addHTML( "<li>" . wfMsgHtml( "config-install-$step" ) . wfMsg( 'ellipsis') );
1009 public function endStage( $step, $status ) {
1010 $msg = $status->isOk() ?
'config-install-step-done' : 'config-install-step-failed';
1011 $html = wfMsgHtml( 'word-separator' ) . wfMsgHtml( $msg );
1012 if ( !$status->isOk() ) {
1013 $html = "<span class=\"error\">$html</span>";
1015 $this->addHTML( $html . "</li>\n" );
1016 if( !$status->isGood() ) {
1017 $this->parent
->showStatusBox( $status );
1023 class WebInstaller_Complete
extends WebInstallerPage
{
1025 public function execute() {
1026 // Pop up a dialog box, to make it difficult for the user to forget
1027 // to download the file
1028 $lsUrl = $GLOBALS['wgServer'] . $this->parent
->getURL( array( 'localsettings' => 1 ) );
1029 $this->parent
->request
->response()->header( "Refresh: 0;$lsUrl" );
1033 $this->parent
->getInfoBox(
1034 wfMsgNoTrans( 'config-install-done',
1036 $GLOBALS['wgServer'] .
1037 $this->getVar( 'wgScriptPath' ) . '/index' .
1038 $this->getVar( 'wgScriptExtension' ),
1043 $this->endForm( false );
1047 class WebInstaller_Restart
extends WebInstallerPage
{
1049 public function execute() {
1050 $r = $this->parent
->request
;
1051 if ( $r->wasPosted() ) {
1052 $really = $r->getVal( 'submit-restart' );
1054 $this->parent
->session
= array();
1055 $this->parent
->happyPages
= array();
1056 $this->parent
->settings
= array();
1062 $s = $this->parent
->getWarningBox( wfMsgNoTrans( 'config-help-restart' ) );
1063 $this->addHTML( $s );
1064 $this->endForm( 'restart' );
1069 abstract class WebInstaller_Document
extends WebInstallerPage
{
1071 protected abstract function getFileName();
1073 public function execute() {
1074 $text = $this->getFileContents();
1075 $text = $this->formatTextFile( $text );
1076 $this->parent
->output
->addWikiText( $text );
1078 $this->endForm( false );
1081 public function getFileContents() {
1082 return file_get_contents( dirname( __FILE__
) . '/../../' . $this->getFileName() );
1085 protected function formatTextFile( $text ) {
1086 // Use Unix line endings, escape some wikitext stuff
1087 $text = str_replace( array( '<', '{{', '[[', "\r" ),
1088 array( '<', '{{', '[[', '' ), $text );
1089 // join word-wrapped lines into one
1092 $text = preg_replace( "/\n([\\*#\t])([^\n]*?)\n([^\n#\\*:]+)/", "\n\\1\\2 \\3", $text );
1093 } while ( $text != $prev );
1094 // Replace tab indents with colons
1095 $text = preg_replace( '/^\t\t/m', '::', $text );
1096 $text = preg_replace( '/^\t/m', ':', $text );
1097 // turn (bug nnnn) into links
1098 $text = preg_replace_callback('/bug (\d+)/', array( $this, 'replaceBugLinks' ), $text );
1099 // add links to manual to every global variable mentioned
1100 $text = preg_replace_callback('/(\$wg[a-z0-9_]+)/i', array( $this, 'replaceConfigLinks' ), $text );
1104 private function replaceBugLinks( $matches ) {
1105 return '<span class="config-plainlink">[https://bugzilla.wikimedia.org/' .
1106 $matches[1] . ' bug ' . $matches[1] . ']</span>';
1109 private function replaceConfigLinks( $matches ) {
1110 return '<span class="config-plainlink">[http://www.mediawiki.org/wiki/Manual:' .
1111 $matches[1] . ' ' . $matches[1] . ']</span>';
1116 class WebInstaller_Readme
extends WebInstaller_Document
{
1117 protected function getFileName() { return 'README'; }
1120 class WebInstaller_ReleaseNotes
extends WebInstaller_Document
{
1121 protected function getFileName() { return 'RELEASE-NOTES'; }
1124 class WebInstaller_UpgradeDoc
extends WebInstaller_Document
{
1125 protected function getFileName() { return 'UPGRADE'; }
1128 class WebInstaller_Copying
extends WebInstaller_Document
{
1129 protected function getFileName() { return 'COPYING'; }