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', $back = 'back' ) {
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 );
175 $this->endForm( 'continue', false );
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' );
223 // If there is no $wgUpgradeKey, tell the user to add one to LocalSettings.php
224 if ( $vars['wgUpgradeKey'] === false ) {
225 if ( $this->getVar( 'wgUpgradeKey', false ) === false ) {
226 $this->parent
->generateUpgradeKey();
227 $this->setVar( '_UpgradeKeySupplied', true );
230 $this->addHTML( $this->parent
->getInfoBox(
231 wfMsgNoTrans( 'config-upgrade-key-missing',
232 "<pre>\$wgUpgradeKey = '" . $this->getVar( 'wgUpgradeKey' ) . "';</pre>" )
234 $this->endForm( 'continue' );
238 // If there is an upgrade key, but it wasn't supplied, prompt the user to enter it
240 $r = $this->parent
->request
;
241 if ( $r->wasPosted() ) {
242 $key = $r->getText( 'config_wgUpgradeKey' );
243 if( !$key ||
$key !== $vars['wgUpgradeKey'] ) {
244 $this->parent
->showError( 'config-localsettings-badkey' );
245 $this->showKeyForm();
249 $status = $this->handleExistingUpgrade( $vars );
250 if ( $status->isOK() ) {
253 $this->parent
->showStatusBox( $status );
254 $this->showKeyForm();
258 $this->showKeyForm();
264 * Show the "enter key" form
266 protected function showKeyForm() {
269 $this->parent
->getInfoBox( wfMsgNoTrans( 'config-localsettings-upgrade' ) ).
271 $this->parent
->getTextBox( array(
272 'var' => 'wgUpgradeKey',
273 'label' => 'config-localsettings-key',
274 'attribs' => array( 'autocomplete' => 'off' ),
277 $this->endForm( 'continue' );
280 protected function importVariables( $names, $vars ) {
281 $status = Status
::newGood();
282 foreach ( $names as $name ) {
283 if ( !isset( $vars[$name] ) ) {
284 $status->fatal( 'config-localsettings-incomplete', $name );
286 $this->setVar( $name, $vars[$name] );
292 * Initiate an upgrade of the existing database
293 * @param $vars Variables from LocalSettings.php and AdminSettings.php
296 protected function handleExistingUpgrade( $vars ) {
298 if ( !isset( $vars['wgDBtype'] ) ||
!in_array( $vars['wgDBtype'], Installer
::getDBTypes() ) ) {
299 return Status
::newFatal( 'config-localsettings-connection-error', '' );
302 // Set the relevant variables from LocalSettings.php
303 $requiredVars = array( 'wgDBtype', 'wgDBuser', 'wgDBpassword' );
304 $status = $this->importVariables( $requiredVars , $vars );
305 $installer = $this->parent
->getDBInstaller();
306 $status->merge( $this->importVariables( $installer->getGlobalNames(), $vars ) );
307 if ( !$status->isOK() ) {
311 if ( isset( $vars['wgDBadminuser'] ) ) {
312 $this->setVar( '_InstallUser', $vars['wgDBadminuser'] );
314 $this->setVar( '_InstallUser', $vars['wgDBuser'] );
316 if ( isset( $vars['wgDBadminpassword'] ) ) {
317 $this->setVar( '_InstallPassword', $vars['wgDBadminpassword'] );
319 $this->setVar( '_InstallPassword', $vars['wgDBpassword'] );
322 // Test the database connection
323 $status = $installer->getConnection();
324 if ( !$status->isOK() ) {
325 // Adjust the error message to explain things correctly
326 $status->replaceMessage( 'config-connection-error',
327 'config-localsettings-connection-error' );
332 $this->setVar( '_ExistingDBSettings', true );
337 class WebInstaller_Welcome
extends WebInstallerPage
{
339 public function execute() {
340 if ( $this->parent
->request
->wasPosted() ) {
341 if ( $this->getVar( '_Environment' ) ) {
345 $this->parent
->output
->addWikiText( wfMsgNoTrans( 'config-welcome' ) );
346 $status = $this->parent
->doEnvironmentChecks();
348 $this->parent
->output
->addWikiText( wfMsgNoTrans( 'config-copyright',
349 SpecialVersion
::getCopyrightAndAuthorList() ) );
357 class WebInstaller_DBConnect
extends WebInstallerPage
{
359 public function execute() {
360 if ( $this->getVar( '_ExistingDBSettings' ) ) {
364 $r = $this->parent
->request
;
365 if ( $r->wasPosted() ) {
366 $status = $this->submit();
367 if ( $status->isGood() ) {
368 $this->setVar( '_UpgradeDone', false );
371 $this->parent
->showStatusBox( $status );
377 $types = "<ul class=\"config-settings-block\">\n";
379 $defaultType = $this->getVar( 'wgDBtype' );
382 foreach( $this->parent
->getDBTypes() as $type ) {
383 $db = 'Database' . ucfirst( $type );
384 $dbSupport .= wfMsgNoTrans( "config-support-$type",
385 call_user_func( array( $db, 'getSoftwareLink' ) ) ) . "\n";
387 $this->addHTML( $this->parent
->getInfoBox(
388 wfMsg( 'config-support-info', $dbSupport ) ) );
390 foreach ( $this->parent
->getVar( '_CompiledDBs' ) as $type ) {
391 $installer = $this->parent
->getDBInstaller( $type );
395 $installer->getReadableName(),
399 $type == $defaultType,
400 array( 'class' => 'dbRadio', 'rel' => "DB_wrapper_$type" )
405 Html
::openElement( 'div', array( 'id' => 'DB_wrapper_' . $type, 'class' => 'dbWrapper' ) ) .
406 Html
::element( 'h3', array(), wfMsg( 'config-header-' . $type ) ) .
407 $installer->getConnectForm() .
410 $types .= "</ul><br clear=\"left\"/>\n";
413 $this->parent
->label( 'config-db-type', false, $types ) .
420 public function submit() {
421 $r = $this->parent
->request
;
422 $type = $r->getVal( 'DBType' );
423 $this->setVar( 'wgDBtype', $type );
424 $installer = $this->parent
->getDBInstaller( $type );
426 return Status
::newFatal( 'config-invalid-db-type' );
428 return $installer->submitConnectForm();
433 class WebInstaller_Upgrade
extends WebInstallerPage
{
435 public function execute() {
436 if ( $this->getVar( '_UpgradeDone' ) ) {
437 // Allow regeneration of LocalSettings.php, unless we are working
438 // from a pre-existing LocalSettings.php file and we want to avoid
439 // leaking its contents
440 if ( $this->parent
->request
->wasPosted() && !$this->getVar( '_ExistingDBSettings' ) ) {
441 // Done message acknowledged
445 // Show the done message again
446 // Make them click back again if they want to do the upgrade again
447 $this->showDoneMessage();
452 // wgDBtype is generally valid here because otherwise the previous page
453 // (connect) wouldn't have declared its happiness
454 $type = $this->getVar( 'wgDBtype' );
455 $installer = $this->parent
->getDBInstaller( $type );
457 if ( !$installer->needsUpgrade() ) {
461 if ( $this->parent
->request
->wasPosted() ) {
462 $installer->preUpgrade();
464 '<div id="config-spinner" style="display:none;"><img src="../skins/common/images/ajax-loader.gif" /></div>' .
465 '<script>jQuery( "#config-spinner" )[0].style.display = "block";</script>' .
466 '<textarea id="config-update-log" name="UpdateLog" rows="10" readonly="readonly">'
468 $this->parent
->output
->flush();
469 $result = $installer->doUpgrade();
470 $this->addHTML( '</textarea>
471 <script>jQuery( "#config-spinner" )[0].style.display = "none";</script>' );
472 $this->parent
->output
->flush();
474 $this->setVar( '_UpgradeDone', true );
475 $this->showDoneMessage();
481 $this->addHTML( $this->parent
->getInfoBox(
482 wfMsgNoTrans( 'config-can-upgrade', $GLOBALS['wgVersion'] ) ) );
486 public function showDoneMessage() {
488 $regenerate = !$this->getVar( '_ExistingDBSettings' );
490 $msg = 'config-upgrade-done';
492 $msg = 'config-upgrade-done-no-regenerate';
494 $this->parent
->disableLinkPopups();
496 $this->parent
->getInfoBox(
498 $GLOBALS['wgServer'] .
499 $this->getVar( 'wgScriptPath' ) . '/index' .
500 $this->getVar( 'wgScriptExtension' )
504 $this->parent
->restoreLinkPopups();
505 $this->endForm( $regenerate ?
'regenerate' : false, false );
510 class WebInstaller_DBSettings
extends WebInstallerPage
{
512 public function execute() {
513 $installer = $this->parent
->getDBInstaller( $this->getVar( 'wgDBtype' ) );
515 $r = $this->parent
->request
;
516 if ( $r->wasPosted() ) {
517 $status = $installer->submitSettingsForm();
518 if ( $status === false ) {
520 } elseif ( $status->isGood() ) {
523 $this->parent
->showStatusBox( $status );
527 $form = $installer->getSettingsForm();
528 if ( $form === false ) {
533 $this->addHTML( $form );
539 class WebInstaller_Name
extends WebInstallerPage
{
541 public function execute() {
542 $r = $this->parent
->request
;
543 if ( $r->wasPosted() ) {
544 if ( $this->submit() ) {
551 if ( $this->getVar( 'wgSitename' ) == $GLOBALS['wgSitename'] ) {
552 $this->setVar( 'wgSitename', '' );
555 // Set wgMetaNamespace to something valid before we show the form.
556 // $wgMetaNamespace defaults to $wgSiteName which is 'MediaWiki'
557 $metaNS = $this->getVar( 'wgMetaNamespace' );
558 $this->setVar( 'wgMetaNamespace', wfMsgForContent( 'config-ns-other-default' ) );
561 $this->parent
->getTextBox( array(
562 'var' => 'wgSitename',
563 'label' => 'config-site-name',
564 'help' => $this->parent
->getHelpBox( 'config-site-name-help' )
566 $this->parent
->getRadioSet( array(
567 'var' => '_NamespaceType',
568 'label' => 'config-project-namespace',
569 'itemLabelPrefix' => 'config-ns-',
570 'values' => array( 'site-name', 'generic', 'other' ),
571 'commonAttribs' => array( 'class' => 'enableForOther', 'rel' => 'config_wgMetaNamespace' ),
572 'help' => $this->parent
->getHelpBox( 'config-project-namespace-help' )
574 $this->parent
->getTextBox( array(
575 'var' => 'wgMetaNamespace',
576 'label' => '', //TODO: Needs a label?
577 'attribs' => array( 'readonly' => 'readonly', 'class' => 'enabledByOther' ),
580 $this->getFieldSetStart( 'config-admin-box' ) .
581 $this->parent
->getTextBox( array(
582 'var' => '_AdminName',
583 'label' => 'config-admin-name',
584 'help' => $this->parent
->getHelpBox( 'config-admin-help' )
586 $this->parent
->getPasswordBox( array(
587 'var' => '_AdminPassword',
588 'label' => 'config-admin-password',
590 $this->parent
->getPasswordBox( array(
591 'var' => '_AdminPassword2',
592 'label' => 'config-admin-password-confirm'
594 $this->parent
->getTextBox( array(
595 'var' => '_AdminEmail',
596 'label' => 'config-admin-email',
597 'help' => $this->parent
->getHelpBox( 'config-admin-email-help' )
600 * Uncomment this feature once we've got some sort of API to mailman
601 * to handle these subscriptions. Some dummy wrapper script on the
602 * mailman box that shell's out to mailman/bin/add_members would do
603 $this->parent->getCheckBox( array(
604 'var' => '_Subscribe',
605 'label' => 'config-subscribe',
606 'help' => $this->parent->getHelpBox( 'config-subscribe-help' )
609 $this->getFieldSetEnd() .
610 $this->parent
->getInfoBox( wfMsg( 'config-almost-done' ) ) .
611 $this->parent
->getRadioSet( array(
612 'var' => '_SkipOptional',
613 'itemLabelPrefix' => 'config-optional-',
614 'values' => array( 'continue', 'skip' )
618 // Restore the default value
619 $this->setVar( 'wgMetaNamespace', $metaNS );
625 public function submit() {
627 $this->parent
->setVarsFromRequest( array( 'wgSitename', '_NamespaceType',
628 '_AdminName', '_AdminPassword', '_AdminPassword2', '_AdminEmail',
629 '_Subscribe', '_SkipOptional' ) );
631 // Validate site name
632 if ( strval( $this->getVar( 'wgSitename' ) ) === '' ) {
633 $this->parent
->showError( 'config-site-name-blank' );
638 $nsType = $this->getVar( '_NamespaceType' );
639 if ( $nsType == 'site-name' ) {
640 $name = $this->getVar( 'wgSitename' );
641 // Sanitize for namespace
642 // This algorithm should match the JS one in WebInstallerOutput.php
643 $name = preg_replace( '/[\[\]\{\}|#<>%+? ]/', '_', $name );
644 $name = str_replace( '&', '&', $name );
645 $name = preg_replace( '/__+/', '_', $name );
646 $name = ucfirst( trim( $name, '_' ) );
647 } elseif ( $nsType == 'generic' ) {
648 $name = wfMsg( 'config-ns-generic' );
650 $name = $this->getVar( 'wgMetaNamespace' );
653 // Validate namespace
654 if ( strpos( $name, ':' ) !== false ) {
657 // Title-style validation
658 $title = Title
::newFromText( $name );
660 $good = $nsType == 'site-name';
662 $name = $title->getDBkey();
667 $this->parent
->showError( 'config-ns-invalid', $name );
670 $this->setVar( 'wgMetaNamespace', $name );
672 // Validate username for creation
673 $name = $this->getVar( '_AdminName' );
674 if ( strval( $name ) === '' ) {
675 $this->parent
->showError( 'config-admin-name-blank' );
679 $cname = User
::getCanonicalName( $name, 'creatable' );
680 if ( $cname === false ) {
681 $this->parent
->showError( 'config-admin-name-invalid', $name );
684 $this->setVar( '_AdminName', $cname );
691 $pwd = $this->getVar( '_AdminPassword' );
692 $user = User
::newFromName( $cname );
693 $valid = $user && $user->getPasswordValidity( $pwd );
694 if ( strval( $pwd ) === '' ) {
695 # $user->getPasswordValidity just checks for $wgMinimalPasswordLength.
696 # This message is more specific and helpful.
697 $msg = 'config-admin-password-blank';
698 } elseif ( $pwd !== $this->getVar( '_AdminPassword2' ) ) {
699 $msg = 'config-admin-password-mismatch';
700 } elseif ( $valid !== true ) {
701 # As of writing this will only catch the username being e.g. 'FOO' and
705 if ( $msg !== false ) {
706 $this->parent
->showError( $msg );
707 $this->setVar( '_AdminPassword', '' );
708 $this->setVar( '_AdminPassword2', '' );
716 class WebInstaller_Options
extends WebInstallerPage
{
718 public function execute() {
719 if ( $this->getVar( '_SkipOptional' ) == 'skip' ) {
722 if ( $this->parent
->request
->wasPosted() ) {
723 if ( $this->submit() ) {
731 $this->parent
->getRadioSet( array(
732 'var' => '_RightsProfile',
733 'label' => 'config-profile',
734 'itemLabelPrefix' => 'config-profile-',
735 'values' => array_keys( $this->parent
->rightsProfiles
),
737 $this->parent
->getHelpBox( 'config-profile-help' ) .
740 $this->parent
->getRadioSet( array(
741 'var' => '_LicenseCode',
742 'label' => 'config-license',
743 'itemLabelPrefix' => 'config-license-',
744 'values' => array_keys( $this->parent
->licenses
),
745 'commonAttribs' => array( 'class' => 'licenseRadio' ),
747 $this->getCCChooser() .
748 $this->parent
->getHelpBox( 'config-license-help' ) .
751 $this->getFieldSetStart( 'config-email-settings' ) .
752 $this->parent
->getCheckBox( array(
753 'var' => 'wgEnableEmail',
754 'label' => 'config-enable-email',
755 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'emailwrapper' ),
757 $this->parent
->getHelpBox( 'config-enable-email-help' ) .
758 "<div id=\"emailwrapper\">" .
759 $this->parent
->getTextBox( array(
760 'var' => 'wgPasswordSender',
761 'label' => 'config-email-sender'
763 $this->parent
->getHelpBox( 'config-email-sender-help' ) .
764 $this->parent
->getCheckBox( array(
765 'var' => 'wgEnableUserEmail',
766 'label' => 'config-email-user',
768 $this->parent
->getHelpBox( 'config-email-user-help' ) .
769 $this->parent
->getCheckBox( array(
770 'var' => 'wgEnotifUserTalk',
771 'label' => 'config-email-usertalk',
773 $this->parent
->getHelpBox( 'config-email-usertalk-help' ) .
774 $this->parent
->getCheckBox( array(
775 'var' => 'wgEnotifWatchlist',
776 'label' => 'config-email-watchlist',
778 $this->parent
->getHelpBox( 'config-email-watchlist-help' ) .
779 $this->parent
->getCheckBox( array(
780 'var' => 'wgEmailAuthentication',
781 'label' => 'config-email-auth',
783 $this->parent
->getHelpBox( 'config-email-auth-help' ) .
785 $this->getFieldSetEnd()
788 $extensions = $this->parent
->findExtensions();
791 $extHtml = $this->getFieldSetStart( 'config-extensions' );
793 foreach( $extensions as $ext ) {
794 $extHtml .= $this->parent
->getCheckBox( array(
800 $extHtml .= $this->parent
->getHelpBox( 'config-extensions-help' ) .
801 $this->getFieldSetEnd();
802 $this->addHTML( $extHtml );
807 $this->getFieldSetStart( 'config-upload-settings' ) .
808 $this->parent
->getCheckBox( array(
809 'var' => 'wgEnableUploads',
810 'label' => 'config-upload-enable',
811 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'uploadwrapper' ),
812 'help' => $this->parent
->getHelpBox( 'config-upload-help' )
814 '<div id="uploadwrapper" style="display: none;">' .
815 $this->parent
->getTextBox( array(
816 'var' => 'wgDeletedDirectory',
817 'label' => 'config-upload-deleted',
818 'help' => $this->parent
->getHelpBox( 'config-upload-deleted-help' )
821 $this->parent
->getTextBox( array(
823 'label' => 'config-logo',
824 'help' => $this->parent
->getHelpBox( 'config-logo-help' )
828 $this->parent
->getCheckBox( array(
829 'var' => 'wgUseInstantCommons',
830 'label' => 'config-instantcommons',
831 'help' => $this->parent
->getHelpBox( 'config-instantcommons-help' )
833 $this->getFieldSetEnd()
836 $caches = array( 'none' );
837 if( count( $this->getVar( '_Caches' ) ) ) {
840 $caches[] = 'memcached';
844 $this->getFieldSetStart( 'config-advanced-settings' ) .
845 # Object cache settings
846 $this->parent
->getRadioSet( array(
847 'var' => 'wgMainCacheType',
848 'label' => 'config-cache-options',
849 'itemLabelPrefix' => 'config-cache-',
853 $this->parent
->getHelpBox( 'config-cache-help' ) .
854 '<div id="config-memcachewrapper">' .
855 $this->parent
->getTextBox( array(
856 'var' => '_MemCachedServers',
857 'label' => 'config-memcached-servers',
858 'help' => $this->parent
->getHelpBox( 'config-memcached-help' )
861 $this->getFieldSetEnd()
866 public function getCCPartnerUrl() {
868 $exitUrl = $wgServer . $this->parent
->getUrl( array(
870 'SubmitCC' => 'indeed',
871 'config__LicenseCode' => 'cc',
872 'config_wgRightsUrl' => '[license_url]',
873 'config_wgRightsText' => '[license_name]',
874 'config_wgRightsIcon' => '[license_button]',
876 $styleUrl = $wgServer . dirname( dirname( $this->parent
->getUrl() ) ) .
877 '/skins/common/config-cc.css';
878 $iframeUrl = 'http://creativecommons.org/license/?' .
880 'partner' => 'MediaWiki',
881 'exit_url' => $exitUrl,
882 'lang' => $this->getVar( '_UserLang' ),
883 'stylesheet' => $styleUrl,
888 public function getCCChooser() {
889 $iframeAttribs = array(
890 'class' => 'config-cc-iframe',
891 'name' => 'config-cc-iframe',
892 'id' => 'config-cc-iframe',
897 if ( $this->getVar( '_CCDone' ) ) {
898 $iframeAttribs['src'] = $this->parent
->getUrl( array( 'ShowCC' => 'yes' ) );
900 $iframeAttribs['src'] = $this->getCCPartnerUrl();
904 "<div class=\"config-cc-wrapper\" id=\"config-cc-wrapper\" style=\"display: none;\">\n" .
905 Html
::element( 'iframe', $iframeAttribs, '', false /* not short */ ) .
909 public function getCCDoneBox() {
910 $js = "parent.document.getElementById('config-cc-wrapper').style.height = '$1';";
911 // If you change this height, also change it in config.css
912 $expandJs = str_replace( '$1', '54em', $js );
913 $reduceJs = str_replace( '$1', '70px', $js );
916 Html
::element( 'img', array( 'src' => $this->getVar( 'wgRightsIcon' ) ) ) .
918 htmlspecialchars( $this->getVar( 'wgRightsText' ) ) .
920 "<p style=\"text-align: center\">" .
923 'href' => $this->getCCPartnerUrl(),
924 'onclick' => $expandJs,
926 wfMsg( 'config-cc-again' )
929 "<script type=\"text/javascript\">\n" .
930 # Reduce the wrapper div height
931 htmlspecialchars( $reduceJs ) .
936 public function submitCC() {
937 $newValues = $this->parent
->setVarsFromRequest(
938 array( 'wgRightsUrl', 'wgRightsText', 'wgRightsIcon' ) );
939 if ( count( $newValues ) != 3 ) {
940 $this->parent
->showError( 'config-cc-error' );
943 $this->setVar( '_CCDone', true );
944 $this->addHTML( $this->getCCDoneBox() );
947 public function submit() {
948 $this->parent
->setVarsFromRequest( array( '_RightsProfile', '_LicenseCode',
949 'wgEnableEmail', 'wgPasswordSender', 'wgEnableUploads', 'wgLogo',
950 'wgEnableUserEmail', 'wgEnotifUserTalk', 'wgEnotifWatchlist',
951 'wgEmailAuthentication', 'wgMainCacheType', '_MemCachedServers',
952 'wgUseInstantCommons' ) );
954 if ( !in_array( $this->getVar( '_RightsProfile' ),
955 array_keys( $this->parent
->rightsProfiles
) ) )
957 reset( $this->parent
->rightsProfiles
);
958 $this->setVar( '_RightsProfile', key( $this->parent
->rightsProfiles
) );
961 $code = $this->getVar( '_LicenseCode' );
962 if ( $code == 'cc-choose' ) {
963 if ( !$this->getVar( '_CCDone' ) ) {
964 $this->parent
->showError( 'config-cc-not-chosen' );
967 } elseif ( in_array( $code, array_keys( $this->parent
->licenses
) ) ) {
968 $entry = $this->parent
->licenses
[$code];
969 if ( isset( $entry['text'] ) ) {
970 $this->setVar( 'wgRightsText', $entry['text'] );
972 $this->setVar( 'wgRightsText', wfMsg( 'config-license-' . $code ) );
974 $this->setVar( 'wgRightsUrl', $entry['url'] );
975 $this->setVar( 'wgRightsIcon', $entry['icon'] );
977 $this->setVar( 'wgRightsText', '' );
978 $this->setVar( 'wgRightsUrl', '' );
979 $this->setVar( 'wgRightsIcon', '' );
982 $extsAvailable = $this->parent
->findExtensions();
983 $extsToInstall = array();
984 foreach( $extsAvailable as $ext ) {
985 if( $this->parent
->request
->getCheck( 'config_ext-' . $ext ) ) {
986 $extsToInstall[] = $ext;
989 $this->parent
->setVar( '_Extensions', $extsToInstall );
995 class WebInstaller_Install
extends WebInstallerPage
{
997 public function execute() {
998 if( $this->parent
->request
->wasPosted() ) {
1000 } elseif( $this->getVar( '_InstallDone' ) ) {
1002 $status = new Status();
1003 $status->warning( 'config-install-alreadydone' );
1004 $this->parent
->showStatusBox( $status );
1005 } elseif( $this->getVar( '_UpgradeDone' ) ) {
1009 $this->addHTML("<ul>");
1010 $this->parent
->performInstallation(
1011 array( $this, 'startStage'),
1012 array( $this, 'endStage' )
1014 $this->addHTML("</ul>");
1020 public function startStage( $step ) {
1021 $this->addHTML( "<li>" . wfMsgHtml( "config-install-$step" ) . wfMsg( 'ellipsis') );
1024 public function endStage( $step, $status ) {
1025 $msg = $status->isOk() ?
'config-install-step-done' : 'config-install-step-failed';
1026 $html = wfMsgHtml( 'word-separator' ) . wfMsgHtml( $msg );
1027 if ( !$status->isOk() ) {
1028 $html = "<span class=\"error\">$html</span>";
1030 $this->addHTML( $html . "</li>\n" );
1031 if( !$status->isGood() ) {
1032 $this->parent
->showStatusBox( $status );
1038 class WebInstaller_Complete
extends WebInstallerPage
{
1040 public function execute() {
1041 // Pop up a dialog box, to make it difficult for the user to forget
1042 // to download the file
1043 $lsUrl = $GLOBALS['wgServer'] . $this->parent
->getURL( array( 'localsettings' => 1 ) );
1044 $this->parent
->request
->response()->header( "Refresh: 0;url=$lsUrl" );
1047 $this->parent
->disableLinkPopups();
1049 $this->parent
->getInfoBox(
1050 wfMsgNoTrans( 'config-install-done',
1052 $GLOBALS['wgServer'] .
1053 $this->getVar( 'wgScriptPath' ) . '/index' .
1054 $this->getVar( 'wgScriptExtension' ),
1059 $this->parent
->restoreLinkPopups();
1060 $this->endForm( false, false );
1064 class WebInstaller_Restart
extends WebInstallerPage
{
1066 public function execute() {
1067 $r = $this->parent
->request
;
1068 if ( $r->wasPosted() ) {
1069 $really = $r->getVal( 'submit-restart' );
1071 $this->parent
->session
= array();
1072 $this->parent
->happyPages
= array();
1073 $this->parent
->settings
= array();
1079 $s = $this->parent
->getWarningBox( wfMsgNoTrans( 'config-help-restart' ) );
1080 $this->addHTML( $s );
1081 $this->endForm( 'restart' );
1086 abstract class WebInstaller_Document
extends WebInstallerPage
{
1088 protected abstract function getFileName();
1090 public function execute() {
1091 $text = $this->getFileContents();
1092 $text = $this->formatTextFile( $text );
1093 $this->parent
->output
->addWikiText( $text );
1095 $this->endForm( false );
1098 public function getFileContents() {
1099 return file_get_contents( dirname( __FILE__
) . '/../../' . $this->getFileName() );
1102 protected function formatTextFile( $text ) {
1103 // Use Unix line endings, escape some wikitext stuff
1104 $text = str_replace( array( '<', '{{', '[[', "\r" ),
1105 array( '<', '{{', '[[', '' ), $text );
1106 // join word-wrapped lines into one
1109 $text = preg_replace( "/\n([\\*#\t])([^\n]*?)\n([^\n#\\*:]+)/", "\n\\1\\2 \\3", $text );
1110 } while ( $text != $prev );
1111 // Replace tab indents with colons
1112 $text = preg_replace( '/^\t\t/m', '::', $text );
1113 $text = preg_replace( '/^\t/m', ':', $text );
1114 // turn (bug nnnn) into links
1115 $text = preg_replace_callback('/bug (\d+)/', array( $this, 'replaceBugLinks' ), $text );
1116 // add links to manual to every global variable mentioned
1117 $text = preg_replace_callback('/(\$wg[a-z0-9_]+)/i', array( $this, 'replaceConfigLinks' ), $text );
1121 private function replaceBugLinks( $matches ) {
1122 return '<span class="config-plainlink">[https://bugzilla.wikimedia.org/' .
1123 $matches[1] . ' bug ' . $matches[1] . ']</span>';
1126 private function replaceConfigLinks( $matches ) {
1127 return '<span class="config-plainlink">[http://www.mediawiki.org/wiki/Manual:' .
1128 $matches[1] . ' ' . $matches[1] . ']</span>';
1133 class WebInstaller_Readme
extends WebInstaller_Document
{
1134 protected function getFileName() { return 'README'; }
1137 class WebInstaller_ReleaseNotes
extends WebInstaller_Document
{
1138 protected function getFileName() { return 'RELEASE-NOTES'; }
1141 class WebInstaller_UpgradeDoc
extends WebInstaller_Document
{
1142 protected function getFileName() { return 'UPGRADE'; }
1145 class WebInstaller_Copying
extends WebInstaller_Document
{
1146 protected function getFileName() { return 'COPYING'; }