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 * Opens a textarea used to display the progress of a long operation
121 protected function startLiveBox() {
123 '<div id="config-spinner" style="display:none;"><img src="../skins/common/images/ajax-loader.gif" /></div>' .
124 '<script>jQuery( "#config-spinner" ).show();</script>' .
125 '<textarea id="config-live-log" name="LiveLog" rows="10" cols="30" readonly="readonly">'
127 $this->parent
->output
->flush();
131 * Opposite to startLiveBox()
133 protected function endLiveBox() {
134 $this->addHTML( '</textarea>
135 <script>jQuery( "#config-spinner" ).hide()</script>' );
136 $this->parent
->output
->flush();
140 class WebInstaller_Language
extends WebInstallerPage
{
142 public function execute() {
144 $r = $this->parent
->request
;
145 $userLang = $r->getVal( 'UserLang' );
146 $contLang = $r->getVal( 'ContLang' );
148 $lifetime = intval( ini_get( 'session.gc_maxlifetime' ) );
150 $lifetime = 1440; // PHP default
153 if ( $r->wasPosted() ) {
155 if ( $this->parent
->getSession( 'test' ) === null ) {
156 $requestTime = $r->getVal( 'LanguageRequestTime' );
157 if ( !$requestTime ) {
158 // The most likely explanation is that the user was knocked back
159 // from another page on POST due to session expiry
160 $msg = 'config-session-expired';
161 } elseif ( time() - $requestTime > $lifetime ) {
162 $msg = 'config-session-expired';
164 $msg = 'config-no-session';
166 $this->parent
->showError( $msg, $wgLang->formatTimePeriod( $lifetime ) );
168 $languages = Language
::getLanguageNames();
169 if ( isset( $languages[$userLang] ) ) {
170 $this->setVar( '_UserLang', $userLang );
172 if ( isset( $languages[$contLang] ) ) {
173 $this->setVar( 'wgLanguageCode', $contLang );
177 } elseif ( $this->parent
->showSessionWarning
) {
178 # The user was knocked back from another page to the start
179 # This probably indicates a session expiry
180 $this->parent
->showError( 'config-session-expired', $wgLang->formatTimePeriod( $lifetime ) );
183 $this->parent
->setSession( 'test', true );
185 if ( !isset( $languages[$userLang] ) ) {
186 $userLang = $this->getVar( '_UserLang', 'en' );
188 if ( !isset( $languages[$contLang] ) ) {
189 $contLang = $this->getVar( 'wgLanguageCode', 'en' );
192 $s = Html
::hidden( 'LanguageRequestTime', time() ) .
193 $this->getLanguageSelector( 'UserLang', 'config-your-language', $userLang, $this->parent
->getHelpBox( 'config-your-language-help' ) ) .
194 $this->getLanguageSelector( 'ContLang', 'config-wiki-language', $contLang, $this->parent
->getHelpBox( 'config-wiki-language-help' ) );
195 $this->addHTML( $s );
196 $this->endForm( 'continue', false );
200 * Get a <select> for selecting languages.
202 public function getLanguageSelector( $name, $label, $selectedCode ) {
203 global $wgDummyLanguageCodes;
204 $s = Html
::openElement( 'select', array( 'id' => $name, 'name' => $name ) ) . "\n";
206 $languages = Language
::getLanguageNames();
208 $dummies = array_flip( $wgDummyLanguageCodes );
209 foreach ( $languages as $code => $lang ) {
210 if ( isset( $dummies[$code] ) ) continue;
211 $s .= "\n" . Xml
::option( "$code - $lang", $code, $code == $selectedCode );
213 $s .= "\n</select>\n";
214 return $this->parent
->label( $label, $name, $s );
219 class WebInstaller_ExistingWiki
extends WebInstallerPage
{
220 public function execute() {
221 // If there is no LocalSettings.php, continue to the installer welcome page
222 $vars = $this->parent
->getExistingLocalSettings();
227 // Check if the upgrade key supplied to the user has appeared in LocalSettings.php
228 if ( $vars['wgUpgradeKey'] !== false
229 && $this->getVar( '_UpgradeKeySupplied' )
230 && $this->getVar( 'wgUpgradeKey' ) === $vars['wgUpgradeKey'] )
232 // It's there, so the user is authorized
233 $status = $this->handleExistingUpgrade( $vars );
234 if ( $status->isOK() ) {
238 $this->parent
->showStatusBox( $status );
239 $this->endForm( 'continue' );
244 // If there is no $wgUpgradeKey, tell the user to add one to LocalSettings.php
245 if ( $vars['wgUpgradeKey'] === false ) {
246 if ( $this->getVar( 'wgUpgradeKey', false ) === false ) {
247 $this->parent
->generateUpgradeKey();
248 $this->setVar( '_UpgradeKeySupplied', true );
251 $this->addHTML( $this->parent
->getInfoBox(
252 wfMsgNoTrans( 'config-upgrade-key-missing',
253 "<pre>\$wgUpgradeKey = '" . $this->getVar( 'wgUpgradeKey' ) . "';</pre>" )
255 $this->endForm( 'continue' );
259 // If there is an upgrade key, but it wasn't supplied, prompt the user to enter it
261 $r = $this->parent
->request
;
262 if ( $r->wasPosted() ) {
263 $key = $r->getText( 'config_wgUpgradeKey' );
264 if( !$key ||
$key !== $vars['wgUpgradeKey'] ) {
265 $this->parent
->showError( 'config-localsettings-badkey' );
266 $this->showKeyForm();
270 $status = $this->handleExistingUpgrade( $vars );
271 if ( $status->isOK() ) {
274 $this->parent
->showStatusBox( $status );
275 $this->showKeyForm();
279 $this->showKeyForm();
285 * Show the "enter key" form
287 protected function showKeyForm() {
290 $this->parent
->getInfoBox( wfMsgNoTrans( 'config-localsettings-upgrade' ) ).
292 $this->parent
->getTextBox( array(
293 'var' => 'wgUpgradeKey',
294 'label' => 'config-localsettings-key',
295 'attribs' => array( 'autocomplete' => 'off' ),
298 $this->endForm( 'continue' );
301 protected function importVariables( $names, $vars ) {
302 $status = Status
::newGood();
303 foreach ( $names as $name ) {
304 if ( !isset( $vars[$name] ) ) {
305 $status->fatal( 'config-localsettings-incomplete', $name );
307 $this->setVar( $name, $vars[$name] );
313 * Initiate an upgrade of the existing database
314 * @param $vars Variables from LocalSettings.php and AdminSettings.php
317 protected function handleExistingUpgrade( $vars ) {
319 if ( !isset( $vars['wgDBtype'] ) ||
!in_array( $vars['wgDBtype'], Installer
::getDBTypes() ) ) {
320 return Status
::newFatal( 'config-localsettings-connection-error', '' );
323 // Set the relevant variables from LocalSettings.php
324 $requiredVars = array( 'wgDBtype' );
325 $status = $this->importVariables( $requiredVars , $vars );
326 $installer = $this->parent
->getDBInstaller();
327 $status->merge( $this->importVariables( $installer->getGlobalNames(), $vars ) );
328 if ( !$status->isOK() ) {
332 if ( isset( $vars['wgDBadminuser'] ) ) {
333 $this->setVar( '_InstallUser', $vars['wgDBadminuser'] );
335 $this->setVar( '_InstallUser', $vars['wgDBuser'] );
337 if ( isset( $vars['wgDBadminpassword'] ) ) {
338 $this->setVar( '_InstallPassword', $vars['wgDBadminpassword'] );
340 $this->setVar( '_InstallPassword', $vars['wgDBpassword'] );
343 // Test the database connection
344 $status = $installer->getConnection();
345 if ( !$status->isOK() ) {
346 // Adjust the error message to explain things correctly
347 $status->replaceMessage( 'config-connection-error',
348 'config-localsettings-connection-error' );
353 $this->setVar( '_ExistingDBSettings', true );
358 class WebInstaller_Welcome
extends WebInstallerPage
{
360 public function execute() {
361 if ( $this->parent
->request
->wasPosted() ) {
362 if ( $this->getVar( '_Environment' ) ) {
366 $this->parent
->output
->addWikiText( wfMsgNoTrans( 'config-welcome' ) );
367 $status = $this->parent
->doEnvironmentChecks();
368 if ( $status->isGood() ) {
369 $this->parent
->output
->addHTML( '<span class="success-message">' .
370 wfMsgHtml( 'config-env-good' ) . '</span>' );
371 $this->parent
->output
->addWikiText( wfMsgNoTrans( 'config-copyright',
372 SpecialVersion
::getCopyrightAndAuthorList() ) );
376 $this->parent
->showStatusMessage( $status );
382 class WebInstaller_DBConnect
extends WebInstallerPage
{
384 public function execute() {
385 if ( $this->getVar( '_ExistingDBSettings' ) ) {
389 $r = $this->parent
->request
;
390 if ( $r->wasPosted() ) {
391 $status = $this->submit();
393 if ( $status->isGood() ) {
394 $this->setVar( '_UpgradeDone', false );
397 $this->parent
->showStatusBox( $status );
403 $types = "<ul class=\"config-settings-block\">\n";
405 $defaultType = $this->getVar( 'wgDBtype' );
408 foreach( $this->parent
->getDBTypes() as $type ) {
409 $link = DatabaseBase
::newFromType( $type )->getSoftwareLink();
410 $dbSupport .= wfMsgNoTrans( "config-support-$type", $link ) . "\n";
412 $this->addHTML( $this->parent
->getInfoBox(
413 wfMsg( 'config-support-info', $dbSupport ) ) );
415 foreach ( $this->parent
->getVar( '_CompiledDBs' ) as $type ) {
416 $installer = $this->parent
->getDBInstaller( $type );
420 $installer->getReadableName(),
424 $type == $defaultType,
425 array( 'class' => 'dbRadio', 'rel' => "DB_wrapper_$type" )
430 Html
::openElement( 'div', array( 'id' => 'DB_wrapper_' . $type, 'class' => 'dbWrapper' ) ) .
431 Html
::element( 'h3', array(), wfMsg( 'config-header-' . $type ) ) .
432 $installer->getConnectForm() .
435 $types .= "</ul><br clear=\"left\"/>\n";
438 $this->parent
->label( 'config-db-type', false, $types ) .
445 public function submit() {
446 $r = $this->parent
->request
;
447 $type = $r->getVal( 'DBType' );
448 $this->setVar( 'wgDBtype', $type );
449 $installer = $this->parent
->getDBInstaller( $type );
451 return Status
::newFatal( 'config-invalid-db-type' );
453 return $installer->submitConnectForm();
458 class WebInstaller_Upgrade
extends WebInstallerPage
{
460 public function execute() {
461 if ( $this->getVar( '_UpgradeDone' ) ) {
462 // Allow regeneration of LocalSettings.php, unless we are working
463 // from a pre-existing LocalSettings.php file and we want to avoid
464 // leaking its contents
465 if ( $this->parent
->request
->wasPosted() && !$this->getVar( '_ExistingDBSettings' ) ) {
466 // Done message acknowledged
470 // Show the done message again
471 // Make them click back again if they want to do the upgrade again
472 $this->showDoneMessage();
477 // wgDBtype is generally valid here because otherwise the previous page
478 // (connect) wouldn't have declared its happiness
479 $type = $this->getVar( 'wgDBtype' );
480 $installer = $this->parent
->getDBInstaller( $type );
482 if ( !$installer->needsUpgrade() ) {
486 if ( $this->parent
->request
->wasPosted() ) {
487 $installer->preUpgrade();
489 $this->startLiveBox();
490 $result = $installer->doUpgrade();
494 // If they're going to possibly regenerate LocalSettings, we
495 // need to create the upgrade/secret keys. Bug 26481
496 if( !$this->getVar( '_ExistingDBSettings' ) ) {
497 $this->parent
->generateKeys();
499 $this->setVar( '_UpgradeDone', true );
500 $this->showDoneMessage();
506 $this->addHTML( $this->parent
->getInfoBox(
507 wfMsgNoTrans( 'config-can-upgrade', $GLOBALS['wgVersion'] ) ) );
511 public function showDoneMessage() {
513 $regenerate = !$this->getVar( '_ExistingDBSettings' );
515 $msg = 'config-upgrade-done';
517 $msg = 'config-upgrade-done-no-regenerate';
519 $this->parent
->disableLinkPopups();
521 $this->parent
->getInfoBox(
523 $GLOBALS['wgServer'] .
524 $this->getVar( 'wgScriptPath' ) . '/index' .
525 $this->getVar( 'wgScriptExtension' )
529 $this->parent
->restoreLinkPopups();
530 $this->endForm( $regenerate ?
'regenerate' : false, false );
535 class WebInstaller_DBSettings
extends WebInstallerPage
{
537 public function execute() {
538 $installer = $this->parent
->getDBInstaller( $this->getVar( 'wgDBtype' ) );
540 $r = $this->parent
->request
;
541 if ( $r->wasPosted() ) {
542 $status = $installer->submitSettingsForm();
543 if ( $status === false ) {
545 } elseif ( $status->isGood() ) {
548 $this->parent
->showStatusBox( $status );
552 $form = $installer->getSettingsForm();
553 if ( $form === false ) {
558 $this->addHTML( $form );
564 class WebInstaller_Name
extends WebInstallerPage
{
566 public function execute() {
567 $r = $this->parent
->request
;
568 if ( $r->wasPosted() ) {
569 if ( $this->submit() ) {
576 // Encourage people to not name their site 'MediaWiki' by blanking the
577 // field. I think that was the intent with the original $GLOBALS['wgSitename']
578 // but these two always were the same so had the effect of making the
579 // installer forget $wgSitename when navigating back to this page.
580 if ( $this->getVar( 'wgSitename' ) == 'MediaWiki' ) {
581 $this->setVar( 'wgSitename', '' );
584 // Set wgMetaNamespace to something valid before we show the form.
585 // $wgMetaNamespace defaults to $wgSiteName which is 'MediaWiki'
586 $metaNS = $this->getVar( 'wgMetaNamespace' );
587 $this->setVar( 'wgMetaNamespace', wfMsgForContent( 'config-ns-other-default' ) );
590 $this->parent
->getTextBox( array(
591 'var' => 'wgSitename',
592 'label' => 'config-site-name',
593 'help' => $this->parent
->getHelpBox( 'config-site-name-help' )
595 $this->parent
->getRadioSet( array(
596 'var' => '_NamespaceType',
597 'label' => 'config-project-namespace',
598 'itemLabelPrefix' => 'config-ns-',
599 'values' => array( 'site-name', 'generic', 'other' ),
600 'commonAttribs' => array( 'class' => 'enableForOther', 'rel' => 'config_wgMetaNamespace' ),
601 'help' => $this->parent
->getHelpBox( 'config-project-namespace-help' )
603 $this->parent
->getTextBox( array(
604 'var' => 'wgMetaNamespace',
605 'label' => '', //TODO: Needs a label?
606 'attribs' => array( 'readonly' => 'readonly', 'class' => 'enabledByOther' ),
609 $this->getFieldSetStart( 'config-admin-box' ) .
610 $this->parent
->getTextBox( array(
611 'var' => '_AdminName',
612 'label' => 'config-admin-name',
613 'help' => $this->parent
->getHelpBox( 'config-admin-help' )
615 $this->parent
->getPasswordBox( array(
616 'var' => '_AdminPassword',
617 'label' => 'config-admin-password',
619 $this->parent
->getPasswordBox( array(
620 'var' => '_AdminPassword2',
621 'label' => 'config-admin-password-confirm'
623 $this->parent
->getTextBox( array(
624 'var' => '_AdminEmail',
625 'label' => 'config-admin-email',
626 'help' => $this->parent
->getHelpBox( 'config-admin-email-help' )
628 $this->parent
->getCheckBox( array(
629 'var' => '_Subscribe',
630 'label' => 'config-subscribe',
631 'help' => $this->parent
->getHelpBox( 'config-subscribe-help' )
633 $this->getFieldSetEnd() .
634 $this->parent
->getInfoBox( wfMsg( 'config-almost-done' ) ) .
635 $this->parent
->getRadioSet( array(
636 'var' => '_SkipOptional',
637 'itemLabelPrefix' => 'config-optional-',
638 'values' => array( 'continue', 'skip' )
642 // Restore the default value
643 $this->setVar( 'wgMetaNamespace', $metaNS );
649 public function submit() {
651 $this->parent
->setVarsFromRequest( array( 'wgSitename', '_NamespaceType',
652 '_AdminName', '_AdminPassword', '_AdminPassword2', '_AdminEmail',
653 '_Subscribe', '_SkipOptional', 'wgMetaNamespace' ) );
655 // Validate site name
656 if ( strval( $this->getVar( 'wgSitename' ) ) === '' ) {
657 $this->parent
->showError( 'config-site-name-blank' );
662 $nsType = $this->getVar( '_NamespaceType' );
663 if ( $nsType == 'site-name' ) {
664 $name = $this->getVar( 'wgSitename' );
665 // Sanitize for namespace
666 // This algorithm should match the JS one in WebInstallerOutput.php
667 $name = preg_replace( '/[\[\]\{\}|#<>%+? ]/', '_', $name );
668 $name = str_replace( '&', '&', $name );
669 $name = preg_replace( '/__+/', '_', $name );
670 $name = ucfirst( trim( $name, '_' ) );
671 } elseif ( $nsType == 'generic' ) {
672 $name = wfMsg( 'config-ns-generic' );
674 $name = $this->getVar( 'wgMetaNamespace' );
677 // Validate namespace
678 if ( strpos( $name, ':' ) !== false ) {
681 // Title-style validation
682 $title = Title
::newFromText( $name );
684 $good = $nsType == 'site-name';
686 $name = $title->getDBkey();
691 $this->parent
->showError( 'config-ns-invalid', $name );
695 // Make sure it won't conflict with any existing namespaces
697 $nsIndex = $wgContLang->getNsIndex( $name );
698 if( $nsIndex !== false && $nsIndex !== NS_PROJECT
) {
699 $this->parent
->showError( 'config-ns-conflict', $name );
703 $this->setVar( 'wgMetaNamespace', $name );
705 // Validate username for creation
706 $name = $this->getVar( '_AdminName' );
707 if ( strval( $name ) === '' ) {
708 $this->parent
->showError( 'config-admin-name-blank' );
712 $cname = User
::getCanonicalName( $name, 'creatable' );
713 if ( $cname === false ) {
714 $this->parent
->showError( 'config-admin-name-invalid', $name );
717 $this->setVar( '_AdminName', $cname );
724 $pwd = $this->getVar( '_AdminPassword' );
725 $user = User
::newFromName( $cname );
726 $valid = $user && $user->getPasswordValidity( $pwd );
727 if ( strval( $pwd ) === '' ) {
728 # $user->getPasswordValidity just checks for $wgMinimalPasswordLength.
729 # This message is more specific and helpful.
730 $msg = 'config-admin-password-blank';
731 } elseif ( $pwd !== $this->getVar( '_AdminPassword2' ) ) {
732 $msg = 'config-admin-password-mismatch';
733 } elseif ( $valid !== true ) {
734 # As of writing this will only catch the username being e.g. 'FOO' and
738 if ( $msg !== false ) {
739 call_user_func_array( array( $this->parent
, 'showError' ), (array)$msg );
740 $this->setVar( '_AdminPassword', '' );
741 $this->setVar( '_AdminPassword2', '' );
745 // Validate e-mail if provided
746 $email = $this->getVar( '_AdminEmail' );
747 if( $email && !User
::isValidEmailAddr( $email ) ) {
748 $this->parent
->showError( 'config-admin-error-bademail' );
757 class WebInstaller_Options
extends WebInstallerPage
{
759 public function execute() {
760 if ( $this->getVar( '_SkipOptional' ) == 'skip' ) {
763 if ( $this->parent
->request
->wasPosted() ) {
764 if ( $this->submit() ) {
769 $emailwrapperStyle = $this->getVar( 'wgEnableEmail' ) ?
'' : 'display: none';
773 $this->parent
->getRadioSet( array(
774 'var' => '_RightsProfile',
775 'label' => 'config-profile',
776 'itemLabelPrefix' => 'config-profile-',
777 'values' => array_keys( $this->parent
->rightsProfiles
),
779 $this->parent
->getInfoBox( wfMsgNoTrans( 'config-profile-help' ) ) .
782 $this->parent
->getRadioSet( array(
783 'var' => '_LicenseCode',
784 'label' => 'config-license',
785 'itemLabelPrefix' => 'config-license-',
786 'values' => array_keys( $this->parent
->licenses
),
787 'commonAttribs' => array( 'class' => 'licenseRadio' ),
789 $this->getCCChooser() .
790 $this->parent
->getHelpBox( 'config-license-help' ) .
793 $this->getFieldSetStart( 'config-email-settings' ) .
794 $this->parent
->getCheckBox( array(
795 'var' => 'wgEnableEmail',
796 'label' => 'config-enable-email',
797 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'emailwrapper' ),
799 $this->parent
->getHelpBox( 'config-enable-email-help' ) .
800 "<div id=\"emailwrapper\" style=\"$emailwrapperStyle\">" .
801 $this->parent
->getTextBox( array(
802 'var' => 'wgPasswordSender',
803 'label' => 'config-email-sender'
805 $this->parent
->getHelpBox( 'config-email-sender-help' ) .
806 $this->parent
->getCheckBox( array(
807 'var' => 'wgEnableUserEmail',
808 'label' => 'config-email-user',
810 $this->parent
->getHelpBox( 'config-email-user-help' ) .
811 $this->parent
->getCheckBox( array(
812 'var' => 'wgEnotifUserTalk',
813 'label' => 'config-email-usertalk',
815 $this->parent
->getHelpBox( 'config-email-usertalk-help' ) .
816 $this->parent
->getCheckBox( array(
817 'var' => 'wgEnotifWatchlist',
818 'label' => 'config-email-watchlist',
820 $this->parent
->getHelpBox( 'config-email-watchlist-help' ) .
821 $this->parent
->getCheckBox( array(
822 'var' => 'wgEmailAuthentication',
823 'label' => 'config-email-auth',
825 $this->parent
->getHelpBox( 'config-email-auth-help' ) .
827 $this->getFieldSetEnd()
830 $extensions = $this->parent
->findExtensions();
833 $extHtml = $this->getFieldSetStart( 'config-extensions' );
835 foreach( $extensions as $ext ) {
836 $extHtml .= $this->parent
->getCheckBox( array(
842 $extHtml .= $this->parent
->getHelpBox( 'config-extensions-help' ) .
843 $this->getFieldSetEnd();
844 $this->addHTML( $extHtml );
847 // Having / in paths in Windows looks funny :)
848 $this->setVar( 'wgDeletedDirectory',
850 '/', DIRECTORY_SEPARATOR
,
851 $this->getVar( 'wgDeletedDirectory' )
855 $uploadwrapperStyle = $this->getVar( 'wgEnableUploads' ) ?
'' : 'display: none';
858 $this->getFieldSetStart( 'config-upload-settings' ) .
859 $this->parent
->getCheckBox( array(
860 'var' => 'wgEnableUploads',
861 'label' => 'config-upload-enable',
862 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'uploadwrapper' ),
863 'help' => $this->parent
->getHelpBox( 'config-upload-help' )
865 '<div id="uploadwrapper" style="' . $uploadwrapperStyle . '">' .
866 $this->parent
->getTextBox( array(
867 'var' => 'wgDeletedDirectory',
868 'label' => 'config-upload-deleted',
869 'help' => $this->parent
->getHelpBox( 'config-upload-deleted-help' )
872 $this->parent
->getTextBox( array(
874 'label' => 'config-logo',
875 'help' => $this->parent
->getHelpBox( 'config-logo-help' )
879 $this->parent
->getCheckBox( array(
880 'var' => 'wgUseInstantCommons',
881 'label' => 'config-instantcommons',
882 'help' => $this->parent
->getHelpBox( 'config-instantcommons-help' )
884 $this->getFieldSetEnd()
887 $caches = array( 'none' );
888 if( count( $this->getVar( '_Caches' ) ) ) {
891 $caches[] = 'memcached';
895 $this->getFieldSetStart( 'config-advanced-settings' ) .
896 # Object cache settings
897 $this->parent
->getRadioSet( array(
898 'var' => 'wgMainCacheType',
899 'label' => 'config-cache-options',
900 'itemLabelPrefix' => 'config-cache-',
904 $this->parent
->getHelpBox( 'config-cache-help' ) .
905 '<div id="config-memcachewrapper">' .
906 $this->parent
->getTextArea( array(
907 'var' => '_MemCachedServers',
908 'label' => 'config-memcached-servers',
909 'help' => $this->parent
->getHelpBox( 'config-memcached-help' )
912 $this->getFieldSetEnd()
917 public function getCCPartnerUrl() {
919 $exitUrl = $wgServer . $this->parent
->getUrl( array(
921 'SubmitCC' => 'indeed',
922 'config__LicenseCode' => 'cc',
923 'config_wgRightsUrl' => '[license_url]',
924 'config_wgRightsText' => '[license_name]',
925 'config_wgRightsIcon' => '[license_button]',
927 $styleUrl = $wgServer . dirname( dirname( $this->parent
->getUrl() ) ) .
928 '/skins/common/config-cc.css';
929 $iframeUrl = 'http://creativecommons.org/license/?' .
931 'partner' => 'MediaWiki',
932 'exit_url' => $exitUrl,
933 'lang' => $this->getVar( '_UserLang' ),
934 'stylesheet' => $styleUrl,
939 public function getCCChooser() {
940 $iframeAttribs = array(
941 'class' => 'config-cc-iframe',
942 'name' => 'config-cc-iframe',
943 'id' => 'config-cc-iframe',
948 if ( $this->getVar( '_CCDone' ) ) {
949 $iframeAttribs['src'] = $this->parent
->getUrl( array( 'ShowCC' => 'yes' ) );
951 $iframeAttribs['src'] = $this->getCCPartnerUrl();
953 $wrapperStyle = ($this->getVar('_LicenseCode') == 'cc-choose') ?
'' : 'display: none';
956 "<div class=\"config-cc-wrapper\" id=\"config-cc-wrapper\" style=\"$wrapperStyle\">\n" .
957 Html
::element( 'iframe', $iframeAttribs, '', false /* not short */ ) .
961 public function getCCDoneBox() {
962 $js = "parent.document.getElementById('config-cc-wrapper').style.height = '$1';";
963 // If you change this height, also change it in config.css
964 $expandJs = str_replace( '$1', '54em', $js );
965 $reduceJs = str_replace( '$1', '70px', $js );
968 Html
::element( 'img', array( 'src' => $this->getVar( 'wgRightsIcon' ) ) ) .
970 htmlspecialchars( $this->getVar( 'wgRightsText' ) ) .
972 "<p style=\"text-align: center\">" .
975 'href' => $this->getCCPartnerUrl(),
976 'onclick' => $expandJs,
978 wfMsg( 'config-cc-again' )
981 "<script type=\"text/javascript\">\n" .
982 # Reduce the wrapper div height
983 htmlspecialchars( $reduceJs ) .
988 public function submitCC() {
989 $newValues = $this->parent
->setVarsFromRequest(
990 array( 'wgRightsUrl', 'wgRightsText', 'wgRightsIcon' ) );
991 if ( count( $newValues ) != 3 ) {
992 $this->parent
->showError( 'config-cc-error' );
995 $this->setVar( '_CCDone', true );
996 $this->addHTML( $this->getCCDoneBox() );
999 public function submit() {
1000 $this->parent
->setVarsFromRequest( array( '_RightsProfile', '_LicenseCode',
1001 'wgEnableEmail', 'wgPasswordSender', 'wgEnableUploads', 'wgLogo',
1002 'wgEnableUserEmail', 'wgEnotifUserTalk', 'wgEnotifWatchlist',
1003 'wgEmailAuthentication', 'wgMainCacheType', '_MemCachedServers',
1004 'wgUseInstantCommons' ) );
1006 if ( !in_array( $this->getVar( '_RightsProfile' ),
1007 array_keys( $this->parent
->rightsProfiles
) ) )
1009 reset( $this->parent
->rightsProfiles
);
1010 $this->setVar( '_RightsProfile', key( $this->parent
->rightsProfiles
) );
1013 $code = $this->getVar( '_LicenseCode' );
1014 if ( $code == 'cc-choose' ) {
1015 if ( !$this->getVar( '_CCDone' ) ) {
1016 $this->parent
->showError( 'config-cc-not-chosen' );
1019 } elseif ( in_array( $code, array_keys( $this->parent
->licenses
) ) ) {
1020 $entry = $this->parent
->licenses
[$code];
1021 if ( isset( $entry['text'] ) ) {
1022 $this->setVar( 'wgRightsText', $entry['text'] );
1024 $this->setVar( 'wgRightsText', wfMsg( 'config-license-' . $code ) );
1026 $this->setVar( 'wgRightsUrl', $entry['url'] );
1027 $this->setVar( 'wgRightsIcon', $entry['icon'] );
1029 $this->setVar( 'wgRightsText', '' );
1030 $this->setVar( 'wgRightsUrl', '' );
1031 $this->setVar( 'wgRightsIcon', '' );
1034 $extsAvailable = $this->parent
->findExtensions();
1035 $extsToInstall = array();
1036 foreach( $extsAvailable as $ext ) {
1037 if( $this->parent
->request
->getCheck( 'config_ext-' . $ext ) ) {
1038 $extsToInstall[] = $ext;
1041 $this->parent
->setVar( '_Extensions', $extsToInstall );
1043 if( $this->getVar( 'wgMainCacheType' ) == 'memcached' ) {
1044 $memcServers = explode( "\n", $this->getVar( '_MemCachedServers' ) );
1045 if( !$memcServers ) {
1046 $this->parent
->showError( 'config-memcache-needservers' );
1050 foreach( $memcServers as $server ) {
1051 $memcParts = explode( ":", $server );
1052 if( !IP
::isValid( $memcParts[0] ) ) {
1053 $this->parent
->showError( 'config-memcache-badip', $memcParts[0] );
1055 } elseif( !isset( $memcParts[1] ) ) {
1056 $this->parent
->showError( 'config-memcache-noport', $memcParts[0] );
1058 } elseif( $memcParts[1] < 1 ||
$memcParts[1] > 65535 ) {
1059 $this->parent
->showError( 'config-memcache-badport', 1, 65535 );
1069 class WebInstaller_Install
extends WebInstallerPage
{
1071 public function execute() {
1072 if( $this->getVar( '_UpgradeDone' ) ) {
1074 } elseif( $this->getVar( '_InstallDone' ) ) {
1076 } elseif( $this->parent
->request
->wasPosted() ) {
1078 $this->addHTML("<ul>");
1079 $results = $this->parent
->performInstallation(
1080 array( $this, 'startStage'),
1081 array( $this, 'endStage' )
1083 $this->addHTML("</ul>");
1084 // PerformInstallation bails on a fatal, so make sure the last item
1085 // completed before giving 'next.' Likewise, only provide back on failure
1086 $lastStep = end( $results );
1087 $continue = $lastStep->isOK() ?
'continue' : false;
1088 $back = $lastStep->isOK() ?
false : 'back';
1089 $this->endForm( $continue, $back );
1092 $this->addHTML( $this->parent
->getInfoBox( wfMsgNoTrans( 'config-install-begin' ) ) );
1098 public function startStage( $step ) {
1099 $this->addHTML( "<li>" . wfMsgHtml( "config-install-$step" ) . wfMsg( 'ellipsis') );
1100 if ( $step == 'extension-tables' ) {
1101 $this->startLiveBox();
1105 public function endStage( $step, $status ) {
1106 if ( $step == 'extension-tables' ) {
1107 $this->endLiveBox();
1109 $msg = $status->isOk() ?
'config-install-step-done' : 'config-install-step-failed';
1110 $html = wfMsgHtml( 'word-separator' ) . wfMsgHtml( $msg );
1111 if ( !$status->isOk() ) {
1112 $html = "<span class=\"error\">$html</span>";
1114 $this->addHTML( $html . "</li>\n" );
1115 if( !$status->isGood() ) {
1116 $this->parent
->showStatusBox( $status );
1122 class WebInstaller_Complete
extends WebInstallerPage
{
1124 public function execute() {
1125 // Pop up a dialog box, to make it difficult for the user to forget
1126 // to download the file
1127 $lsUrl = $GLOBALS['wgServer'] . $this->parent
->getURL( array( 'localsettings' => 1 ) );
1128 if ( isset( $_SERVER['HTTP_USER_AGENT'] ) && strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE' ) !== false ) {
1129 // JS appears the only method that works consistently with IE7+
1130 $this->addHtml( "\n<script type=\"" . $GLOBALS['wgJsMimeType'] . '">jQuery( document ).ready( function() { document.location='
1131 . Xml
::encodeJsVar( $lsUrl) . "; } );</script>\n" );
1133 $this->parent
->request
->response()->header( "Refresh: 0;url=$lsUrl" );
1137 $this->parent
->disableLinkPopups();
1139 $this->parent
->getInfoBox(
1140 wfMsgNoTrans( 'config-install-done',
1142 $GLOBALS['wgServer'] .
1143 $this->getVar( 'wgScriptPath' ) . '/index' .
1144 $this->getVar( 'wgScriptExtension' ),
1149 $this->parent
->restoreLinkPopups();
1150 $this->endForm( false, false );
1154 class WebInstaller_Restart
extends WebInstallerPage
{
1156 public function execute() {
1157 $r = $this->parent
->request
;
1158 if ( $r->wasPosted() ) {
1159 $really = $r->getVal( 'submit-restart' );
1161 $this->parent
->reset();
1167 $s = $this->parent
->getWarningBox( wfMsgNoTrans( 'config-help-restart' ) );
1168 $this->addHTML( $s );
1169 $this->endForm( 'restart' );
1174 abstract class WebInstaller_Document
extends WebInstallerPage
{
1176 protected abstract function getFileName();
1178 public function execute() {
1179 $text = $this->getFileContents();
1180 $text = $this->formatTextFile( $text );
1181 $this->parent
->output
->addWikiText( $text );
1183 $this->endForm( false );
1186 public function getFileContents() {
1187 return file_get_contents( dirname( __FILE__
) . '/../../' . $this->getFileName() );
1190 protected function formatTextFile( $text ) {
1191 // Use Unix line endings, escape some wikitext stuff
1192 $text = str_replace( array( '<', '{{', '[[', "\r" ),
1193 array( '<', '{{', '[[', '' ), $text );
1194 // join word-wrapped lines into one
1197 $text = preg_replace( "/\n([\\*#\t])([^\n]*?)\n([^\n#\\*:]+)/", "\n\\1\\2 \\3", $text );
1198 } while ( $text != $prev );
1199 // Replace tab indents with colons
1200 $text = preg_replace( '/^\t\t/m', '::', $text );
1201 $text = preg_replace( '/^\t/m', ':', $text );
1202 // turn (bug nnnn) into links
1203 $text = preg_replace_callback('/bug (\d+)/', array( $this, 'replaceBugLinks' ), $text );
1204 // add links to manual to every global variable mentioned
1205 $text = preg_replace_callback('/(\$wg[a-z0-9_]+)/i', array( $this, 'replaceConfigLinks' ), $text );
1209 private function replaceBugLinks( $matches ) {
1210 return '<span class="config-plainlink">[https://bugzilla.wikimedia.org/' .
1211 $matches[1] . ' bug ' . $matches[1] . ']</span>';
1214 private function replaceConfigLinks( $matches ) {
1215 return '<span class="config-plainlink">[http://www.mediawiki.org/wiki/Manual:' .
1216 $matches[1] . ' ' . $matches[1] . ']</span>';
1221 class WebInstaller_Readme
extends WebInstaller_Document
{
1222 protected function getFileName() { return 'README'; }
1225 class WebInstaller_ReleaseNotes
extends WebInstaller_Document
{
1226 protected function getFileName() { return 'RELEASE-NOTES'; }
1229 class WebInstaller_UpgradeDoc
extends WebInstaller_Document
{
1230 protected function getFileName() { return 'UPGRADE'; }
1233 class WebInstaller_Copying
extends WebInstaller_Document
{
1234 protected function getFileName() { return 'COPYING'; }