3 * Base code for web installer pages.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
25 * Abstract class to define pages for the web installer.
30 abstract class WebInstallerPage
{
33 * The WebInstaller object this WebInstallerPage belongs to.
39 abstract public function execute();
44 * @param $parent WebInstaller
46 public function __construct( WebInstaller
$parent ) {
47 $this->parent
= $parent;
51 * Is this a slow-running page in the installer? If so, WebInstaller will
52 * set_time_limit(0) before calling execute(). Right now this only applies
53 * to Install and Upgrade pages
56 public function isSlow() {
60 public function addHTML( $html ) {
61 $this->parent
->output
->addHTML( $html );
64 public function startForm() {
66 "<div class=\"config-section\">\n" .
71 'action' => $this->parent
->getUrl( array( 'page' => $this->getName() ) )
78 * @param string|bool $continue
79 * @param string|bool $back
81 public function endForm( $continue = 'continue', $back = 'back' ) {
82 $s = "<div class=\"config-submit\">\n";
85 if ( $id === false ) {
86 $s .= Html
::hidden( 'lastPage', $this->parent
->request
->getVal( 'lastPage' ) );
90 // Fake submit button for enter keypress (bug 26267)
91 // Messages: config-continue, config-restart, config-regenerate
92 $s .= Xml
::submitButton(
93 wfMessage( "config-$continue" )->text(),
95 'name' => "enter-$continue",
96 'style' => 'visibility:hidden;overflow:hidden;width:1px;margin:0'
102 // Message: config-back
103 $s .= Xml
::submitButton(
104 wfMessage( "config-$back" )->text(),
106 'name' => "submit-$back",
107 'tabindex' => $this->parent
->nextTabIndex()
113 // Messages: config-continue, config-restart, config-regenerate
114 $s .= Xml
::submitButton(
115 wfMessage( "config-$continue" )->text(),
117 'name' => "submit-$continue",
118 'tabindex' => $this->parent
->nextTabIndex(),
123 $s .= "</div></form></div>\n";
124 $this->addHTML( $s );
127 public function getName() {
128 return str_replace( 'WebInstaller_', '', get_class( $this ) );
131 protected function getId() {
132 return array_search( $this->getName(), $this->parent
->pageSequence
);
135 public function getVar( $var ) {
136 return $this->parent
->getVar( $var );
139 public function setVar( $name, $value ) {
140 $this->parent
->setVar( $name, $value );
144 * Get the starting tags of a fieldset.
146 * @param string $legend message name
150 protected function getFieldsetStart( $legend ) {
151 return "\n<fieldset><legend>" . wfMessage( $legend )->escaped() . "</legend>\n";
155 * Get the end tag of a fieldset.
159 protected function getFieldsetEnd() {
160 return "</fieldset>\n";
164 * Opens a textarea used to display the progress of a long operation
166 protected function startLiveBox() {
168 '<div id="config-spinner" style="display:none;">' .
169 '<img src="../skins/common/images/ajax-loader.gif" /></div>' .
170 '<script>jQuery( "#config-spinner" ).show();</script>' .
171 '<div id="config-live-log">' .
172 '<textarea name="LiveLog" rows="10" cols="30" readonly="readonly">'
174 $this->parent
->output
->flush();
178 * Opposite to startLiveBox()
180 protected function endLiveBox() {
181 $this->addHTML( '</textarea></div>
182 <script>jQuery( "#config-spinner" ).hide()</script>' );
183 $this->parent
->output
->flush();
187 class WebInstaller_Language
extends WebInstallerPage
{
188 public function execute() {
190 $r = $this->parent
->request
;
191 $userLang = $r->getVal( 'uselang' );
192 $contLang = $r->getVal( 'ContLang' );
194 $languages = Language
::fetchLanguageNames();
195 $lifetime = intval( ini_get( 'session.gc_maxlifetime' ) );
197 $lifetime = 1440; // PHP default
200 if ( $r->wasPosted() ) {
202 if ( $this->parent
->getSession( 'test' ) === null ) {
203 $requestTime = $r->getVal( 'LanguageRequestTime' );
204 if ( !$requestTime ) {
205 // The most likely explanation is that the user was knocked back
206 // from another page on POST due to session expiry
207 $msg = 'config-session-expired';
208 } elseif ( time() - $requestTime > $lifetime ) {
209 $msg = 'config-session-expired';
211 $msg = 'config-no-session';
213 $this->parent
->showError( $msg, $wgLang->formatTimePeriod( $lifetime ) );
215 if ( isset( $languages[$userLang] ) ) {
216 $this->setVar( '_UserLang', $userLang );
218 if ( isset( $languages[$contLang] ) ) {
219 $this->setVar( 'wgLanguageCode', $contLang );
224 } elseif ( $this->parent
->showSessionWarning
) {
225 # The user was knocked back from another page to the start
226 # This probably indicates a session expiry
227 $this->parent
->showError( 'config-session-expired',
228 $wgLang->formatTimePeriod( $lifetime ) );
231 $this->parent
->setSession( 'test', true );
233 if ( !isset( $languages[$userLang] ) ) {
234 $userLang = $this->getVar( '_UserLang', 'en' );
236 if ( !isset( $languages[$contLang] ) ) {
237 $contLang = $this->getVar( 'wgLanguageCode', 'en' );
240 $s = Html
::hidden( 'LanguageRequestTime', time() ) .
241 $this->getLanguageSelector( 'uselang', 'config-your-language', $userLang,
242 $this->parent
->getHelpBox( 'config-your-language-help' ) ) .
243 $this->getLanguageSelector( 'ContLang', 'config-wiki-language', $contLang,
244 $this->parent
->getHelpBox( 'config-wiki-language-help' ) );
245 $this->addHTML( $s );
246 $this->endForm( 'continue', false );
250 * Get a "<select>" for selecting languages.
254 * @param $selectedCode
255 * @param $helpHtml string
258 public function getLanguageSelector( $name, $label, $selectedCode, $helpHtml = '' ) {
259 global $wgDummyLanguageCodes;
263 $s .= Html
::openElement( 'select', array( 'id' => $name, 'name' => $name,
264 'tabindex' => $this->parent
->nextTabIndex() ) ) . "\n";
266 $languages = Language
::fetchLanguageNames();
268 foreach ( $languages as $code => $lang ) {
269 if ( isset( $wgDummyLanguageCodes[$code] ) ) {
272 $s .= "\n" . Xml
::option( "$code - $lang", $code, $code == $selectedCode );
274 $s .= "\n</select>\n";
276 return $this->parent
->label( $label, $name, $s );
280 class WebInstaller_ExistingWiki
extends WebInstallerPage
{
281 public function execute() {
282 // If there is no LocalSettings.php, continue to the installer welcome page
283 $vars = Installer
::getExistingLocalSettings();
288 // Check if the upgrade key supplied to the user has appeared in LocalSettings.php
289 if ( $vars['wgUpgradeKey'] !== false
290 && $this->getVar( '_UpgradeKeySupplied' )
291 && $this->getVar( 'wgUpgradeKey' ) === $vars['wgUpgradeKey']
293 // It's there, so the user is authorized
294 $status = $this->handleExistingUpgrade( $vars );
295 if ( $status->isOK() ) {
299 $this->parent
->showStatusBox( $status );
300 $this->endForm( 'continue' );
306 // If there is no $wgUpgradeKey, tell the user to add one to LocalSettings.php
307 if ( $vars['wgUpgradeKey'] === false ) {
308 if ( $this->getVar( 'wgUpgradeKey', false ) === false ) {
309 $secretKey = $this->getVar( 'wgSecretKey' ); // preserve $wgSecretKey
310 $this->parent
->generateKeys();
311 $this->setVar( 'wgSecretKey', $secretKey );
312 $this->setVar( '_UpgradeKeySupplied', true );
315 $this->addHTML( $this->parent
->getInfoBox(
316 wfMessage( 'config-upgrade-key-missing', "<pre dir=\"ltr\">\$wgUpgradeKey = '" .
317 $this->getVar( 'wgUpgradeKey' ) . "';</pre>" )->plain()
319 $this->endForm( 'continue' );
324 // If there is an upgrade key, but it wasn't supplied, prompt the user to enter it
326 $r = $this->parent
->request
;
327 if ( $r->wasPosted() ) {
328 $key = $r->getText( 'config_wgUpgradeKey' );
329 if ( !$key ||
$key !== $vars['wgUpgradeKey'] ) {
330 $this->parent
->showError( 'config-localsettings-badkey' );
331 $this->showKeyForm();
336 $status = $this->handleExistingUpgrade( $vars );
337 if ( $status->isOK() ) {
340 $this->parent
->showStatusBox( $status );
341 $this->showKeyForm();
346 $this->showKeyForm();
353 * Show the "enter key" form
355 protected function showKeyForm() {
358 $this->parent
->getInfoBox( wfMessage( 'config-localsettings-upgrade' )->plain() ) .
360 $this->parent
->getTextBox( array(
361 'var' => 'wgUpgradeKey',
362 'label' => 'config-localsettings-key',
363 'attribs' => array( 'autocomplete' => 'off' ),
366 $this->endForm( 'continue' );
369 protected function importVariables( $names, $vars ) {
370 $status = Status
::newGood();
371 foreach ( $names as $name ) {
372 if ( !isset( $vars[$name] ) ) {
373 $status->fatal( 'config-localsettings-incomplete', $name );
375 $this->setVar( $name, $vars[$name] );
382 * Initiate an upgrade of the existing database
383 * @param array $vars Variables from LocalSettings.php
386 protected function handleExistingUpgrade( $vars ) {
388 if ( !isset( $vars['wgDBtype'] ) ||
389 !in_array( $vars['wgDBtype'], Installer
::getDBTypes() )
391 return Status
::newFatal( 'config-localsettings-connection-error', '' );
394 // Set the relevant variables from LocalSettings.php
395 $requiredVars = array( 'wgDBtype' );
396 $status = $this->importVariables( $requiredVars, $vars );
397 $installer = $this->parent
->getDBInstaller();
398 $status->merge( $this->importVariables( $installer->getGlobalNames(), $vars ) );
399 if ( !$status->isOK() ) {
403 if ( isset( $vars['wgDBadminuser'] ) ) {
404 $this->setVar( '_InstallUser', $vars['wgDBadminuser'] );
406 $this->setVar( '_InstallUser', $vars['wgDBuser'] );
408 if ( isset( $vars['wgDBadminpassword'] ) ) {
409 $this->setVar( '_InstallPassword', $vars['wgDBadminpassword'] );
411 $this->setVar( '_InstallPassword', $vars['wgDBpassword'] );
414 // Test the database connection
415 $status = $installer->getConnection();
416 if ( !$status->isOK() ) {
417 // Adjust the error message to explain things correctly
418 $status->replaceMessage( 'config-connection-error',
419 'config-localsettings-connection-error' );
425 $this->setVar( '_ExistingDBSettings', true );
431 class WebInstaller_Welcome
extends WebInstallerPage
{
433 public function execute() {
434 if ( $this->parent
->request
->wasPosted() ) {
435 if ( $this->getVar( '_Environment' ) ) {
439 $this->parent
->output
->addWikiText( wfMessage( 'config-welcome' )->plain() );
440 $status = $this->parent
->doEnvironmentChecks();
441 if ( $status->isGood() ) {
442 $this->parent
->output
->addHTML( '<span class="success-message">' .
443 wfMessage( 'config-env-good' )->escaped() . '</span>' );
444 $this->parent
->output
->addWikiText( wfMessage( 'config-copyright',
445 SpecialVersion
::getCopyrightAndAuthorList() )->plain() );
449 $this->parent
->showStatusMessage( $status );
456 class WebInstaller_DBConnect
extends WebInstallerPage
{
458 * @return string|void When string, "skip" or "continue"
460 public function execute() {
461 if ( $this->getVar( '_ExistingDBSettings' ) ) {
465 $r = $this->parent
->request
;
466 if ( $r->wasPosted() ) {
467 $status = $this->submit();
469 if ( $status->isGood() ) {
470 $this->setVar( '_UpgradeDone', false );
474 $this->parent
->showStatusBox( $status );
480 $types = "<ul class=\"config-settings-block\">\n";
482 $defaultType = $this->getVar( 'wgDBtype' );
484 // Messages: config-dbsupport-mysql, config-dbsupport-postgres, config-dbsupport-oracle,
485 // config-dbsupport-sqlite
487 foreach ( Installer
::getDBTypes() as $type ) {
488 $dbSupport .= wfMessage( "config-dbsupport-$type" )->plain() . "\n";
490 $this->addHTML( $this->parent
->getInfoBox(
491 wfMessage( 'config-support-info', trim( $dbSupport ) )->text() ) );
493 // It's possible that the library for the default DB type is not compiled in.
494 // In that case, instead select the first supported DB type in the list.
495 $compiledDBs = $this->parent
->getCompiledDBs();
496 if ( !in_array( $defaultType, $compiledDBs ) ) {
497 $defaultType = $compiledDBs[0];
500 foreach ( $compiledDBs as $type ) {
501 $installer = $this->parent
->getDBInstaller( $type );
505 $installer->getReadableName(),
509 $type == $defaultType,
510 array( 'class' => 'dbRadio', 'rel' => "DB_wrapper_$type" )
514 // Messages: config-header-mysql, config-header-postgres, config-header-oracle,
515 // config-header-sqlite
516 $settings .= Html
::openElement(
519 'id' => 'DB_wrapper_' . $type,
520 'class' => 'dbWrapper'
523 Html
::element( 'h3', array(), wfMessage( 'config-header-' . $type )->text() ) .
524 $installer->getConnectForm() .
528 $types .= "</ul><br style=\"clear: left\"/>\n";
530 $this->addHTML( $this->parent
->label( 'config-db-type', false, $types ) . $settings );
534 public function submit() {
535 $r = $this->parent
->request
;
536 $type = $r->getVal( 'DBType' );
538 return Status
::newFatal( 'config-invalid-db-type' );
540 $this->setVar( 'wgDBtype', $type );
541 $installer = $this->parent
->getDBInstaller( $type );
543 return Status
::newFatal( 'config-invalid-db-type' );
546 return $installer->submitConnectForm();
550 class WebInstaller_Upgrade
extends WebInstallerPage
{
551 public function isSlow() {
555 public function execute() {
556 if ( $this->getVar( '_UpgradeDone' ) ) {
557 // Allow regeneration of LocalSettings.php, unless we are working
558 // from a pre-existing LocalSettings.php file and we want to avoid
559 // leaking its contents
560 if ( $this->parent
->request
->wasPosted() && !$this->getVar( '_ExistingDBSettings' ) ) {
561 // Done message acknowledged
565 // Show the done message again
566 // Make them click back again if they want to do the upgrade again
567 $this->showDoneMessage();
573 // wgDBtype is generally valid here because otherwise the previous page
574 // (connect) wouldn't have declared its happiness
575 $type = $this->getVar( 'wgDBtype' );
576 $installer = $this->parent
->getDBInstaller( $type );
578 if ( !$installer->needsUpgrade() ) {
582 if ( $this->parent
->request
->wasPosted() ) {
583 $installer->preUpgrade();
585 $this->startLiveBox();
586 $result = $installer->doUpgrade();
590 // If they're going to possibly regenerate LocalSettings, we
591 // need to create the upgrade/secret keys. Bug 26481
592 if ( !$this->getVar( '_ExistingDBSettings' ) ) {
593 $this->parent
->generateKeys();
595 $this->setVar( '_UpgradeDone', true );
596 $this->showDoneMessage();
603 $this->addHTML( $this->parent
->getInfoBox(
604 wfMessage( 'config-can-upgrade', $GLOBALS['wgVersion'] )->plain() ) );
608 public function showDoneMessage() {
610 $regenerate = !$this->getVar( '_ExistingDBSettings' );
612 $msg = 'config-upgrade-done';
614 $msg = 'config-upgrade-done-no-regenerate';
616 $this->parent
->disableLinkPopups();
618 $this->parent
->getInfoBox(
620 $this->getVar( 'wgServer' ) .
621 $this->getVar( 'wgScriptPath' ) . '/index' .
622 $this->getVar( 'wgScriptExtension' )
623 )->plain(), 'tick-32.png'
626 $this->parent
->restoreLinkPopups();
627 $this->endForm( $regenerate ?
'regenerate' : false, false );
631 class WebInstaller_DBSettings
extends WebInstallerPage
{
633 public function execute() {
634 $installer = $this->parent
->getDBInstaller( $this->getVar( 'wgDBtype' ) );
636 $r = $this->parent
->request
;
637 if ( $r->wasPosted() ) {
638 $status = $installer->submitSettingsForm();
639 if ( $status === false ) {
641 } elseif ( $status->isGood() ) {
644 $this->parent
->showStatusBox( $status );
648 $form = $installer->getSettingsForm();
649 if ( $form === false ) {
654 $this->addHTML( $form );
659 class WebInstaller_Name
extends WebInstallerPage
{
661 public function execute() {
662 $r = $this->parent
->request
;
663 if ( $r->wasPosted() ) {
664 if ( $this->submit() ) {
671 // Encourage people to not name their site 'MediaWiki' by blanking the
672 // field. I think that was the intent with the original $GLOBALS['wgSitename']
673 // but these two always were the same so had the effect of making the
674 // installer forget $wgSitename when navigating back to this page.
675 if ( $this->getVar( 'wgSitename' ) == 'MediaWiki' ) {
676 $this->setVar( 'wgSitename', '' );
679 // Set wgMetaNamespace to something valid before we show the form.
680 // $wgMetaNamespace defaults to $wgSiteName which is 'MediaWiki'
681 $metaNS = $this->getVar( 'wgMetaNamespace' );
684 wfMessage( 'config-ns-other-default' )->inContentLanguage()->text()
688 $this->parent
->getTextBox( array(
689 'var' => 'wgSitename',
690 'label' => 'config-site-name',
691 'help' => $this->parent
->getHelpBox( 'config-site-name-help' )
693 // getRadioSet() builds a set of labeled radio buttons.
694 // For grep: The following messages are used as the item labels:
695 // config-ns-site-name, config-ns-generic, config-ns-other
696 $this->parent
->getRadioSet( array(
697 'var' => '_NamespaceType',
698 'label' => 'config-project-namespace',
699 'itemLabelPrefix' => 'config-ns-',
700 'values' => array( 'site-name', 'generic', 'other' ),
701 'commonAttribs' => array( 'class' => 'enableForOther',
702 'rel' => 'config_wgMetaNamespace' ),
703 'help' => $this->parent
->getHelpBox( 'config-project-namespace-help' )
705 $this->parent
->getTextBox( array(
706 'var' => 'wgMetaNamespace',
707 'label' => '', // @todo Needs a label?
708 'attribs' => array( 'readonly' => 'readonly', 'class' => 'enabledByOther' )
710 $this->getFieldSetStart( 'config-admin-box' ) .
711 $this->parent
->getTextBox( array(
712 'var' => '_AdminName',
713 'label' => 'config-admin-name',
714 'help' => $this->parent
->getHelpBox( 'config-admin-help' )
716 $this->parent
->getPasswordBox( array(
717 'var' => '_AdminPassword',
718 'label' => 'config-admin-password',
720 $this->parent
->getPasswordBox( array(
721 'var' => '_AdminPassword2',
722 'label' => 'config-admin-password-confirm'
724 $this->parent
->getTextBox( array(
725 'var' => '_AdminEmail',
726 'label' => 'config-admin-email',
727 'help' => $this->parent
->getHelpBox( 'config-admin-email-help' )
729 $this->parent
->getCheckBox( array(
730 'var' => '_Subscribe',
731 'label' => 'config-subscribe',
732 'help' => $this->parent
->getHelpBox( 'config-subscribe-help' )
734 $this->getFieldSetEnd() .
735 $this->parent
->getInfoBox( wfMessage( 'config-almost-done' )->text() ) .
736 // getRadioSet() builds a set of labeled radio buttons.
737 // For grep: The following messages are used as the item labels:
738 // config-optional-continue, config-optional-skip
739 $this->parent
->getRadioSet( array(
740 'var' => '_SkipOptional',
741 'itemLabelPrefix' => 'config-optional-',
742 'values' => array( 'continue', 'skip' )
746 // Restore the default value
747 $this->setVar( 'wgMetaNamespace', $metaNS );
754 public function submit() {
756 $this->parent
->setVarsFromRequest( array( 'wgSitename', '_NamespaceType',
757 '_AdminName', '_AdminPassword', '_AdminPassword2', '_AdminEmail',
758 '_Subscribe', '_SkipOptional', 'wgMetaNamespace' ) );
760 // Validate site name
761 if ( strval( $this->getVar( 'wgSitename' ) ) === '' ) {
762 $this->parent
->showError( 'config-site-name-blank' );
767 $nsType = $this->getVar( '_NamespaceType' );
768 if ( $nsType == 'site-name' ) {
769 $name = $this->getVar( 'wgSitename' );
770 // Sanitize for namespace
771 // This algorithm should match the JS one in WebInstallerOutput.php
772 $name = preg_replace( '/[\[\]\{\}|#<>%+? ]/', '_', $name );
773 $name = str_replace( '&', '&', $name );
774 $name = preg_replace( '/__+/', '_', $name );
775 $name = ucfirst( trim( $name, '_' ) );
776 } elseif ( $nsType == 'generic' ) {
777 $name = wfMessage( 'config-ns-generic' )->text();
779 $name = $this->getVar( 'wgMetaNamespace' );
782 // Validate namespace
783 if ( strpos( $name, ':' ) !== false ) {
786 // Title-style validation
787 $title = Title
::newFromText( $name );
789 $good = $nsType == 'site-name';
791 $name = $title->getDBkey();
796 $this->parent
->showError( 'config-ns-invalid', $name );
800 // Make sure it won't conflict with any existing namespaces
802 $nsIndex = $wgContLang->getNsIndex( $name );
803 if ( $nsIndex !== false && $nsIndex !== NS_PROJECT
) {
804 $this->parent
->showError( 'config-ns-conflict', $name );
808 $this->setVar( 'wgMetaNamespace', $name );
810 // Validate username for creation
811 $name = $this->getVar( '_AdminName' );
812 if ( strval( $name ) === '' ) {
813 $this->parent
->showError( 'config-admin-name-blank' );
817 $cname = User
::getCanonicalName( $name, 'creatable' );
818 if ( $cname === false ) {
819 $this->parent
->showError( 'config-admin-name-invalid', $name );
822 $this->setVar( '_AdminName', $cname );
828 $pwd = $this->getVar( '_AdminPassword' );
829 $user = User
::newFromName( $cname );
831 $valid = $user->getPasswordValidity( $pwd );
833 $valid = 'config-admin-name-invalid';
835 if ( strval( $pwd ) === '' ) {
836 # $user->getPasswordValidity just checks for $wgMinimalPasswordLength.
837 # This message is more specific and helpful.
838 $msg = 'config-admin-password-blank';
839 } elseif ( $pwd !== $this->getVar( '_AdminPassword2' ) ) {
840 $msg = 'config-admin-password-mismatch';
841 } elseif ( $valid !== true ) {
844 if ( $msg !== false ) {
845 call_user_func_array( array( $this->parent
, 'showError' ), (array)$msg );
846 $this->setVar( '_AdminPassword', '' );
847 $this->setVar( '_AdminPassword2', '' );
851 // Validate e-mail if provided
852 $email = $this->getVar( '_AdminEmail' );
853 if ( $email && !Sanitizer
::validateEmail( $email ) ) {
854 $this->parent
->showError( 'config-admin-error-bademail' );
857 // If they asked to subscribe to mediawiki-announce but didn't give
858 // an e-mail, show an error. Bug 29332
859 if ( !$email && $this->getVar( '_Subscribe' ) ) {
860 $this->parent
->showError( 'config-subscribe-noemail' );
868 class WebInstaller_Options
extends WebInstallerPage
{
869 public function execute() {
870 if ( $this->getVar( '_SkipOptional' ) == 'skip' ) {
873 if ( $this->parent
->request
->wasPosted() ) {
874 if ( $this->submit() ) {
879 $emailwrapperStyle = $this->getVar( 'wgEnableEmail' ) ?
'' : 'display: none';
883 // getRadioSet() builds a set of labeled radio buttons.
884 // For grep: The following messages are used as the item labels:
885 // config-profile-wiki, config-profile-no-anon, config-profile-fishbowl, config-profile-private
886 $this->parent
->getRadioSet( array(
887 'var' => '_RightsProfile',
888 'label' => 'config-profile',
889 'itemLabelPrefix' => 'config-profile-',
890 'values' => array_keys( $this->parent
->rightsProfiles
),
892 $this->parent
->getInfoBox( wfMessage( 'config-profile-help' )->plain() ) .
895 // getRadioSet() builds a set of labeled radio buttons.
896 // For grep: The following messages are used as the item labels:
897 // config-license-cc-by, config-license-cc-by-sa, config-license-cc-by-nc-sa,
898 // config-license-cc-0, config-license-pd, config-license-gfdl,
899 // config-license-none, config-license-cc-choose
900 $this->parent
->getRadioSet( array(
901 'var' => '_LicenseCode',
902 'label' => 'config-license',
903 'itemLabelPrefix' => 'config-license-',
904 'values' => array_keys( $this->parent
->licenses
),
905 'commonAttribs' => array( 'class' => 'licenseRadio' ),
907 $this->getCCChooser() .
908 $this->parent
->getHelpBox( 'config-license-help' ) .
911 $this->getFieldSetStart( 'config-email-settings' ) .
912 $this->parent
->getCheckBox( array(
913 'var' => 'wgEnableEmail',
914 'label' => 'config-enable-email',
915 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'emailwrapper' ),
917 $this->parent
->getHelpBox( 'config-enable-email-help' ) .
918 "<div id=\"emailwrapper\" style=\"$emailwrapperStyle\">" .
919 $this->parent
->getTextBox( array(
920 'var' => 'wgPasswordSender',
921 'label' => 'config-email-sender'
923 $this->parent
->getHelpBox( 'config-email-sender-help' ) .
924 $this->parent
->getCheckBox( array(
925 'var' => 'wgEnableUserEmail',
926 'label' => 'config-email-user',
928 $this->parent
->getHelpBox( 'config-email-user-help' ) .
929 $this->parent
->getCheckBox( array(
930 'var' => 'wgEnotifUserTalk',
931 'label' => 'config-email-usertalk',
933 $this->parent
->getHelpBox( 'config-email-usertalk-help' ) .
934 $this->parent
->getCheckBox( array(
935 'var' => 'wgEnotifWatchlist',
936 'label' => 'config-email-watchlist',
938 $this->parent
->getHelpBox( 'config-email-watchlist-help' ) .
939 $this->parent
->getCheckBox( array(
940 'var' => 'wgEmailAuthentication',
941 'label' => 'config-email-auth',
943 $this->parent
->getHelpBox( 'config-email-auth-help' ) .
945 $this->getFieldSetEnd()
948 $extensions = $this->parent
->findExtensions();
951 $extHtml = $this->getFieldSetStart( 'config-extensions' );
953 foreach ( $extensions as $ext ) {
954 $extHtml .= $this->parent
->getCheckBox( array(
960 $extHtml .= $this->parent
->getHelpBox( 'config-extensions-help' ) .
961 $this->getFieldSetEnd();
962 $this->addHTML( $extHtml );
965 // Having / in paths in Windows looks funny :)
966 $this->setVar( 'wgDeletedDirectory',
968 '/', DIRECTORY_SEPARATOR
,
969 $this->getVar( 'wgDeletedDirectory' )
972 // If we're using the default, let the user set it relative to $wgScriptPath
973 $curLogo = $this->getVar( 'wgLogo' );
974 $logoString = ( $curLogo == "/wiki/skins/common/images/wiki.png" ) ?
975 '$wgStylePath/common/images/wiki.png' : $curLogo;
977 $uploadwrapperStyle = $this->getVar( 'wgEnableUploads' ) ?
'' : 'display: none';
980 $this->getFieldSetStart( 'config-upload-settings' ) .
981 $this->parent
->getCheckBox( array(
982 'var' => 'wgEnableUploads',
983 'label' => 'config-upload-enable',
984 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'uploadwrapper' ),
985 'help' => $this->parent
->getHelpBox( 'config-upload-help' )
987 '<div id="uploadwrapper" style="' . $uploadwrapperStyle . '">' .
988 $this->parent
->getTextBox( array(
989 'var' => 'wgDeletedDirectory',
990 'label' => 'config-upload-deleted',
991 'attribs' => array( 'dir' => 'ltr' ),
992 'help' => $this->parent
->getHelpBox( 'config-upload-deleted-help' )
995 $this->parent
->getTextBox( array(
997 'value' => $logoString,
998 'label' => 'config-logo',
999 'attribs' => array( 'dir' => 'ltr' ),
1000 'help' => $this->parent
->getHelpBox( 'config-logo-help' )
1004 $this->parent
->getCheckBox( array(
1005 'var' => 'wgUseInstantCommons',
1006 'label' => 'config-instantcommons',
1007 'help' => $this->parent
->getHelpBox( 'config-instantcommons-help' )
1009 $this->getFieldSetEnd()
1012 $caches = array( 'none' );
1013 if ( count( $this->getVar( '_Caches' ) ) ) {
1014 $caches[] = 'accel';
1016 $caches[] = 'memcached';
1018 // We'll hide/show this on demand when the value changes, see config.js.
1019 $cacheval = $this->getVar( 'wgMainCacheType' );
1021 // We need to set a default here; but don't hardcode it
1022 // or we lose it every time we reload the page for validation
1026 $hidden = ( $cacheval == 'memcached' ) ?
'' : 'display: none';
1029 $this->getFieldSetStart( 'config-advanced-settings' ) .
1030 # Object cache settings
1031 // getRadioSet() builds a set of labeled radio buttons.
1032 // For grep: The following messages are used as the item labels:
1033 // config-cache-none, config-cache-accel, config-cache-memcached
1034 $this->parent
->getRadioSet( array(
1035 'var' => 'wgMainCacheType',
1036 'label' => 'config-cache-options',
1037 'itemLabelPrefix' => 'config-cache-',
1038 'values' => $caches,
1039 'value' => $cacheval,
1041 $this->parent
->getHelpBox( 'config-cache-help' ) .
1042 "<div id=\"config-memcachewrapper\" style=\"$hidden\">" .
1043 $this->parent
->getTextArea( array(
1044 'var' => '_MemCachedServers',
1045 'label' => 'config-memcached-servers',
1046 'help' => $this->parent
->getHelpBox( 'config-memcached-help' )
1049 $this->getFieldSetEnd()
1057 public function getCCPartnerUrl() {
1058 $server = $this->getVar( 'wgServer' );
1059 $exitUrl = $server . $this->parent
->getUrl( array(
1060 'page' => 'Options',
1061 'SubmitCC' => 'indeed',
1062 'config__LicenseCode' => 'cc',
1063 'config_wgRightsUrl' => '[license_url]',
1064 'config_wgRightsText' => '[license_name]',
1065 'config_wgRightsIcon' => '[license_button]',
1067 $styleUrl = $server . dirname( dirname( $this->parent
->getUrl() ) ) .
1068 '/skins/common/config-cc.css';
1069 $iframeUrl = 'http://creativecommons.org/license/?' .
1070 wfArrayToCgi( array(
1071 'partner' => 'MediaWiki',
1072 'exit_url' => $exitUrl,
1073 'lang' => $this->getVar( '_UserLang' ),
1074 'stylesheet' => $styleUrl,
1080 public function getCCChooser() {
1081 $iframeAttribs = array(
1082 'class' => 'config-cc-iframe',
1083 'name' => 'config-cc-iframe',
1084 'id' => 'config-cc-iframe',
1089 if ( $this->getVar( '_CCDone' ) ) {
1090 $iframeAttribs['src'] = $this->parent
->getUrl( array( 'ShowCC' => 'yes' ) );
1092 $iframeAttribs['src'] = $this->getCCPartnerUrl();
1094 $wrapperStyle = ( $this->getVar( '_LicenseCode' ) == 'cc-choose' ) ?
'' : 'display: none';
1096 return "<div class=\"config-cc-wrapper\" id=\"config-cc-wrapper\" style=\"$wrapperStyle\">\n" .
1097 Html
::element( 'iframe', $iframeAttribs, '', false /* not short */ ) .
1101 public function getCCDoneBox() {
1102 $js = "parent.document.getElementById('config-cc-wrapper').style.height = '$1';";
1103 // If you change this height, also change it in config.css
1104 $expandJs = str_replace( '$1', '54em', $js );
1105 $reduceJs = str_replace( '$1', '70px', $js );
1108 Html
::element( 'img', array( 'src' => $this->getVar( 'wgRightsIcon' ) ) ) .
1110 htmlspecialchars( $this->getVar( 'wgRightsText' ) ) .
1112 "<p style=\"text-align: center;\">" .
1115 'href' => $this->getCCPartnerUrl(),
1116 'onclick' => $expandJs,
1118 wfMessage( 'config-cc-again' )->text()
1122 # Reduce the wrapper div height
1123 htmlspecialchars( $reduceJs ) .
1128 public function submitCC() {
1129 $newValues = $this->parent
->setVarsFromRequest(
1130 array( 'wgRightsUrl', 'wgRightsText', 'wgRightsIcon' ) );
1131 if ( count( $newValues ) != 3 ) {
1132 $this->parent
->showError( 'config-cc-error' );
1136 $this->setVar( '_CCDone', true );
1137 $this->addHTML( $this->getCCDoneBox() );
1140 public function submit() {
1141 $this->parent
->setVarsFromRequest( array( '_RightsProfile', '_LicenseCode',
1142 'wgEnableEmail', 'wgPasswordSender', 'wgEnableUploads', 'wgLogo',
1143 'wgEnableUserEmail', 'wgEnotifUserTalk', 'wgEnotifWatchlist',
1144 'wgEmailAuthentication', 'wgMainCacheType', '_MemCachedServers',
1145 'wgUseInstantCommons' ) );
1147 if ( !in_array( $this->getVar( '_RightsProfile' ),
1148 array_keys( $this->parent
->rightsProfiles
) )
1150 reset( $this->parent
->rightsProfiles
);
1151 $this->setVar( '_RightsProfile', key( $this->parent
->rightsProfiles
) );
1154 $code = $this->getVar( '_LicenseCode' );
1155 if ( $code == 'cc-choose' ) {
1156 if ( !$this->getVar( '_CCDone' ) ) {
1157 $this->parent
->showError( 'config-cc-not-chosen' );
1161 } elseif ( in_array( $code, array_keys( $this->parent
->licenses
) ) ) {
1163 // config-license-cc-by, config-license-cc-by-sa, config-license-cc-by-nc-sa,
1164 // config-license-cc-0, config-license-pd, config-license-gfdl, config-license-none,
1165 // config-license-cc-choose
1166 $entry = $this->parent
->licenses
[$code];
1167 if ( isset( $entry['text'] ) ) {
1168 $this->setVar( 'wgRightsText', $entry['text'] );
1170 $this->setVar( 'wgRightsText', wfMessage( 'config-license-' . $code )->text() );
1172 $this->setVar( 'wgRightsUrl', $entry['url'] );
1173 $this->setVar( 'wgRightsIcon', $entry['icon'] );
1175 $this->setVar( 'wgRightsText', '' );
1176 $this->setVar( 'wgRightsUrl', '' );
1177 $this->setVar( 'wgRightsIcon', '' );
1180 $extsAvailable = $this->parent
->findExtensions();
1181 $extsToInstall = array();
1182 foreach ( $extsAvailable as $ext ) {
1183 if ( $this->parent
->request
->getCheck( 'config_ext-' . $ext ) ) {
1184 $extsToInstall[] = $ext;
1187 $this->parent
->setVar( '_Extensions', $extsToInstall );
1189 if ( $this->getVar( 'wgMainCacheType' ) == 'memcached' ) {
1190 $memcServers = explode( "\n", $this->getVar( '_MemCachedServers' ) );
1191 if ( !$memcServers ) {
1192 $this->parent
->showError( 'config-memcache-needservers' );
1197 foreach ( $memcServers as $server ) {
1198 $memcParts = explode( ":", $server, 2 );
1199 if ( !isset( $memcParts[0] )
1200 ||
( !IP
::isValid( $memcParts[0] )
1201 && ( gethostbyname( $memcParts[0] ) == $memcParts[0] ) )
1203 $this->parent
->showError( 'config-memcache-badip', $memcParts[0] );
1206 } elseif ( !isset( $memcParts[1] ) ) {
1207 $this->parent
->showError( 'config-memcache-noport', $memcParts[0] );
1210 } elseif ( $memcParts[1] < 1 ||
$memcParts[1] > 65535 ) {
1211 $this->parent
->showError( 'config-memcache-badport', 1, 65535 );
1222 class WebInstaller_Install
extends WebInstallerPage
{
1223 public function isSlow() {
1227 public function execute() {
1228 if ( $this->getVar( '_UpgradeDone' ) ) {
1230 } elseif ( $this->getVar( '_InstallDone' ) ) {
1232 } elseif ( $this->parent
->request
->wasPosted() ) {
1234 $this->addHTML( "<ul>" );
1235 $results = $this->parent
->performInstallation(
1236 array( $this, 'startStage' ),
1237 array( $this, 'endStage' )
1239 $this->addHTML( "</ul>" );
1240 // PerformInstallation bails on a fatal, so make sure the last item
1241 // completed before giving 'next.' Likewise, only provide back on failure
1242 $lastStep = end( $results );
1243 $continue = $lastStep->isOK() ?
'continue' : false;
1244 $back = $lastStep->isOK() ?
false : 'back';
1245 $this->endForm( $continue, $back );
1248 $this->addHTML( $this->parent
->getInfoBox( wfMessage( 'config-install-begin' )->plain() ) );
1255 public function startStage( $step ) {
1256 // Messages: config-install-database, config-install-tables, config-install-interwiki,
1257 // config-install-stats, config-install-keys, config-install-sysop, config-install-mainpage
1258 $this->addHTML( "<li>" . wfMessage( "config-install-$step" )->escaped() .
1259 wfMessage( 'ellipsis' )->escaped() );
1261 if ( $step == 'extension-tables' ) {
1262 $this->startLiveBox();
1268 * @param $status Status
1270 public function endStage( $step, $status ) {
1271 if ( $step == 'extension-tables' ) {
1272 $this->endLiveBox();
1274 $msg = $status->isOk() ?
'config-install-step-done' : 'config-install-step-failed';
1275 $html = wfMessage( 'word-separator' )->escaped() . wfMessage( $msg )->escaped();
1276 if ( !$status->isOk() ) {
1277 $html = "<span class=\"error\">$html</span>";
1279 $this->addHTML( $html . "</li>\n" );
1280 if ( !$status->isGood() ) {
1281 $this->parent
->showStatusBox( $status );
1286 class WebInstaller_Complete
extends WebInstallerPage
{
1287 public function execute() {
1288 // Pop up a dialog box, to make it difficult for the user to forget
1289 // to download the file
1290 $lsUrl = $this->getVar( 'wgServer' ) . $this->parent
->getURL( array( 'localsettings' => 1 ) );
1291 if ( isset( $_SERVER['HTTP_USER_AGENT'] ) &&
1292 strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE' ) !== false
1294 // JS appears to be the only method that works consistently with IE7+
1295 $this->addHtml( "\n<script>jQuery( function () { document.location = " .
1296 Xml
::encodeJsVar( $lsUrl ) . "; } );</script>\n" );
1298 $this->parent
->request
->response()->header( "Refresh: 0;url=$lsUrl" );
1302 $this->parent
->disableLinkPopups();
1304 $this->parent
->getInfoBox(
1305 wfMessage( 'config-install-done',
1307 $this->getVar( 'wgServer' ) .
1308 $this->getVar( 'wgScriptPath' ) . '/index' .
1309 $this->getVar( 'wgScriptExtension' ),
1311 )->plain(), 'tick-32.png'
1314 $this->addHTML( $this->parent
->getInfoBox(
1315 wfMessage( 'config-extension-link' )->text() ) );
1317 $this->parent
->restoreLinkPopups();
1318 $this->endForm( false, false );
1322 class WebInstaller_Restart
extends WebInstallerPage
{
1324 public function execute() {
1325 $r = $this->parent
->request
;
1326 if ( $r->wasPosted() ) {
1327 $really = $r->getVal( 'submit-restart' );
1329 $this->parent
->reset();
1336 $s = $this->parent
->getWarningBox( wfMessage( 'config-help-restart' )->plain() );
1337 $this->addHTML( $s );
1338 $this->endForm( 'restart' );
1342 abstract class WebInstaller_Document
extends WebInstallerPage
{
1344 abstract protected function getFileName();
1346 public function execute() {
1347 $text = $this->getFileContents();
1348 $text = InstallDocFormatter
::format( $text );
1349 $this->parent
->output
->addWikiText( $text );
1351 $this->endForm( false );
1354 public function getFileContents() {
1355 $file = __DIR__
. '/../../' . $this->getFileName();
1356 if ( !file_exists( $file ) ) {
1357 return wfMessage( 'config-nofile', $file )->plain();
1360 return file_get_contents( $file );
1364 class WebInstaller_Readme
extends WebInstaller_Document
{
1365 protected function getFileName() {
1370 class WebInstaller_ReleaseNotes
extends WebInstaller_Document
{
1371 protected function getFileName() {
1374 if ( !preg_match( '/^(\d+)\.(\d+).*/i', $wgVersion, $result ) ) {
1375 throw new MWException( 'Variable $wgVersion has an invalid value.' );
1378 return 'RELEASE-NOTES-' . $result[1] . '.' . $result[2];
1382 class WebInstaller_UpgradeDoc
extends WebInstaller_Document
{
1383 protected function getFileName() {
1388 class WebInstaller_Copying
extends WebInstaller_Document
{
1389 protected function getFileName() {