3 * Base code for web installer pages.
10 * Abstract class to define pages for the web installer.
15 abstract class WebInstallerPage
{
18 * The WebInstaller object this WebInstallerPage belongs to.
24 public abstract function execute();
29 * @param $parent WebInstaller
31 public function __construct( WebInstaller
$parent ) {
32 $this->parent
= $parent;
35 public function addHTML( $html ) {
36 $this->parent
->output
->addHTML( $html );
39 public function startForm() {
41 "<div class=\"config-section\">\n" .
46 'action' => $this->parent
->getUrl( array( 'page' => $this->getName() ) )
52 public function endForm( $continue = 'continue', $back = 'back' ) {
53 $s = "<div class=\"config-submit\">\n";
56 if ( $id === false ) {
57 $s .= Html
::hidden( 'lastPage', $this->parent
->request
->getVal( 'lastPage' ) );
61 // Fake submit button for enter keypress (bug 26267)
62 $s .= Xml
::submitButton( wfMsg( "config-$continue" ),
63 array( 'name' => "enter-$continue", 'style' => 'visibility:hidden;overflow:hidden;width:1px;margin:0' ) ) . "\n";
67 $s .= Xml
::submitButton( wfMsg( "config-$back" ),
69 'name' => "submit-$back",
70 'tabindex' => $this->parent
->nextTabIndex()
75 $s .= Xml
::submitButton( wfMsg( "config-$continue" ),
77 'name' => "submit-$continue",
78 'tabindex' => $this->parent
->nextTabIndex(),
82 $s .= "</div></form></div>\n";
86 public function getName() {
87 return str_replace( 'WebInstaller_', '', get_class( $this ) );
90 protected function getId() {
91 return array_search( $this->getName(), $this->parent
->pageSequence
);
94 public function getVar( $var ) {
95 return $this->parent
->getVar( $var );
98 public function setVar( $name, $value ) {
99 $this->parent
->setVar( $name, $value );
103 * Get the starting tags of a fieldset.
105 * @param $legend String: message name
107 protected function getFieldsetStart( $legend ) {
108 return "\n<fieldset><legend>" . wfMsgHtml( $legend ) . "</legend>\n";
112 * Get the end tag of a fieldset.
114 protected function getFieldsetEnd() {
115 return "</fieldset>\n";
119 class WebInstaller_Language
extends WebInstallerPage
{
121 public function execute() {
123 $r = $this->parent
->request
;
124 $userLang = $r->getVal( 'UserLang' );
125 $contLang = $r->getVal( 'ContLang' );
127 $lifetime = intval( ini_get( 'session.gc_maxlifetime' ) );
129 $lifetime = 1440; // PHP default
132 if ( $r->wasPosted() ) {
134 if ( $this->parent
->getSession( 'test' ) === null ) {
135 $requestTime = $r->getVal( 'LanguageRequestTime' );
136 if ( !$requestTime ) {
137 // The most likely explanation is that the user was knocked back
138 // from another page on POST due to session expiry
139 $msg = 'config-session-expired';
140 } elseif ( time() - $requestTime > $lifetime ) {
141 $msg = 'config-session-expired';
143 $msg = 'config-no-session';
145 $this->parent
->showError( $msg, $wgLang->formatTimePeriod( $lifetime ) );
147 $languages = Language
::getLanguageNames();
148 if ( isset( $languages[$userLang] ) ) {
149 $this->setVar( '_UserLang', $userLang );
151 if ( isset( $languages[$contLang] ) ) {
152 $this->setVar( 'wgLanguageCode', $contLang );
156 } elseif ( $this->parent
->showSessionWarning
) {
157 # The user was knocked back from another page to the start
158 # This probably indicates a session expiry
159 $this->parent
->showError( 'config-session-expired', $wgLang->formatTimePeriod( $lifetime ) );
162 $this->parent
->setSession( 'test', true );
164 if ( !isset( $languages[$userLang] ) ) {
165 $userLang = $this->getVar( '_UserLang', 'en' );
167 if ( !isset( $languages[$contLang] ) ) {
168 $contLang = $this->getVar( 'wgLanguageCode', 'en' );
171 $s = Html
::hidden( 'LanguageRequestTime', time() ) .
172 $this->getLanguageSelector( 'UserLang', 'config-your-language', $userLang, $this->parent
->getHelpBox( 'config-your-language-help' ) ) .
173 $this->getLanguageSelector( 'ContLang', 'config-wiki-language', $contLang, $this->parent
->getHelpBox( 'config-wiki-language-help' ) );
174 $this->addHTML( $s );
175 $this->endForm( 'continue', false );
179 * Get a <select> for selecting languages.
181 public function getLanguageSelector( $name, $label, $selectedCode ) {
182 global $wgDummyLanguageCodes;
183 $s = Html
::openElement( 'select', array( 'id' => $name, 'name' => $name ) ) . "\n";
185 $languages = Language
::getLanguageNames();
187 $dummies = array_flip( $wgDummyLanguageCodes );
188 foreach ( $languages as $code => $lang ) {
189 if ( isset( $dummies[$code] ) ) continue;
190 $s .= "\n" . Xml
::option( "$code - $lang", $code, $code == $selectedCode );
192 $s .= "\n</select>\n";
193 return $this->parent
->label( $label, $name, $s );
198 class WebInstaller_ExistingWiki
extends WebInstallerPage
{
199 public function execute() {
200 // If there is no LocalSettings.php, continue to the installer welcome page
201 $vars = $this->parent
->getExistingLocalSettings();
206 // Check if the upgrade key supplied to the user has appeared in LocalSettings.php
207 if ( $vars['wgUpgradeKey'] !== false
208 && $this->getVar( '_UpgradeKeySupplied' )
209 && $this->getVar( 'wgUpgradeKey' ) === $vars['wgUpgradeKey'] )
211 // It's there, so the user is authorized
212 $status = $this->handleExistingUpgrade( $vars );
213 if ( $status->isOK() ) {
217 $this->parent
->showStatusBox( $status );
218 $this->endForm( 'continue' );
223 // If there is no $wgUpgradeKey, tell the user to add one to LocalSettings.php
224 if ( $vars['wgUpgradeKey'] === false ) {
225 if ( $this->getVar( 'wgUpgradeKey', false ) === false ) {
226 $this->parent
->generateUpgradeKey();
227 $this->setVar( '_UpgradeKeySupplied', true );
230 $this->addHTML( $this->parent
->getInfoBox(
231 wfMsgNoTrans( 'config-upgrade-key-missing',
232 "<pre>\$wgUpgradeKey = '" . $this->getVar( 'wgUpgradeKey' ) . "';</pre>" )
234 $this->endForm( 'continue' );
238 // If there is an upgrade key, but it wasn't supplied, prompt the user to enter it
240 $r = $this->parent
->request
;
241 if ( $r->wasPosted() ) {
242 $key = $r->getText( 'config_wgUpgradeKey' );
243 if( !$key ||
$key !== $vars['wgUpgradeKey'] ) {
244 $this->parent
->showError( 'config-localsettings-badkey' );
245 $this->showKeyForm();
249 $status = $this->handleExistingUpgrade( $vars );
250 if ( $status->isOK() ) {
253 $this->parent
->showStatusBox( $status );
254 $this->showKeyForm();
258 $this->showKeyForm();
264 * Show the "enter key" form
266 protected function showKeyForm() {
269 $this->parent
->getInfoBox( wfMsgNoTrans( 'config-localsettings-upgrade' ) ).
271 $this->parent
->getTextBox( array(
272 'var' => 'wgUpgradeKey',
273 'label' => 'config-localsettings-key',
274 'attribs' => array( 'autocomplete' => 'off' ),
277 $this->endForm( 'continue' );
280 protected function importVariables( $names, $vars ) {
281 $status = Status
::newGood();
282 foreach ( $names as $name ) {
283 if ( !isset( $vars[$name] ) ) {
284 $status->fatal( 'config-localsettings-incomplete', $name );
286 $this->setVar( $name, $vars[$name] );
292 * Initiate an upgrade of the existing database
293 * @param $vars Variables from LocalSettings.php and AdminSettings.php
296 protected function handleExistingUpgrade( $vars ) {
298 if ( !isset( $vars['wgDBtype'] ) ||
!in_array( $vars['wgDBtype'], Installer
::getDBTypes() ) ) {
299 return Status
::newFatal( 'config-localsettings-connection-error', '' );
302 // Set the relevant variables from LocalSettings.php
303 $requiredVars = array( 'wgDBtype' );
304 $status = $this->importVariables( $requiredVars , $vars );
305 $installer = $this->parent
->getDBInstaller();
306 $status->merge( $this->importVariables( $installer->getGlobalNames(), $vars ) );
307 if ( !$status->isOK() ) {
311 if ( isset( $vars['wgDBadminuser'] ) ) {
312 $this->setVar( '_InstallUser', $vars['wgDBadminuser'] );
314 $this->setVar( '_InstallUser', $vars['wgDBuser'] );
316 if ( isset( $vars['wgDBadminpassword'] ) ) {
317 $this->setVar( '_InstallPassword', $vars['wgDBadminpassword'] );
319 $this->setVar( '_InstallPassword', $vars['wgDBpassword'] );
322 // Test the database connection
323 $status = $installer->getConnection();
324 if ( !$status->isOK() ) {
325 // Adjust the error message to explain things correctly
326 $status->replaceMessage( 'config-connection-error',
327 'config-localsettings-connection-error' );
332 $this->setVar( '_ExistingDBSettings', true );
337 class WebInstaller_Welcome
extends WebInstallerPage
{
339 public function execute() {
340 if ( $this->parent
->request
->wasPosted() ) {
341 if ( $this->getVar( '_Environment' ) ) {
345 $this->parent
->output
->addWikiText( wfMsgNoTrans( 'config-welcome' ) );
346 $status = $this->parent
->doEnvironmentChecks();
347 if ( $status->isGood() ) {
348 $this->parent
->output
->addHTML( '<span class="success-message">' .
349 wfMsgHtml( 'config-env-good' ) . '</span>' );
350 $this->parent
->output
->addWikiText( wfMsgNoTrans( 'config-copyright',
351 SpecialVersion
::getCopyrightAndAuthorList() ) );
355 $this->parent
->showStatusMessage( $status );
361 class WebInstaller_DBConnect
extends WebInstallerPage
{
363 public function execute() {
364 if ( $this->getVar( '_ExistingDBSettings' ) ) {
368 $r = $this->parent
->request
;
369 if ( $r->wasPosted() ) {
370 $status = $this->submit();
372 if ( $status->isGood() ) {
373 $this->setVar( '_UpgradeDone', false );
376 $this->parent
->showStatusBox( $status );
382 $types = "<ul class=\"config-settings-block\">\n";
384 $defaultType = $this->getVar( 'wgDBtype' );
387 foreach( $this->parent
->getDBTypes() as $type ) {
388 $link = DatabaseBase
::newFromType( $type )->getSoftwareLink();
389 $dbSupport .= wfMsgNoTrans( "config-support-$type", $link ) . "\n";
391 $this->addHTML( $this->parent
->getInfoBox(
392 wfMsg( 'config-support-info', $dbSupport ) ) );
394 foreach ( $this->parent
->getVar( '_CompiledDBs' ) as $type ) {
395 $installer = $this->parent
->getDBInstaller( $type );
399 $installer->getReadableName(),
403 $type == $defaultType,
404 array( 'class' => 'dbRadio', 'rel' => "DB_wrapper_$type" )
409 Html
::openElement( 'div', array( 'id' => 'DB_wrapper_' . $type, 'class' => 'dbWrapper' ) ) .
410 Html
::element( 'h3', array(), wfMsg( 'config-header-' . $type ) ) .
411 $installer->getConnectForm() .
414 $types .= "</ul><br clear=\"left\"/>\n";
417 $this->parent
->label( 'config-db-type', false, $types ) .
424 public function submit() {
425 $r = $this->parent
->request
;
426 $type = $r->getVal( 'DBType' );
427 $this->setVar( 'wgDBtype', $type );
428 $installer = $this->parent
->getDBInstaller( $type );
430 return Status
::newFatal( 'config-invalid-db-type' );
432 return $installer->submitConnectForm();
437 class WebInstaller_Upgrade
extends WebInstallerPage
{
439 public function execute() {
440 if ( $this->getVar( '_UpgradeDone' ) ) {
441 // Allow regeneration of LocalSettings.php, unless we are working
442 // from a pre-existing LocalSettings.php file and we want to avoid
443 // leaking its contents
444 if ( $this->parent
->request
->wasPosted() && !$this->getVar( '_ExistingDBSettings' ) ) {
445 // Done message acknowledged
449 // Show the done message again
450 // Make them click back again if they want to do the upgrade again
451 $this->showDoneMessage();
456 // wgDBtype is generally valid here because otherwise the previous page
457 // (connect) wouldn't have declared its happiness
458 $type = $this->getVar( 'wgDBtype' );
459 $installer = $this->parent
->getDBInstaller( $type );
461 if ( !$installer->needsUpgrade() ) {
465 if ( $this->parent
->request
->wasPosted() ) {
466 $installer->preUpgrade();
468 '<div id="config-spinner" style="display:none;"><img src="../skins/common/images/ajax-loader.gif" /></div>' .
469 '<script>jQuery( "#config-spinner" )[0].style.display = "block";</script>' .
470 '<textarea id="config-update-log" name="UpdateLog" rows="10" readonly="readonly">'
472 $this->parent
->output
->flush();
473 $result = $installer->doUpgrade();
474 $this->addHTML( '</textarea>
475 <script>jQuery( "#config-spinner" )[0].style.display = "none";</script>' );
476 $this->parent
->output
->flush();
478 // If they're going to possibly regenerate LocalSettings, we
479 // need to create the upgrade/secret keys. Bug 26481
480 if( !$this->getVar( '_ExistingDBSettings' ) ) {
481 $this->parent
->generateSecretKey();
482 $this->parent
->generateUpgradeKey();
484 $this->setVar( '_UpgradeDone', true );
485 $this->showDoneMessage();
491 $this->addHTML( $this->parent
->getInfoBox(
492 wfMsgNoTrans( 'config-can-upgrade', $GLOBALS['wgVersion'] ) ) );
496 public function showDoneMessage() {
498 $regenerate = !$this->getVar( '_ExistingDBSettings' );
500 $msg = 'config-upgrade-done';
502 $msg = 'config-upgrade-done-no-regenerate';
504 $this->parent
->disableLinkPopups();
506 $this->parent
->getInfoBox(
508 $GLOBALS['wgServer'] .
509 $this->getVar( 'wgScriptPath' ) . '/index' .
510 $this->getVar( 'wgScriptExtension' )
514 $this->parent
->restoreLinkPopups();
515 $this->endForm( $regenerate ?
'regenerate' : false, false );
520 class WebInstaller_DBSettings
extends WebInstallerPage
{
522 public function execute() {
523 $installer = $this->parent
->getDBInstaller( $this->getVar( 'wgDBtype' ) );
525 $r = $this->parent
->request
;
526 if ( $r->wasPosted() ) {
527 $status = $installer->submitSettingsForm();
528 if ( $status === false ) {
530 } elseif ( $status->isGood() ) {
533 $this->parent
->showStatusBox( $status );
537 $form = $installer->getSettingsForm();
538 if ( $form === false ) {
543 $this->addHTML( $form );
549 class WebInstaller_Name
extends WebInstallerPage
{
551 public function execute() {
552 $r = $this->parent
->request
;
553 if ( $r->wasPosted() ) {
554 if ( $this->submit() ) {
561 // Encourage people to not name their site 'MediaWiki' by blanking the
562 // field. I think that was the intent with the original $GLOBALS['wgSitename']
563 // but these two always were the same so had the effect of making the
564 // installer forget $wgSitename when navigating back to this page.
565 if ( $this->getVar( 'wgSitename' ) == 'MediaWiki' ) {
566 $this->setVar( 'wgSitename', '' );
569 // Set wgMetaNamespace to something valid before we show the form.
570 // $wgMetaNamespace defaults to $wgSiteName which is 'MediaWiki'
571 $metaNS = $this->getVar( 'wgMetaNamespace' );
572 $this->setVar( 'wgMetaNamespace', wfMsgForContent( 'config-ns-other-default' ) );
575 $this->parent
->getTextBox( array(
576 'var' => 'wgSitename',
577 'label' => 'config-site-name',
578 'help' => $this->parent
->getHelpBox( 'config-site-name-help' )
580 $this->parent
->getRadioSet( array(
581 'var' => '_NamespaceType',
582 'label' => 'config-project-namespace',
583 'itemLabelPrefix' => 'config-ns-',
584 'values' => array( 'site-name', 'generic', 'other' ),
585 'commonAttribs' => array( 'class' => 'enableForOther', 'rel' => 'config_wgMetaNamespace' ),
586 'help' => $this->parent
->getHelpBox( 'config-project-namespace-help' )
588 $this->parent
->getTextBox( array(
589 'var' => 'wgMetaNamespace',
590 'label' => '', //TODO: Needs a label?
591 'attribs' => array( 'readonly' => 'readonly', 'class' => 'enabledByOther' ),
594 $this->getFieldSetStart( 'config-admin-box' ) .
595 $this->parent
->getTextBox( array(
596 'var' => '_AdminName',
597 'label' => 'config-admin-name',
598 'help' => $this->parent
->getHelpBox( 'config-admin-help' )
600 $this->parent
->getPasswordBox( array(
601 'var' => '_AdminPassword',
602 'label' => 'config-admin-password',
604 $this->parent
->getPasswordBox( array(
605 'var' => '_AdminPassword2',
606 'label' => 'config-admin-password-confirm'
608 $this->parent
->getTextBox( array(
609 'var' => '_AdminEmail',
610 'label' => 'config-admin-email',
611 'help' => $this->parent
->getHelpBox( 'config-admin-email-help' )
613 $this->parent
->getCheckBox( array(
614 'var' => '_Subscribe',
615 'label' => 'config-subscribe',
616 'help' => $this->parent
->getHelpBox( 'config-subscribe-help' )
618 $this->getFieldSetEnd() .
619 $this->parent
->getInfoBox( wfMsg( 'config-almost-done' ) ) .
620 $this->parent
->getRadioSet( array(
621 'var' => '_SkipOptional',
622 'itemLabelPrefix' => 'config-optional-',
623 'values' => array( 'continue', 'skip' )
627 // Restore the default value
628 $this->setVar( 'wgMetaNamespace', $metaNS );
634 public function submit() {
636 $this->parent
->setVarsFromRequest( array( 'wgSitename', '_NamespaceType',
637 '_AdminName', '_AdminPassword', '_AdminPassword2', '_AdminEmail',
638 '_Subscribe', '_SkipOptional', 'wgMetaNamespace' ) );
640 // Validate site name
641 if ( strval( $this->getVar( 'wgSitename' ) ) === '' ) {
642 $this->parent
->showError( 'config-site-name-blank' );
647 $nsType = $this->getVar( '_NamespaceType' );
648 if ( $nsType == 'site-name' ) {
649 $name = $this->getVar( 'wgSitename' );
650 // Sanitize for namespace
651 // This algorithm should match the JS one in WebInstallerOutput.php
652 $name = preg_replace( '/[\[\]\{\}|#<>%+? ]/', '_', $name );
653 $name = str_replace( '&', '&', $name );
654 $name = preg_replace( '/__+/', '_', $name );
655 $name = ucfirst( trim( $name, '_' ) );
656 } elseif ( $nsType == 'generic' ) {
657 $name = wfMsg( 'config-ns-generic' );
659 $name = $this->getVar( 'wgMetaNamespace' );
662 // Validate namespace
663 if ( strpos( $name, ':' ) !== false ) {
666 // Title-style validation
667 $title = Title
::newFromText( $name );
669 $good = $nsType == 'site-name';
671 $name = $title->getDBkey();
676 $this->parent
->showError( 'config-ns-invalid', $name );
680 // Make sure it won't conflict with any existing namespaces
682 $nsIndex = $wgContLang->getNsIndex( $name );
683 if( $nsIndex !== false && $nsIndex !== NS_PROJECT
) {
684 $this->parent
->showError( 'config-ns-conflict', $name );
688 $this->setVar( 'wgMetaNamespace', $name );
690 // Validate username for creation
691 $name = $this->getVar( '_AdminName' );
692 if ( strval( $name ) === '' ) {
693 $this->parent
->showError( 'config-admin-name-blank' );
697 $cname = User
::getCanonicalName( $name, 'creatable' );
698 if ( $cname === false ) {
699 $this->parent
->showError( 'config-admin-name-invalid', $name );
702 $this->setVar( '_AdminName', $cname );
709 $pwd = $this->getVar( '_AdminPassword' );
710 $user = User
::newFromName( $cname );
711 $valid = $user && $user->getPasswordValidity( $pwd );
712 if ( strval( $pwd ) === '' ) {
713 # $user->getPasswordValidity just checks for $wgMinimalPasswordLength.
714 # This message is more specific and helpful.
715 $msg = 'config-admin-password-blank';
716 } elseif ( $pwd !== $this->getVar( '_AdminPassword2' ) ) {
717 $msg = 'config-admin-password-mismatch';
718 } elseif ( $valid !== true ) {
719 # As of writing this will only catch the username being e.g. 'FOO' and
723 if ( $msg !== false ) {
724 call_user_func_array( array( $this->parent
, 'showError' ), (array)$msg );
725 $this->setVar( '_AdminPassword', '' );
726 $this->setVar( '_AdminPassword2', '' );
730 // Validate e-mail if provided
731 $email = $this->getVar( '_AdminEmail' );
732 if( $email && !User
::isValidEmailAddr( $email ) ) {
733 $this->parent
->showError( 'config-admin-error-bademail' );
742 class WebInstaller_Options
extends WebInstallerPage
{
744 public function execute() {
745 if ( $this->getVar( '_SkipOptional' ) == 'skip' ) {
748 if ( $this->parent
->request
->wasPosted() ) {
749 if ( $this->submit() ) {
754 $emailwrapperStyle = $this->getVar( 'wgEnableEmail' ) ?
'' : 'display: none';
758 $this->parent
->getRadioSet( array(
759 'var' => '_RightsProfile',
760 'label' => 'config-profile',
761 'itemLabelPrefix' => 'config-profile-',
762 'values' => array_keys( $this->parent
->rightsProfiles
),
764 $this->parent
->getInfoBox( wfMsgNoTrans( 'config-profile-help' ) ) .
767 $this->parent
->getRadioSet( array(
768 'var' => '_LicenseCode',
769 'label' => 'config-license',
770 'itemLabelPrefix' => 'config-license-',
771 'values' => array_keys( $this->parent
->licenses
),
772 'commonAttribs' => array( 'class' => 'licenseRadio' ),
774 $this->getCCChooser() .
775 $this->parent
->getHelpBox( 'config-license-help' ) .
778 $this->getFieldSetStart( 'config-email-settings' ) .
779 $this->parent
->getCheckBox( array(
780 'var' => 'wgEnableEmail',
781 'label' => 'config-enable-email',
782 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'emailwrapper' ),
784 $this->parent
->getHelpBox( 'config-enable-email-help' ) .
785 "<div id=\"emailwrapper\" style=\"$emailwrapperStyle\">" .
786 $this->parent
->getTextBox( array(
787 'var' => 'wgPasswordSender',
788 'label' => 'config-email-sender'
790 $this->parent
->getHelpBox( 'config-email-sender-help' ) .
791 $this->parent
->getCheckBox( array(
792 'var' => 'wgEnableUserEmail',
793 'label' => 'config-email-user',
795 $this->parent
->getHelpBox( 'config-email-user-help' ) .
796 $this->parent
->getCheckBox( array(
797 'var' => 'wgEnotifUserTalk',
798 'label' => 'config-email-usertalk',
800 $this->parent
->getHelpBox( 'config-email-usertalk-help' ) .
801 $this->parent
->getCheckBox( array(
802 'var' => 'wgEnotifWatchlist',
803 'label' => 'config-email-watchlist',
805 $this->parent
->getHelpBox( 'config-email-watchlist-help' ) .
806 $this->parent
->getCheckBox( array(
807 'var' => 'wgEmailAuthentication',
808 'label' => 'config-email-auth',
810 $this->parent
->getHelpBox( 'config-email-auth-help' ) .
812 $this->getFieldSetEnd()
815 $extensions = $this->parent
->findExtensions();
818 $extHtml = $this->getFieldSetStart( 'config-extensions' );
820 foreach( $extensions as $ext ) {
821 $extHtml .= $this->parent
->getCheckBox( array(
827 $extHtml .= $this->parent
->getHelpBox( 'config-extensions-help' ) .
828 $this->getFieldSetEnd();
829 $this->addHTML( $extHtml );
832 // Having / in paths in Windows looks funny :)
833 $this->setVar( 'wgDeletedDirectory',
835 '/', DIRECTORY_SEPARATOR
,
836 $this->getVar( 'wgDeletedDirectory' )
840 $uploadwrapperStyle = $this->getVar( 'wgEnableUploads' ) ?
'' : 'display: none';
843 $this->getFieldSetStart( 'config-upload-settings' ) .
844 $this->parent
->getCheckBox( array(
845 'var' => 'wgEnableUploads',
846 'label' => 'config-upload-enable',
847 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'uploadwrapper' ),
848 'help' => $this->parent
->getHelpBox( 'config-upload-help' )
850 '<div id="uploadwrapper" style="' . $uploadwrapperStyle . '">' .
851 $this->parent
->getTextBox( array(
852 'var' => 'wgDeletedDirectory',
853 'label' => 'config-upload-deleted',
854 'help' => $this->parent
->getHelpBox( 'config-upload-deleted-help' )
857 $this->parent
->getTextBox( array(
859 'label' => 'config-logo',
860 'help' => $this->parent
->getHelpBox( 'config-logo-help' )
864 $this->parent
->getCheckBox( array(
865 'var' => 'wgUseInstantCommons',
866 'label' => 'config-instantcommons',
867 'help' => $this->parent
->getHelpBox( 'config-instantcommons-help' )
869 $this->getFieldSetEnd()
872 $caches = array( 'none' );
873 if( count( $this->getVar( '_Caches' ) ) ) {
876 $caches[] = 'memcached';
880 $this->getFieldSetStart( 'config-advanced-settings' ) .
881 # Object cache settings
882 $this->parent
->getRadioSet( array(
883 'var' => 'wgMainCacheType',
884 'label' => 'config-cache-options',
885 'itemLabelPrefix' => 'config-cache-',
889 $this->parent
->getHelpBox( 'config-cache-help' ) .
890 '<div id="config-memcachewrapper">' .
891 $this->parent
->getTextArea( array(
892 'var' => '_MemCachedServers',
893 'label' => 'config-memcached-servers',
894 'help' => $this->parent
->getHelpBox( 'config-memcached-help' )
897 $this->getFieldSetEnd()
902 public function getCCPartnerUrl() {
904 $exitUrl = $wgServer . $this->parent
->getUrl( array(
906 'SubmitCC' => 'indeed',
907 'config__LicenseCode' => 'cc',
908 'config_wgRightsUrl' => '[license_url]',
909 'config_wgRightsText' => '[license_name]',
910 'config_wgRightsIcon' => '[license_button]',
912 $styleUrl = $wgServer . dirname( dirname( $this->parent
->getUrl() ) ) .
913 '/skins/common/config-cc.css';
914 $iframeUrl = 'http://creativecommons.org/license/?' .
916 'partner' => 'MediaWiki',
917 'exit_url' => $exitUrl,
918 'lang' => $this->getVar( '_UserLang' ),
919 'stylesheet' => $styleUrl,
924 public function getCCChooser() {
925 $iframeAttribs = array(
926 'class' => 'config-cc-iframe',
927 'name' => 'config-cc-iframe',
928 'id' => 'config-cc-iframe',
933 if ( $this->getVar( '_CCDone' ) ) {
934 $iframeAttribs['src'] = $this->parent
->getUrl( array( 'ShowCC' => 'yes' ) );
936 $iframeAttribs['src'] = $this->getCCPartnerUrl();
938 $wrapperStyle = ($this->getVar('_LicenseCode') == 'cc-choose') ?
'' : 'display: none';
941 "<div class=\"config-cc-wrapper\" id=\"config-cc-wrapper\" style=\"$wrapperStyle\">\n" .
942 Html
::element( 'iframe', $iframeAttribs, '', false /* not short */ ) .
946 public function getCCDoneBox() {
947 $js = "parent.document.getElementById('config-cc-wrapper').style.height = '$1';";
948 // If you change this height, also change it in config.css
949 $expandJs = str_replace( '$1', '54em', $js );
950 $reduceJs = str_replace( '$1', '70px', $js );
953 Html
::element( 'img', array( 'src' => $this->getVar( 'wgRightsIcon' ) ) ) .
955 htmlspecialchars( $this->getVar( 'wgRightsText' ) ) .
957 "<p style=\"text-align: center\">" .
960 'href' => $this->getCCPartnerUrl(),
961 'onclick' => $expandJs,
963 wfMsg( 'config-cc-again' )
966 "<script type=\"text/javascript\">\n" .
967 # Reduce the wrapper div height
968 htmlspecialchars( $reduceJs ) .
973 public function submitCC() {
974 $newValues = $this->parent
->setVarsFromRequest(
975 array( 'wgRightsUrl', 'wgRightsText', 'wgRightsIcon' ) );
976 if ( count( $newValues ) != 3 ) {
977 $this->parent
->showError( 'config-cc-error' );
980 $this->setVar( '_CCDone', true );
981 $this->addHTML( $this->getCCDoneBox() );
984 public function submit() {
985 $this->parent
->setVarsFromRequest( array( '_RightsProfile', '_LicenseCode',
986 'wgEnableEmail', 'wgPasswordSender', 'wgEnableUploads', 'wgLogo',
987 'wgEnableUserEmail', 'wgEnotifUserTalk', 'wgEnotifWatchlist',
988 'wgEmailAuthentication', 'wgMainCacheType', '_MemCachedServers',
989 'wgUseInstantCommons' ) );
991 if ( !in_array( $this->getVar( '_RightsProfile' ),
992 array_keys( $this->parent
->rightsProfiles
) ) )
994 reset( $this->parent
->rightsProfiles
);
995 $this->setVar( '_RightsProfile', key( $this->parent
->rightsProfiles
) );
998 $code = $this->getVar( '_LicenseCode' );
999 if ( $code == 'cc-choose' ) {
1000 if ( !$this->getVar( '_CCDone' ) ) {
1001 $this->parent
->showError( 'config-cc-not-chosen' );
1004 } elseif ( in_array( $code, array_keys( $this->parent
->licenses
) ) ) {
1005 $entry = $this->parent
->licenses
[$code];
1006 if ( isset( $entry['text'] ) ) {
1007 $this->setVar( 'wgRightsText', $entry['text'] );
1009 $this->setVar( 'wgRightsText', wfMsg( 'config-license-' . $code ) );
1011 $this->setVar( 'wgRightsUrl', $entry['url'] );
1012 $this->setVar( 'wgRightsIcon', $entry['icon'] );
1014 $this->setVar( 'wgRightsText', '' );
1015 $this->setVar( 'wgRightsUrl', '' );
1016 $this->setVar( 'wgRightsIcon', '' );
1019 $extsAvailable = $this->parent
->findExtensions();
1020 $extsToInstall = array();
1021 foreach( $extsAvailable as $ext ) {
1022 if( $this->parent
->request
->getCheck( 'config_ext-' . $ext ) ) {
1023 $extsToInstall[] = $ext;
1026 $this->parent
->setVar( '_Extensions', $extsToInstall );
1028 if( $this->getVar( 'wgMainCacheType' ) == 'memcached' ) {
1029 $memcServers = explode( "\n", $this->getVar( '_MemCachedServers' ) );
1030 if( !$memcServers ) {
1031 $this->parent
->showError( 'config-memcache-needservers' );
1035 foreach( $memcServers as $server ) {
1036 $memcParts = explode( ":", $server );
1037 if( !IP
::isValid( $memcParts[0] ) ) {
1038 $this->parent
->showError( 'config-memcache-badip', $memcParts[0] );
1040 } elseif( !isset( $memcParts[1] ) ) {
1041 $this->parent
->showError( 'config-memcache-noport', $memcParts[0] );
1043 } elseif( $memcParts[1] < 1 ||
$memcParts[1] > 65535 ) {
1044 $this->parent
->showError( 'config-memcache-badport', 1, 65535 );
1054 class WebInstaller_Install
extends WebInstallerPage
{
1056 public function execute() {
1057 if( $this->getVar( '_UpgradeDone' ) ) {
1059 } elseif( $this->getVar( '_InstallDone' ) ) {
1061 } elseif( $this->parent
->request
->wasPosted() ) {
1063 $this->addHTML("<ul>");
1064 $results = $this->parent
->performInstallation(
1065 array( $this, 'startStage'),
1066 array( $this, 'endStage' )
1068 $this->addHTML("</ul>");
1069 // PerformInstallation bails on a fatal, so make sure the last item
1070 // completed before giving 'next.' Likewise, only provide back on failure
1071 $lastStep = end( $results );
1072 $continue = $lastStep->isOK() ?
'continue' : false;
1073 $back = $lastStep->isOK() ?
false : 'back';
1074 $this->endForm( $continue, $back );
1077 $this->addHTML( $this->parent
->getInfoBox( wfMsgNoTrans( 'config-install-begin' ) ) );
1083 public function startStage( $step ) {
1084 $this->addHTML( "<li>" . wfMsgHtml( "config-install-$step" ) . wfMsg( 'ellipsis') );
1087 public function endStage( $step, $status ) {
1088 $msg = $status->isOk() ?
'config-install-step-done' : 'config-install-step-failed';
1089 $html = wfMsgHtml( 'word-separator' ) . wfMsgHtml( $msg );
1090 if ( !$status->isOk() ) {
1091 $html = "<span class=\"error\">$html</span>";
1093 $this->addHTML( $html . "</li>\n" );
1094 if( !$status->isGood() ) {
1095 $this->parent
->showStatusBox( $status );
1101 class WebInstaller_Complete
extends WebInstallerPage
{
1103 public function execute() {
1104 // Pop up a dialog box, to make it difficult for the user to forget
1105 // to download the file
1106 $lsUrl = $GLOBALS['wgServer'] . $this->parent
->getURL( array( 'localsettings' => 1 ) );
1107 if ( isset( $_SERVER['HTTP_USER_AGENT'] ) && strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE' ) !== false ) {
1108 // JS appears the only method that works consistently with IE7+
1109 $this->addHtml( "\n<script type=\"" . $GLOBALS['wgJsMimeType'] . '">jQuery( document ).ready( function() { document.location='
1110 . Xml
::encodeJsVar( $lsUrl) . "; } );</script>\n" );
1112 $this->parent
->request
->response()->header( "Refresh: 0;url=$lsUrl" );
1116 $this->parent
->disableLinkPopups();
1118 $this->parent
->getInfoBox(
1119 wfMsgNoTrans( 'config-install-done',
1121 $GLOBALS['wgServer'] .
1122 $this->getVar( 'wgScriptPath' ) . '/index' .
1123 $this->getVar( 'wgScriptExtension' ),
1128 $this->parent
->restoreLinkPopups();
1129 $this->endForm( false, false );
1133 class WebInstaller_Restart
extends WebInstallerPage
{
1135 public function execute() {
1136 $r = $this->parent
->request
;
1137 if ( $r->wasPosted() ) {
1138 $really = $r->getVal( 'submit-restart' );
1140 $this->parent
->reset();
1146 $s = $this->parent
->getWarningBox( wfMsgNoTrans( 'config-help-restart' ) );
1147 $this->addHTML( $s );
1148 $this->endForm( 'restart' );
1153 abstract class WebInstaller_Document
extends WebInstallerPage
{
1155 protected abstract function getFileName();
1157 public function execute() {
1158 $text = $this->getFileContents();
1159 $text = $this->formatTextFile( $text );
1160 $this->parent
->output
->addWikiText( $text );
1162 $this->endForm( false );
1165 public function getFileContents() {
1166 return file_get_contents( dirname( __FILE__
) . '/../../' . $this->getFileName() );
1169 protected function formatTextFile( $text ) {
1170 // Use Unix line endings, escape some wikitext stuff
1171 $text = str_replace( array( '<', '{{', '[[', "\r" ),
1172 array( '<', '{{', '[[', '' ), $text );
1173 // join word-wrapped lines into one
1176 $text = preg_replace( "/\n([\\*#\t])([^\n]*?)\n([^\n#\\*:]+)/", "\n\\1\\2 \\3", $text );
1177 } while ( $text != $prev );
1178 // Replace tab indents with colons
1179 $text = preg_replace( '/^\t\t/m', '::', $text );
1180 $text = preg_replace( '/^\t/m', ':', $text );
1181 // turn (bug nnnn) into links
1182 $text = preg_replace_callback('/bug (\d+)/', array( $this, 'replaceBugLinks' ), $text );
1183 // add links to manual to every global variable mentioned
1184 $text = preg_replace_callback('/(\$wg[a-z0-9_]+)/i', array( $this, 'replaceConfigLinks' ), $text );
1188 private function replaceBugLinks( $matches ) {
1189 return '<span class="config-plainlink">[https://bugzilla.wikimedia.org/' .
1190 $matches[1] . ' bug ' . $matches[1] . ']</span>';
1193 private function replaceConfigLinks( $matches ) {
1194 return '<span class="config-plainlink">[http://www.mediawiki.org/wiki/Manual:' .
1195 $matches[1] . ' ' . $matches[1] . ']</span>';
1200 class WebInstaller_Readme
extends WebInstaller_Document
{
1201 protected function getFileName() { return 'README'; }
1204 class WebInstaller_ReleaseNotes
extends WebInstaller_Document
{
1205 protected function getFileName() { return 'RELEASE-NOTES'; }
1208 class WebInstaller_UpgradeDoc
extends WebInstaller_Document
{
1209 protected function getFileName() { return 'UPGRADE'; }
1212 class WebInstaller_Copying
extends WebInstaller_Document
{
1213 protected function getFileName() { return 'COPYING'; }