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
109 protected function getFieldsetStart( $legend ) {
110 return "\n<fieldset><legend>" . wfMsgHtml( $legend ) . "</legend>\n";
114 * Get the end tag of a fieldset.
118 protected function getFieldsetEnd() {
119 return "</fieldset>\n";
123 * Opens a textarea used to display the progress of a long operation
125 protected function startLiveBox() {
127 '<div id="config-spinner" style="display:none;"><img src="../skins/common/images/ajax-loader.gif" /></div>' .
128 '<script>jQuery( "#config-spinner" ).show();</script>' .
129 '<textarea id="config-live-log" name="LiveLog" rows="10" cols="30" readonly="readonly">'
131 $this->parent
->output
->flush();
135 * Opposite to startLiveBox()
137 protected function endLiveBox() {
138 $this->addHTML( '</textarea>
139 <script>jQuery( "#config-spinner" ).hide()</script>' );
140 $this->parent
->output
->flush();
144 class WebInstaller_Language
extends WebInstallerPage
{
146 public function execute() {
148 $r = $this->parent
->request
;
149 $userLang = $r->getVal( 'UserLang' );
150 $contLang = $r->getVal( 'ContLang' );
152 $lifetime = intval( ini_get( 'session.gc_maxlifetime' ) );
154 $lifetime = 1440; // PHP default
157 if ( $r->wasPosted() ) {
159 if ( $this->parent
->getSession( 'test' ) === null ) {
160 $requestTime = $r->getVal( 'LanguageRequestTime' );
161 if ( !$requestTime ) {
162 // The most likely explanation is that the user was knocked back
163 // from another page on POST due to session expiry
164 $msg = 'config-session-expired';
165 } elseif ( time() - $requestTime > $lifetime ) {
166 $msg = 'config-session-expired';
168 $msg = 'config-no-session';
170 $this->parent
->showError( $msg, $wgLang->formatTimePeriod( $lifetime ) );
172 $languages = Language
::getLanguageNames();
173 if ( isset( $languages[$userLang] ) ) {
174 $this->setVar( '_UserLang', $userLang );
176 if ( isset( $languages[$contLang] ) ) {
177 $this->setVar( 'wgLanguageCode', $contLang );
181 } elseif ( $this->parent
->showSessionWarning
) {
182 # The user was knocked back from another page to the start
183 # This probably indicates a session expiry
184 $this->parent
->showError( 'config-session-expired', $wgLang->formatTimePeriod( $lifetime ) );
187 $this->parent
->setSession( 'test', true );
189 if ( !isset( $languages[$userLang] ) ) {
190 $userLang = $this->getVar( '_UserLang', 'en' );
192 if ( !isset( $languages[$contLang] ) ) {
193 $contLang = $this->getVar( 'wgLanguageCode', 'en' );
196 $s = Html
::hidden( 'LanguageRequestTime', time() ) .
197 $this->getLanguageSelector( 'UserLang', 'config-your-language', $userLang, $this->parent
->getHelpBox( 'config-your-language-help' ) ) .
198 $this->getLanguageSelector( 'ContLang', 'config-wiki-language', $contLang, $this->parent
->getHelpBox( 'config-wiki-language-help' ) );
199 $this->addHTML( $s );
200 $this->endForm( 'continue', false );
204 * Get a <select> for selecting languages.
208 public function getLanguageSelector( $name, $label, $selectedCode ) {
209 global $wgDummyLanguageCodes;
210 $s = Html
::openElement( 'select', array( 'id' => $name, 'name' => $name ) ) . "\n";
212 $languages = Language
::getLanguageNames();
214 $dummies = array_flip( $wgDummyLanguageCodes );
215 foreach ( $languages as $code => $lang ) {
216 if ( isset( $dummies[$code] ) ) continue;
217 $s .= "\n" . Xml
::option( "$code - $lang", $code, $code == $selectedCode );
219 $s .= "\n</select>\n";
220 return $this->parent
->label( $label, $name, $s );
225 class WebInstaller_ExistingWiki
extends WebInstallerPage
{
226 public function execute() {
227 // If there is no LocalSettings.php, continue to the installer welcome page
228 $vars = $this->parent
->getExistingLocalSettings();
233 // Check if the upgrade key supplied to the user has appeared in LocalSettings.php
234 if ( $vars['wgUpgradeKey'] !== false
235 && $this->getVar( '_UpgradeKeySupplied' )
236 && $this->getVar( 'wgUpgradeKey' ) === $vars['wgUpgradeKey'] )
238 // It's there, so the user is authorized
239 $status = $this->handleExistingUpgrade( $vars );
240 if ( $status->isOK() ) {
244 $this->parent
->showStatusBox( $status );
245 $this->endForm( 'continue' );
250 // If there is no $wgUpgradeKey, tell the user to add one to LocalSettings.php
251 if ( $vars['wgUpgradeKey'] === false ) {
252 if ( $this->getVar( 'wgUpgradeKey', false ) === false ) {
253 $secretKey = $this->getVar( 'wgSecretKey' ); // preserve $wgSecretKey
254 $this->parent
->generateKeys();
255 $this->setVar( 'wgSecretKey', $secretKey );
256 $this->setVar( '_UpgradeKeySupplied', true );
259 $this->addHTML( $this->parent
->getInfoBox(
260 wfMsgNoTrans( 'config-upgrade-key-missing',
261 "<pre>\$wgUpgradeKey = '" . $this->getVar( 'wgUpgradeKey' ) . "';</pre>" )
263 $this->endForm( 'continue' );
267 // If there is an upgrade key, but it wasn't supplied, prompt the user to enter it
269 $r = $this->parent
->request
;
270 if ( $r->wasPosted() ) {
271 $key = $r->getText( 'config_wgUpgradeKey' );
272 if( !$key ||
$key !== $vars['wgUpgradeKey'] ) {
273 $this->parent
->showError( 'config-localsettings-badkey' );
274 $this->showKeyForm();
278 $status = $this->handleExistingUpgrade( $vars );
279 if ( $status->isOK() ) {
282 $this->parent
->showStatusBox( $status );
283 $this->showKeyForm();
287 $this->showKeyForm();
293 * Show the "enter key" form
295 protected function showKeyForm() {
298 $this->parent
->getInfoBox( wfMsgNoTrans( 'config-localsettings-upgrade' ) ).
300 $this->parent
->getTextBox( array(
301 'var' => 'wgUpgradeKey',
302 'label' => 'config-localsettings-key',
303 'attribs' => array( 'autocomplete' => 'off' ),
306 $this->endForm( 'continue' );
309 protected function importVariables( $names, $vars ) {
310 $status = Status
::newGood();
311 foreach ( $names as $name ) {
312 if ( !isset( $vars[$name] ) ) {
313 $status->fatal( 'config-localsettings-incomplete', $name );
315 $this->setVar( $name, $vars[$name] );
321 * Initiate an upgrade of the existing database
322 * @param $vars Variables from LocalSettings.php and AdminSettings.php
325 protected function handleExistingUpgrade( $vars ) {
327 if ( !isset( $vars['wgDBtype'] ) ||
!in_array( $vars['wgDBtype'], Installer
::getDBTypes() ) ) {
328 return Status
::newFatal( 'config-localsettings-connection-error', '' );
331 // Set the relevant variables from LocalSettings.php
332 $requiredVars = array( 'wgDBtype' );
333 $status = $this->importVariables( $requiredVars , $vars );
334 $installer = $this->parent
->getDBInstaller();
335 $status->merge( $this->importVariables( $installer->getGlobalNames(), $vars ) );
336 if ( !$status->isOK() ) {
340 if ( isset( $vars['wgDBadminuser'] ) ) {
341 $this->setVar( '_InstallUser', $vars['wgDBadminuser'] );
343 $this->setVar( '_InstallUser', $vars['wgDBuser'] );
345 if ( isset( $vars['wgDBadminpassword'] ) ) {
346 $this->setVar( '_InstallPassword', $vars['wgDBadminpassword'] );
348 $this->setVar( '_InstallPassword', $vars['wgDBpassword'] );
351 // Test the database connection
352 $status = $installer->getConnection();
353 if ( !$status->isOK() ) {
354 // Adjust the error message to explain things correctly
355 $status->replaceMessage( 'config-connection-error',
356 'config-localsettings-connection-error' );
361 $this->setVar( '_ExistingDBSettings', true );
366 class WebInstaller_Welcome
extends WebInstallerPage
{
368 public function execute() {
369 if ( $this->parent
->request
->wasPosted() ) {
370 if ( $this->getVar( '_Environment' ) ) {
374 $this->parent
->output
->addWikiText( wfMsgNoTrans( 'config-welcome' ) );
375 $status = $this->parent
->doEnvironmentChecks();
376 if ( $status->isGood() ) {
377 $this->parent
->output
->addHTML( '<span class="success-message">' .
378 wfMsgHtml( 'config-env-good' ) . '</span>' );
379 $this->parent
->output
->addWikiText( wfMsgNoTrans( 'config-copyright',
380 SpecialVersion
::getCopyrightAndAuthorList() ) );
384 $this->parent
->showStatusMessage( $status );
390 class WebInstaller_DBConnect
extends WebInstallerPage
{
392 public function execute() {
393 if ( $this->getVar( '_ExistingDBSettings' ) ) {
397 $r = $this->parent
->request
;
398 if ( $r->wasPosted() ) {
399 $status = $this->submit();
401 if ( $status->isGood() ) {
402 $this->setVar( '_UpgradeDone', false );
405 $this->parent
->showStatusBox( $status );
411 $types = "<ul class=\"config-settings-block\">\n";
413 $defaultType = $this->getVar( 'wgDBtype' );
416 foreach( $this->parent
->getDBTypes() as $type ) {
417 $link = DatabaseBase
::newFromType( $type )->getSoftwareLink();
418 $dbSupport .= wfMsgNoTrans( "config-support-$type", $link ) . "\n";
420 $this->addHTML( $this->parent
->getInfoBox(
421 wfMsg( 'config-support-info', $dbSupport ) ) );
423 foreach ( $this->parent
->getVar( '_CompiledDBs' ) as $type ) {
424 $installer = $this->parent
->getDBInstaller( $type );
428 $installer->getReadableName(),
432 $type == $defaultType,
433 array( 'class' => 'dbRadio', 'rel' => "DB_wrapper_$type" )
438 Html
::openElement( 'div', array( 'id' => 'DB_wrapper_' . $type, 'class' => 'dbWrapper' ) ) .
439 Html
::element( 'h3', array(), wfMsg( 'config-header-' . $type ) ) .
440 $installer->getConnectForm() .
443 $types .= "</ul><br clear=\"left\"/>\n";
446 $this->parent
->label( 'config-db-type', false, $types ) .
453 public function submit() {
454 $r = $this->parent
->request
;
455 $type = $r->getVal( 'DBType' );
456 $this->setVar( 'wgDBtype', $type );
457 $installer = $this->parent
->getDBInstaller( $type );
459 return Status
::newFatal( 'config-invalid-db-type' );
461 return $installer->submitConnectForm();
466 class WebInstaller_Upgrade
extends WebInstallerPage
{
468 public function execute() {
469 if ( $this->getVar( '_UpgradeDone' ) ) {
470 // Allow regeneration of LocalSettings.php, unless we are working
471 // from a pre-existing LocalSettings.php file and we want to avoid
472 // leaking its contents
473 if ( $this->parent
->request
->wasPosted() && !$this->getVar( '_ExistingDBSettings' ) ) {
474 // Done message acknowledged
478 // Show the done message again
479 // Make them click back again if they want to do the upgrade again
480 $this->showDoneMessage();
485 // wgDBtype is generally valid here because otherwise the previous page
486 // (connect) wouldn't have declared its happiness
487 $type = $this->getVar( 'wgDBtype' );
488 $installer = $this->parent
->getDBInstaller( $type );
490 if ( !$installer->needsUpgrade() ) {
494 if ( $this->parent
->request
->wasPosted() ) {
495 $installer->preUpgrade();
497 $this->startLiveBox();
498 $result = $installer->doUpgrade();
502 // If they're going to possibly regenerate LocalSettings, we
503 // need to create the upgrade/secret keys. Bug 26481
504 if( !$this->getVar( '_ExistingDBSettings' ) ) {
505 $this->parent
->generateKeys();
507 $this->setVar( '_UpgradeDone', true );
508 $this->showDoneMessage();
514 $this->addHTML( $this->parent
->getInfoBox(
515 wfMsgNoTrans( 'config-can-upgrade', $GLOBALS['wgVersion'] ) ) );
519 public function showDoneMessage() {
521 $regenerate = !$this->getVar( '_ExistingDBSettings' );
523 $msg = 'config-upgrade-done';
525 $msg = 'config-upgrade-done-no-regenerate';
527 $this->parent
->disableLinkPopups();
529 $this->parent
->getInfoBox(
531 $GLOBALS['wgServer'] .
532 $this->getVar( 'wgScriptPath' ) . '/index' .
533 $this->getVar( 'wgScriptExtension' )
537 $this->parent
->restoreLinkPopups();
538 $this->endForm( $regenerate ?
'regenerate' : false, false );
543 class WebInstaller_DBSettings
extends WebInstallerPage
{
545 public function execute() {
546 $installer = $this->parent
->getDBInstaller( $this->getVar( 'wgDBtype' ) );
548 $r = $this->parent
->request
;
549 if ( $r->wasPosted() ) {
550 $status = $installer->submitSettingsForm();
551 if ( $status === false ) {
553 } elseif ( $status->isGood() ) {
556 $this->parent
->showStatusBox( $status );
560 $form = $installer->getSettingsForm();
561 if ( $form === false ) {
566 $this->addHTML( $form );
572 class WebInstaller_Name
extends WebInstallerPage
{
574 public function execute() {
575 $r = $this->parent
->request
;
576 if ( $r->wasPosted() ) {
577 if ( $this->submit() ) {
584 // Encourage people to not name their site 'MediaWiki' by blanking the
585 // field. I think that was the intent with the original $GLOBALS['wgSitename']
586 // but these two always were the same so had the effect of making the
587 // installer forget $wgSitename when navigating back to this page.
588 if ( $this->getVar( 'wgSitename' ) == 'MediaWiki' ) {
589 $this->setVar( 'wgSitename', '' );
592 // Set wgMetaNamespace to something valid before we show the form.
593 // $wgMetaNamespace defaults to $wgSiteName which is 'MediaWiki'
594 $metaNS = $this->getVar( 'wgMetaNamespace' );
595 $this->setVar( 'wgMetaNamespace', wfMsgForContent( 'config-ns-other-default' ) );
598 $this->parent
->getTextBox( array(
599 'var' => 'wgSitename',
600 'label' => 'config-site-name',
601 'help' => $this->parent
->getHelpBox( 'config-site-name-help' )
603 $this->parent
->getRadioSet( array(
604 'var' => '_NamespaceType',
605 'label' => 'config-project-namespace',
606 'itemLabelPrefix' => 'config-ns-',
607 'values' => array( 'site-name', 'generic', 'other' ),
608 'commonAttribs' => array( 'class' => 'enableForOther', 'rel' => 'config_wgMetaNamespace' ),
609 'help' => $this->parent
->getHelpBox( 'config-project-namespace-help' )
611 $this->parent
->getTextBox( array(
612 'var' => 'wgMetaNamespace',
613 'label' => '', //TODO: Needs a label?
614 'attribs' => array( 'readonly' => 'readonly', 'class' => 'enabledByOther' ),
617 $this->getFieldSetStart( 'config-admin-box' ) .
618 $this->parent
->getTextBox( array(
619 'var' => '_AdminName',
620 'label' => 'config-admin-name',
621 'help' => $this->parent
->getHelpBox( 'config-admin-help' )
623 $this->parent
->getPasswordBox( array(
624 'var' => '_AdminPassword',
625 'label' => 'config-admin-password',
627 $this->parent
->getPasswordBox( array(
628 'var' => '_AdminPassword2',
629 'label' => 'config-admin-password-confirm'
631 $this->parent
->getTextBox( array(
632 'var' => '_AdminEmail',
633 'label' => 'config-admin-email',
634 'help' => $this->parent
->getHelpBox( 'config-admin-email-help' )
636 $this->parent
->getCheckBox( array(
637 'var' => '_Subscribe',
638 'label' => 'config-subscribe',
639 'help' => $this->parent
->getHelpBox( 'config-subscribe-help' )
641 $this->getFieldSetEnd() .
642 $this->parent
->getInfoBox( wfMsg( 'config-almost-done' ) ) .
643 $this->parent
->getRadioSet( array(
644 'var' => '_SkipOptional',
645 'itemLabelPrefix' => 'config-optional-',
646 'values' => array( 'continue', 'skip' )
650 // Restore the default value
651 $this->setVar( 'wgMetaNamespace', $metaNS );
657 public function submit() {
659 $this->parent
->setVarsFromRequest( array( 'wgSitename', '_NamespaceType',
660 '_AdminName', '_AdminPassword', '_AdminPassword2', '_AdminEmail',
661 '_Subscribe', '_SkipOptional', 'wgMetaNamespace' ) );
663 // Validate site name
664 if ( strval( $this->getVar( 'wgSitename' ) ) === '' ) {
665 $this->parent
->showError( 'config-site-name-blank' );
670 $nsType = $this->getVar( '_NamespaceType' );
671 if ( $nsType == 'site-name' ) {
672 $name = $this->getVar( 'wgSitename' );
673 // Sanitize for namespace
674 // This algorithm should match the JS one in WebInstallerOutput.php
675 $name = preg_replace( '/[\[\]\{\}|#<>%+? ]/', '_', $name );
676 $name = str_replace( '&', '&', $name );
677 $name = preg_replace( '/__+/', '_', $name );
678 $name = ucfirst( trim( $name, '_' ) );
679 } elseif ( $nsType == 'generic' ) {
680 $name = wfMsg( 'config-ns-generic' );
682 $name = $this->getVar( 'wgMetaNamespace' );
685 // Validate namespace
686 if ( strpos( $name, ':' ) !== false ) {
689 // Title-style validation
690 $title = Title
::newFromText( $name );
692 $good = $nsType == 'site-name';
694 $name = $title->getDBkey();
699 $this->parent
->showError( 'config-ns-invalid', $name );
703 // Make sure it won't conflict with any existing namespaces
705 $nsIndex = $wgContLang->getNsIndex( $name );
706 if( $nsIndex !== false && $nsIndex !== NS_PROJECT
) {
707 $this->parent
->showError( 'config-ns-conflict', $name );
711 $this->setVar( 'wgMetaNamespace', $name );
713 // Validate username for creation
714 $name = $this->getVar( '_AdminName' );
715 if ( strval( $name ) === '' ) {
716 $this->parent
->showError( 'config-admin-name-blank' );
720 $cname = User
::getCanonicalName( $name, 'creatable' );
721 if ( $cname === false ) {
722 $this->parent
->showError( 'config-admin-name-invalid', $name );
725 $this->setVar( '_AdminName', $cname );
732 $pwd = $this->getVar( '_AdminPassword' );
733 $user = User
::newFromName( $cname );
734 $valid = $user && $user->getPasswordValidity( $pwd );
735 if ( strval( $pwd ) === '' ) {
736 # $user->getPasswordValidity just checks for $wgMinimalPasswordLength.
737 # This message is more specific and helpful.
738 $msg = 'config-admin-password-blank';
739 } elseif ( $pwd !== $this->getVar( '_AdminPassword2' ) ) {
740 $msg = 'config-admin-password-mismatch';
741 } elseif ( $valid !== true ) {
742 # As of writing this will only catch the username being e.g. 'FOO' and
746 if ( $msg !== false ) {
747 call_user_func_array( array( $this->parent
, 'showError' ), (array)$msg );
748 $this->setVar( '_AdminPassword', '' );
749 $this->setVar( '_AdminPassword2', '' );
753 // Validate e-mail if provided
754 $email = $this->getVar( '_AdminEmail' );
755 if( $email && !User
::isValidEmailAddr( $email ) ) {
756 $this->parent
->showError( 'config-admin-error-bademail' );
765 class WebInstaller_Options
extends WebInstallerPage
{
767 public function execute() {
768 if ( $this->getVar( '_SkipOptional' ) == 'skip' ) {
771 if ( $this->parent
->request
->wasPosted() ) {
772 if ( $this->submit() ) {
777 $emailwrapperStyle = $this->getVar( 'wgEnableEmail' ) ?
'' : 'display: none';
781 $this->parent
->getRadioSet( array(
782 'var' => '_RightsProfile',
783 'label' => 'config-profile',
784 'itemLabelPrefix' => 'config-profile-',
785 'values' => array_keys( $this->parent
->rightsProfiles
),
787 $this->parent
->getInfoBox( wfMsgNoTrans( 'config-profile-help' ) ) .
790 $this->parent
->getRadioSet( array(
791 'var' => '_LicenseCode',
792 'label' => 'config-license',
793 'itemLabelPrefix' => 'config-license-',
794 'values' => array_keys( $this->parent
->licenses
),
795 'commonAttribs' => array( 'class' => 'licenseRadio' ),
797 $this->getCCChooser() .
798 $this->parent
->getHelpBox( 'config-license-help' ) .
801 $this->getFieldSetStart( 'config-email-settings' ) .
802 $this->parent
->getCheckBox( array(
803 'var' => 'wgEnableEmail',
804 'label' => 'config-enable-email',
805 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'emailwrapper' ),
807 $this->parent
->getHelpBox( 'config-enable-email-help' ) .
808 "<div id=\"emailwrapper\" style=\"$emailwrapperStyle\">" .
809 $this->parent
->getTextBox( array(
810 'var' => 'wgPasswordSender',
811 'label' => 'config-email-sender'
813 $this->parent
->getHelpBox( 'config-email-sender-help' ) .
814 $this->parent
->getCheckBox( array(
815 'var' => 'wgEnableUserEmail',
816 'label' => 'config-email-user',
818 $this->parent
->getHelpBox( 'config-email-user-help' ) .
819 $this->parent
->getCheckBox( array(
820 'var' => 'wgEnotifUserTalk',
821 'label' => 'config-email-usertalk',
823 $this->parent
->getHelpBox( 'config-email-usertalk-help' ) .
824 $this->parent
->getCheckBox( array(
825 'var' => 'wgEnotifWatchlist',
826 'label' => 'config-email-watchlist',
828 $this->parent
->getHelpBox( 'config-email-watchlist-help' ) .
829 $this->parent
->getCheckBox( array(
830 'var' => 'wgEmailAuthentication',
831 'label' => 'config-email-auth',
833 $this->parent
->getHelpBox( 'config-email-auth-help' ) .
835 $this->getFieldSetEnd()
838 $extensions = $this->parent
->findExtensions();
841 $extHtml = $this->getFieldSetStart( 'config-extensions' );
843 foreach( $extensions as $ext ) {
844 $extHtml .= $this->parent
->getCheckBox( array(
850 $extHtml .= $this->parent
->getHelpBox( 'config-extensions-help' ) .
851 $this->getFieldSetEnd();
852 $this->addHTML( $extHtml );
855 // Having / in paths in Windows looks funny :)
856 $this->setVar( 'wgDeletedDirectory',
858 '/', DIRECTORY_SEPARATOR
,
859 $this->getVar( 'wgDeletedDirectory' )
863 $uploadwrapperStyle = $this->getVar( 'wgEnableUploads' ) ?
'' : 'display: none';
866 $this->getFieldSetStart( 'config-upload-settings' ) .
867 $this->parent
->getCheckBox( array(
868 'var' => 'wgEnableUploads',
869 'label' => 'config-upload-enable',
870 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'uploadwrapper' ),
871 'help' => $this->parent
->getHelpBox( 'config-upload-help' )
873 '<div id="uploadwrapper" style="' . $uploadwrapperStyle . '">' .
874 $this->parent
->getTextBox( array(
875 'var' => 'wgDeletedDirectory',
876 'label' => 'config-upload-deleted',
877 'help' => $this->parent
->getHelpBox( 'config-upload-deleted-help' )
880 $this->parent
->getTextBox( array(
882 'label' => 'config-logo',
883 'help' => $this->parent
->getHelpBox( 'config-logo-help' )
887 $this->parent
->getCheckBox( array(
888 'var' => 'wgUseInstantCommons',
889 'label' => 'config-instantcommons',
890 'help' => $this->parent
->getHelpBox( 'config-instantcommons-help' )
892 $this->getFieldSetEnd()
895 $caches = array( 'none' );
896 if( count( $this->getVar( '_Caches' ) ) ) {
899 $caches[] = 'memcached';
903 $this->getFieldSetStart( 'config-advanced-settings' ) .
904 # Object cache settings
905 $this->parent
->getRadioSet( array(
906 'var' => 'wgMainCacheType',
907 'label' => 'config-cache-options',
908 'itemLabelPrefix' => 'config-cache-',
912 $this->parent
->getHelpBox( 'config-cache-help' ) .
913 '<div id="config-memcachewrapper">' .
914 $this->parent
->getTextArea( array(
915 'var' => '_MemCachedServers',
916 'label' => 'config-memcached-servers',
917 'help' => $this->parent
->getHelpBox( 'config-memcached-help' )
920 $this->getFieldSetEnd()
925 public function getCCPartnerUrl() {
927 $exitUrl = $wgServer . $this->parent
->getUrl( array(
929 'SubmitCC' => 'indeed',
930 'config__LicenseCode' => 'cc',
931 'config_wgRightsUrl' => '[license_url]',
932 'config_wgRightsText' => '[license_name]',
933 'config_wgRightsIcon' => '[license_button]',
935 $styleUrl = $wgServer . dirname( dirname( $this->parent
->getUrl() ) ) .
936 '/skins/common/config-cc.css';
937 $iframeUrl = 'http://creativecommons.org/license/?' .
939 'partner' => 'MediaWiki',
940 'exit_url' => $exitUrl,
941 'lang' => $this->getVar( '_UserLang' ),
942 'stylesheet' => $styleUrl,
947 public function getCCChooser() {
948 $iframeAttribs = array(
949 'class' => 'config-cc-iframe',
950 'name' => 'config-cc-iframe',
951 'id' => 'config-cc-iframe',
956 if ( $this->getVar( '_CCDone' ) ) {
957 $iframeAttribs['src'] = $this->parent
->getUrl( array( 'ShowCC' => 'yes' ) );
959 $iframeAttribs['src'] = $this->getCCPartnerUrl();
961 $wrapperStyle = ($this->getVar('_LicenseCode') == 'cc-choose') ?
'' : 'display: none';
964 "<div class=\"config-cc-wrapper\" id=\"config-cc-wrapper\" style=\"$wrapperStyle\">\n" .
965 Html
::element( 'iframe', $iframeAttribs, '', false /* not short */ ) .
969 public function getCCDoneBox() {
970 $js = "parent.document.getElementById('config-cc-wrapper').style.height = '$1';";
971 // If you change this height, also change it in config.css
972 $expandJs = str_replace( '$1', '54em', $js );
973 $reduceJs = str_replace( '$1', '70px', $js );
976 Html
::element( 'img', array( 'src' => $this->getVar( 'wgRightsIcon' ) ) ) .
978 htmlspecialchars( $this->getVar( 'wgRightsText' ) ) .
980 "<p style=\"text-align: center\">" .
983 'href' => $this->getCCPartnerUrl(),
984 'onclick' => $expandJs,
986 wfMsg( 'config-cc-again' )
989 "<script type=\"text/javascript\">\n" .
990 # Reduce the wrapper div height
991 htmlspecialchars( $reduceJs ) .
996 public function submitCC() {
997 $newValues = $this->parent
->setVarsFromRequest(
998 array( 'wgRightsUrl', 'wgRightsText', 'wgRightsIcon' ) );
999 if ( count( $newValues ) != 3 ) {
1000 $this->parent
->showError( 'config-cc-error' );
1003 $this->setVar( '_CCDone', true );
1004 $this->addHTML( $this->getCCDoneBox() );
1007 public function submit() {
1008 $this->parent
->setVarsFromRequest( array( '_RightsProfile', '_LicenseCode',
1009 'wgEnableEmail', 'wgPasswordSender', 'wgEnableUploads', 'wgLogo',
1010 'wgEnableUserEmail', 'wgEnotifUserTalk', 'wgEnotifWatchlist',
1011 'wgEmailAuthentication', 'wgMainCacheType', '_MemCachedServers',
1012 'wgUseInstantCommons' ) );
1014 if ( !in_array( $this->getVar( '_RightsProfile' ),
1015 array_keys( $this->parent
->rightsProfiles
) ) )
1017 reset( $this->parent
->rightsProfiles
);
1018 $this->setVar( '_RightsProfile', key( $this->parent
->rightsProfiles
) );
1021 $code = $this->getVar( '_LicenseCode' );
1022 if ( $code == 'cc-choose' ) {
1023 if ( !$this->getVar( '_CCDone' ) ) {
1024 $this->parent
->showError( 'config-cc-not-chosen' );
1027 } elseif ( in_array( $code, array_keys( $this->parent
->licenses
) ) ) {
1028 $entry = $this->parent
->licenses
[$code];
1029 if ( isset( $entry['text'] ) ) {
1030 $this->setVar( 'wgRightsText', $entry['text'] );
1032 $this->setVar( 'wgRightsText', wfMsg( 'config-license-' . $code ) );
1034 $this->setVar( 'wgRightsUrl', $entry['url'] );
1035 $this->setVar( 'wgRightsIcon', $entry['icon'] );
1037 $this->setVar( 'wgRightsText', '' );
1038 $this->setVar( 'wgRightsUrl', '' );
1039 $this->setVar( 'wgRightsIcon', '' );
1042 $extsAvailable = $this->parent
->findExtensions();
1043 $extsToInstall = array();
1044 foreach( $extsAvailable as $ext ) {
1045 if( $this->parent
->request
->getCheck( 'config_ext-' . $ext ) ) {
1046 $extsToInstall[] = $ext;
1049 $this->parent
->setVar( '_Extensions', $extsToInstall );
1051 if( $this->getVar( 'wgMainCacheType' ) == 'memcached' ) {
1052 $memcServers = explode( "\n", $this->getVar( '_MemCachedServers' ) );
1053 if( !$memcServers ) {
1054 $this->parent
->showError( 'config-memcache-needservers' );
1058 foreach( $memcServers as $server ) {
1059 $memcParts = explode( ":", $server );
1060 if( !IP
::isValid( $memcParts[0] ) ) {
1061 $this->parent
->showError( 'config-memcache-badip', $memcParts[0] );
1063 } elseif( !isset( $memcParts[1] ) ) {
1064 $this->parent
->showError( 'config-memcache-noport', $memcParts[0] );
1066 } elseif( $memcParts[1] < 1 ||
$memcParts[1] > 65535 ) {
1067 $this->parent
->showError( 'config-memcache-badport', 1, 65535 );
1077 class WebInstaller_Install
extends WebInstallerPage
{
1079 public function execute() {
1080 if( $this->getVar( '_UpgradeDone' ) ) {
1082 } elseif( $this->getVar( '_InstallDone' ) ) {
1084 } elseif( $this->parent
->request
->wasPosted() ) {
1086 $this->addHTML("<ul>");
1087 $results = $this->parent
->performInstallation(
1088 array( $this, 'startStage'),
1089 array( $this, 'endStage' )
1091 $this->addHTML("</ul>");
1092 // PerformInstallation bails on a fatal, so make sure the last item
1093 // completed before giving 'next.' Likewise, only provide back on failure
1094 $lastStep = end( $results );
1095 $continue = $lastStep->isOK() ?
'continue' : false;
1096 $back = $lastStep->isOK() ?
false : 'back';
1097 $this->endForm( $continue, $back );
1100 $this->addHTML( $this->parent
->getInfoBox( wfMsgNoTrans( 'config-install-begin' ) ) );
1106 public function startStage( $step ) {
1107 $this->addHTML( "<li>" . wfMsgHtml( "config-install-$step" ) . wfMsg( 'ellipsis') );
1108 if ( $step == 'extension-tables' ) {
1109 $this->startLiveBox();
1113 public function endStage( $step, $status ) {
1114 if ( $step == 'extension-tables' ) {
1115 $this->endLiveBox();
1117 $msg = $status->isOk() ?
'config-install-step-done' : 'config-install-step-failed';
1118 $html = wfMsgHtml( 'word-separator' ) . wfMsgHtml( $msg );
1119 if ( !$status->isOk() ) {
1120 $html = "<span class=\"error\">$html</span>";
1122 $this->addHTML( $html . "</li>\n" );
1123 if( !$status->isGood() ) {
1124 $this->parent
->showStatusBox( $status );
1130 class WebInstaller_Complete
extends WebInstallerPage
{
1132 public function execute() {
1133 // Pop up a dialog box, to make it difficult for the user to forget
1134 // to download the file
1135 $lsUrl = $GLOBALS['wgServer'] . $this->parent
->getURL( array( 'localsettings' => 1 ) );
1136 if ( isset( $_SERVER['HTTP_USER_AGENT'] ) && strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE' ) !== false ) {
1137 // JS appears the only method that works consistently with IE7+
1138 $this->addHtml( "\n<script type=\"" . $GLOBALS['wgJsMimeType'] . '">jQuery( document ).ready( function() { document.location='
1139 . Xml
::encodeJsVar( $lsUrl) . "; } );</script>\n" );
1141 $this->parent
->request
->response()->header( "Refresh: 0;url=$lsUrl" );
1145 $this->parent
->disableLinkPopups();
1147 $this->parent
->getInfoBox(
1148 wfMsgNoTrans( 'config-install-done',
1150 $GLOBALS['wgServer'] .
1151 $this->getVar( 'wgScriptPath' ) . '/index' .
1152 $this->getVar( 'wgScriptExtension' ),
1157 $this->parent
->restoreLinkPopups();
1158 $this->endForm( false, false );
1162 class WebInstaller_Restart
extends WebInstallerPage
{
1164 public function execute() {
1165 $r = $this->parent
->request
;
1166 if ( $r->wasPosted() ) {
1167 $really = $r->getVal( 'submit-restart' );
1169 $this->parent
->reset();
1175 $s = $this->parent
->getWarningBox( wfMsgNoTrans( 'config-help-restart' ) );
1176 $this->addHTML( $s );
1177 $this->endForm( 'restart' );
1182 abstract class WebInstaller_Document
extends WebInstallerPage
{
1184 protected abstract function getFileName();
1186 public function execute() {
1187 $text = $this->getFileContents();
1188 $text = $this->formatTextFile( $text );
1189 $this->parent
->output
->addWikiText( $text );
1191 $this->endForm( false );
1194 public function getFileContents() {
1195 return file_get_contents( dirname( __FILE__
) . '/../../' . $this->getFileName() );
1198 protected function formatTextFile( $text ) {
1199 // Use Unix line endings, escape some wikitext stuff
1200 $text = str_replace( array( '<', '{{', '[[', "\r" ),
1201 array( '<', '{{', '[[', '' ), $text );
1202 // join word-wrapped lines into one
1205 $text = preg_replace( "/\n([\\*#\t])([^\n]*?)\n([^\n#\\*:]+)/", "\n\\1\\2 \\3", $text );
1206 } while ( $text != $prev );
1207 // Replace tab indents with colons
1208 $text = preg_replace( '/^\t\t/m', '::', $text );
1209 $text = preg_replace( '/^\t/m', ':', $text );
1210 // turn (bug nnnn) into links
1211 $text = preg_replace_callback('/bug (\d+)/', array( $this, 'replaceBugLinks' ), $text );
1212 // add links to manual to every global variable mentioned
1213 $text = preg_replace_callback('/(\$wg[a-z0-9_]+)/i', array( $this, 'replaceConfigLinks' ), $text );
1217 private function replaceBugLinks( $matches ) {
1218 return '<span class="config-plainlink">[https://bugzilla.wikimedia.org/' .
1219 $matches[1] . ' bug ' . $matches[1] . ']</span>';
1222 private function replaceConfigLinks( $matches ) {
1223 return '<span class="config-plainlink">[http://www.mediawiki.org/wiki/Manual:' .
1224 $matches[1] . ' ' . $matches[1] . ']</span>';
1229 class WebInstaller_Readme
extends WebInstaller_Document
{
1230 protected function getFileName() { return 'README'; }
1233 class WebInstaller_ReleaseNotes
extends WebInstaller_Document
{
1234 protected function getFileName() { return 'RELEASE-NOTES'; }
1237 class WebInstaller_UpgradeDoc
extends WebInstaller_Document
{
1238 protected function getFileName() { return 'UPGRADE'; }
1241 class WebInstaller_Copying
extends WebInstaller_Document
{
1242 protected function getFileName() { return 'COPYING'; }