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, $helpHtml = '' ) {
209 global $wgDummyLanguageCodes;
213 $s .= Html
::openElement( 'select', array( 'id' => $name, 'name' => $name ) ) . "\n";
215 $languages = Language
::getLanguageNames();
217 $dummies = array_flip( $wgDummyLanguageCodes );
218 foreach ( $languages as $code => $lang ) {
219 if ( isset( $dummies[$code] ) ) continue;
220 $s .= "\n" . Xml
::option( "$code - $lang", $code, $code == $selectedCode );
222 $s .= "\n</select>\n";
223 return $this->parent
->label( $label, $name, $s );
228 class WebInstaller_ExistingWiki
extends WebInstallerPage
{
229 public function execute() {
230 // If there is no LocalSettings.php, continue to the installer welcome page
231 $vars = $this->parent
->getExistingLocalSettings();
236 // Check if the upgrade key supplied to the user has appeared in LocalSettings.php
237 if ( $vars['wgUpgradeKey'] !== false
238 && $this->getVar( '_UpgradeKeySupplied' )
239 && $this->getVar( 'wgUpgradeKey' ) === $vars['wgUpgradeKey'] )
241 // It's there, so the user is authorized
242 $status = $this->handleExistingUpgrade( $vars );
243 if ( $status->isOK() ) {
247 $this->parent
->showStatusBox( $status );
248 $this->endForm( 'continue' );
253 // If there is no $wgUpgradeKey, tell the user to add one to LocalSettings.php
254 if ( $vars['wgUpgradeKey'] === false ) {
255 if ( $this->getVar( 'wgUpgradeKey', false ) === false ) {
256 $secretKey = $this->getVar( 'wgSecretKey' ); // preserve $wgSecretKey
257 $this->parent
->generateKeys();
258 $this->setVar( 'wgSecretKey', $secretKey );
259 $this->setVar( '_UpgradeKeySupplied', true );
262 $this->addHTML( $this->parent
->getInfoBox(
263 wfMsgNoTrans( 'config-upgrade-key-missing',
264 "<pre>\$wgUpgradeKey = '" . $this->getVar( 'wgUpgradeKey' ) . "';</pre>" )
266 $this->endForm( 'continue' );
270 // If there is an upgrade key, but it wasn't supplied, prompt the user to enter it
272 $r = $this->parent
->request
;
273 if ( $r->wasPosted() ) {
274 $key = $r->getText( 'config_wgUpgradeKey' );
275 if( !$key ||
$key !== $vars['wgUpgradeKey'] ) {
276 $this->parent
->showError( 'config-localsettings-badkey' );
277 $this->showKeyForm();
281 $status = $this->handleExistingUpgrade( $vars );
282 if ( $status->isOK() ) {
285 $this->parent
->showStatusBox( $status );
286 $this->showKeyForm();
290 $this->showKeyForm();
296 * Show the "enter key" form
298 protected function showKeyForm() {
301 $this->parent
->getInfoBox( wfMsgNoTrans( 'config-localsettings-upgrade' ) ).
303 $this->parent
->getTextBox( array(
304 'var' => 'wgUpgradeKey',
305 'label' => 'config-localsettings-key',
306 'attribs' => array( 'autocomplete' => 'off' ),
309 $this->endForm( 'continue' );
312 protected function importVariables( $names, $vars ) {
313 $status = Status
::newGood();
314 foreach ( $names as $name ) {
315 if ( !isset( $vars[$name] ) ) {
316 $status->fatal( 'config-localsettings-incomplete', $name );
318 $this->setVar( $name, $vars[$name] );
324 * Initiate an upgrade of the existing database
325 * @param $vars Variables from LocalSettings.php and AdminSettings.php
328 protected function handleExistingUpgrade( $vars ) {
330 if ( !isset( $vars['wgDBtype'] ) ||
!in_array( $vars['wgDBtype'], Installer
::getDBTypes() ) ) {
331 return Status
::newFatal( 'config-localsettings-connection-error', '' );
334 // Set the relevant variables from LocalSettings.php
335 $requiredVars = array( 'wgDBtype' );
336 $status = $this->importVariables( $requiredVars , $vars );
337 $installer = $this->parent
->getDBInstaller();
338 $status->merge( $this->importVariables( $installer->getGlobalNames(), $vars ) );
339 if ( !$status->isOK() ) {
343 if ( isset( $vars['wgDBadminuser'] ) ) {
344 $this->setVar( '_InstallUser', $vars['wgDBadminuser'] );
346 $this->setVar( '_InstallUser', $vars['wgDBuser'] );
348 if ( isset( $vars['wgDBadminpassword'] ) ) {
349 $this->setVar( '_InstallPassword', $vars['wgDBadminpassword'] );
351 $this->setVar( '_InstallPassword', $vars['wgDBpassword'] );
354 // Test the database connection
355 $status = $installer->getConnection();
356 if ( !$status->isOK() ) {
357 // Adjust the error message to explain things correctly
358 $status->replaceMessage( 'config-connection-error',
359 'config-localsettings-connection-error' );
364 $this->setVar( '_ExistingDBSettings', true );
369 class WebInstaller_Welcome
extends WebInstallerPage
{
371 public function execute() {
372 if ( $this->parent
->request
->wasPosted() ) {
373 if ( $this->getVar( '_Environment' ) ) {
377 $this->parent
->output
->addWikiText( wfMsgNoTrans( 'config-welcome' ) );
378 $status = $this->parent
->doEnvironmentChecks();
379 if ( $status->isGood() ) {
380 $this->parent
->output
->addHTML( '<span class="success-message">' .
381 wfMsgHtml( 'config-env-good' ) . '</span>' );
382 $this->parent
->output
->addWikiText( wfMsgNoTrans( 'config-copyright',
383 SpecialVersion
::getCopyrightAndAuthorList() ) );
387 $this->parent
->showStatusMessage( $status );
393 class WebInstaller_DBConnect
extends WebInstallerPage
{
395 public function execute() {
396 if ( $this->getVar( '_ExistingDBSettings' ) ) {
400 $r = $this->parent
->request
;
401 if ( $r->wasPosted() ) {
402 $status = $this->submit();
404 if ( $status->isGood() ) {
405 $this->setVar( '_UpgradeDone', false );
408 $this->parent
->showStatusBox( $status );
414 $types = "<ul class=\"config-settings-block\">\n";
416 $defaultType = $this->getVar( 'wgDBtype' );
419 foreach( $this->parent
->getDBTypes() as $type ) {
420 $link = DatabaseBase
::newFromType( $type )->getSoftwareLink();
421 $dbSupport .= wfMsgNoTrans( "config-support-$type", $link ) . "\n";
423 $this->addHTML( $this->parent
->getInfoBox(
424 wfMsg( 'config-support-info', $dbSupport ) ) );
426 foreach ( $this->parent
->getVar( '_CompiledDBs' ) as $type ) {
427 $installer = $this->parent
->getDBInstaller( $type );
431 $installer->getReadableName(),
435 $type == $defaultType,
436 array( 'class' => 'dbRadio', 'rel' => "DB_wrapper_$type" )
441 Html
::openElement( 'div', array( 'id' => 'DB_wrapper_' . $type, 'class' => 'dbWrapper' ) ) .
442 Html
::element( 'h3', array(), wfMsg( 'config-header-' . $type ) ) .
443 $installer->getConnectForm() .
446 $types .= "</ul><br clear=\"left\"/>\n";
449 $this->parent
->label( 'config-db-type', false, $types ) .
456 public function submit() {
457 $r = $this->parent
->request
;
458 $type = $r->getVal( 'DBType' );
459 $this->setVar( 'wgDBtype', $type );
460 $installer = $this->parent
->getDBInstaller( $type );
462 return Status
::newFatal( 'config-invalid-db-type' );
464 return $installer->submitConnectForm();
469 class WebInstaller_Upgrade
extends WebInstallerPage
{
471 public function execute() {
472 if ( $this->getVar( '_UpgradeDone' ) ) {
473 // Allow regeneration of LocalSettings.php, unless we are working
474 // from a pre-existing LocalSettings.php file and we want to avoid
475 // leaking its contents
476 if ( $this->parent
->request
->wasPosted() && !$this->getVar( '_ExistingDBSettings' ) ) {
477 // Done message acknowledged
481 // Show the done message again
482 // Make them click back again if they want to do the upgrade again
483 $this->showDoneMessage();
488 // wgDBtype is generally valid here because otherwise the previous page
489 // (connect) wouldn't have declared its happiness
490 $type = $this->getVar( 'wgDBtype' );
491 $installer = $this->parent
->getDBInstaller( $type );
493 if ( !$installer->needsUpgrade() ) {
497 if ( $this->parent
->request
->wasPosted() ) {
498 $installer->preUpgrade();
500 $this->startLiveBox();
501 $result = $installer->doUpgrade();
505 // If they're going to possibly regenerate LocalSettings, we
506 // need to create the upgrade/secret keys. Bug 26481
507 if( !$this->getVar( '_ExistingDBSettings' ) ) {
508 $this->parent
->generateKeys();
510 $this->setVar( '_UpgradeDone', true );
511 $this->showDoneMessage();
517 $this->addHTML( $this->parent
->getInfoBox(
518 wfMsgNoTrans( 'config-can-upgrade', $GLOBALS['wgVersion'] ) ) );
522 public function showDoneMessage() {
524 $regenerate = !$this->getVar( '_ExistingDBSettings' );
526 $msg = 'config-upgrade-done';
528 $msg = 'config-upgrade-done-no-regenerate';
530 $this->parent
->disableLinkPopups();
532 $this->parent
->getInfoBox(
534 $GLOBALS['wgServer'] .
535 $this->getVar( 'wgScriptPath' ) . '/index' .
536 $this->getVar( 'wgScriptExtension' )
540 $this->parent
->restoreLinkPopups();
541 $this->endForm( $regenerate ?
'regenerate' : false, false );
546 class WebInstaller_DBSettings
extends WebInstallerPage
{
548 public function execute() {
549 $installer = $this->parent
->getDBInstaller( $this->getVar( 'wgDBtype' ) );
551 $r = $this->parent
->request
;
552 if ( $r->wasPosted() ) {
553 $status = $installer->submitSettingsForm();
554 if ( $status === false ) {
556 } elseif ( $status->isGood() ) {
559 $this->parent
->showStatusBox( $status );
563 $form = $installer->getSettingsForm();
564 if ( $form === false ) {
569 $this->addHTML( $form );
575 class WebInstaller_Name
extends WebInstallerPage
{
577 public function execute() {
578 $r = $this->parent
->request
;
579 if ( $r->wasPosted() ) {
580 if ( $this->submit() ) {
587 // Encourage people to not name their site 'MediaWiki' by blanking the
588 // field. I think that was the intent with the original $GLOBALS['wgSitename']
589 // but these two always were the same so had the effect of making the
590 // installer forget $wgSitename when navigating back to this page.
591 if ( $this->getVar( 'wgSitename' ) == 'MediaWiki' ) {
592 $this->setVar( 'wgSitename', '' );
595 // Set wgMetaNamespace to something valid before we show the form.
596 // $wgMetaNamespace defaults to $wgSiteName which is 'MediaWiki'
597 $metaNS = $this->getVar( 'wgMetaNamespace' );
598 $this->setVar( 'wgMetaNamespace', wfMsgForContent( 'config-ns-other-default' ) );
601 $this->parent
->getTextBox( array(
602 'var' => 'wgSitename',
603 'label' => 'config-site-name',
604 'help' => $this->parent
->getHelpBox( 'config-site-name-help' )
606 $this->parent
->getRadioSet( array(
607 'var' => '_NamespaceType',
608 'label' => 'config-project-namespace',
609 'itemLabelPrefix' => 'config-ns-',
610 'values' => array( 'site-name', 'generic', 'other' ),
611 'commonAttribs' => array( 'class' => 'enableForOther', 'rel' => 'config_wgMetaNamespace' ),
612 'help' => $this->parent
->getHelpBox( 'config-project-namespace-help' )
614 $this->parent
->getTextBox( array(
615 'var' => 'wgMetaNamespace',
616 'label' => '', //TODO: Needs a label?
617 'attribs' => array( 'readonly' => 'readonly', 'class' => 'enabledByOther' ),
620 $this->getFieldSetStart( 'config-admin-box' ) .
621 $this->parent
->getTextBox( array(
622 'var' => '_AdminName',
623 'label' => 'config-admin-name',
624 'help' => $this->parent
->getHelpBox( 'config-admin-help' )
626 $this->parent
->getPasswordBox( array(
627 'var' => '_AdminPassword',
628 'label' => 'config-admin-password',
630 $this->parent
->getPasswordBox( array(
631 'var' => '_AdminPassword2',
632 'label' => 'config-admin-password-confirm'
634 $this->parent
->getTextBox( array(
635 'var' => '_AdminEmail',
636 'label' => 'config-admin-email',
637 'help' => $this->parent
->getHelpBox( 'config-admin-email-help' )
639 $this->parent
->getCheckBox( array(
640 'var' => '_Subscribe',
641 'label' => 'config-subscribe',
642 'help' => $this->parent
->getHelpBox( 'config-subscribe-help' )
644 $this->getFieldSetEnd() .
645 $this->parent
->getInfoBox( wfMsg( 'config-almost-done' ) ) .
646 $this->parent
->getRadioSet( array(
647 'var' => '_SkipOptional',
648 'itemLabelPrefix' => 'config-optional-',
649 'values' => array( 'continue', 'skip' )
653 // Restore the default value
654 $this->setVar( 'wgMetaNamespace', $metaNS );
660 public function submit() {
662 $this->parent
->setVarsFromRequest( array( 'wgSitename', '_NamespaceType',
663 '_AdminName', '_AdminPassword', '_AdminPassword2', '_AdminEmail',
664 '_Subscribe', '_SkipOptional', 'wgMetaNamespace' ) );
666 // Validate site name
667 if ( strval( $this->getVar( 'wgSitename' ) ) === '' ) {
668 $this->parent
->showError( 'config-site-name-blank' );
673 $nsType = $this->getVar( '_NamespaceType' );
674 if ( $nsType == 'site-name' ) {
675 $name = $this->getVar( 'wgSitename' );
676 // Sanitize for namespace
677 // This algorithm should match the JS one in WebInstallerOutput.php
678 $name = preg_replace( '/[\[\]\{\}|#<>%+? ]/', '_', $name );
679 $name = str_replace( '&', '&', $name );
680 $name = preg_replace( '/__+/', '_', $name );
681 $name = ucfirst( trim( $name, '_' ) );
682 } elseif ( $nsType == 'generic' ) {
683 $name = wfMsg( 'config-ns-generic' );
685 $name = $this->getVar( 'wgMetaNamespace' );
688 // Validate namespace
689 if ( strpos( $name, ':' ) !== false ) {
692 // Title-style validation
693 $title = Title
::newFromText( $name );
695 $good = $nsType == 'site-name';
697 $name = $title->getDBkey();
702 $this->parent
->showError( 'config-ns-invalid', $name );
706 // Make sure it won't conflict with any existing namespaces
708 $nsIndex = $wgContLang->getNsIndex( $name );
709 if( $nsIndex !== false && $nsIndex !== NS_PROJECT
) {
710 $this->parent
->showError( 'config-ns-conflict', $name );
714 $this->setVar( 'wgMetaNamespace', $name );
716 // Validate username for creation
717 $name = $this->getVar( '_AdminName' );
718 if ( strval( $name ) === '' ) {
719 $this->parent
->showError( 'config-admin-name-blank' );
723 $cname = User
::getCanonicalName( $name, 'creatable' );
724 if ( $cname === false ) {
725 $this->parent
->showError( 'config-admin-name-invalid', $name );
728 $this->setVar( '_AdminName', $cname );
734 $pwd = $this->getVar( '_AdminPassword' );
735 $user = User
::newFromName( $cname );
736 $valid = $user && $user->getPasswordValidity( $pwd );
737 if ( strval( $pwd ) === '' ) {
738 # $user->getPasswordValidity just checks for $wgMinimalPasswordLength.
739 # This message is more specific and helpful.
740 $msg = 'config-admin-password-blank';
741 } elseif ( $pwd !== $this->getVar( '_AdminPassword2' ) ) {
742 $msg = 'config-admin-password-mismatch';
743 } elseif ( $valid !== true ) {
744 # As of writing this will only catch the username being e.g. 'FOO' and
748 if ( $msg !== false ) {
749 call_user_func_array( array( $this->parent
, 'showError' ), (array)$msg );
750 $this->setVar( '_AdminPassword', '' );
751 $this->setVar( '_AdminPassword2', '' );
755 // Validate e-mail if provided
756 $email = $this->getVar( '_AdminEmail' );
757 if( $email && !User
::isValidEmailAddr( $email ) ) {
758 $this->parent
->showError( 'config-admin-error-bademail' );
767 class WebInstaller_Options
extends WebInstallerPage
{
769 public function execute() {
770 if ( $this->getVar( '_SkipOptional' ) == 'skip' ) {
773 if ( $this->parent
->request
->wasPosted() ) {
774 if ( $this->submit() ) {
779 $emailwrapperStyle = $this->getVar( 'wgEnableEmail' ) ?
'' : 'display: none';
783 $this->parent
->getRadioSet( array(
784 'var' => '_RightsProfile',
785 'label' => 'config-profile',
786 'itemLabelPrefix' => 'config-profile-',
787 'values' => array_keys( $this->parent
->rightsProfiles
),
789 $this->parent
->getInfoBox( wfMsgNoTrans( 'config-profile-help' ) ) .
792 $this->parent
->getRadioSet( array(
793 'var' => '_LicenseCode',
794 'label' => 'config-license',
795 'itemLabelPrefix' => 'config-license-',
796 'values' => array_keys( $this->parent
->licenses
),
797 'commonAttribs' => array( 'class' => 'licenseRadio' ),
799 $this->getCCChooser() .
800 $this->parent
->getHelpBox( 'config-license-help' ) .
803 $this->getFieldSetStart( 'config-email-settings' ) .
804 $this->parent
->getCheckBox( array(
805 'var' => 'wgEnableEmail',
806 'label' => 'config-enable-email',
807 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'emailwrapper' ),
809 $this->parent
->getHelpBox( 'config-enable-email-help' ) .
810 "<div id=\"emailwrapper\" style=\"$emailwrapperStyle\">" .
811 $this->parent
->getTextBox( array(
812 'var' => 'wgPasswordSender',
813 'label' => 'config-email-sender'
815 $this->parent
->getHelpBox( 'config-email-sender-help' ) .
816 $this->parent
->getCheckBox( array(
817 'var' => 'wgEnableUserEmail',
818 'label' => 'config-email-user',
820 $this->parent
->getHelpBox( 'config-email-user-help' ) .
821 $this->parent
->getCheckBox( array(
822 'var' => 'wgEnotifUserTalk',
823 'label' => 'config-email-usertalk',
825 $this->parent
->getHelpBox( 'config-email-usertalk-help' ) .
826 $this->parent
->getCheckBox( array(
827 'var' => 'wgEnotifWatchlist',
828 'label' => 'config-email-watchlist',
830 $this->parent
->getHelpBox( 'config-email-watchlist-help' ) .
831 $this->parent
->getCheckBox( array(
832 'var' => 'wgEmailAuthentication',
833 'label' => 'config-email-auth',
835 $this->parent
->getHelpBox( 'config-email-auth-help' ) .
837 $this->getFieldSetEnd()
840 $extensions = $this->parent
->findExtensions();
843 $extHtml = $this->getFieldSetStart( 'config-extensions' );
845 foreach( $extensions as $ext ) {
846 $extHtml .= $this->parent
->getCheckBox( array(
852 $extHtml .= $this->parent
->getHelpBox( 'config-extensions-help' ) .
853 $this->getFieldSetEnd();
854 $this->addHTML( $extHtml );
857 // Having / in paths in Windows looks funny :)
858 $this->setVar( 'wgDeletedDirectory',
860 '/', DIRECTORY_SEPARATOR
,
861 $this->getVar( 'wgDeletedDirectory' )
865 $uploadwrapperStyle = $this->getVar( 'wgEnableUploads' ) ?
'' : 'display: none';
868 $this->getFieldSetStart( 'config-upload-settings' ) .
869 $this->parent
->getCheckBox( array(
870 'var' => 'wgEnableUploads',
871 'label' => 'config-upload-enable',
872 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'uploadwrapper' ),
873 'help' => $this->parent
->getHelpBox( 'config-upload-help' )
875 '<div id="uploadwrapper" style="' . $uploadwrapperStyle . '">' .
876 $this->parent
->getTextBox( array(
877 'var' => 'wgDeletedDirectory',
878 'label' => 'config-upload-deleted',
879 'help' => $this->parent
->getHelpBox( 'config-upload-deleted-help' )
882 $this->parent
->getTextBox( array(
884 'label' => 'config-logo',
885 'help' => $this->parent
->getHelpBox( 'config-logo-help' )
889 $this->parent
->getCheckBox( array(
890 'var' => 'wgUseInstantCommons',
891 'label' => 'config-instantcommons',
892 'help' => $this->parent
->getHelpBox( 'config-instantcommons-help' )
894 $this->getFieldSetEnd()
897 $caches = array( 'none' );
898 if( count( $this->getVar( '_Caches' ) ) ) {
901 $caches[] = 'memcached';
905 $this->getFieldSetStart( 'config-advanced-settings' ) .
906 # Object cache settings
907 $this->parent
->getRadioSet( array(
908 'var' => 'wgMainCacheType',
909 'label' => 'config-cache-options',
910 'itemLabelPrefix' => 'config-cache-',
914 $this->parent
->getHelpBox( 'config-cache-help' ) .
915 '<div id="config-memcachewrapper">' .
916 $this->parent
->getTextArea( array(
917 'var' => '_MemCachedServers',
918 'label' => 'config-memcached-servers',
919 'help' => $this->parent
->getHelpBox( 'config-memcached-help' )
922 $this->getFieldSetEnd()
927 public function getCCPartnerUrl() {
929 $exitUrl = $wgServer . $this->parent
->getUrl( array(
931 'SubmitCC' => 'indeed',
932 'config__LicenseCode' => 'cc',
933 'config_wgRightsUrl' => '[license_url]',
934 'config_wgRightsText' => '[license_name]',
935 'config_wgRightsIcon' => '[license_button]',
937 $styleUrl = $wgServer . dirname( dirname( $this->parent
->getUrl() ) ) .
938 '/skins/common/config-cc.css';
939 $iframeUrl = 'http://creativecommons.org/license/?' .
941 'partner' => 'MediaWiki',
942 'exit_url' => $exitUrl,
943 'lang' => $this->getVar( '_UserLang' ),
944 'stylesheet' => $styleUrl,
949 public function getCCChooser() {
950 $iframeAttribs = array(
951 'class' => 'config-cc-iframe',
952 'name' => 'config-cc-iframe',
953 'id' => 'config-cc-iframe',
958 if ( $this->getVar( '_CCDone' ) ) {
959 $iframeAttribs['src'] = $this->parent
->getUrl( array( 'ShowCC' => 'yes' ) );
961 $iframeAttribs['src'] = $this->getCCPartnerUrl();
963 $wrapperStyle = ($this->getVar('_LicenseCode') == 'cc-choose') ?
'' : 'display: none';
966 "<div class=\"config-cc-wrapper\" id=\"config-cc-wrapper\" style=\"$wrapperStyle\">\n" .
967 Html
::element( 'iframe', $iframeAttribs, '', false /* not short */ ) .
971 public function getCCDoneBox() {
972 $js = "parent.document.getElementById('config-cc-wrapper').style.height = '$1';";
973 // If you change this height, also change it in config.css
974 $expandJs = str_replace( '$1', '54em', $js );
975 $reduceJs = str_replace( '$1', '70px', $js );
978 Html
::element( 'img', array( 'src' => $this->getVar( 'wgRightsIcon' ) ) ) .
980 htmlspecialchars( $this->getVar( 'wgRightsText' ) ) .
982 "<p style=\"text-align: center\">" .
985 'href' => $this->getCCPartnerUrl(),
986 'onclick' => $expandJs,
988 wfMsg( 'config-cc-again' )
991 "<script type=\"text/javascript\">\n" .
992 # Reduce the wrapper div height
993 htmlspecialchars( $reduceJs ) .
998 public function submitCC() {
999 $newValues = $this->parent
->setVarsFromRequest(
1000 array( 'wgRightsUrl', 'wgRightsText', 'wgRightsIcon' ) );
1001 if ( count( $newValues ) != 3 ) {
1002 $this->parent
->showError( 'config-cc-error' );
1005 $this->setVar( '_CCDone', true );
1006 $this->addHTML( $this->getCCDoneBox() );
1009 public function submit() {
1010 $this->parent
->setVarsFromRequest( array( '_RightsProfile', '_LicenseCode',
1011 'wgEnableEmail', 'wgPasswordSender', 'wgEnableUploads', 'wgLogo',
1012 'wgEnableUserEmail', 'wgEnotifUserTalk', 'wgEnotifWatchlist',
1013 'wgEmailAuthentication', 'wgMainCacheType', '_MemCachedServers',
1014 'wgUseInstantCommons' ) );
1016 if ( !in_array( $this->getVar( '_RightsProfile' ),
1017 array_keys( $this->parent
->rightsProfiles
) ) )
1019 reset( $this->parent
->rightsProfiles
);
1020 $this->setVar( '_RightsProfile', key( $this->parent
->rightsProfiles
) );
1023 $code = $this->getVar( '_LicenseCode' );
1024 if ( $code == 'cc-choose' ) {
1025 if ( !$this->getVar( '_CCDone' ) ) {
1026 $this->parent
->showError( 'config-cc-not-chosen' );
1029 } elseif ( in_array( $code, array_keys( $this->parent
->licenses
) ) ) {
1030 $entry = $this->parent
->licenses
[$code];
1031 if ( isset( $entry['text'] ) ) {
1032 $this->setVar( 'wgRightsText', $entry['text'] );
1034 $this->setVar( 'wgRightsText', wfMsg( 'config-license-' . $code ) );
1036 $this->setVar( 'wgRightsUrl', $entry['url'] );
1037 $this->setVar( 'wgRightsIcon', $entry['icon'] );
1039 $this->setVar( 'wgRightsText', '' );
1040 $this->setVar( 'wgRightsUrl', '' );
1041 $this->setVar( 'wgRightsIcon', '' );
1044 $extsAvailable = $this->parent
->findExtensions();
1045 $extsToInstall = array();
1046 foreach( $extsAvailable as $ext ) {
1047 if( $this->parent
->request
->getCheck( 'config_ext-' . $ext ) ) {
1048 $extsToInstall[] = $ext;
1051 $this->parent
->setVar( '_Extensions', $extsToInstall );
1053 if( $this->getVar( 'wgMainCacheType' ) == 'memcached' ) {
1054 $memcServers = explode( "\n", $this->getVar( '_MemCachedServers' ) );
1055 if( !$memcServers ) {
1056 $this->parent
->showError( 'config-memcache-needservers' );
1060 foreach( $memcServers as $server ) {
1061 $memcParts = explode( ":", $server );
1062 if( !IP
::isValid( $memcParts[0] ) ) {
1063 $this->parent
->showError( 'config-memcache-badip', $memcParts[0] );
1065 } elseif( !isset( $memcParts[1] ) ) {
1066 $this->parent
->showError( 'config-memcache-noport', $memcParts[0] );
1068 } elseif( $memcParts[1] < 1 ||
$memcParts[1] > 65535 ) {
1069 $this->parent
->showError( 'config-memcache-badport', 1, 65535 );
1079 class WebInstaller_Install
extends WebInstallerPage
{
1081 public function execute() {
1082 if( $this->getVar( '_UpgradeDone' ) ) {
1084 } elseif( $this->getVar( '_InstallDone' ) ) {
1086 } elseif( $this->parent
->request
->wasPosted() ) {
1088 $this->addHTML("<ul>");
1089 $results = $this->parent
->performInstallation(
1090 array( $this, 'startStage'),
1091 array( $this, 'endStage' )
1093 $this->addHTML("</ul>");
1094 // PerformInstallation bails on a fatal, so make sure the last item
1095 // completed before giving 'next.' Likewise, only provide back on failure
1096 $lastStep = end( $results );
1097 $continue = $lastStep->isOK() ?
'continue' : false;
1098 $back = $lastStep->isOK() ?
false : 'back';
1099 $this->endForm( $continue, $back );
1102 $this->addHTML( $this->parent
->getInfoBox( wfMsgNoTrans( 'config-install-begin' ) ) );
1108 public function startStage( $step ) {
1109 $this->addHTML( "<li>" . wfMsgHtml( "config-install-$step" ) . wfMsg( 'ellipsis') );
1110 if ( $step == 'extension-tables' ) {
1111 $this->startLiveBox();
1115 public function endStage( $step, $status ) {
1116 if ( $step == 'extension-tables' ) {
1117 $this->endLiveBox();
1119 $msg = $status->isOk() ?
'config-install-step-done' : 'config-install-step-failed';
1120 $html = wfMsgHtml( 'word-separator' ) . wfMsgHtml( $msg );
1121 if ( !$status->isOk() ) {
1122 $html = "<span class=\"error\">$html</span>";
1124 $this->addHTML( $html . "</li>\n" );
1125 if( !$status->isGood() ) {
1126 $this->parent
->showStatusBox( $status );
1132 class WebInstaller_Complete
extends WebInstallerPage
{
1134 public function execute() {
1135 // Pop up a dialog box, to make it difficult for the user to forget
1136 // to download the file
1137 $lsUrl = $GLOBALS['wgServer'] . $this->parent
->getURL( array( 'localsettings' => 1 ) );
1138 if ( isset( $_SERVER['HTTP_USER_AGENT'] ) && strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE' ) !== false ) {
1139 // JS appears the only method that works consistently with IE7+
1140 $this->addHtml( "\n<script type=\"" . $GLOBALS['wgJsMimeType'] . '">jQuery( document ).ready( function() { document.location='
1141 . Xml
::encodeJsVar( $lsUrl) . "; } );</script>\n" );
1143 $this->parent
->request
->response()->header( "Refresh: 0;url=$lsUrl" );
1147 $this->parent
->disableLinkPopups();
1149 $this->parent
->getInfoBox(
1150 wfMsgNoTrans( 'config-install-done',
1152 $GLOBALS['wgServer'] .
1153 $this->getVar( 'wgScriptPath' ) . '/index' .
1154 $this->getVar( 'wgScriptExtension' ),
1159 $this->parent
->restoreLinkPopups();
1160 $this->endForm( false, false );
1164 class WebInstaller_Restart
extends WebInstallerPage
{
1166 public function execute() {
1167 $r = $this->parent
->request
;
1168 if ( $r->wasPosted() ) {
1169 $really = $r->getVal( 'submit-restart' );
1171 $this->parent
->reset();
1177 $s = $this->parent
->getWarningBox( wfMsgNoTrans( 'config-help-restart' ) );
1178 $this->addHTML( $s );
1179 $this->endForm( 'restart' );
1184 abstract class WebInstaller_Document
extends WebInstallerPage
{
1186 protected abstract function getFileName();
1188 public function execute() {
1189 $text = $this->getFileContents();
1190 $text = $this->formatTextFile( $text );
1191 $this->parent
->output
->addWikiText( $text );
1193 $this->endForm( false );
1196 public function getFileContents() {
1197 return file_get_contents( dirname( __FILE__
) . '/../../' . $this->getFileName() );
1200 protected function formatTextFile( $text ) {
1201 // Use Unix line endings, escape some wikitext stuff
1202 $text = str_replace( array( '<', '{{', '[[', "\r" ),
1203 array( '<', '{{', '[[', '' ), $text );
1204 // join word-wrapped lines into one
1207 $text = preg_replace( "/\n([\\*#\t])([^\n]*?)\n([^\n#\\*:]+)/", "\n\\1\\2 \\3", $text );
1208 } while ( $text != $prev );
1209 // Replace tab indents with colons
1210 $text = preg_replace( '/^\t\t/m', '::', $text );
1211 $text = preg_replace( '/^\t/m', ':', $text );
1212 // turn (bug nnnn) into links
1213 $text = preg_replace_callback('/bug (\d+)/', array( $this, 'replaceBugLinks' ), $text );
1214 // add links to manual to every global variable mentioned
1215 $text = preg_replace_callback('/(\$wg[a-z0-9_]+)/i', array( $this, 'replaceConfigLinks' ), $text );
1219 private function replaceBugLinks( $matches ) {
1220 return '<span class="config-plainlink">[https://bugzilla.wikimedia.org/' .
1221 $matches[1] . ' bug ' . $matches[1] . ']</span>';
1224 private function replaceConfigLinks( $matches ) {
1225 return '<span class="config-plainlink">[http://www.mediawiki.org/wiki/Manual:' .
1226 $matches[1] . ' ' . $matches[1] . ']</span>';
1231 class WebInstaller_Readme
extends WebInstaller_Document
{
1232 protected function getFileName() { return 'README'; }
1235 class WebInstaller_ReleaseNotes
extends WebInstaller_Document
{
1236 protected function getFileName() { return 'RELEASE-NOTES'; }
1239 class WebInstaller_UpgradeDoc
extends WebInstaller_Document
{
1240 protected function getFileName() { return 'UPGRADE'; }
1243 class WebInstaller_Copying
extends WebInstaller_Document
{
1244 protected function getFileName() { return 'COPYING'; }