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() ) )
77 public function endForm( $continue = 'continue', $back = 'back' ) {
78 $s = "<div class=\"config-submit\">\n";
81 if ( $id === false ) {
82 $s .= Html
::hidden( 'lastPage', $this->parent
->request
->getVal( 'lastPage' ) );
86 // Fake submit button for enter keypress (bug 26267)
87 // Give grep a chance to find the usages: config-continue
88 $s .= Xml
::submitButton( wfMessage( "config-$continue" )->text(),
89 array( 'name' => "enter-$continue", 'style' =>
90 'visibility:hidden;overflow:hidden;width:1px;margin:0' ) ) . "\n";
94 // Give grep a chance to find the usages: config-back
95 $s .= Xml
::submitButton( wfMessage( "config-$back" )->text(),
97 'name' => "submit-$back",
98 'tabindex' => $this->parent
->nextTabIndex()
103 // Give grep a chance to find the usages: config-continue
104 $s .= Xml
::submitButton( wfMessage( "config-$continue" )->text(),
106 'name' => "submit-$continue",
107 'tabindex' => $this->parent
->nextTabIndex(),
111 $s .= "</div></form></div>\n";
112 $this->addHTML( $s );
115 public function getName() {
116 return str_replace( 'WebInstaller_', '', get_class( $this ) );
119 protected function getId() {
120 return array_search( $this->getName(), $this->parent
->pageSequence
);
123 public function getVar( $var ) {
124 return $this->parent
->getVar( $var );
127 public function setVar( $name, $value ) {
128 $this->parent
->setVar( $name, $value );
132 * Get the starting tags of a fieldset.
134 * @param string $legend message name
138 protected function getFieldsetStart( $legend ) {
139 return "\n<fieldset><legend>" . wfMessage( $legend )->escaped() . "</legend>\n";
143 * Get the end tag of a fieldset.
147 protected function getFieldsetEnd() {
148 return "</fieldset>\n";
152 * Opens a textarea used to display the progress of a long operation
154 protected function startLiveBox() {
156 '<div id="config-spinner" style="display:none;">' .
157 '<img src="../skins/common/images/ajax-loader.gif" /></div>' .
158 '<script>jQuery( "#config-spinner" ).show();</script>' .
159 '<div id="config-live-log">' .
160 '<textarea name="LiveLog" rows="10" cols="30" readonly="readonly">'
162 $this->parent
->output
->flush();
166 * Opposite to startLiveBox()
168 protected function endLiveBox() {
169 $this->addHTML( '</textarea></div>
170 <script>jQuery( "#config-spinner" ).hide()</script>' );
171 $this->parent
->output
->flush();
175 class WebInstaller_Language
extends WebInstallerPage
{
177 public function execute() {
179 $r = $this->parent
->request
;
180 $userLang = $r->getVal( 'uselang' );
181 $contLang = $r->getVal( 'ContLang' );
183 $languages = Language
::fetchLanguageNames();
184 $lifetime = intval( ini_get( 'session.gc_maxlifetime' ) );
186 $lifetime = 1440; // PHP default
189 if ( $r->wasPosted() ) {
191 if ( $this->parent
->getSession( 'test' ) === null ) {
192 $requestTime = $r->getVal( 'LanguageRequestTime' );
193 if ( !$requestTime ) {
194 // The most likely explanation is that the user was knocked back
195 // from another page on POST due to session expiry
196 $msg = 'config-session-expired';
197 } elseif ( time() - $requestTime > $lifetime ) {
198 $msg = 'config-session-expired';
200 $msg = 'config-no-session';
202 $this->parent
->showError( $msg, $wgLang->formatTimePeriod( $lifetime ) );
204 if ( isset( $languages[$userLang] ) ) {
205 $this->setVar( '_UserLang', $userLang );
207 if ( isset( $languages[$contLang] ) ) {
208 $this->setVar( 'wgLanguageCode', $contLang );
212 } elseif ( $this->parent
->showSessionWarning
) {
213 # The user was knocked back from another page to the start
214 # This probably indicates a session expiry
215 $this->parent
->showError( 'config-session-expired',
216 $wgLang->formatTimePeriod( $lifetime ) );
219 $this->parent
->setSession( 'test', true );
221 if ( !isset( $languages[$userLang] ) ) {
222 $userLang = $this->getVar( '_UserLang', 'en' );
224 if ( !isset( $languages[$contLang] ) ) {
225 $contLang = $this->getVar( 'wgLanguageCode', 'en' );
228 $s = Html
::hidden( 'LanguageRequestTime', time() ) .
229 $this->getLanguageSelector( 'uselang', 'config-your-language', $userLang,
230 $this->parent
->getHelpBox( 'config-your-language-help' ) ) .
231 $this->getLanguageSelector( 'ContLang', 'config-wiki-language', $contLang,
232 $this->parent
->getHelpBox( 'config-wiki-language-help' ) );
233 $this->addHTML( $s );
234 $this->endForm( 'continue', false );
238 * Get a "<select>" for selecting languages.
242 * @param $selectedCode
243 * @param $helpHtml string
246 public function getLanguageSelector( $name, $label, $selectedCode, $helpHtml = '' ) {
247 global $wgDummyLanguageCodes;
251 $s .= Html
::openElement( 'select', array( 'id' => $name, 'name' => $name,
252 'tabindex' => $this->parent
->nextTabIndex() ) ) . "\n";
254 $languages = Language
::fetchLanguageNames();
256 foreach ( $languages as $code => $lang ) {
257 if ( isset( $wgDummyLanguageCodes[$code] ) ) {
260 $s .= "\n" . Xml
::option( "$code - $lang", $code, $code == $selectedCode );
262 $s .= "\n</select>\n";
263 return $this->parent
->label( $label, $name, $s );
268 class WebInstaller_ExistingWiki
extends WebInstallerPage
{
269 public function execute() {
270 // If there is no LocalSettings.php, continue to the installer welcome page
271 $vars = Installer
::getExistingLocalSettings();
276 // Check if the upgrade key supplied to the user has appeared in LocalSettings.php
277 if ( $vars['wgUpgradeKey'] !== false
278 && $this->getVar( '_UpgradeKeySupplied' )
279 && $this->getVar( 'wgUpgradeKey' ) === $vars['wgUpgradeKey'] )
281 // It's there, so the user is authorized
282 $status = $this->handleExistingUpgrade( $vars );
283 if ( $status->isOK() ) {
287 $this->parent
->showStatusBox( $status );
288 $this->endForm( 'continue' );
293 // If there is no $wgUpgradeKey, tell the user to add one to LocalSettings.php
294 if ( $vars['wgUpgradeKey'] === false ) {
295 if ( $this->getVar( 'wgUpgradeKey', false ) === false ) {
296 $secretKey = $this->getVar( 'wgSecretKey' ); // preserve $wgSecretKey
297 $this->parent
->generateKeys();
298 $this->setVar( 'wgSecretKey', $secretKey );
299 $this->setVar( '_UpgradeKeySupplied', true );
302 $this->addHTML( $this->parent
->getInfoBox(
303 wfMessage( 'config-upgrade-key-missing', "<pre dir=\"ltr\">\$wgUpgradeKey = '" .
304 $this->getVar( 'wgUpgradeKey' ) . "';</pre>" )->plain()
306 $this->endForm( 'continue' );
310 // If there is an upgrade key, but it wasn't supplied, prompt the user to enter it
312 $r = $this->parent
->request
;
313 if ( $r->wasPosted() ) {
314 $key = $r->getText( 'config_wgUpgradeKey' );
315 if ( !$key ||
$key !== $vars['wgUpgradeKey'] ) {
316 $this->parent
->showError( 'config-localsettings-badkey' );
317 $this->showKeyForm();
321 $status = $this->handleExistingUpgrade( $vars );
322 if ( $status->isOK() ) {
325 $this->parent
->showStatusBox( $status );
326 $this->showKeyForm();
330 $this->showKeyForm();
336 * Show the "enter key" form
338 protected function showKeyForm() {
341 $this->parent
->getInfoBox( wfMessage( 'config-localsettings-upgrade' )->plain() ) .
343 $this->parent
->getTextBox( array(
344 'var' => 'wgUpgradeKey',
345 'label' => 'config-localsettings-key',
346 'attribs' => array( 'autocomplete' => 'off' ),
349 $this->endForm( 'continue' );
352 protected function importVariables( $names, $vars ) {
353 $status = Status
::newGood();
354 foreach ( $names as $name ) {
355 if ( !isset( $vars[$name] ) ) {
356 $status->fatal( 'config-localsettings-incomplete', $name );
358 $this->setVar( $name, $vars[$name] );
364 * Initiate an upgrade of the existing database
365 * @param array $vars Variables from LocalSettings.php and AdminSettings.php
368 protected function handleExistingUpgrade( $vars ) {
370 if ( !isset( $vars['wgDBtype'] ) ||
371 !in_array( $vars['wgDBtype'], Installer
::getDBTypes() ) ) {
372 return Status
::newFatal( 'config-localsettings-connection-error', '' );
375 // Set the relevant variables from LocalSettings.php
376 $requiredVars = array( 'wgDBtype' );
377 $status = $this->importVariables( $requiredVars, $vars );
378 $installer = $this->parent
->getDBInstaller();
379 $status->merge( $this->importVariables( $installer->getGlobalNames(), $vars ) );
380 if ( !$status->isOK() ) {
384 if ( isset( $vars['wgDBadminuser'] ) ) {
385 $this->setVar( '_InstallUser', $vars['wgDBadminuser'] );
387 $this->setVar( '_InstallUser', $vars['wgDBuser'] );
389 if ( isset( $vars['wgDBadminpassword'] ) ) {
390 $this->setVar( '_InstallPassword', $vars['wgDBadminpassword'] );
392 $this->setVar( '_InstallPassword', $vars['wgDBpassword'] );
395 // Test the database connection
396 $status = $installer->getConnection();
397 if ( !$status->isOK() ) {
398 // Adjust the error message to explain things correctly
399 $status->replaceMessage( 'config-connection-error',
400 'config-localsettings-connection-error' );
405 $this->setVar( '_ExistingDBSettings', true );
410 class WebInstaller_Welcome
extends WebInstallerPage
{
412 public function execute() {
413 if ( $this->parent
->request
->wasPosted() ) {
414 if ( $this->getVar( '_Environment' ) ) {
418 $this->parent
->output
->addWikiText( wfMessage( 'config-welcome' )->plain() );
419 $status = $this->parent
->doEnvironmentChecks();
420 if ( $status->isGood() ) {
421 $this->parent
->output
->addHTML( '<span class="success-message">' .
422 wfMessage( 'config-env-good' )->escaped() . '</span>' );
423 $this->parent
->output
->addWikiText( wfMessage( 'config-copyright',
424 SpecialVersion
::getCopyrightAndAuthorList() )->plain() );
428 $this->parent
->showStatusMessage( $status );
435 class WebInstaller_DBConnect
extends WebInstallerPage
{
437 public function execute() {
438 if ( $this->getVar( '_ExistingDBSettings' ) ) {
442 $r = $this->parent
->request
;
443 if ( $r->wasPosted() ) {
444 $status = $this->submit();
446 if ( $status->isGood() ) {
447 $this->setVar( '_UpgradeDone', false );
450 $this->parent
->showStatusBox( $status );
456 $types = "<ul class=\"config-settings-block\">\n";
458 $defaultType = $this->getVar( 'wgDBtype' );
460 // Give grep a chance to find the usages:
461 // config-support-mysql, config-support-postgres, config-support-oracle, config-support-sqlite
463 foreach ( $this->parent
->getDBTypes() as $type ) {
464 $link = DatabaseBase
::factory( $type )->getSoftwareLink();
465 $dbSupport .= wfMessage( "config-support-$type", $link )->plain() . "\n";
467 $this->addHTML( $this->parent
->getInfoBox(
468 wfMessage( 'config-support-info', trim( $dbSupport ) )->text() ) );
470 // It's possible that the library for the default DB type is not compiled in.
471 // In that case, instead select the first supported DB type in the list.
472 $compiledDBs = $this->parent
->getCompiledDBs();
473 if ( !in_array( $defaultType, $compiledDBs ) ) {
474 $defaultType = $compiledDBs[0];
477 foreach ( $compiledDBs as $type ) {
478 $installer = $this->parent
->getDBInstaller( $type );
482 $installer->getReadableName(),
486 $type == $defaultType,
487 array( 'class' => 'dbRadio', 'rel' => "DB_wrapper_$type" )
491 // Give grep a chance to find the usages:
492 // config-header-mysql, config-header-postgres, config-header-oracle, config-header-sqlite
494 Html
::openElement( 'div', array( 'id' => 'DB_wrapper_' . $type,
495 'class' => 'dbWrapper' ) ) .
496 Html
::element( 'h3', array(), wfMessage( 'config-header-' . $type )->text() ) .
497 $installer->getConnectForm() .
500 $types .= "</ul><br style=\"clear: left\"/>\n";
503 $this->parent
->label( 'config-db-type', false, $types ) .
510 public function submit() {
511 $r = $this->parent
->request
;
512 $type = $r->getVal( 'DBType' );
514 return Status
::newFatal( 'config-invalid-db-type' );
516 $this->setVar( 'wgDBtype', $type );
517 $installer = $this->parent
->getDBInstaller( $type );
519 return Status
::newFatal( 'config-invalid-db-type' );
521 return $installer->submitConnectForm();
526 class WebInstaller_Upgrade
extends WebInstallerPage
{
527 public function isSlow() {
531 public function execute() {
532 if ( $this->getVar( '_UpgradeDone' ) ) {
533 // Allow regeneration of LocalSettings.php, unless we are working
534 // from a pre-existing LocalSettings.php file and we want to avoid
535 // leaking its contents
536 if ( $this->parent
->request
->wasPosted() && !$this->getVar( '_ExistingDBSettings' ) ) {
537 // Done message acknowledged
541 // Show the done message again
542 // Make them click back again if they want to do the upgrade again
543 $this->showDoneMessage();
548 // wgDBtype is generally valid here because otherwise the previous page
549 // (connect) wouldn't have declared its happiness
550 $type = $this->getVar( 'wgDBtype' );
551 $installer = $this->parent
->getDBInstaller( $type );
553 if ( !$installer->needsUpgrade() ) {
557 if ( $this->parent
->request
->wasPosted() ) {
558 $installer->preUpgrade();
560 $this->startLiveBox();
561 $result = $installer->doUpgrade();
565 // If they're going to possibly regenerate LocalSettings, we
566 // need to create the upgrade/secret keys. Bug 26481
567 if ( !$this->getVar( '_ExistingDBSettings' ) ) {
568 $this->parent
->generateKeys();
570 $this->setVar( '_UpgradeDone', true );
571 $this->showDoneMessage();
577 $this->addHTML( $this->parent
->getInfoBox(
578 wfMessage( 'config-can-upgrade', $GLOBALS['wgVersion'] )->plain() ) );
582 public function showDoneMessage() {
584 $regenerate = !$this->getVar( '_ExistingDBSettings' );
586 $msg = 'config-upgrade-done';
588 $msg = 'config-upgrade-done-no-regenerate';
590 $this->parent
->disableLinkPopups();
592 $this->parent
->getInfoBox(
594 $this->getVar( 'wgServer' ) .
595 $this->getVar( 'wgScriptPath' ) . '/index' .
596 $this->getVar( 'wgScriptExtension' )
597 )->plain(), 'tick-32.png'
600 $this->parent
->restoreLinkPopups();
601 $this->endForm( $regenerate ?
'regenerate' : false, false );
606 class WebInstaller_DBSettings
extends WebInstallerPage
{
608 public function execute() {
609 $installer = $this->parent
->getDBInstaller( $this->getVar( 'wgDBtype' ) );
611 $r = $this->parent
->request
;
612 if ( $r->wasPosted() ) {
613 $status = $installer->submitSettingsForm();
614 if ( $status === false ) {
616 } elseif ( $status->isGood() ) {
619 $this->parent
->showStatusBox( $status );
623 $form = $installer->getSettingsForm();
624 if ( $form === false ) {
629 $this->addHTML( $form );
635 class WebInstaller_Name
extends WebInstallerPage
{
637 public function execute() {
638 $r = $this->parent
->request
;
639 if ( $r->wasPosted() ) {
640 if ( $this->submit() ) {
647 // Encourage people to not name their site 'MediaWiki' by blanking the
648 // field. I think that was the intent with the original $GLOBALS['wgSitename']
649 // but these two always were the same so had the effect of making the
650 // installer forget $wgSitename when navigating back to this page.
651 if ( $this->getVar( 'wgSitename' ) == 'MediaWiki' ) {
652 $this->setVar( 'wgSitename', '' );
655 // Set wgMetaNamespace to something valid before we show the form.
656 // $wgMetaNamespace defaults to $wgSiteName which is 'MediaWiki'
657 $metaNS = $this->getVar( 'wgMetaNamespace' );
660 wfMessage( 'config-ns-other-default' )->inContentLanguage()->text()
664 $this->parent
->getTextBox( array(
665 'var' => 'wgSitename',
666 'label' => 'config-site-name',
667 'help' => $this->parent
->getHelpBox( 'config-site-name-help' )
669 // getRadioSet() builds a set of labeled radio buttons.
670 // For grep: The following messages are used as the item labels:
671 // config-ns-site-name, config-ns-generic, config-ns-other
672 $this->parent
->getRadioSet( array(
673 'var' => '_NamespaceType',
674 'label' => 'config-project-namespace',
675 'itemLabelPrefix' => 'config-ns-',
676 'values' => array( 'site-name', 'generic', 'other' ),
677 'commonAttribs' => array( 'class' => 'enableForOther',
678 'rel' => 'config_wgMetaNamespace' ),
679 'help' => $this->parent
->getHelpBox( 'config-project-namespace-help' )
681 $this->parent
->getTextBox( array(
682 'var' => 'wgMetaNamespace',
683 'label' => '', //TODO: Needs a label?
684 'attribs' => array( 'readonly' => 'readonly', 'class' => 'enabledByOther' ),
687 $this->getFieldSetStart( 'config-admin-box' ) .
688 $this->parent
->getTextBox( array(
689 'var' => '_AdminName',
690 'label' => 'config-admin-name',
691 'help' => $this->parent
->getHelpBox( 'config-admin-help' )
693 $this->parent
->getPasswordBox( array(
694 'var' => '_AdminPassword',
695 'label' => 'config-admin-password',
697 $this->parent
->getPasswordBox( array(
698 'var' => '_AdminPassword2',
699 'label' => 'config-admin-password-confirm'
701 $this->parent
->getTextBox( array(
702 'var' => '_AdminEmail',
703 'label' => 'config-admin-email',
704 'help' => $this->parent
->getHelpBox( 'config-admin-email-help' )
706 $this->parent
->getCheckBox( array(
707 'var' => '_Subscribe',
708 'label' => 'config-subscribe',
709 'help' => $this->parent
->getHelpBox( 'config-subscribe-help' )
711 $this->getFieldSetEnd() .
712 $this->parent
->getInfoBox( wfMessage( 'config-almost-done' )->text() ) .
713 // getRadioSet() builds a set of labeled radio buttons.
714 // For grep: The following messages are used as the item labels:
715 // config-optional-continue, config-optional-skip
716 $this->parent
->getRadioSet( array(
717 'var' => '_SkipOptional',
718 'itemLabelPrefix' => 'config-optional-',
719 'values' => array( 'continue', 'skip' )
723 // Restore the default value
724 $this->setVar( 'wgMetaNamespace', $metaNS );
730 public function submit() {
732 $this->parent
->setVarsFromRequest( array( 'wgSitename', '_NamespaceType',
733 '_AdminName', '_AdminPassword', '_AdminPassword2', '_AdminEmail',
734 '_Subscribe', '_SkipOptional', 'wgMetaNamespace' ) );
736 // Validate site name
737 if ( strval( $this->getVar( 'wgSitename' ) ) === '' ) {
738 $this->parent
->showError( 'config-site-name-blank' );
743 $nsType = $this->getVar( '_NamespaceType' );
744 if ( $nsType == 'site-name' ) {
745 $name = $this->getVar( 'wgSitename' );
746 // Sanitize for namespace
747 // This algorithm should match the JS one in WebInstallerOutput.php
748 $name = preg_replace( '/[\[\]\{\}|#<>%+? ]/', '_', $name );
749 $name = str_replace( '&', '&', $name );
750 $name = preg_replace( '/__+/', '_', $name );
751 $name = ucfirst( trim( $name, '_' ) );
752 } elseif ( $nsType == 'generic' ) {
753 $name = wfMessage( 'config-ns-generic' )->text();
755 $name = $this->getVar( 'wgMetaNamespace' );
758 // Validate namespace
759 if ( strpos( $name, ':' ) !== false ) {
762 // Title-style validation
763 $title = Title
::newFromText( $name );
765 $good = $nsType == 'site-name';
767 $name = $title->getDBkey();
772 $this->parent
->showError( 'config-ns-invalid', $name );
776 // Make sure it won't conflict with any existing namespaces
778 $nsIndex = $wgContLang->getNsIndex( $name );
779 if ( $nsIndex !== false && $nsIndex !== NS_PROJECT
) {
780 $this->parent
->showError( 'config-ns-conflict', $name );
784 $this->setVar( 'wgMetaNamespace', $name );
786 // Validate username for creation
787 $name = $this->getVar( '_AdminName' );
788 if ( strval( $name ) === '' ) {
789 $this->parent
->showError( 'config-admin-name-blank' );
793 $cname = User
::getCanonicalName( $name, 'creatable' );
794 if ( $cname === false ) {
795 $this->parent
->showError( 'config-admin-name-invalid', $name );
798 $this->setVar( '_AdminName', $cname );
804 $pwd = $this->getVar( '_AdminPassword' );
805 $user = User
::newFromName( $cname );
806 $valid = $user && $user->getPasswordValidity( $pwd );
807 if ( strval( $pwd ) === '' ) {
808 # $user->getPasswordValidity just checks for $wgMinimalPasswordLength.
809 # This message is more specific and helpful.
810 $msg = 'config-admin-password-blank';
811 } elseif ( $pwd !== $this->getVar( '_AdminPassword2' ) ) {
812 $msg = 'config-admin-password-mismatch';
813 } elseif ( $valid !== true ) {
814 # As of writing this will only catch the username being e.g. 'FOO' and
818 if ( $msg !== false ) {
819 call_user_func_array( array( $this->parent
, 'showError' ), (array)$msg );
820 $this->setVar( '_AdminPassword', '' );
821 $this->setVar( '_AdminPassword2', '' );
825 // Validate e-mail if provided
826 $email = $this->getVar( '_AdminEmail' );
827 if ( $email && !Sanitizer
::validateEmail( $email ) ) {
828 $this->parent
->showError( 'config-admin-error-bademail' );
831 // If they asked to subscribe to mediawiki-announce but didn't give
832 // an e-mail, show an error. Bug 29332
833 if ( !$email && $this->getVar( '_Subscribe' ) ) {
834 $this->parent
->showError( 'config-subscribe-noemail' );
843 class WebInstaller_Options
extends WebInstallerPage
{
845 public function execute() {
846 if ( $this->getVar( '_SkipOptional' ) == 'skip' ) {
849 if ( $this->parent
->request
->wasPosted() ) {
850 if ( $this->submit() ) {
855 $emailwrapperStyle = $this->getVar( 'wgEnableEmail' ) ?
'' : 'display: none';
859 // getRadioSet() builds a set of labeled radio buttons.
860 // For grep: The following messages are used as the item labels:
861 // config-profile-wiki, config-profile-no-anon, config-profile-fishbowl, config-profile-private
862 $this->parent
->getRadioSet( array(
863 'var' => '_RightsProfile',
864 'label' => 'config-profile',
865 'itemLabelPrefix' => 'config-profile-',
866 'values' => array_keys( $this->parent
->rightsProfiles
),
868 $this->parent
->getInfoBox( wfMessage( 'config-profile-help' )->plain() ) .
871 // getRadioSet() builds a set of labeled radio buttons.
872 // For grep: The following messages are used as the item labels:
873 // config-license-cc-by, config-license-cc-by-sa, config-license-cc-by-nc-sa,
874 // config-license-cc-0, config-license-pd, config-license-gfdl,
875 // config-license-none, config-license-cc-choose
876 $this->parent
->getRadioSet( array(
877 'var' => '_LicenseCode',
878 'label' => 'config-license',
879 'itemLabelPrefix' => 'config-license-',
880 'values' => array_keys( $this->parent
->licenses
),
881 'commonAttribs' => array( 'class' => 'licenseRadio' ),
883 $this->getCCChooser() .
884 $this->parent
->getHelpBox( 'config-license-help' ) .
887 $this->getFieldSetStart( 'config-email-settings' ) .
888 $this->parent
->getCheckBox( array(
889 'var' => 'wgEnableEmail',
890 'label' => 'config-enable-email',
891 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'emailwrapper' ),
893 $this->parent
->getHelpBox( 'config-enable-email-help' ) .
894 "<div id=\"emailwrapper\" style=\"$emailwrapperStyle\">" .
895 $this->parent
->getTextBox( array(
896 'var' => 'wgPasswordSender',
897 'label' => 'config-email-sender'
899 $this->parent
->getHelpBox( 'config-email-sender-help' ) .
900 $this->parent
->getCheckBox( array(
901 'var' => 'wgEnableUserEmail',
902 'label' => 'config-email-user',
904 $this->parent
->getHelpBox( 'config-email-user-help' ) .
905 $this->parent
->getCheckBox( array(
906 'var' => 'wgEnotifUserTalk',
907 'label' => 'config-email-usertalk',
909 $this->parent
->getHelpBox( 'config-email-usertalk-help' ) .
910 $this->parent
->getCheckBox( array(
911 'var' => 'wgEnotifWatchlist',
912 'label' => 'config-email-watchlist',
914 $this->parent
->getHelpBox( 'config-email-watchlist-help' ) .
915 $this->parent
->getCheckBox( array(
916 'var' => 'wgEmailAuthentication',
917 'label' => 'config-email-auth',
919 $this->parent
->getHelpBox( 'config-email-auth-help' ) .
921 $this->getFieldSetEnd()
924 $extensions = $this->parent
->findExtensions();
927 $extHtml = $this->getFieldSetStart( 'config-extensions' );
929 foreach ( $extensions as $ext ) {
930 $extHtml .= $this->parent
->getCheckBox( array(
936 $extHtml .= $this->parent
->getHelpBox( 'config-extensions-help' ) .
937 $this->getFieldSetEnd();
938 $this->addHTML( $extHtml );
941 // Having / in paths in Windows looks funny :)
942 $this->setVar( 'wgDeletedDirectory',
944 '/', DIRECTORY_SEPARATOR
,
945 $this->getVar( 'wgDeletedDirectory' )
948 // If we're using the default, let the user set it relative to $wgScriptPath
949 $curLogo = $this->getVar( 'wgLogo' );
950 $logoString = ( $curLogo == "/wiki/skins/common/images/wiki.png" ) ?
951 '$wgStylePath/common/images/wiki.png' : $curLogo;
953 $uploadwrapperStyle = $this->getVar( 'wgEnableUploads' ) ?
'' : 'display: none';
956 $this->getFieldSetStart( 'config-upload-settings' ) .
957 $this->parent
->getCheckBox( array(
958 'var' => 'wgEnableUploads',
959 'label' => 'config-upload-enable',
960 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'uploadwrapper' ),
961 'help' => $this->parent
->getHelpBox( 'config-upload-help' )
963 '<div id="uploadwrapper" style="' . $uploadwrapperStyle . '">' .
964 $this->parent
->getTextBox( array(
965 'var' => 'wgDeletedDirectory',
966 'label' => 'config-upload-deleted',
967 'attribs' => array( 'dir' => 'ltr' ),
968 'help' => $this->parent
->getHelpBox( 'config-upload-deleted-help' )
971 $this->parent
->getTextBox( array(
973 'value' => $logoString,
974 'label' => 'config-logo',
975 'attribs' => array( 'dir' => 'ltr' ),
976 'help' => $this->parent
->getHelpBox( 'config-logo-help' )
980 $this->parent
->getCheckBox( array(
981 'var' => 'wgUseInstantCommons',
982 'label' => 'config-instantcommons',
983 'help' => $this->parent
->getHelpBox( 'config-instantcommons-help' )
985 $this->getFieldSetEnd()
988 $caches = array( 'none' );
989 if ( count( $this->getVar( '_Caches' ) ) ) {
992 $caches[] = 'memcached';
994 // We'll hide/show this on demand when the value changes, see config.js.
995 $cacheval = $this->getVar( 'wgMainCacheType' );
997 // We need to set a default here; but don't hardcode it
998 // or we lose it every time we reload the page for validation
1002 $hidden = ( $cacheval == 'memcached' ) ?
'' : 'display: none';
1005 $this->getFieldSetStart( 'config-advanced-settings' ) .
1006 # Object cache settings
1007 // getRadioSet() builds a set of labeled radio buttons.
1008 // For grep: The following messages are used as the item labels:
1009 // config-cache-none, config-cache-accel, config-cache-memcached
1010 $this->parent
->getRadioSet( array(
1011 'var' => 'wgMainCacheType',
1012 'label' => 'config-cache-options',
1013 'itemLabelPrefix' => 'config-cache-',
1014 'values' => $caches,
1015 'value' => $cacheval,
1017 $this->parent
->getHelpBox( 'config-cache-help' ) .
1018 "<div id=\"config-memcachewrapper\" style=\"$hidden\">" .
1019 $this->parent
->getTextArea( array(
1020 'var' => '_MemCachedServers',
1021 'label' => 'config-memcached-servers',
1022 'help' => $this->parent
->getHelpBox( 'config-memcached-help' )
1025 $this->getFieldSetEnd()
1033 public function getCCPartnerUrl() {
1034 $server = $this->getVar( 'wgServer' );
1035 $exitUrl = $server . $this->parent
->getUrl( array(
1036 'page' => 'Options',
1037 'SubmitCC' => 'indeed',
1038 'config__LicenseCode' => 'cc',
1039 'config_wgRightsUrl' => '[license_url]',
1040 'config_wgRightsText' => '[license_name]',
1041 'config_wgRightsIcon' => '[license_button]',
1043 $styleUrl = $server . dirname( dirname( $this->parent
->getUrl() ) ) .
1044 '/skins/common/config-cc.css';
1045 $iframeUrl = 'http://creativecommons.org/license/?' .
1046 wfArrayToCgi( array(
1047 'partner' => 'MediaWiki',
1048 'exit_url' => $exitUrl,
1049 'lang' => $this->getVar( '_UserLang' ),
1050 'stylesheet' => $styleUrl,
1055 public function getCCChooser() {
1056 $iframeAttribs = array(
1057 'class' => 'config-cc-iframe',
1058 'name' => 'config-cc-iframe',
1059 'id' => 'config-cc-iframe',
1064 if ( $this->getVar( '_CCDone' ) ) {
1065 $iframeAttribs['src'] = $this->parent
->getUrl( array( 'ShowCC' => 'yes' ) );
1067 $iframeAttribs['src'] = $this->getCCPartnerUrl();
1069 $wrapperStyle = ( $this->getVar( '_LicenseCode' ) == 'cc-choose' ) ?
'' : 'display: none';
1071 return "<div class=\"config-cc-wrapper\" id=\"config-cc-wrapper\" style=\"$wrapperStyle\">\n" .
1072 Html
::element( 'iframe', $iframeAttribs, '', false /* not short */ ) .
1076 public function getCCDoneBox() {
1077 $js = "parent.document.getElementById('config-cc-wrapper').style.height = '$1';";
1078 // If you change this height, also change it in config.css
1079 $expandJs = str_replace( '$1', '54em', $js );
1080 $reduceJs = str_replace( '$1', '70px', $js );
1082 Html
::element( 'img', array( 'src' => $this->getVar( 'wgRightsIcon' ) ) ) .
1084 htmlspecialchars( $this->getVar( 'wgRightsText' ) ) .
1086 "<p style=\"text-align: center;\">" .
1089 'href' => $this->getCCPartnerUrl(),
1090 'onclick' => $expandJs,
1092 wfMessage( 'config-cc-again' )->text()
1096 # Reduce the wrapper div height
1097 htmlspecialchars( $reduceJs ) .
1102 public function submitCC() {
1103 $newValues = $this->parent
->setVarsFromRequest(
1104 array( 'wgRightsUrl', 'wgRightsText', 'wgRightsIcon' ) );
1105 if ( count( $newValues ) != 3 ) {
1106 $this->parent
->showError( 'config-cc-error' );
1109 $this->setVar( '_CCDone', true );
1110 $this->addHTML( $this->getCCDoneBox() );
1113 public function submit() {
1114 $this->parent
->setVarsFromRequest( array( '_RightsProfile', '_LicenseCode',
1115 'wgEnableEmail', 'wgPasswordSender', 'wgEnableUploads', 'wgLogo',
1116 'wgEnableUserEmail', 'wgEnotifUserTalk', 'wgEnotifWatchlist',
1117 'wgEmailAuthentication', 'wgMainCacheType', '_MemCachedServers',
1118 'wgUseInstantCommons' ) );
1120 if ( !in_array( $this->getVar( '_RightsProfile' ),
1121 array_keys( $this->parent
->rightsProfiles
) ) )
1123 reset( $this->parent
->rightsProfiles
);
1124 $this->setVar( '_RightsProfile', key( $this->parent
->rightsProfiles
) );
1127 $code = $this->getVar( '_LicenseCode' );
1128 if ( $code == 'cc-choose' ) {
1129 if ( !$this->getVar( '_CCDone' ) ) {
1130 $this->parent
->showError( 'config-cc-not-chosen' );
1133 } elseif ( in_array( $code, array_keys( $this->parent
->licenses
) ) ) {
1134 // Give grep a chance to find the usages:
1135 // config-license-cc-by, config-license-cc-by-sa, config-license-cc-by-nc-sa,
1136 // config-license-cc-0, config-license-pd, config-license-gfdl,
1137 // config-license-none, config-license-cc-choose
1138 $entry = $this->parent
->licenses
[$code];
1139 if ( isset( $entry['text'] ) ) {
1140 $this->setVar( 'wgRightsText', $entry['text'] );
1142 $this->setVar( 'wgRightsText', wfMessage( 'config-license-' . $code )->text() );
1144 $this->setVar( 'wgRightsUrl', $entry['url'] );
1145 $this->setVar( 'wgRightsIcon', $entry['icon'] );
1147 $this->setVar( 'wgRightsText', '' );
1148 $this->setVar( 'wgRightsUrl', '' );
1149 $this->setVar( 'wgRightsIcon', '' );
1152 $extsAvailable = $this->parent
->findExtensions();
1153 $extsToInstall = array();
1154 foreach ( $extsAvailable as $ext ) {
1155 if ( $this->parent
->request
->getCheck( 'config_ext-' . $ext ) ) {
1156 $extsToInstall[] = $ext;
1159 $this->parent
->setVar( '_Extensions', $extsToInstall );
1161 if ( $this->getVar( 'wgMainCacheType' ) == 'memcached' ) {
1162 $memcServers = explode( "\n", $this->getVar( '_MemCachedServers' ) );
1163 if ( !$memcServers ) {
1164 $this->parent
->showError( 'config-memcache-needservers' );
1168 foreach ( $memcServers as $server ) {
1169 $memcParts = explode( ":", $server, 2 );
1170 if ( !isset( $memcParts[0] )
1171 ||
( !IP
::isValid( $memcParts[0] )
1172 && ( gethostbyname( $memcParts[0] ) == $memcParts[0] ) ) ) {
1173 $this->parent
->showError( 'config-memcache-badip', $memcParts[0] );
1175 } elseif ( !isset( $memcParts[1] ) ) {
1176 $this->parent
->showError( 'config-memcache-noport', $memcParts[0] );
1178 } elseif ( $memcParts[1] < 1 ||
$memcParts[1] > 65535 ) {
1179 $this->parent
->showError( 'config-memcache-badport', 1, 65535 );
1189 class WebInstaller_Install
extends WebInstallerPage
{
1190 public function isSlow() {
1194 public function execute() {
1195 if ( $this->getVar( '_UpgradeDone' ) ) {
1197 } elseif ( $this->getVar( '_InstallDone' ) ) {
1199 } elseif ( $this->parent
->request
->wasPosted() ) {
1201 $this->addHTML( "<ul>" );
1202 $results = $this->parent
->performInstallation(
1203 array( $this, 'startStage' ),
1204 array( $this, 'endStage' )
1206 $this->addHTML( "</ul>" );
1207 // PerformInstallation bails on a fatal, so make sure the last item
1208 // completed before giving 'next.' Likewise, only provide back on failure
1209 $lastStep = end( $results );
1210 $continue = $lastStep->isOK() ?
'continue' : false;
1211 $back = $lastStep->isOK() ?
false : 'back';
1212 $this->endForm( $continue, $back );
1215 $this->addHTML( $this->parent
->getInfoBox( wfMessage( 'config-install-begin' )->plain() ) );
1221 public function startStage( $step ) {
1222 $this->addHTML( "<li>" . wfMessage( "config-install-$step" )->escaped() . wfMessage( 'ellipsis' )->escaped() );
1223 if ( $step == 'extension-tables' ) {
1224 $this->startLiveBox();
1230 * @param $status Status
1232 public function endStage( $step, $status ) {
1233 if ( $step == 'extension-tables' ) {
1234 $this->endLiveBox();
1236 $msg = $status->isOk() ?
'config-install-step-done' : 'config-install-step-failed';
1237 $html = wfMessage( 'word-separator' )->escaped() . wfMessage( $msg )->escaped();
1238 if ( !$status->isOk() ) {
1239 $html = "<span class=\"error\">$html</span>";
1241 $this->addHTML( $html . "</li>\n" );
1242 if ( !$status->isGood() ) {
1243 $this->parent
->showStatusBox( $status );
1249 class WebInstaller_Complete
extends WebInstallerPage
{
1251 public function execute() {
1252 // Pop up a dialog box, to make it difficult for the user to forget
1253 // to download the file
1254 $lsUrl = $this->getVar( 'wgServer' ) . $this->parent
->getURL( array( 'localsettings' => 1 ) );
1255 if ( isset( $_SERVER['HTTP_USER_AGENT'] ) &&
1256 strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE' ) !== false ) {
1257 // JS appears to be the only method that works consistently with IE7+
1258 $this->addHtml( "\n<script>jQuery( function () { document.location = " .
1259 Xml
::encodeJsVar( $lsUrl ) . "; } );</script>\n" );
1261 $this->parent
->request
->response()->header( "Refresh: 0;url=$lsUrl" );
1265 $this->parent
->disableLinkPopups();
1267 $this->parent
->getInfoBox(
1268 wfMessage( 'config-install-done',
1270 $this->getVar( 'wgServer' ) .
1271 $this->getVar( 'wgScriptPath' ) . '/index' .
1272 $this->getVar( 'wgScriptExtension' ),
1274 )->plain(), 'tick-32.png'
1277 $this->addHTML( $this->parent
->getInfoBox(
1278 wfMessage( 'config-extension-link' )->text() ) );
1280 $this->parent
->restoreLinkPopups();
1281 $this->endForm( false, false );
1285 class WebInstaller_Restart
extends WebInstallerPage
{
1287 public function execute() {
1288 $r = $this->parent
->request
;
1289 if ( $r->wasPosted() ) {
1290 $really = $r->getVal( 'submit-restart' );
1292 $this->parent
->reset();
1298 $s = $this->parent
->getWarningBox( wfMessage( 'config-help-restart' )->plain() );
1299 $this->addHTML( $s );
1300 $this->endForm( 'restart' );
1305 abstract class WebInstaller_Document
extends WebInstallerPage
{
1307 abstract protected function getFileName();
1309 public function execute() {
1310 $text = $this->getFileContents();
1311 $text = InstallDocFormatter
::format( $text );
1312 $this->parent
->output
->addWikiText( $text );
1314 $this->endForm( false );
1317 public function getFileContents() {
1318 $file = __DIR__
. '/../../' . $this->getFileName();
1319 if ( ! file_exists( $file ) ) {
1320 return wfMessage( 'config-nofile', $file )->plain();
1322 return file_get_contents( $file );
1327 class WebInstaller_Readme
extends WebInstaller_Document
{
1328 protected function getFileName() {
1333 class WebInstaller_ReleaseNotes
extends WebInstaller_Document
{
1334 protected function getFileName() {
1337 if ( !preg_match( '/^(\d+)\.(\d+).*/i', $wgVersion, $result ) ) {
1338 throw new MWException( 'Variable $wgVersion has an invalid value.' );
1341 return 'RELEASE-NOTES-' . $result[1] . '.' . $result[2];
1345 class WebInstaller_UpgradeDoc
extends WebInstaller_Document
{
1346 protected function getFileName() {
1351 class WebInstaller_Copying
extends WebInstaller_Document
{
1352 protected function getFileName() {