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;
36 * Is this a slow-running page in the installer? If so, WebInstaller will
37 * set_time_limit(0) before calling execute(). Right now this only applies
38 * to Install and Upgrade pages
41 public function isSlow() {
45 public function addHTML( $html ) {
46 $this->parent
->output
->addHTML( $html );
49 public function startForm() {
51 "<div class=\"config-section\">\n" .
56 'action' => $this->parent
->getUrl( array( 'page' => $this->getName() ) )
62 public function endForm( $continue = 'continue', $back = 'back' ) {
63 $s = "<div class=\"config-submit\">\n";
66 if ( $id === false ) {
67 $s .= Html
::hidden( 'lastPage', $this->parent
->request
->getVal( 'lastPage' ) );
71 // Fake submit button for enter keypress (bug 26267)
72 $s .= Xml
::submitButton( wfMsg( "config-$continue" ),
73 array( 'name' => "enter-$continue", 'style' =>
74 'visibility:hidden;overflow:hidden;width:1px;margin:0' ) ) . "\n";
78 $s .= Xml
::submitButton( wfMsg( "config-$back" ),
80 'name' => "submit-$back",
81 'tabindex' => $this->parent
->nextTabIndex()
86 $s .= Xml
::submitButton( wfMsg( "config-$continue" ),
88 'name' => "submit-$continue",
89 'tabindex' => $this->parent
->nextTabIndex(),
93 $s .= "</div></form></div>\n";
97 public function getName() {
98 return str_replace( 'WebInstaller_', '', get_class( $this ) );
101 protected function getId() {
102 return array_search( $this->getName(), $this->parent
->pageSequence
);
105 public function getVar( $var ) {
106 return $this->parent
->getVar( $var );
109 public function setVar( $name, $value ) {
110 $this->parent
->setVar( $name, $value );
114 * Get the starting tags of a fieldset.
116 * @param $legend String: message name
120 protected function getFieldsetStart( $legend ) {
121 return "\n<fieldset><legend>" . wfMsgHtml( $legend ) . "</legend>\n";
125 * Get the end tag of a fieldset.
129 protected function getFieldsetEnd() {
130 return "</fieldset>\n";
134 * Opens a textarea used to display the progress of a long operation
136 protected function startLiveBox() {
138 '<div id="config-spinner" style="display:none;">' .
139 '<img src="../skins/common/images/ajax-loader.gif" /></div>' .
140 '<script>jQuery( "#config-spinner" ).show();</script>' .
141 '<div id="config-live-log">' .
142 '<textarea name="LiveLog" rows="10" cols="30" readonly="readonly">'
144 $this->parent
->output
->flush();
148 * Opposite to startLiveBox()
150 protected function endLiveBox() {
151 $this->addHTML( '</textarea></div>
152 <script>jQuery( "#config-spinner" ).hide()</script>' );
153 $this->parent
->output
->flush();
157 class WebInstaller_Language
extends WebInstallerPage
{
159 public function execute() {
161 $r = $this->parent
->request
;
162 $userLang = $r->getVal( 'uselang' );
163 $contLang = $r->getVal( 'ContLang' );
165 $languages = Language
::getLanguageNames();
166 $lifetime = intval( ini_get( 'session.gc_maxlifetime' ) );
168 $lifetime = 1440; // PHP default
171 if ( $r->wasPosted() ) {
173 if ( $this->parent
->getSession( 'test' ) === null ) {
174 $requestTime = $r->getVal( 'LanguageRequestTime' );
175 if ( !$requestTime ) {
176 // The most likely explanation is that the user was knocked back
177 // from another page on POST due to session expiry
178 $msg = 'config-session-expired';
179 } elseif ( time() - $requestTime > $lifetime ) {
180 $msg = 'config-session-expired';
182 $msg = 'config-no-session';
184 $this->parent
->showError( $msg, $wgLang->formatTimePeriod( $lifetime ) );
186 if ( isset( $languages[$userLang] ) ) {
187 $this->setVar( '_UserLang', $userLang );
189 if ( isset( $languages[$contLang] ) ) {
190 $this->setVar( 'wgLanguageCode', $contLang );
194 } elseif ( $this->parent
->showSessionWarning
) {
195 # The user was knocked back from another page to the start
196 # This probably indicates a session expiry
197 $this->parent
->showError( 'config-session-expired',
198 $wgLang->formatTimePeriod( $lifetime ) );
201 $this->parent
->setSession( 'test', true );
203 if ( !isset( $languages[$userLang] ) ) {
204 $userLang = $this->getVar( '_UserLang', 'en' );
206 if ( !isset( $languages[$contLang] ) ) {
207 $contLang = $this->getVar( 'wgLanguageCode', 'en' );
210 $s = Html
::hidden( 'LanguageRequestTime', time() ) .
211 $this->getLanguageSelector( 'uselang', 'config-your-language', $userLang,
212 $this->parent
->getHelpBox( 'config-your-language-help' ) ) .
213 $this->getLanguageSelector( 'ContLang', 'config-wiki-language', $contLang,
214 $this->parent
->getHelpBox( 'config-wiki-language-help' ) );
215 $this->addHTML( $s );
216 $this->endForm( 'continue', false );
220 * Get a <select> for selecting languages.
224 * @param $selectedCode
225 * @param $helpHtml string
228 public function getLanguageSelector( $name, $label, $selectedCode, $helpHtml = '' ) {
229 global $wgDummyLanguageCodes;
233 $s .= Html
::openElement( 'select', array( 'id' => $name, 'name' => $name,
234 'tabindex' => $this->parent
->nextTabIndex() ) ) . "\n";
236 $languages = Language
::getLanguageNames();
238 foreach ( $languages as $code => $lang ) {
239 if ( isset( $wgDummyLanguageCodes[$code] ) ) continue;
240 $s .= "\n" . Xml
::option( "$code - $lang", $code, $code == $selectedCode );
242 $s .= "\n</select>\n";
243 return $this->parent
->label( $label, $name, $s );
248 class WebInstaller_ExistingWiki
extends WebInstallerPage
{
249 public function execute() {
250 // If there is no LocalSettings.php, continue to the installer welcome page
251 $vars = Installer
::getExistingLocalSettings();
256 // Check if the upgrade key supplied to the user has appeared in LocalSettings.php
257 if ( $vars['wgUpgradeKey'] !== false
258 && $this->getVar( '_UpgradeKeySupplied' )
259 && $this->getVar( 'wgUpgradeKey' ) === $vars['wgUpgradeKey'] )
261 // It's there, so the user is authorized
262 $status = $this->handleExistingUpgrade( $vars );
263 if ( $status->isOK() ) {
267 $this->parent
->showStatusBox( $status );
268 $this->endForm( 'continue' );
273 // If there is no $wgUpgradeKey, tell the user to add one to LocalSettings.php
274 if ( $vars['wgUpgradeKey'] === false ) {
275 if ( $this->getVar( 'wgUpgradeKey', false ) === false ) {
276 $secretKey = $this->getVar( 'wgSecretKey' ); // preserve $wgSecretKey
277 $this->parent
->generateKeys();
278 $this->setVar( 'wgSecretKey', $secretKey );
279 $this->setVar( '_UpgradeKeySupplied', true );
282 $this->addHTML( $this->parent
->getInfoBox(
283 wfMsgNoTrans( 'config-upgrade-key-missing',
284 "<pre dir=\"ltr\">\$wgUpgradeKey = '" . $this->getVar( 'wgUpgradeKey' ) . "';</pre>" )
286 $this->endForm( 'continue' );
290 // If there is an upgrade key, but it wasn't supplied, prompt the user to enter it
292 $r = $this->parent
->request
;
293 if ( $r->wasPosted() ) {
294 $key = $r->getText( 'config_wgUpgradeKey' );
295 if( !$key ||
$key !== $vars['wgUpgradeKey'] ) {
296 $this->parent
->showError( 'config-localsettings-badkey' );
297 $this->showKeyForm();
301 $status = $this->handleExistingUpgrade( $vars );
302 if ( $status->isOK() ) {
305 $this->parent
->showStatusBox( $status );
306 $this->showKeyForm();
310 $this->showKeyForm();
316 * Show the "enter key" form
318 protected function showKeyForm() {
321 $this->parent
->getInfoBox( wfMsgNoTrans( 'config-localsettings-upgrade' ) ).
323 $this->parent
->getTextBox( array(
324 'var' => 'wgUpgradeKey',
325 'label' => 'config-localsettings-key',
326 'attribs' => array( 'autocomplete' => 'off' ),
329 $this->endForm( 'continue' );
332 protected function importVariables( $names, $vars ) {
333 $status = Status
::newGood();
334 foreach ( $names as $name ) {
335 if ( !isset( $vars[$name] ) ) {
336 $status->fatal( 'config-localsettings-incomplete', $name );
338 $this->setVar( $name, $vars[$name] );
344 * Initiate an upgrade of the existing database
345 * @param $vars array Variables from LocalSettings.php and AdminSettings.php
348 protected function handleExistingUpgrade( $vars ) {
350 if ( !isset( $vars['wgDBtype'] ) ||
351 !in_array( $vars['wgDBtype'], Installer
::getDBTypes() ) ) {
352 return Status
::newFatal( 'config-localsettings-connection-error', '' );
355 // Set the relevant variables from LocalSettings.php
356 $requiredVars = array( 'wgDBtype' );
357 $status = $this->importVariables( $requiredVars , $vars );
358 $installer = $this->parent
->getDBInstaller();
359 $status->merge( $this->importVariables( $installer->getGlobalNames(), $vars ) );
360 if ( !$status->isOK() ) {
364 if ( isset( $vars['wgDBadminuser'] ) ) {
365 $this->setVar( '_InstallUser', $vars['wgDBadminuser'] );
367 $this->setVar( '_InstallUser', $vars['wgDBuser'] );
369 if ( isset( $vars['wgDBadminpassword'] ) ) {
370 $this->setVar( '_InstallPassword', $vars['wgDBadminpassword'] );
372 $this->setVar( '_InstallPassword', $vars['wgDBpassword'] );
375 // Test the database connection
376 $status = $installer->getConnection();
377 if ( !$status->isOK() ) {
378 // Adjust the error message to explain things correctly
379 $status->replaceMessage( 'config-connection-error',
380 'config-localsettings-connection-error' );
385 $this->setVar( '_ExistingDBSettings', true );
390 class WebInstaller_Welcome
extends WebInstallerPage
{
392 public function execute() {
393 if ( $this->parent
->request
->wasPosted() ) {
394 if ( $this->getVar( '_Environment' ) ) {
398 $this->parent
->output
->addWikiText( wfMsgNoTrans( 'config-welcome' ) );
399 $status = $this->parent
->doEnvironmentChecks();
400 if ( $status->isGood() ) {
401 $this->parent
->output
->addHTML( '<span class="success-message">' .
402 wfMsgHtml( 'config-env-good' ) . '</span>' );
403 $this->parent
->output
->addWikiText( wfMsgNoTrans( 'config-copyright',
404 SpecialVersion
::getCopyrightAndAuthorList() ) );
408 $this->parent
->showStatusMessage( $status );
414 class WebInstaller_DBConnect
extends WebInstallerPage
{
416 public function execute() {
417 if ( $this->getVar( '_ExistingDBSettings' ) ) {
421 $r = $this->parent
->request
;
422 if ( $r->wasPosted() ) {
423 $status = $this->submit();
425 if ( $status->isGood() ) {
426 $this->setVar( '_UpgradeDone', false );
429 $this->parent
->showStatusBox( $status );
435 $types = "<ul class=\"config-settings-block\">\n";
437 $defaultType = $this->getVar( 'wgDBtype' );
440 foreach( $this->parent
->getDBTypes() as $type ) {
441 $link = DatabaseBase
::factory( $type )->getSoftwareLink();
442 $dbSupport .= wfMsgNoTrans( "config-support-$type", $link ) . "\n";
444 $this->addHTML( $this->parent
->getInfoBox(
445 wfMsg( 'config-support-info', $dbSupport ) ) );
447 foreach ( $this->parent
->getVar( '_CompiledDBs' ) as $type ) {
448 $installer = $this->parent
->getDBInstaller( $type );
452 $installer->getReadableName(),
456 $type == $defaultType,
457 array( 'class' => 'dbRadio', 'rel' => "DB_wrapper_$type" )
462 Html
::openElement( 'div', array( 'id' => 'DB_wrapper_' . $type,
463 'class' => 'dbWrapper' ) ) .
464 Html
::element( 'h3', array(), wfMsg( 'config-header-' . $type ) ) .
465 $installer->getConnectForm() .
468 $types .= "</ul><br style=\"clear: left\"/>\n";
471 $this->parent
->label( 'config-db-type', false, $types ) .
478 public function submit() {
479 $r = $this->parent
->request
;
480 $type = $r->getVal( 'DBType' );
481 $this->setVar( 'wgDBtype', $type );
482 $installer = $this->parent
->getDBInstaller( $type );
484 return Status
::newFatal( 'config-invalid-db-type' );
486 return $installer->submitConnectForm();
491 class WebInstaller_Upgrade
extends WebInstallerPage
{
492 public function isSlow() {
496 public function execute() {
497 if ( $this->getVar( '_UpgradeDone' ) ) {
498 // Allow regeneration of LocalSettings.php, unless we are working
499 // from a pre-existing LocalSettings.php file and we want to avoid
500 // leaking its contents
501 if ( $this->parent
->request
->wasPosted() && !$this->getVar( '_ExistingDBSettings' ) ) {
502 // Done message acknowledged
506 // Show the done message again
507 // Make them click back again if they want to do the upgrade again
508 $this->showDoneMessage();
513 // wgDBtype is generally valid here because otherwise the previous page
514 // (connect) wouldn't have declared its happiness
515 $type = $this->getVar( 'wgDBtype' );
516 $installer = $this->parent
->getDBInstaller( $type );
518 if ( !$installer->needsUpgrade() ) {
522 if ( $this->parent
->request
->wasPosted() ) {
523 $installer->preUpgrade();
525 $this->startLiveBox();
526 $result = $installer->doUpgrade();
530 // If they're going to possibly regenerate LocalSettings, we
531 // need to create the upgrade/secret keys. Bug 26481
532 if( !$this->getVar( '_ExistingDBSettings' ) ) {
533 $this->parent
->generateKeys();
535 $this->setVar( '_UpgradeDone', true );
536 $this->showDoneMessage();
542 $this->addHTML( $this->parent
->getInfoBox(
543 wfMsgNoTrans( 'config-can-upgrade', $GLOBALS['wgVersion'] ) ) );
547 public function showDoneMessage() {
549 $regenerate = !$this->getVar( '_ExistingDBSettings' );
551 $msg = 'config-upgrade-done';
553 $msg = 'config-upgrade-done-no-regenerate';
555 $this->parent
->disableLinkPopups();
557 $this->parent
->getInfoBox(
559 $this->getVar( 'wgServer' ) .
560 $this->getVar( 'wgScriptPath' ) . '/index' .
561 $this->getVar( 'wgScriptExtension' )
565 $this->parent
->restoreLinkPopups();
566 $this->endForm( $regenerate ?
'regenerate' : false, false );
571 class WebInstaller_DBSettings
extends WebInstallerPage
{
573 public function execute() {
574 $installer = $this->parent
->getDBInstaller( $this->getVar( 'wgDBtype' ) );
576 $r = $this->parent
->request
;
577 if ( $r->wasPosted() ) {
578 $status = $installer->submitSettingsForm();
579 if ( $status === false ) {
581 } elseif ( $status->isGood() ) {
584 $this->parent
->showStatusBox( $status );
588 $form = $installer->getSettingsForm();
589 if ( $form === false ) {
594 $this->addHTML( $form );
600 class WebInstaller_Name
extends WebInstallerPage
{
602 public function execute() {
603 $r = $this->parent
->request
;
604 if ( $r->wasPosted() ) {
605 if ( $this->submit() ) {
612 // Encourage people to not name their site 'MediaWiki' by blanking the
613 // field. I think that was the intent with the original $GLOBALS['wgSitename']
614 // but these two always were the same so had the effect of making the
615 // installer forget $wgSitename when navigating back to this page.
616 if ( $this->getVar( 'wgSitename' ) == 'MediaWiki' ) {
617 $this->setVar( 'wgSitename', '' );
620 // Set wgMetaNamespace to something valid before we show the form.
621 // $wgMetaNamespace defaults to $wgSiteName which is 'MediaWiki'
622 $metaNS = $this->getVar( 'wgMetaNamespace' );
623 $this->setVar( 'wgMetaNamespace', wfMsgForContent( 'config-ns-other-default' ) );
626 $this->parent
->getTextBox( array(
627 'var' => 'wgSitename',
628 'label' => 'config-site-name',
629 'help' => $this->parent
->getHelpBox( 'config-site-name-help' )
631 $this->parent
->getRadioSet( array(
632 'var' => '_NamespaceType',
633 'label' => 'config-project-namespace',
634 'itemLabelPrefix' => 'config-ns-',
635 'values' => array( 'site-name', 'generic', 'other' ),
636 'commonAttribs' => array( 'class' => 'enableForOther',
637 'rel' => 'config_wgMetaNamespace' ),
638 'help' => $this->parent
->getHelpBox( 'config-project-namespace-help' )
640 $this->parent
->getTextBox( array(
641 'var' => 'wgMetaNamespace',
642 'label' => '', //TODO: Needs a label?
643 'attribs' => array( 'readonly' => 'readonly', 'class' => 'enabledByOther' ),
646 $this->getFieldSetStart( 'config-admin-box' ) .
647 $this->parent
->getTextBox( array(
648 'var' => '_AdminName',
649 'label' => 'config-admin-name',
650 'help' => $this->parent
->getHelpBox( 'config-admin-help' )
652 $this->parent
->getPasswordBox( array(
653 'var' => '_AdminPassword',
654 'label' => 'config-admin-password',
656 $this->parent
->getPasswordBox( array(
657 'var' => '_AdminPassword2',
658 'label' => 'config-admin-password-confirm'
660 $this->parent
->getTextBox( array(
661 'var' => '_AdminEmail',
662 'label' => 'config-admin-email',
663 'help' => $this->parent
->getHelpBox( 'config-admin-email-help' )
665 $this->parent
->getCheckBox( array(
666 'var' => '_Subscribe',
667 'label' => 'config-subscribe',
668 'help' => $this->parent
->getHelpBox( 'config-subscribe-help' )
670 $this->getFieldSetEnd() .
671 $this->parent
->getInfoBox( wfMsg( 'config-almost-done' ) ) .
672 $this->parent
->getRadioSet( array(
673 'var' => '_SkipOptional',
674 'itemLabelPrefix' => 'config-optional-',
675 'values' => array( 'continue', 'skip' )
679 // Restore the default value
680 $this->setVar( 'wgMetaNamespace', $metaNS );
686 public function submit() {
688 $this->parent
->setVarsFromRequest( array( 'wgSitename', '_NamespaceType',
689 '_AdminName', '_AdminPassword', '_AdminPassword2', '_AdminEmail',
690 '_Subscribe', '_SkipOptional', 'wgMetaNamespace' ) );
692 // Validate site name
693 if ( strval( $this->getVar( 'wgSitename' ) ) === '' ) {
694 $this->parent
->showError( 'config-site-name-blank' );
699 $nsType = $this->getVar( '_NamespaceType' );
700 if ( $nsType == 'site-name' ) {
701 $name = $this->getVar( 'wgSitename' );
702 // Sanitize for namespace
703 // This algorithm should match the JS one in WebInstallerOutput.php
704 $name = preg_replace( '/[\[\]\{\}|#<>%+? ]/', '_', $name );
705 $name = str_replace( '&', '&', $name );
706 $name = preg_replace( '/__+/', '_', $name );
707 $name = ucfirst( trim( $name, '_' ) );
708 } elseif ( $nsType == 'generic' ) {
709 $name = wfMsg( 'config-ns-generic' );
711 $name = $this->getVar( 'wgMetaNamespace' );
714 // Validate namespace
715 if ( strpos( $name, ':' ) !== false ) {
718 // Title-style validation
719 $title = Title
::newFromText( $name );
721 $good = $nsType == 'site-name';
723 $name = $title->getDBkey();
728 $this->parent
->showError( 'config-ns-invalid', $name );
732 // Make sure it won't conflict with any existing namespaces
734 $nsIndex = $wgContLang->getNsIndex( $name );
735 if( $nsIndex !== false && $nsIndex !== NS_PROJECT
) {
736 $this->parent
->showError( 'config-ns-conflict', $name );
740 $this->setVar( 'wgMetaNamespace', $name );
742 // Validate username for creation
743 $name = $this->getVar( '_AdminName' );
744 if ( strval( $name ) === '' ) {
745 $this->parent
->showError( 'config-admin-name-blank' );
749 $cname = User
::getCanonicalName( $name, 'creatable' );
750 if ( $cname === false ) {
751 $this->parent
->showError( 'config-admin-name-invalid', $name );
754 $this->setVar( '_AdminName', $cname );
760 $pwd = $this->getVar( '_AdminPassword' );
761 $user = User
::newFromName( $cname );
762 $valid = $user && $user->getPasswordValidity( $pwd );
763 if ( strval( $pwd ) === '' ) {
764 # $user->getPasswordValidity just checks for $wgMinimalPasswordLength.
765 # This message is more specific and helpful.
766 $msg = 'config-admin-password-blank';
767 } elseif ( $pwd !== $this->getVar( '_AdminPassword2' ) ) {
768 $msg = 'config-admin-password-mismatch';
769 } elseif ( $valid !== true ) {
770 # As of writing this will only catch the username being e.g. 'FOO' and
774 if ( $msg !== false ) {
775 call_user_func_array( array( $this->parent
, 'showError' ), (array)$msg );
776 $this->setVar( '_AdminPassword', '' );
777 $this->setVar( '_AdminPassword2', '' );
781 // Validate e-mail if provided
782 $email = $this->getVar( '_AdminEmail' );
783 if( $email && !Sanitizer
::validateEmail( $email ) ) {
784 $this->parent
->showError( 'config-admin-error-bademail' );
787 // If they asked to subscribe to mediawiki-announce but didn't give
788 // an e-mail, show an error. Bug 29332
789 if( !$email && $this->getVar( '_Subscribe' ) ) {
790 $this->parent
->showError( 'config-subscribe-noemail' );
799 class WebInstaller_Options
extends WebInstallerPage
{
801 public function execute() {
802 if ( $this->getVar( '_SkipOptional' ) == 'skip' ) {
805 if ( $this->parent
->request
->wasPosted() ) {
806 if ( $this->submit() ) {
811 $emailwrapperStyle = $this->getVar( 'wgEnableEmail' ) ?
'' : 'display: none';
815 $this->parent
->getRadioSet( array(
816 'var' => '_RightsProfile',
817 'label' => 'config-profile',
818 'itemLabelPrefix' => 'config-profile-',
819 'values' => array_keys( $this->parent
->rightsProfiles
),
821 $this->parent
->getInfoBox( wfMsgNoTrans( 'config-profile-help' ) ) .
824 $this->parent
->getRadioSet( array(
825 'var' => '_LicenseCode',
826 'label' => 'config-license',
827 'itemLabelPrefix' => 'config-license-',
828 'values' => array_keys( $this->parent
->licenses
),
829 'commonAttribs' => array( 'class' => 'licenseRadio' ),
831 $this->getCCChooser() .
832 $this->parent
->getHelpBox( 'config-license-help' ) .
835 $this->getFieldSetStart( 'config-email-settings' ) .
836 $this->parent
->getCheckBox( array(
837 'var' => 'wgEnableEmail',
838 'label' => 'config-enable-email',
839 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'emailwrapper' ),
841 $this->parent
->getHelpBox( 'config-enable-email-help' ) .
842 "<div id=\"emailwrapper\" style=\"$emailwrapperStyle\">" .
843 $this->parent
->getTextBox( array(
844 'var' => 'wgPasswordSender',
845 'label' => 'config-email-sender'
847 $this->parent
->getHelpBox( 'config-email-sender-help' ) .
848 $this->parent
->getCheckBox( array(
849 'var' => 'wgEnableUserEmail',
850 'label' => 'config-email-user',
852 $this->parent
->getHelpBox( 'config-email-user-help' ) .
853 $this->parent
->getCheckBox( array(
854 'var' => 'wgEnotifUserTalk',
855 'label' => 'config-email-usertalk',
857 $this->parent
->getHelpBox( 'config-email-usertalk-help' ) .
858 $this->parent
->getCheckBox( array(
859 'var' => 'wgEnotifWatchlist',
860 'label' => 'config-email-watchlist',
862 $this->parent
->getHelpBox( 'config-email-watchlist-help' ) .
863 $this->parent
->getCheckBox( array(
864 'var' => 'wgEmailAuthentication',
865 'label' => 'config-email-auth',
867 $this->parent
->getHelpBox( 'config-email-auth-help' ) .
869 $this->getFieldSetEnd()
872 $extensions = $this->parent
->findExtensions();
875 $extHtml = $this->getFieldSetStart( 'config-extensions' );
877 foreach( $extensions as $ext ) {
878 $extHtml .= $this->parent
->getCheckBox( array(
884 $extHtml .= $this->parent
->getHelpBox( 'config-extensions-help' ) .
885 $this->getFieldSetEnd();
886 $this->addHTML( $extHtml );
889 // Having / in paths in Windows looks funny :)
890 $this->setVar( 'wgDeletedDirectory',
892 '/', DIRECTORY_SEPARATOR
,
893 $this->getVar( 'wgDeletedDirectory' )
897 $uploadwrapperStyle = $this->getVar( 'wgEnableUploads' ) ?
'' : 'display: none';
900 $this->getFieldSetStart( 'config-upload-settings' ) .
901 $this->parent
->getCheckBox( array(
902 'var' => 'wgEnableUploads',
903 'label' => 'config-upload-enable',
904 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'uploadwrapper' ),
905 'help' => $this->parent
->getHelpBox( 'config-upload-help' )
907 '<div id="uploadwrapper" style="' . $uploadwrapperStyle . '">' .
908 $this->parent
->getTextBox( array(
909 'var' => 'wgDeletedDirectory',
910 'label' => 'config-upload-deleted',
911 'attribs' => array( 'dir' => 'ltr' ),
912 'help' => $this->parent
->getHelpBox( 'config-upload-deleted-help' )
915 $this->parent
->getTextBox( array(
917 'label' => 'config-logo',
918 'attribs' => array( 'dir' => 'ltr' ),
919 'help' => $this->parent
->getHelpBox( 'config-logo-help' )
923 $this->parent
->getCheckBox( array(
924 'var' => 'wgUseInstantCommons',
925 'label' => 'config-instantcommons',
926 'help' => $this->parent
->getHelpBox( 'config-instantcommons-help' )
928 $this->getFieldSetEnd()
931 $caches = array( 'none' );
932 if( count( $this->getVar( '_Caches' ) ) ) {
935 $caches[] = 'memcached';
937 // We'll hide/show this on demand when the value changes, see config.js.
938 $cacheval = $this->getVar( 'wgMainCacheType' );
940 // We need to set a default here; but don't hardcode it
941 // or we lose it every time we reload the page for validation
945 $hidden = ($cacheval == 'memcached') ?
'' : 'display: none';
948 $this->getFieldSetStart( 'config-advanced-settings' ) .
949 # Object cache settings
950 $this->parent
->getRadioSet( array(
951 'var' => 'wgMainCacheType',
952 'label' => 'config-cache-options',
953 'itemLabelPrefix' => 'config-cache-',
955 'value' => $cacheval,
957 $this->parent
->getHelpBox( 'config-cache-help' ) .
958 "<div id=\"config-memcachewrapper\" style=\"$hidden\">" .
959 $this->parent
->getTextArea( array(
960 'var' => '_MemCachedServers',
961 'label' => 'config-memcached-servers',
962 'help' => $this->parent
->getHelpBox( 'config-memcached-help' )
965 $this->getFieldSetEnd()
973 public function getCCPartnerUrl() {
974 $server = $this->getVar( 'wgServer' );
975 $exitUrl = $server . $this->parent
->getUrl( array(
977 'SubmitCC' => 'indeed',
978 'config__LicenseCode' => 'cc',
979 'config_wgRightsUrl' => '[license_url]',
980 'config_wgRightsText' => '[license_name]',
981 'config_wgRightsIcon' => '[license_button]',
983 $styleUrl = $server . dirname( dirname( $this->parent
->getUrl() ) ) .
984 '/skins/common/config-cc.css';
985 $iframeUrl = 'http://creativecommons.org/license/?' .
987 'partner' => 'MediaWiki',
988 'exit_url' => $exitUrl,
989 'lang' => $this->getVar( '_UserLang' ),
990 'stylesheet' => $styleUrl,
995 public function getCCChooser() {
996 $iframeAttribs = array(
997 'class' => 'config-cc-iframe',
998 'name' => 'config-cc-iframe',
999 'id' => 'config-cc-iframe',
1004 if ( $this->getVar( '_CCDone' ) ) {
1005 $iframeAttribs['src'] = $this->parent
->getUrl( array( 'ShowCC' => 'yes' ) );
1007 $iframeAttribs['src'] = $this->getCCPartnerUrl();
1009 $wrapperStyle = ($this->getVar('_LicenseCode') == 'cc-choose') ?
'' : 'display: none';
1012 "<div class=\"config-cc-wrapper\" id=\"config-cc-wrapper\" style=\"$wrapperStyle\">\n" .
1013 Html
::element( 'iframe', $iframeAttribs, '', false /* not short */ ) .
1017 public function getCCDoneBox() {
1018 $js = "parent.document.getElementById('config-cc-wrapper').style.height = '$1';";
1019 // If you change this height, also change it in config.css
1020 $expandJs = str_replace( '$1', '54em', $js );
1021 $reduceJs = str_replace( '$1', '70px', $js );
1024 Html
::element( 'img', array( 'src' => $this->getVar( 'wgRightsIcon' ) ) ) .
1026 htmlspecialchars( $this->getVar( 'wgRightsText' ) ) .
1028 "<p style=\"text-align: center\">" .
1031 'href' => $this->getCCPartnerUrl(),
1032 'onclick' => $expandJs,
1034 wfMsg( 'config-cc-again' )
1037 "<script type=\"text/javascript\">\n" .
1038 # Reduce the wrapper div height
1039 htmlspecialchars( $reduceJs ) .
1044 public function submitCC() {
1045 $newValues = $this->parent
->setVarsFromRequest(
1046 array( 'wgRightsUrl', 'wgRightsText', 'wgRightsIcon' ) );
1047 if ( count( $newValues ) != 3 ) {
1048 $this->parent
->showError( 'config-cc-error' );
1051 $this->setVar( '_CCDone', true );
1052 $this->addHTML( $this->getCCDoneBox() );
1055 public function submit() {
1056 $this->parent
->setVarsFromRequest( array( '_RightsProfile', '_LicenseCode',
1057 'wgEnableEmail', 'wgPasswordSender', 'wgEnableUploads', 'wgLogo',
1058 'wgEnableUserEmail', 'wgEnotifUserTalk', 'wgEnotifWatchlist',
1059 'wgEmailAuthentication', 'wgMainCacheType', '_MemCachedServers',
1060 'wgUseInstantCommons' ) );
1062 if ( !in_array( $this->getVar( '_RightsProfile' ),
1063 array_keys( $this->parent
->rightsProfiles
) ) )
1065 reset( $this->parent
->rightsProfiles
);
1066 $this->setVar( '_RightsProfile', key( $this->parent
->rightsProfiles
) );
1069 $code = $this->getVar( '_LicenseCode' );
1070 if ( $code == 'cc-choose' ) {
1071 if ( !$this->getVar( '_CCDone' ) ) {
1072 $this->parent
->showError( 'config-cc-not-chosen' );
1075 } elseif ( in_array( $code, array_keys( $this->parent
->licenses
) ) ) {
1076 $entry = $this->parent
->licenses
[$code];
1077 if ( isset( $entry['text'] ) ) {
1078 $this->setVar( 'wgRightsText', $entry['text'] );
1080 $this->setVar( 'wgRightsText', wfMsg( 'config-license-' . $code ) );
1082 $this->setVar( 'wgRightsUrl', $entry['url'] );
1083 $this->setVar( 'wgRightsIcon', $entry['icon'] );
1085 $this->setVar( 'wgRightsText', '' );
1086 $this->setVar( 'wgRightsUrl', '' );
1087 $this->setVar( 'wgRightsIcon', '' );
1090 $extsAvailable = $this->parent
->findExtensions();
1091 $extsToInstall = array();
1092 foreach( $extsAvailable as $ext ) {
1093 if( $this->parent
->request
->getCheck( 'config_ext-' . $ext ) ) {
1094 $extsToInstall[] = $ext;
1097 $this->parent
->setVar( '_Extensions', $extsToInstall );
1099 if( $this->getVar( 'wgMainCacheType' ) == 'memcached' ) {
1100 $memcServers = explode( "\n", $this->getVar( '_MemCachedServers' ) );
1101 if( !$memcServers ) {
1102 $this->parent
->showError( 'config-memcache-needservers' );
1106 foreach( $memcServers as $server ) {
1107 $memcParts = explode( ":", $server, 2 );
1108 if ( !isset( $memcParts[0] )
1109 ||
( !IP
::isValid( $memcParts[0] )
1110 && ( gethostbyname( $memcParts[0] ) == $memcParts[0] ) ) ) {
1111 $this->parent
->showError( 'config-memcache-badip', $memcParts[0] );
1113 } elseif( !isset( $memcParts[1] ) ) {
1114 $this->parent
->showError( 'config-memcache-noport', $memcParts[0] );
1116 } elseif( $memcParts[1] < 1 ||
$memcParts[1] > 65535 ) {
1117 $this->parent
->showError( 'config-memcache-badport', 1, 65535 );
1127 class WebInstaller_Install
extends WebInstallerPage
{
1128 public function isSlow() {
1132 public function execute() {
1133 if( $this->getVar( '_UpgradeDone' ) ) {
1135 } elseif( $this->getVar( '_InstallDone' ) ) {
1137 } elseif( $this->parent
->request
->wasPosted() ) {
1139 $this->addHTML("<ul>");
1140 $results = $this->parent
->performInstallation(
1141 array( $this, 'startStage'),
1142 array( $this, 'endStage' )
1144 $this->addHTML("</ul>");
1145 // PerformInstallation bails on a fatal, so make sure the last item
1146 // completed before giving 'next.' Likewise, only provide back on failure
1147 $lastStep = end( $results );
1148 $continue = $lastStep->isOK() ?
'continue' : false;
1149 $back = $lastStep->isOK() ?
false : 'back';
1150 $this->endForm( $continue, $back );
1153 $this->addHTML( $this->parent
->getInfoBox( wfMsgNoTrans( 'config-install-begin' ) ) );
1159 public function startStage( $step ) {
1160 $this->addHTML( "<li>" . wfMsgHtml( "config-install-$step" ) . wfMsg( 'ellipsis') );
1161 if ( $step == 'extension-tables' ) {
1162 $this->startLiveBox();
1168 * @param $status Status
1170 public function endStage( $step, $status ) {
1171 if ( $step == 'extension-tables' ) {
1172 $this->endLiveBox();
1174 $msg = $status->isOk() ?
'config-install-step-done' : 'config-install-step-failed';
1175 $html = wfMsgHtml( 'word-separator' ) . wfMsgHtml( $msg );
1176 if ( !$status->isOk() ) {
1177 $html = "<span class=\"error\">$html</span>";
1179 $this->addHTML( $html . "</li>\n" );
1180 if( !$status->isGood() ) {
1181 $this->parent
->showStatusBox( $status );
1187 class WebInstaller_Complete
extends WebInstallerPage
{
1189 public function execute() {
1190 // Pop up a dialog box, to make it difficult for the user to forget
1191 // to download the file
1192 $lsUrl = $this->getVar( 'wgServer' ) . $this->parent
->getURL( array( 'localsettings' => 1 ) );
1193 if ( isset( $_SERVER['HTTP_USER_AGENT'] ) &&
1194 strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE' ) !== false ) {
1195 // JS appears the only method that works consistently with IE7+
1196 $this->addHtml( "\n<script type=\"" . $GLOBALS['wgJsMimeType'] .
1197 '">jQuery( document ).ready( function() { document.location=' .
1198 Xml
::encodeJsVar( $lsUrl) . "; } );</script>\n" );
1200 $this->parent
->request
->response()->header( "Refresh: 0;url=$lsUrl" );
1204 $this->parent
->disableLinkPopups();
1206 $this->parent
->getInfoBox(
1207 wfMsgNoTrans( 'config-install-done',
1209 $this->getVar( 'wgServer' ) .
1210 $this->getVar( 'wgScriptPath' ) . '/index' .
1211 $this->getVar( 'wgScriptExtension' ),
1216 $this->parent
->restoreLinkPopups();
1217 $this->endForm( false, false );
1221 class WebInstaller_Restart
extends WebInstallerPage
{
1223 public function execute() {
1224 $r = $this->parent
->request
;
1225 if ( $r->wasPosted() ) {
1226 $really = $r->getVal( 'submit-restart' );
1228 $this->parent
->reset();
1234 $s = $this->parent
->getWarningBox( wfMsgNoTrans( 'config-help-restart' ) );
1235 $this->addHTML( $s );
1236 $this->endForm( 'restart' );
1241 abstract class WebInstaller_Document
extends WebInstallerPage
{
1243 protected abstract function getFileName();
1245 public function execute() {
1246 $text = $this->getFileContents();
1247 $text = InstallDocFormatter
::format( $text );
1248 $this->parent
->output
->addWikiText( $text );
1250 $this->endForm( false );
1253 public function getFileContents() {
1254 return file_get_contents( dirname( __FILE__
) . '/../../' . $this->getFileName() );
1259 class WebInstaller_Readme
extends WebInstaller_Document
{
1260 protected function getFileName() { return 'README'; }
1263 class WebInstaller_ReleaseNotes
extends WebInstaller_Document
{
1264 protected function getFileName() { return 'RELEASE-NOTES'; }
1267 class WebInstaller_UpgradeDoc
extends WebInstaller_Document
{
1268 protected function getFileName() { return 'UPGRADE'; }
1271 class WebInstaller_Copying
extends WebInstaller_Document
{
1272 protected function getFileName() { return 'COPYING'; }