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" ).show();</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" ).hide()</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
->generateKeys();
483 $this->setVar( '_UpgradeDone', true );
484 $this->showDoneMessage();
490 $this->addHTML( $this->parent
->getInfoBox(
491 wfMsgNoTrans( 'config-can-upgrade', $GLOBALS['wgVersion'] ) ) );
495 public function showDoneMessage() {
497 $regenerate = !$this->getVar( '_ExistingDBSettings' );
499 $msg = 'config-upgrade-done';
501 $msg = 'config-upgrade-done-no-regenerate';
503 $this->parent
->disableLinkPopups();
505 $this->parent
->getInfoBox(
507 $GLOBALS['wgServer'] .
508 $this->getVar( 'wgScriptPath' ) . '/index' .
509 $this->getVar( 'wgScriptExtension' )
513 $this->parent
->restoreLinkPopups();
514 $this->endForm( $regenerate ?
'regenerate' : false, false );
519 class WebInstaller_DBSettings
extends WebInstallerPage
{
521 public function execute() {
522 $installer = $this->parent
->getDBInstaller( $this->getVar( 'wgDBtype' ) );
524 $r = $this->parent
->request
;
525 if ( $r->wasPosted() ) {
526 $status = $installer->submitSettingsForm();
527 if ( $status === false ) {
529 } elseif ( $status->isGood() ) {
532 $this->parent
->showStatusBox( $status );
536 $form = $installer->getSettingsForm();
537 if ( $form === false ) {
542 $this->addHTML( $form );
548 class WebInstaller_Name
extends WebInstallerPage
{
550 public function execute() {
551 $r = $this->parent
->request
;
552 if ( $r->wasPosted() ) {
553 if ( $this->submit() ) {
560 // Encourage people to not name their site 'MediaWiki' by blanking the
561 // field. I think that was the intent with the original $GLOBALS['wgSitename']
562 // but these two always were the same so had the effect of making the
563 // installer forget $wgSitename when navigating back to this page.
564 if ( $this->getVar( 'wgSitename' ) == 'MediaWiki' ) {
565 $this->setVar( 'wgSitename', '' );
568 // Set wgMetaNamespace to something valid before we show the form.
569 // $wgMetaNamespace defaults to $wgSiteName which is 'MediaWiki'
570 $metaNS = $this->getVar( 'wgMetaNamespace' );
571 $this->setVar( 'wgMetaNamespace', wfMsgForContent( 'config-ns-other-default' ) );
574 $this->parent
->getTextBox( array(
575 'var' => 'wgSitename',
576 'label' => 'config-site-name',
577 'help' => $this->parent
->getHelpBox( 'config-site-name-help' )
579 $this->parent
->getRadioSet( array(
580 'var' => '_NamespaceType',
581 'label' => 'config-project-namespace',
582 'itemLabelPrefix' => 'config-ns-',
583 'values' => array( 'site-name', 'generic', 'other' ),
584 'commonAttribs' => array( 'class' => 'enableForOther', 'rel' => 'config_wgMetaNamespace' ),
585 'help' => $this->parent
->getHelpBox( 'config-project-namespace-help' )
587 $this->parent
->getTextBox( array(
588 'var' => 'wgMetaNamespace',
589 'label' => '', //TODO: Needs a label?
590 'attribs' => array( 'readonly' => 'readonly', 'class' => 'enabledByOther' ),
593 $this->getFieldSetStart( 'config-admin-box' ) .
594 $this->parent
->getTextBox( array(
595 'var' => '_AdminName',
596 'label' => 'config-admin-name',
597 'help' => $this->parent
->getHelpBox( 'config-admin-help' )
599 $this->parent
->getPasswordBox( array(
600 'var' => '_AdminPassword',
601 'label' => 'config-admin-password',
603 $this->parent
->getPasswordBox( array(
604 'var' => '_AdminPassword2',
605 'label' => 'config-admin-password-confirm'
607 $this->parent
->getTextBox( array(
608 'var' => '_AdminEmail',
609 'label' => 'config-admin-email',
610 'help' => $this->parent
->getHelpBox( 'config-admin-email-help' )
612 $this->parent
->getCheckBox( array(
613 'var' => '_Subscribe',
614 'label' => 'config-subscribe',
615 'help' => $this->parent
->getHelpBox( 'config-subscribe-help' )
617 $this->getFieldSetEnd() .
618 $this->parent
->getInfoBox( wfMsg( 'config-almost-done' ) ) .
619 $this->parent
->getRadioSet( array(
620 'var' => '_SkipOptional',
621 'itemLabelPrefix' => 'config-optional-',
622 'values' => array( 'continue', 'skip' )
626 // Restore the default value
627 $this->setVar( 'wgMetaNamespace', $metaNS );
633 public function submit() {
635 $this->parent
->setVarsFromRequest( array( 'wgSitename', '_NamespaceType',
636 '_AdminName', '_AdminPassword', '_AdminPassword2', '_AdminEmail',
637 '_Subscribe', '_SkipOptional', 'wgMetaNamespace' ) );
639 // Validate site name
640 if ( strval( $this->getVar( 'wgSitename' ) ) === '' ) {
641 $this->parent
->showError( 'config-site-name-blank' );
646 $nsType = $this->getVar( '_NamespaceType' );
647 if ( $nsType == 'site-name' ) {
648 $name = $this->getVar( 'wgSitename' );
649 // Sanitize for namespace
650 // This algorithm should match the JS one in WebInstallerOutput.php
651 $name = preg_replace( '/[\[\]\{\}|#<>%+? ]/', '_', $name );
652 $name = str_replace( '&', '&', $name );
653 $name = preg_replace( '/__+/', '_', $name );
654 $name = ucfirst( trim( $name, '_' ) );
655 } elseif ( $nsType == 'generic' ) {
656 $name = wfMsg( 'config-ns-generic' );
658 $name = $this->getVar( 'wgMetaNamespace' );
661 // Validate namespace
662 if ( strpos( $name, ':' ) !== false ) {
665 // Title-style validation
666 $title = Title
::newFromText( $name );
668 $good = $nsType == 'site-name';
670 $name = $title->getDBkey();
675 $this->parent
->showError( 'config-ns-invalid', $name );
679 // Make sure it won't conflict with any existing namespaces
681 $nsIndex = $wgContLang->getNsIndex( $name );
682 if( $nsIndex !== false && $nsIndex !== NS_PROJECT
) {
683 $this->parent
->showError( 'config-ns-conflict', $name );
687 $this->setVar( 'wgMetaNamespace', $name );
689 // Validate username for creation
690 $name = $this->getVar( '_AdminName' );
691 if ( strval( $name ) === '' ) {
692 $this->parent
->showError( 'config-admin-name-blank' );
696 $cname = User
::getCanonicalName( $name, 'creatable' );
697 if ( $cname === false ) {
698 $this->parent
->showError( 'config-admin-name-invalid', $name );
701 $this->setVar( '_AdminName', $cname );
708 $pwd = $this->getVar( '_AdminPassword' );
709 $user = User
::newFromName( $cname );
710 $valid = $user && $user->getPasswordValidity( $pwd );
711 if ( strval( $pwd ) === '' ) {
712 # $user->getPasswordValidity just checks for $wgMinimalPasswordLength.
713 # This message is more specific and helpful.
714 $msg = 'config-admin-password-blank';
715 } elseif ( $pwd !== $this->getVar( '_AdminPassword2' ) ) {
716 $msg = 'config-admin-password-mismatch';
717 } elseif ( $valid !== true ) {
718 # As of writing this will only catch the username being e.g. 'FOO' and
722 if ( $msg !== false ) {
723 call_user_func_array( array( $this->parent
, 'showError' ), (array)$msg );
724 $this->setVar( '_AdminPassword', '' );
725 $this->setVar( '_AdminPassword2', '' );
729 // Validate e-mail if provided
730 $email = $this->getVar( '_AdminEmail' );
731 if( $email && !User
::isValidEmailAddr( $email ) ) {
732 $this->parent
->showError( 'config-admin-error-bademail' );
741 class WebInstaller_Options
extends WebInstallerPage
{
743 public function execute() {
744 if ( $this->getVar( '_SkipOptional' ) == 'skip' ) {
747 if ( $this->parent
->request
->wasPosted() ) {
748 if ( $this->submit() ) {
753 $emailwrapperStyle = $this->getVar( 'wgEnableEmail' ) ?
'' : 'display: none';
757 $this->parent
->getRadioSet( array(
758 'var' => '_RightsProfile',
759 'label' => 'config-profile',
760 'itemLabelPrefix' => 'config-profile-',
761 'values' => array_keys( $this->parent
->rightsProfiles
),
763 $this->parent
->getInfoBox( wfMsgNoTrans( 'config-profile-help' ) ) .
766 $this->parent
->getRadioSet( array(
767 'var' => '_LicenseCode',
768 'label' => 'config-license',
769 'itemLabelPrefix' => 'config-license-',
770 'values' => array_keys( $this->parent
->licenses
),
771 'commonAttribs' => array( 'class' => 'licenseRadio' ),
773 $this->getCCChooser() .
774 $this->parent
->getHelpBox( 'config-license-help' ) .
777 $this->getFieldSetStart( 'config-email-settings' ) .
778 $this->parent
->getCheckBox( array(
779 'var' => 'wgEnableEmail',
780 'label' => 'config-enable-email',
781 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'emailwrapper' ),
783 $this->parent
->getHelpBox( 'config-enable-email-help' ) .
784 "<div id=\"emailwrapper\" style=\"$emailwrapperStyle\">" .
785 $this->parent
->getTextBox( array(
786 'var' => 'wgPasswordSender',
787 'label' => 'config-email-sender'
789 $this->parent
->getHelpBox( 'config-email-sender-help' ) .
790 $this->parent
->getCheckBox( array(
791 'var' => 'wgEnableUserEmail',
792 'label' => 'config-email-user',
794 $this->parent
->getHelpBox( 'config-email-user-help' ) .
795 $this->parent
->getCheckBox( array(
796 'var' => 'wgEnotifUserTalk',
797 'label' => 'config-email-usertalk',
799 $this->parent
->getHelpBox( 'config-email-usertalk-help' ) .
800 $this->parent
->getCheckBox( array(
801 'var' => 'wgEnotifWatchlist',
802 'label' => 'config-email-watchlist',
804 $this->parent
->getHelpBox( 'config-email-watchlist-help' ) .
805 $this->parent
->getCheckBox( array(
806 'var' => 'wgEmailAuthentication',
807 'label' => 'config-email-auth',
809 $this->parent
->getHelpBox( 'config-email-auth-help' ) .
811 $this->getFieldSetEnd()
814 $extensions = $this->parent
->findExtensions();
817 $extHtml = $this->getFieldSetStart( 'config-extensions' );
819 foreach( $extensions as $ext ) {
820 $extHtml .= $this->parent
->getCheckBox( array(
826 $extHtml .= $this->parent
->getHelpBox( 'config-extensions-help' ) .
827 $this->getFieldSetEnd();
828 $this->addHTML( $extHtml );
831 // Having / in paths in Windows looks funny :)
832 $this->setVar( 'wgDeletedDirectory',
834 '/', DIRECTORY_SEPARATOR
,
835 $this->getVar( 'wgDeletedDirectory' )
839 $uploadwrapperStyle = $this->getVar( 'wgEnableUploads' ) ?
'' : 'display: none';
842 $this->getFieldSetStart( 'config-upload-settings' ) .
843 $this->parent
->getCheckBox( array(
844 'var' => 'wgEnableUploads',
845 'label' => 'config-upload-enable',
846 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'uploadwrapper' ),
847 'help' => $this->parent
->getHelpBox( 'config-upload-help' )
849 '<div id="uploadwrapper" style="' . $uploadwrapperStyle . '">' .
850 $this->parent
->getTextBox( array(
851 'var' => 'wgDeletedDirectory',
852 'label' => 'config-upload-deleted',
853 'help' => $this->parent
->getHelpBox( 'config-upload-deleted-help' )
856 $this->parent
->getTextBox( array(
858 'label' => 'config-logo',
859 'help' => $this->parent
->getHelpBox( 'config-logo-help' )
863 $this->parent
->getCheckBox( array(
864 'var' => 'wgUseInstantCommons',
865 'label' => 'config-instantcommons',
866 'help' => $this->parent
->getHelpBox( 'config-instantcommons-help' )
868 $this->getFieldSetEnd()
871 $caches = array( 'none' );
872 if( count( $this->getVar( '_Caches' ) ) ) {
875 $caches[] = 'memcached';
879 $this->getFieldSetStart( 'config-advanced-settings' ) .
880 # Object cache settings
881 $this->parent
->getRadioSet( array(
882 'var' => 'wgMainCacheType',
883 'label' => 'config-cache-options',
884 'itemLabelPrefix' => 'config-cache-',
888 $this->parent
->getHelpBox( 'config-cache-help' ) .
889 '<div id="config-memcachewrapper">' .
890 $this->parent
->getTextArea( array(
891 'var' => '_MemCachedServers',
892 'label' => 'config-memcached-servers',
893 'help' => $this->parent
->getHelpBox( 'config-memcached-help' )
896 $this->getFieldSetEnd()
901 public function getCCPartnerUrl() {
903 $exitUrl = $wgServer . $this->parent
->getUrl( array(
905 'SubmitCC' => 'indeed',
906 'config__LicenseCode' => 'cc',
907 'config_wgRightsUrl' => '[license_url]',
908 'config_wgRightsText' => '[license_name]',
909 'config_wgRightsIcon' => '[license_button]',
911 $styleUrl = $wgServer . dirname( dirname( $this->parent
->getUrl() ) ) .
912 '/skins/common/config-cc.css';
913 $iframeUrl = 'http://creativecommons.org/license/?' .
915 'partner' => 'MediaWiki',
916 'exit_url' => $exitUrl,
917 'lang' => $this->getVar( '_UserLang' ),
918 'stylesheet' => $styleUrl,
923 public function getCCChooser() {
924 $iframeAttribs = array(
925 'class' => 'config-cc-iframe',
926 'name' => 'config-cc-iframe',
927 'id' => 'config-cc-iframe',
932 if ( $this->getVar( '_CCDone' ) ) {
933 $iframeAttribs['src'] = $this->parent
->getUrl( array( 'ShowCC' => 'yes' ) );
935 $iframeAttribs['src'] = $this->getCCPartnerUrl();
937 $wrapperStyle = ($this->getVar('_LicenseCode') == 'cc-choose') ?
'' : 'display: none';
940 "<div class=\"config-cc-wrapper\" id=\"config-cc-wrapper\" style=\"$wrapperStyle\">\n" .
941 Html
::element( 'iframe', $iframeAttribs, '', false /* not short */ ) .
945 public function getCCDoneBox() {
946 $js = "parent.document.getElementById('config-cc-wrapper').style.height = '$1';";
947 // If you change this height, also change it in config.css
948 $expandJs = str_replace( '$1', '54em', $js );
949 $reduceJs = str_replace( '$1', '70px', $js );
952 Html
::element( 'img', array( 'src' => $this->getVar( 'wgRightsIcon' ) ) ) .
954 htmlspecialchars( $this->getVar( 'wgRightsText' ) ) .
956 "<p style=\"text-align: center\">" .
959 'href' => $this->getCCPartnerUrl(),
960 'onclick' => $expandJs,
962 wfMsg( 'config-cc-again' )
965 "<script type=\"text/javascript\">\n" .
966 # Reduce the wrapper div height
967 htmlspecialchars( $reduceJs ) .
972 public function submitCC() {
973 $newValues = $this->parent
->setVarsFromRequest(
974 array( 'wgRightsUrl', 'wgRightsText', 'wgRightsIcon' ) );
975 if ( count( $newValues ) != 3 ) {
976 $this->parent
->showError( 'config-cc-error' );
979 $this->setVar( '_CCDone', true );
980 $this->addHTML( $this->getCCDoneBox() );
983 public function submit() {
984 $this->parent
->setVarsFromRequest( array( '_RightsProfile', '_LicenseCode',
985 'wgEnableEmail', 'wgPasswordSender', 'wgEnableUploads', 'wgLogo',
986 'wgEnableUserEmail', 'wgEnotifUserTalk', 'wgEnotifWatchlist',
987 'wgEmailAuthentication', 'wgMainCacheType', '_MemCachedServers',
988 'wgUseInstantCommons' ) );
990 if ( !in_array( $this->getVar( '_RightsProfile' ),
991 array_keys( $this->parent
->rightsProfiles
) ) )
993 reset( $this->parent
->rightsProfiles
);
994 $this->setVar( '_RightsProfile', key( $this->parent
->rightsProfiles
) );
997 $code = $this->getVar( '_LicenseCode' );
998 if ( $code == 'cc-choose' ) {
999 if ( !$this->getVar( '_CCDone' ) ) {
1000 $this->parent
->showError( 'config-cc-not-chosen' );
1003 } elseif ( in_array( $code, array_keys( $this->parent
->licenses
) ) ) {
1004 $entry = $this->parent
->licenses
[$code];
1005 if ( isset( $entry['text'] ) ) {
1006 $this->setVar( 'wgRightsText', $entry['text'] );
1008 $this->setVar( 'wgRightsText', wfMsg( 'config-license-' . $code ) );
1010 $this->setVar( 'wgRightsUrl', $entry['url'] );
1011 $this->setVar( 'wgRightsIcon', $entry['icon'] );
1013 $this->setVar( 'wgRightsText', '' );
1014 $this->setVar( 'wgRightsUrl', '' );
1015 $this->setVar( 'wgRightsIcon', '' );
1018 $extsAvailable = $this->parent
->findExtensions();
1019 $extsToInstall = array();
1020 foreach( $extsAvailable as $ext ) {
1021 if( $this->parent
->request
->getCheck( 'config_ext-' . $ext ) ) {
1022 $extsToInstall[] = $ext;
1025 $this->parent
->setVar( '_Extensions', $extsToInstall );
1027 if( $this->getVar( 'wgMainCacheType' ) == 'memcached' ) {
1028 $memcServers = explode( "\n", $this->getVar( '_MemCachedServers' ) );
1029 if( !$memcServers ) {
1030 $this->parent
->showError( 'config-memcache-needservers' );
1034 foreach( $memcServers as $server ) {
1035 $memcParts = explode( ":", $server );
1036 if( !IP
::isValid( $memcParts[0] ) ) {
1037 $this->parent
->showError( 'config-memcache-badip', $memcParts[0] );
1039 } elseif( !isset( $memcParts[1] ) ) {
1040 $this->parent
->showError( 'config-memcache-noport', $memcParts[0] );
1042 } elseif( $memcParts[1] < 1 ||
$memcParts[1] > 65535 ) {
1043 $this->parent
->showError( 'config-memcache-badport', 1, 65535 );
1053 class WebInstaller_Install
extends WebInstallerPage
{
1055 public function execute() {
1056 if( $this->getVar( '_UpgradeDone' ) ) {
1058 } elseif( $this->getVar( '_InstallDone' ) ) {
1060 } elseif( $this->parent
->request
->wasPosted() ) {
1062 $this->addHTML("<ul>");
1063 $results = $this->parent
->performInstallation(
1064 array( $this, 'startStage'),
1065 array( $this, 'endStage' )
1067 $this->addHTML("</ul>");
1068 // PerformInstallation bails on a fatal, so make sure the last item
1069 // completed before giving 'next.' Likewise, only provide back on failure
1070 $lastStep = end( $results );
1071 $continue = $lastStep->isOK() ?
'continue' : false;
1072 $back = $lastStep->isOK() ?
false : 'back';
1073 $this->endForm( $continue, $back );
1076 $this->addHTML( $this->parent
->getInfoBox( wfMsgNoTrans( 'config-install-begin' ) ) );
1082 public function startStage( $step ) {
1083 $this->addHTML( "<li>" . wfMsgHtml( "config-install-$step" ) . wfMsg( 'ellipsis') );
1086 public function endStage( $step, $status ) {
1087 $msg = $status->isOk() ?
'config-install-step-done' : 'config-install-step-failed';
1088 $html = wfMsgHtml( 'word-separator' ) . wfMsgHtml( $msg );
1089 if ( !$status->isOk() ) {
1090 $html = "<span class=\"error\">$html</span>";
1092 $this->addHTML( $html . "</li>\n" );
1093 if( !$status->isGood() ) {
1094 $this->parent
->showStatusBox( $status );
1100 class WebInstaller_Complete
extends WebInstallerPage
{
1102 public function execute() {
1103 // Pop up a dialog box, to make it difficult for the user to forget
1104 // to download the file
1105 $lsUrl = $GLOBALS['wgServer'] . $this->parent
->getURL( array( 'localsettings' => 1 ) );
1106 if ( isset( $_SERVER['HTTP_USER_AGENT'] ) && strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE' ) !== false ) {
1107 // JS appears the only method that works consistently with IE7+
1108 $this->addHtml( "\n<script type=\"" . $GLOBALS['wgJsMimeType'] . '">jQuery( document ).ready( function() { document.location='
1109 . Xml
::encodeJsVar( $lsUrl) . "; } );</script>\n" );
1111 $this->parent
->request
->response()->header( "Refresh: 0;url=$lsUrl" );
1115 $this->parent
->disableLinkPopups();
1117 $this->parent
->getInfoBox(
1118 wfMsgNoTrans( 'config-install-done',
1120 $GLOBALS['wgServer'] .
1121 $this->getVar( 'wgScriptPath' ) . '/index' .
1122 $this->getVar( 'wgScriptExtension' ),
1127 $this->parent
->restoreLinkPopups();
1128 $this->endForm( false, false );
1132 class WebInstaller_Restart
extends WebInstallerPage
{
1134 public function execute() {
1135 $r = $this->parent
->request
;
1136 if ( $r->wasPosted() ) {
1137 $really = $r->getVal( 'submit-restart' );
1139 $this->parent
->reset();
1145 $s = $this->parent
->getWarningBox( wfMsgNoTrans( 'config-help-restart' ) );
1146 $this->addHTML( $s );
1147 $this->endForm( 'restart' );
1152 abstract class WebInstaller_Document
extends WebInstallerPage
{
1154 protected abstract function getFileName();
1156 public function execute() {
1157 $text = $this->getFileContents();
1158 $text = $this->formatTextFile( $text );
1159 $this->parent
->output
->addWikiText( $text );
1161 $this->endForm( false );
1164 public function getFileContents() {
1165 return file_get_contents( dirname( __FILE__
) . '/../../' . $this->getFileName() );
1168 protected function formatTextFile( $text ) {
1169 // Use Unix line endings, escape some wikitext stuff
1170 $text = str_replace( array( '<', '{{', '[[', "\r" ),
1171 array( '<', '{{', '[[', '' ), $text );
1172 // join word-wrapped lines into one
1175 $text = preg_replace( "/\n([\\*#\t])([^\n]*?)\n([^\n#\\*:]+)/", "\n\\1\\2 \\3", $text );
1176 } while ( $text != $prev );
1177 // Replace tab indents with colons
1178 $text = preg_replace( '/^\t\t/m', '::', $text );
1179 $text = preg_replace( '/^\t/m', ':', $text );
1180 // turn (bug nnnn) into links
1181 $text = preg_replace_callback('/bug (\d+)/', array( $this, 'replaceBugLinks' ), $text );
1182 // add links to manual to every global variable mentioned
1183 $text = preg_replace_callback('/(\$wg[a-z0-9_]+)/i', array( $this, 'replaceConfigLinks' ), $text );
1187 private function replaceBugLinks( $matches ) {
1188 return '<span class="config-plainlink">[https://bugzilla.wikimedia.org/' .
1189 $matches[1] . ' bug ' . $matches[1] . ']</span>';
1192 private function replaceConfigLinks( $matches ) {
1193 return '<span class="config-plainlink">[http://www.mediawiki.org/wiki/Manual:' .
1194 $matches[1] . ' ' . $matches[1] . ']</span>';
1199 class WebInstaller_Readme
extends WebInstaller_Document
{
1200 protected function getFileName() { return 'README'; }
1203 class WebInstaller_ReleaseNotes
extends WebInstaller_Document
{
1204 protected function getFileName() { return 'RELEASE-NOTES'; }
1207 class WebInstaller_UpgradeDoc
extends WebInstaller_Document
{
1208 protected function getFileName() { return 'UPGRADE'; }
1211 class WebInstaller_Copying
extends WebInstaller_Document
{
1212 protected function getFileName() { return 'COPYING'; }