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 $this->parent
->generateUpgradeKey();
254 $this->setVar( '_UpgradeKeySupplied', true );
257 $this->addHTML( $this->parent
->getInfoBox(
258 wfMsgNoTrans( 'config-upgrade-key-missing',
259 "<pre>\$wgUpgradeKey = '" . $this->getVar( 'wgUpgradeKey' ) . "';</pre>" )
261 $this->endForm( 'continue' );
265 // If there is an upgrade key, but it wasn't supplied, prompt the user to enter it
267 $r = $this->parent
->request
;
268 if ( $r->wasPosted() ) {
269 $key = $r->getText( 'config_wgUpgradeKey' );
270 if( !$key ||
$key !== $vars['wgUpgradeKey'] ) {
271 $this->parent
->showError( 'config-localsettings-badkey' );
272 $this->showKeyForm();
276 $status = $this->handleExistingUpgrade( $vars );
277 if ( $status->isOK() ) {
280 $this->parent
->showStatusBox( $status );
281 $this->showKeyForm();
285 $this->showKeyForm();
291 * Show the "enter key" form
293 protected function showKeyForm() {
296 $this->parent
->getInfoBox( wfMsgNoTrans( 'config-localsettings-upgrade' ) ).
298 $this->parent
->getTextBox( array(
299 'var' => 'wgUpgradeKey',
300 'label' => 'config-localsettings-key',
301 'attribs' => array( 'autocomplete' => 'off' ),
304 $this->endForm( 'continue' );
307 protected function importVariables( $names, $vars ) {
308 $status = Status
::newGood();
309 foreach ( $names as $name ) {
310 if ( !isset( $vars[$name] ) ) {
311 $status->fatal( 'config-localsettings-incomplete', $name );
313 $this->setVar( $name, $vars[$name] );
319 * Initiate an upgrade of the existing database
320 * @param $vars Variables from LocalSettings.php and AdminSettings.php
323 protected function handleExistingUpgrade( $vars ) {
325 if ( !isset( $vars['wgDBtype'] ) ||
!in_array( $vars['wgDBtype'], Installer
::getDBTypes() ) ) {
326 return Status
::newFatal( 'config-localsettings-connection-error', '' );
329 // Set the relevant variables from LocalSettings.php
330 $requiredVars = array( 'wgDBtype' );
331 $status = $this->importVariables( $requiredVars , $vars );
332 $installer = $this->parent
->getDBInstaller();
333 $status->merge( $this->importVariables( $installer->getGlobalNames(), $vars ) );
334 if ( !$status->isOK() ) {
338 if ( isset( $vars['wgDBadminuser'] ) ) {
339 $this->setVar( '_InstallUser', $vars['wgDBadminuser'] );
341 $this->setVar( '_InstallUser', $vars['wgDBuser'] );
343 if ( isset( $vars['wgDBadminpassword'] ) ) {
344 $this->setVar( '_InstallPassword', $vars['wgDBadminpassword'] );
346 $this->setVar( '_InstallPassword', $vars['wgDBpassword'] );
349 // Test the database connection
350 $status = $installer->getConnection();
351 if ( !$status->isOK() ) {
352 // Adjust the error message to explain things correctly
353 $status->replaceMessage( 'config-connection-error',
354 'config-localsettings-connection-error' );
359 $this->setVar( '_ExistingDBSettings', true );
364 class WebInstaller_Welcome
extends WebInstallerPage
{
366 public function execute() {
367 if ( $this->parent
->request
->wasPosted() ) {
368 if ( $this->getVar( '_Environment' ) ) {
372 $this->parent
->output
->addWikiText( wfMsgNoTrans( 'config-welcome' ) );
373 $status = $this->parent
->doEnvironmentChecks();
374 if ( $status->isGood() ) {
375 $this->parent
->output
->addHTML( '<span class="success-message">' .
376 wfMsgHtml( 'config-env-good' ) . '</span>' );
377 $this->parent
->output
->addWikiText( wfMsgNoTrans( 'config-copyright',
378 SpecialVersion
::getCopyrightAndAuthorList() ) );
382 $this->parent
->showStatusMessage( $status );
388 class WebInstaller_DBConnect
extends WebInstallerPage
{
390 public function execute() {
391 if ( $this->getVar( '_ExistingDBSettings' ) ) {
395 $r = $this->parent
->request
;
396 if ( $r->wasPosted() ) {
397 $status = $this->submit();
399 if ( $status->isGood() ) {
400 $this->setVar( '_UpgradeDone', false );
403 $this->parent
->showStatusBox( $status );
409 $types = "<ul class=\"config-settings-block\">\n";
411 $defaultType = $this->getVar( 'wgDBtype' );
414 foreach( $this->parent
->getDBTypes() as $type ) {
415 $link = DatabaseBase
::newFromType( $type )->getSoftwareLink();
416 $dbSupport .= wfMsgNoTrans( "config-support-$type", $link ) . "\n";
418 $this->addHTML( $this->parent
->getInfoBox(
419 wfMsg( 'config-support-info', $dbSupport ) ) );
421 foreach ( $this->parent
->getVar( '_CompiledDBs' ) as $type ) {
422 $installer = $this->parent
->getDBInstaller( $type );
426 $installer->getReadableName(),
430 $type == $defaultType,
431 array( 'class' => 'dbRadio', 'rel' => "DB_wrapper_$type" )
436 Html
::openElement( 'div', array( 'id' => 'DB_wrapper_' . $type, 'class' => 'dbWrapper' ) ) .
437 Html
::element( 'h3', array(), wfMsg( 'config-header-' . $type ) ) .
438 $installer->getConnectForm() .
441 $types .= "</ul><br clear=\"left\"/>\n";
444 $this->parent
->label( 'config-db-type', false, $types ) .
451 public function submit() {
452 $r = $this->parent
->request
;
453 $type = $r->getVal( 'DBType' );
454 $this->setVar( 'wgDBtype', $type );
455 $installer = $this->parent
->getDBInstaller( $type );
457 return Status
::newFatal( 'config-invalid-db-type' );
459 return $installer->submitConnectForm();
464 class WebInstaller_Upgrade
extends WebInstallerPage
{
466 public function execute() {
467 if ( $this->getVar( '_UpgradeDone' ) ) {
468 // Allow regeneration of LocalSettings.php, unless we are working
469 // from a pre-existing LocalSettings.php file and we want to avoid
470 // leaking its contents
471 if ( $this->parent
->request
->wasPosted() && !$this->getVar( '_ExistingDBSettings' ) ) {
472 // Done message acknowledged
476 // Show the done message again
477 // Make them click back again if they want to do the upgrade again
478 $this->showDoneMessage();
483 // wgDBtype is generally valid here because otherwise the previous page
484 // (connect) wouldn't have declared its happiness
485 $type = $this->getVar( 'wgDBtype' );
486 $installer = $this->parent
->getDBInstaller( $type );
488 if ( !$installer->needsUpgrade() ) {
492 if ( $this->parent
->request
->wasPosted() ) {
493 $installer->preUpgrade();
495 $this->startLiveBox();
496 $result = $installer->doUpgrade();
500 // If they're going to possibly regenerate LocalSettings, we
501 // need to create the upgrade/secret keys. Bug 26481
502 if( !$this->getVar( '_ExistingDBSettings' ) ) {
503 $this->parent
->generateKeys();
505 $this->setVar( '_UpgradeDone', true );
506 $this->showDoneMessage();
512 $this->addHTML( $this->parent
->getInfoBox(
513 wfMsgNoTrans( 'config-can-upgrade', $GLOBALS['wgVersion'] ) ) );
517 public function showDoneMessage() {
519 $regenerate = !$this->getVar( '_ExistingDBSettings' );
521 $msg = 'config-upgrade-done';
523 $msg = 'config-upgrade-done-no-regenerate';
525 $this->parent
->disableLinkPopups();
527 $this->parent
->getInfoBox(
529 $GLOBALS['wgServer'] .
530 $this->getVar( 'wgScriptPath' ) . '/index' .
531 $this->getVar( 'wgScriptExtension' )
535 $this->parent
->restoreLinkPopups();
536 $this->endForm( $regenerate ?
'regenerate' : false, false );
541 class WebInstaller_DBSettings
extends WebInstallerPage
{
543 public function execute() {
544 $installer = $this->parent
->getDBInstaller( $this->getVar( 'wgDBtype' ) );
546 $r = $this->parent
->request
;
547 if ( $r->wasPosted() ) {
548 $status = $installer->submitSettingsForm();
549 if ( $status === false ) {
551 } elseif ( $status->isGood() ) {
554 $this->parent
->showStatusBox( $status );
558 $form = $installer->getSettingsForm();
559 if ( $form === false ) {
564 $this->addHTML( $form );
570 class WebInstaller_Name
extends WebInstallerPage
{
572 public function execute() {
573 $r = $this->parent
->request
;
574 if ( $r->wasPosted() ) {
575 if ( $this->submit() ) {
582 // Encourage people to not name their site 'MediaWiki' by blanking the
583 // field. I think that was the intent with the original $GLOBALS['wgSitename']
584 // but these two always were the same so had the effect of making the
585 // installer forget $wgSitename when navigating back to this page.
586 if ( $this->getVar( 'wgSitename' ) == 'MediaWiki' ) {
587 $this->setVar( 'wgSitename', '' );
590 // Set wgMetaNamespace to something valid before we show the form.
591 // $wgMetaNamespace defaults to $wgSiteName which is 'MediaWiki'
592 $metaNS = $this->getVar( 'wgMetaNamespace' );
593 $this->setVar( 'wgMetaNamespace', wfMsgForContent( 'config-ns-other-default' ) );
596 $this->parent
->getTextBox( array(
597 'var' => 'wgSitename',
598 'label' => 'config-site-name',
599 'help' => $this->parent
->getHelpBox( 'config-site-name-help' )
601 $this->parent
->getRadioSet( array(
602 'var' => '_NamespaceType',
603 'label' => 'config-project-namespace',
604 'itemLabelPrefix' => 'config-ns-',
605 'values' => array( 'site-name', 'generic', 'other' ),
606 'commonAttribs' => array( 'class' => 'enableForOther', 'rel' => 'config_wgMetaNamespace' ),
607 'help' => $this->parent
->getHelpBox( 'config-project-namespace-help' )
609 $this->parent
->getTextBox( array(
610 'var' => 'wgMetaNamespace',
611 'label' => '', //TODO: Needs a label?
612 'attribs' => array( 'readonly' => 'readonly', 'class' => 'enabledByOther' ),
615 $this->getFieldSetStart( 'config-admin-box' ) .
616 $this->parent
->getTextBox( array(
617 'var' => '_AdminName',
618 'label' => 'config-admin-name',
619 'help' => $this->parent
->getHelpBox( 'config-admin-help' )
621 $this->parent
->getPasswordBox( array(
622 'var' => '_AdminPassword',
623 'label' => 'config-admin-password',
625 $this->parent
->getPasswordBox( array(
626 'var' => '_AdminPassword2',
627 'label' => 'config-admin-password-confirm'
629 $this->parent
->getTextBox( array(
630 'var' => '_AdminEmail',
631 'label' => 'config-admin-email',
632 'help' => $this->parent
->getHelpBox( 'config-admin-email-help' )
634 $this->parent
->getCheckBox( array(
635 'var' => '_Subscribe',
636 'label' => 'config-subscribe',
637 'help' => $this->parent
->getHelpBox( 'config-subscribe-help' )
639 $this->getFieldSetEnd() .
640 $this->parent
->getInfoBox( wfMsg( 'config-almost-done' ) ) .
641 $this->parent
->getRadioSet( array(
642 'var' => '_SkipOptional',
643 'itemLabelPrefix' => 'config-optional-',
644 'values' => array( 'continue', 'skip' )
648 // Restore the default value
649 $this->setVar( 'wgMetaNamespace', $metaNS );
655 public function submit() {
657 $this->parent
->setVarsFromRequest( array( 'wgSitename', '_NamespaceType',
658 '_AdminName', '_AdminPassword', '_AdminPassword2', '_AdminEmail',
659 '_Subscribe', '_SkipOptional', 'wgMetaNamespace' ) );
661 // Validate site name
662 if ( strval( $this->getVar( 'wgSitename' ) ) === '' ) {
663 $this->parent
->showError( 'config-site-name-blank' );
668 $nsType = $this->getVar( '_NamespaceType' );
669 if ( $nsType == 'site-name' ) {
670 $name = $this->getVar( 'wgSitename' );
671 // Sanitize for namespace
672 // This algorithm should match the JS one in WebInstallerOutput.php
673 $name = preg_replace( '/[\[\]\{\}|#<>%+? ]/', '_', $name );
674 $name = str_replace( '&', '&', $name );
675 $name = preg_replace( '/__+/', '_', $name );
676 $name = ucfirst( trim( $name, '_' ) );
677 } elseif ( $nsType == 'generic' ) {
678 $name = wfMsg( 'config-ns-generic' );
680 $name = $this->getVar( 'wgMetaNamespace' );
683 // Validate namespace
684 if ( strpos( $name, ':' ) !== false ) {
687 // Title-style validation
688 $title = Title
::newFromText( $name );
690 $good = $nsType == 'site-name';
692 $name = $title->getDBkey();
697 $this->parent
->showError( 'config-ns-invalid', $name );
701 // Make sure it won't conflict with any existing namespaces
703 $nsIndex = $wgContLang->getNsIndex( $name );
704 if( $nsIndex !== false && $nsIndex !== NS_PROJECT
) {
705 $this->parent
->showError( 'config-ns-conflict', $name );
709 $this->setVar( 'wgMetaNamespace', $name );
711 // Validate username for creation
712 $name = $this->getVar( '_AdminName' );
713 if ( strval( $name ) === '' ) {
714 $this->parent
->showError( 'config-admin-name-blank' );
718 $cname = User
::getCanonicalName( $name, 'creatable' );
719 if ( $cname === false ) {
720 $this->parent
->showError( 'config-admin-name-invalid', $name );
723 $this->setVar( '_AdminName', $cname );
730 $pwd = $this->getVar( '_AdminPassword' );
731 $user = User
::newFromName( $cname );
732 $valid = $user && $user->getPasswordValidity( $pwd );
733 if ( strval( $pwd ) === '' ) {
734 # $user->getPasswordValidity just checks for $wgMinimalPasswordLength.
735 # This message is more specific and helpful.
736 $msg = 'config-admin-password-blank';
737 } elseif ( $pwd !== $this->getVar( '_AdminPassword2' ) ) {
738 $msg = 'config-admin-password-mismatch';
739 } elseif ( $valid !== true ) {
740 # As of writing this will only catch the username being e.g. 'FOO' and
744 if ( $msg !== false ) {
745 call_user_func_array( array( $this->parent
, 'showError' ), (array)$msg );
746 $this->setVar( '_AdminPassword', '' );
747 $this->setVar( '_AdminPassword2', '' );
751 // Validate e-mail if provided
752 $email = $this->getVar( '_AdminEmail' );
753 if( $email && !User
::isValidEmailAddr( $email ) ) {
754 $this->parent
->showError( 'config-admin-error-bademail' );
763 class WebInstaller_Options
extends WebInstallerPage
{
765 public function execute() {
766 if ( $this->getVar( '_SkipOptional' ) == 'skip' ) {
769 if ( $this->parent
->request
->wasPosted() ) {
770 if ( $this->submit() ) {
775 $emailwrapperStyle = $this->getVar( 'wgEnableEmail' ) ?
'' : 'display: none';
779 $this->parent
->getRadioSet( array(
780 'var' => '_RightsProfile',
781 'label' => 'config-profile',
782 'itemLabelPrefix' => 'config-profile-',
783 'values' => array_keys( $this->parent
->rightsProfiles
),
785 $this->parent
->getInfoBox( wfMsgNoTrans( 'config-profile-help' ) ) .
788 $this->parent
->getRadioSet( array(
789 'var' => '_LicenseCode',
790 'label' => 'config-license',
791 'itemLabelPrefix' => 'config-license-',
792 'values' => array_keys( $this->parent
->licenses
),
793 'commonAttribs' => array( 'class' => 'licenseRadio' ),
795 $this->getCCChooser() .
796 $this->parent
->getHelpBox( 'config-license-help' ) .
799 $this->getFieldSetStart( 'config-email-settings' ) .
800 $this->parent
->getCheckBox( array(
801 'var' => 'wgEnableEmail',
802 'label' => 'config-enable-email',
803 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'emailwrapper' ),
805 $this->parent
->getHelpBox( 'config-enable-email-help' ) .
806 "<div id=\"emailwrapper\" style=\"$emailwrapperStyle\">" .
807 $this->parent
->getTextBox( array(
808 'var' => 'wgPasswordSender',
809 'label' => 'config-email-sender'
811 $this->parent
->getHelpBox( 'config-email-sender-help' ) .
812 $this->parent
->getCheckBox( array(
813 'var' => 'wgEnableUserEmail',
814 'label' => 'config-email-user',
816 $this->parent
->getHelpBox( 'config-email-user-help' ) .
817 $this->parent
->getCheckBox( array(
818 'var' => 'wgEnotifUserTalk',
819 'label' => 'config-email-usertalk',
821 $this->parent
->getHelpBox( 'config-email-usertalk-help' ) .
822 $this->parent
->getCheckBox( array(
823 'var' => 'wgEnotifWatchlist',
824 'label' => 'config-email-watchlist',
826 $this->parent
->getHelpBox( 'config-email-watchlist-help' ) .
827 $this->parent
->getCheckBox( array(
828 'var' => 'wgEmailAuthentication',
829 'label' => 'config-email-auth',
831 $this->parent
->getHelpBox( 'config-email-auth-help' ) .
833 $this->getFieldSetEnd()
836 $extensions = $this->parent
->findExtensions();
839 $extHtml = $this->getFieldSetStart( 'config-extensions' );
841 foreach( $extensions as $ext ) {
842 $extHtml .= $this->parent
->getCheckBox( array(
848 $extHtml .= $this->parent
->getHelpBox( 'config-extensions-help' ) .
849 $this->getFieldSetEnd();
850 $this->addHTML( $extHtml );
853 // Having / in paths in Windows looks funny :)
854 $this->setVar( 'wgDeletedDirectory',
856 '/', DIRECTORY_SEPARATOR
,
857 $this->getVar( 'wgDeletedDirectory' )
861 $uploadwrapperStyle = $this->getVar( 'wgEnableUploads' ) ?
'' : 'display: none';
864 $this->getFieldSetStart( 'config-upload-settings' ) .
865 $this->parent
->getCheckBox( array(
866 'var' => 'wgEnableUploads',
867 'label' => 'config-upload-enable',
868 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'uploadwrapper' ),
869 'help' => $this->parent
->getHelpBox( 'config-upload-help' )
871 '<div id="uploadwrapper" style="' . $uploadwrapperStyle . '">' .
872 $this->parent
->getTextBox( array(
873 'var' => 'wgDeletedDirectory',
874 'label' => 'config-upload-deleted',
875 'help' => $this->parent
->getHelpBox( 'config-upload-deleted-help' )
878 $this->parent
->getTextBox( array(
880 'label' => 'config-logo',
881 'help' => $this->parent
->getHelpBox( 'config-logo-help' )
885 $this->parent
->getCheckBox( array(
886 'var' => 'wgUseInstantCommons',
887 'label' => 'config-instantcommons',
888 'help' => $this->parent
->getHelpBox( 'config-instantcommons-help' )
890 $this->getFieldSetEnd()
893 $caches = array( 'none' );
894 if( count( $this->getVar( '_Caches' ) ) ) {
897 $caches[] = 'memcached';
901 $this->getFieldSetStart( 'config-advanced-settings' ) .
902 # Object cache settings
903 $this->parent
->getRadioSet( array(
904 'var' => 'wgMainCacheType',
905 'label' => 'config-cache-options',
906 'itemLabelPrefix' => 'config-cache-',
910 $this->parent
->getHelpBox( 'config-cache-help' ) .
911 '<div id="config-memcachewrapper">' .
912 $this->parent
->getTextArea( array(
913 'var' => '_MemCachedServers',
914 'label' => 'config-memcached-servers',
915 'help' => $this->parent
->getHelpBox( 'config-memcached-help' )
918 $this->getFieldSetEnd()
923 public function getCCPartnerUrl() {
925 $exitUrl = $wgServer . $this->parent
->getUrl( array(
927 'SubmitCC' => 'indeed',
928 'config__LicenseCode' => 'cc',
929 'config_wgRightsUrl' => '[license_url]',
930 'config_wgRightsText' => '[license_name]',
931 'config_wgRightsIcon' => '[license_button]',
933 $styleUrl = $wgServer . dirname( dirname( $this->parent
->getUrl() ) ) .
934 '/skins/common/config-cc.css';
935 $iframeUrl = 'http://creativecommons.org/license/?' .
937 'partner' => 'MediaWiki',
938 'exit_url' => $exitUrl,
939 'lang' => $this->getVar( '_UserLang' ),
940 'stylesheet' => $styleUrl,
945 public function getCCChooser() {
946 $iframeAttribs = array(
947 'class' => 'config-cc-iframe',
948 'name' => 'config-cc-iframe',
949 'id' => 'config-cc-iframe',
954 if ( $this->getVar( '_CCDone' ) ) {
955 $iframeAttribs['src'] = $this->parent
->getUrl( array( 'ShowCC' => 'yes' ) );
957 $iframeAttribs['src'] = $this->getCCPartnerUrl();
959 $wrapperStyle = ($this->getVar('_LicenseCode') == 'cc-choose') ?
'' : 'display: none';
962 "<div class=\"config-cc-wrapper\" id=\"config-cc-wrapper\" style=\"$wrapperStyle\">\n" .
963 Html
::element( 'iframe', $iframeAttribs, '', false /* not short */ ) .
967 public function getCCDoneBox() {
968 $js = "parent.document.getElementById('config-cc-wrapper').style.height = '$1';";
969 // If you change this height, also change it in config.css
970 $expandJs = str_replace( '$1', '54em', $js );
971 $reduceJs = str_replace( '$1', '70px', $js );
974 Html
::element( 'img', array( 'src' => $this->getVar( 'wgRightsIcon' ) ) ) .
976 htmlspecialchars( $this->getVar( 'wgRightsText' ) ) .
978 "<p style=\"text-align: center\">" .
981 'href' => $this->getCCPartnerUrl(),
982 'onclick' => $expandJs,
984 wfMsg( 'config-cc-again' )
987 "<script type=\"text/javascript\">\n" .
988 # Reduce the wrapper div height
989 htmlspecialchars( $reduceJs ) .
994 public function submitCC() {
995 $newValues = $this->parent
->setVarsFromRequest(
996 array( 'wgRightsUrl', 'wgRightsText', 'wgRightsIcon' ) );
997 if ( count( $newValues ) != 3 ) {
998 $this->parent
->showError( 'config-cc-error' );
1001 $this->setVar( '_CCDone', true );
1002 $this->addHTML( $this->getCCDoneBox() );
1005 public function submit() {
1006 $this->parent
->setVarsFromRequest( array( '_RightsProfile', '_LicenseCode',
1007 'wgEnableEmail', 'wgPasswordSender', 'wgEnableUploads', 'wgLogo',
1008 'wgEnableUserEmail', 'wgEnotifUserTalk', 'wgEnotifWatchlist',
1009 'wgEmailAuthentication', 'wgMainCacheType', '_MemCachedServers',
1010 'wgUseInstantCommons' ) );
1012 if ( !in_array( $this->getVar( '_RightsProfile' ),
1013 array_keys( $this->parent
->rightsProfiles
) ) )
1015 reset( $this->parent
->rightsProfiles
);
1016 $this->setVar( '_RightsProfile', key( $this->parent
->rightsProfiles
) );
1019 $code = $this->getVar( '_LicenseCode' );
1020 if ( $code == 'cc-choose' ) {
1021 if ( !$this->getVar( '_CCDone' ) ) {
1022 $this->parent
->showError( 'config-cc-not-chosen' );
1025 } elseif ( in_array( $code, array_keys( $this->parent
->licenses
) ) ) {
1026 $entry = $this->parent
->licenses
[$code];
1027 if ( isset( $entry['text'] ) ) {
1028 $this->setVar( 'wgRightsText', $entry['text'] );
1030 $this->setVar( 'wgRightsText', wfMsg( 'config-license-' . $code ) );
1032 $this->setVar( 'wgRightsUrl', $entry['url'] );
1033 $this->setVar( 'wgRightsIcon', $entry['icon'] );
1035 $this->setVar( 'wgRightsText', '' );
1036 $this->setVar( 'wgRightsUrl', '' );
1037 $this->setVar( 'wgRightsIcon', '' );
1040 $extsAvailable = $this->parent
->findExtensions();
1041 $extsToInstall = array();
1042 foreach( $extsAvailable as $ext ) {
1043 if( $this->parent
->request
->getCheck( 'config_ext-' . $ext ) ) {
1044 $extsToInstall[] = $ext;
1047 $this->parent
->setVar( '_Extensions', $extsToInstall );
1049 if( $this->getVar( 'wgMainCacheType' ) == 'memcached' ) {
1050 $memcServers = explode( "\n", $this->getVar( '_MemCachedServers' ) );
1051 if( !$memcServers ) {
1052 $this->parent
->showError( 'config-memcache-needservers' );
1056 foreach( $memcServers as $server ) {
1057 $memcParts = explode( ":", $server );
1058 if( !IP
::isValid( $memcParts[0] ) ) {
1059 $this->parent
->showError( 'config-memcache-badip', $memcParts[0] );
1061 } elseif( !isset( $memcParts[1] ) ) {
1062 $this->parent
->showError( 'config-memcache-noport', $memcParts[0] );
1064 } elseif( $memcParts[1] < 1 ||
$memcParts[1] > 65535 ) {
1065 $this->parent
->showError( 'config-memcache-badport', 1, 65535 );
1075 class WebInstaller_Install
extends WebInstallerPage
{
1077 public function execute() {
1078 if( $this->getVar( '_UpgradeDone' ) ) {
1080 } elseif( $this->getVar( '_InstallDone' ) ) {
1082 } elseif( $this->parent
->request
->wasPosted() ) {
1084 $this->addHTML("<ul>");
1085 $results = $this->parent
->performInstallation(
1086 array( $this, 'startStage'),
1087 array( $this, 'endStage' )
1089 $this->addHTML("</ul>");
1090 // PerformInstallation bails on a fatal, so make sure the last item
1091 // completed before giving 'next.' Likewise, only provide back on failure
1092 $lastStep = end( $results );
1093 $continue = $lastStep->isOK() ?
'continue' : false;
1094 $back = $lastStep->isOK() ?
false : 'back';
1095 $this->endForm( $continue, $back );
1098 $this->addHTML( $this->parent
->getInfoBox( wfMsgNoTrans( 'config-install-begin' ) ) );
1104 public function startStage( $step ) {
1105 $this->addHTML( "<li>" . wfMsgHtml( "config-install-$step" ) . wfMsg( 'ellipsis') );
1106 if ( $step == 'extension-tables' ) {
1107 $this->startLiveBox();
1111 public function endStage( $step, $status ) {
1112 if ( $step == 'extension-tables' ) {
1113 $this->endLiveBox();
1115 $msg = $status->isOk() ?
'config-install-step-done' : 'config-install-step-failed';
1116 $html = wfMsgHtml( 'word-separator' ) . wfMsgHtml( $msg );
1117 if ( !$status->isOk() ) {
1118 $html = "<span class=\"error\">$html</span>";
1120 $this->addHTML( $html . "</li>\n" );
1121 if( !$status->isGood() ) {
1122 $this->parent
->showStatusBox( $status );
1128 class WebInstaller_Complete
extends WebInstallerPage
{
1130 public function execute() {
1131 // Pop up a dialog box, to make it difficult for the user to forget
1132 // to download the file
1133 $lsUrl = $GLOBALS['wgServer'] . $this->parent
->getURL( array( 'localsettings' => 1 ) );
1134 if ( isset( $_SERVER['HTTP_USER_AGENT'] ) && strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE' ) !== false ) {
1135 // JS appears the only method that works consistently with IE7+
1136 $this->addHtml( "\n<script type=\"" . $GLOBALS['wgJsMimeType'] . '">jQuery( document ).ready( function() { document.location='
1137 . Xml
::encodeJsVar( $lsUrl) . "; } );</script>\n" );
1139 $this->parent
->request
->response()->header( "Refresh: 0;url=$lsUrl" );
1143 $this->parent
->disableLinkPopups();
1145 $this->parent
->getInfoBox(
1146 wfMsgNoTrans( 'config-install-done',
1148 $GLOBALS['wgServer'] .
1149 $this->getVar( 'wgScriptPath' ) . '/index' .
1150 $this->getVar( 'wgScriptExtension' ),
1155 $this->parent
->restoreLinkPopups();
1156 $this->endForm( false, false );
1160 class WebInstaller_Restart
extends WebInstallerPage
{
1162 public function execute() {
1163 $r = $this->parent
->request
;
1164 if ( $r->wasPosted() ) {
1165 $really = $r->getVal( 'submit-restart' );
1167 $this->parent
->reset();
1173 $s = $this->parent
->getWarningBox( wfMsgNoTrans( 'config-help-restart' ) );
1174 $this->addHTML( $s );
1175 $this->endForm( 'restart' );
1180 abstract class WebInstaller_Document
extends WebInstallerPage
{
1182 protected abstract function getFileName();
1184 public function execute() {
1185 $text = $this->getFileContents();
1186 $text = $this->formatTextFile( $text );
1187 $this->parent
->output
->addWikiText( $text );
1189 $this->endForm( false );
1192 public function getFileContents() {
1193 return file_get_contents( dirname( __FILE__
) . '/../../' . $this->getFileName() );
1196 protected function formatTextFile( $text ) {
1197 // Use Unix line endings, escape some wikitext stuff
1198 $text = str_replace( array( '<', '{{', '[[', "\r" ),
1199 array( '<', '{{', '[[', '' ), $text );
1200 // join word-wrapped lines into one
1203 $text = preg_replace( "/\n([\\*#\t])([^\n]*?)\n([^\n#\\*:]+)/", "\n\\1\\2 \\3", $text );
1204 } while ( $text != $prev );
1205 // Replace tab indents with colons
1206 $text = preg_replace( '/^\t\t/m', '::', $text );
1207 $text = preg_replace( '/^\t/m', ':', $text );
1208 // turn (bug nnnn) into links
1209 $text = preg_replace_callback('/bug (\d+)/', array( $this, 'replaceBugLinks' ), $text );
1210 // add links to manual to every global variable mentioned
1211 $text = preg_replace_callback('/(\$wg[a-z0-9_]+)/i', array( $this, 'replaceConfigLinks' ), $text );
1215 private function replaceBugLinks( $matches ) {
1216 return '<span class="config-plainlink">[https://bugzilla.wikimedia.org/' .
1217 $matches[1] . ' bug ' . $matches[1] . ']</span>';
1220 private function replaceConfigLinks( $matches ) {
1221 return '<span class="config-plainlink">[http://www.mediawiki.org/wiki/Manual:' .
1222 $matches[1] . ' ' . $matches[1] . ']</span>';
1227 class WebInstaller_Readme
extends WebInstaller_Document
{
1228 protected function getFileName() { return 'README'; }
1231 class WebInstaller_ReleaseNotes
extends WebInstaller_Document
{
1232 protected function getFileName() { return 'RELEASE-NOTES'; }
1235 class WebInstaller_UpgradeDoc
extends WebInstaller_Document
{
1236 protected function getFileName() { return 'UPGRADE'; }
1239 class WebInstaller_Copying
extends WebInstaller_Document
{
1240 protected function getFileName() { return 'COPYING'; }