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 foreach ( $this->parent
->getVar( '_CompiledDBs' ) as $type ) {
471 $installer = $this->parent
->getDBInstaller( $type );
475 $installer->getReadableName(),
479 $type == $defaultType,
480 array( 'class' => 'dbRadio', 'rel' => "DB_wrapper_$type" )
484 // Give grep a chance to find the usages:
485 // config-header-mysql, config-header-postgres, config-header-oracle, config-header-sqlite
487 Html
::openElement( 'div', array( 'id' => 'DB_wrapper_' . $type,
488 'class' => 'dbWrapper' ) ) .
489 Html
::element( 'h3', array(), wfMessage( 'config-header-' . $type )->text() ) .
490 $installer->getConnectForm() .
493 $types .= "</ul><br style=\"clear: left\"/>\n";
496 $this->parent
->label( 'config-db-type', false, $types ) .
503 public function submit() {
504 $r = $this->parent
->request
;
505 $type = $r->getVal( 'DBType' );
506 $this->setVar( 'wgDBtype', $type );
507 $installer = $this->parent
->getDBInstaller( $type );
509 return Status
::newFatal( 'config-invalid-db-type' );
511 return $installer->submitConnectForm();
516 class WebInstaller_Upgrade
extends WebInstallerPage
{
517 public function isSlow() {
521 public function execute() {
522 if ( $this->getVar( '_UpgradeDone' ) ) {
523 // Allow regeneration of LocalSettings.php, unless we are working
524 // from a pre-existing LocalSettings.php file and we want to avoid
525 // leaking its contents
526 if ( $this->parent
->request
->wasPosted() && !$this->getVar( '_ExistingDBSettings' ) ) {
527 // Done message acknowledged
531 // Show the done message again
532 // Make them click back again if they want to do the upgrade again
533 $this->showDoneMessage();
538 // wgDBtype is generally valid here because otherwise the previous page
539 // (connect) wouldn't have declared its happiness
540 $type = $this->getVar( 'wgDBtype' );
541 $installer = $this->parent
->getDBInstaller( $type );
543 if ( !$installer->needsUpgrade() ) {
547 if ( $this->parent
->request
->wasPosted() ) {
548 $installer->preUpgrade();
550 $this->startLiveBox();
551 $result = $installer->doUpgrade();
555 // If they're going to possibly regenerate LocalSettings, we
556 // need to create the upgrade/secret keys. Bug 26481
557 if ( !$this->getVar( '_ExistingDBSettings' ) ) {
558 $this->parent
->generateKeys();
560 $this->setVar( '_UpgradeDone', true );
561 $this->showDoneMessage();
567 $this->addHTML( $this->parent
->getInfoBox(
568 wfMessage( 'config-can-upgrade', $GLOBALS['wgVersion'] )->plain() ) );
572 public function showDoneMessage() {
574 $regenerate = !$this->getVar( '_ExistingDBSettings' );
576 $msg = 'config-upgrade-done';
578 $msg = 'config-upgrade-done-no-regenerate';
580 $this->parent
->disableLinkPopups();
582 $this->parent
->getInfoBox(
584 $this->getVar( 'wgServer' ) .
585 $this->getVar( 'wgScriptPath' ) . '/index' .
586 $this->getVar( 'wgScriptExtension' )
587 )->plain(), 'tick-32.png'
590 $this->parent
->restoreLinkPopups();
591 $this->endForm( $regenerate ?
'regenerate' : false, false );
596 class WebInstaller_DBSettings
extends WebInstallerPage
{
598 public function execute() {
599 $installer = $this->parent
->getDBInstaller( $this->getVar( 'wgDBtype' ) );
601 $r = $this->parent
->request
;
602 if ( $r->wasPosted() ) {
603 $status = $installer->submitSettingsForm();
604 if ( $status === false ) {
606 } elseif ( $status->isGood() ) {
609 $this->parent
->showStatusBox( $status );
613 $form = $installer->getSettingsForm();
614 if ( $form === false ) {
619 $this->addHTML( $form );
625 class WebInstaller_Name
extends WebInstallerPage
{
627 public function execute() {
628 $r = $this->parent
->request
;
629 if ( $r->wasPosted() ) {
630 if ( $this->submit() ) {
637 // Encourage people to not name their site 'MediaWiki' by blanking the
638 // field. I think that was the intent with the original $GLOBALS['wgSitename']
639 // but these two always were the same so had the effect of making the
640 // installer forget $wgSitename when navigating back to this page.
641 if ( $this->getVar( 'wgSitename' ) == 'MediaWiki' ) {
642 $this->setVar( 'wgSitename', '' );
645 // Set wgMetaNamespace to something valid before we show the form.
646 // $wgMetaNamespace defaults to $wgSiteName which is 'MediaWiki'
647 $metaNS = $this->getVar( 'wgMetaNamespace' );
650 wfMessage( 'config-ns-other-default' )->inContentLanguage()->text()
654 $this->parent
->getTextBox( array(
655 'var' => 'wgSitename',
656 'label' => 'config-site-name',
657 'help' => $this->parent
->getHelpBox( 'config-site-name-help' )
659 // getRadioSet() builds a set of labeled radio buttons.
660 // For grep: The following messages are used as the item labels:
661 // config-ns-site-name, config-ns-generic, config-ns-other
662 $this->parent
->getRadioSet( array(
663 'var' => '_NamespaceType',
664 'label' => 'config-project-namespace',
665 'itemLabelPrefix' => 'config-ns-',
666 'values' => array( 'site-name', 'generic', 'other' ),
667 'commonAttribs' => array( 'class' => 'enableForOther',
668 'rel' => 'config_wgMetaNamespace' ),
669 'help' => $this->parent
->getHelpBox( 'config-project-namespace-help' )
671 $this->parent
->getTextBox( array(
672 'var' => 'wgMetaNamespace',
673 'label' => '', //TODO: Needs a label?
674 'attribs' => array( 'readonly' => 'readonly', 'class' => 'enabledByOther' ),
677 $this->getFieldSetStart( 'config-admin-box' ) .
678 $this->parent
->getTextBox( array(
679 'var' => '_AdminName',
680 'label' => 'config-admin-name',
681 'help' => $this->parent
->getHelpBox( 'config-admin-help' )
683 $this->parent
->getPasswordBox( array(
684 'var' => '_AdminPassword',
685 'label' => 'config-admin-password',
687 $this->parent
->getPasswordBox( array(
688 'var' => '_AdminPassword2',
689 'label' => 'config-admin-password-confirm'
691 $this->parent
->getTextBox( array(
692 'var' => '_AdminEmail',
693 'label' => 'config-admin-email',
694 'help' => $this->parent
->getHelpBox( 'config-admin-email-help' )
696 $this->parent
->getCheckBox( array(
697 'var' => '_Subscribe',
698 'label' => 'config-subscribe',
699 'help' => $this->parent
->getHelpBox( 'config-subscribe-help' )
701 $this->getFieldSetEnd() .
702 $this->parent
->getInfoBox( wfMessage( 'config-almost-done' )->text() ) .
703 // getRadioSet() builds a set of labeled radio buttons.
704 // For grep: The following messages are used as the item labels:
705 // config-optional-continue, config-optional-skip
706 $this->parent
->getRadioSet( array(
707 'var' => '_SkipOptional',
708 'itemLabelPrefix' => 'config-optional-',
709 'values' => array( 'continue', 'skip' )
713 // Restore the default value
714 $this->setVar( 'wgMetaNamespace', $metaNS );
720 public function submit() {
722 $this->parent
->setVarsFromRequest( array( 'wgSitename', '_NamespaceType',
723 '_AdminName', '_AdminPassword', '_AdminPassword2', '_AdminEmail',
724 '_Subscribe', '_SkipOptional', 'wgMetaNamespace' ) );
726 // Validate site name
727 if ( strval( $this->getVar( 'wgSitename' ) ) === '' ) {
728 $this->parent
->showError( 'config-site-name-blank' );
733 $nsType = $this->getVar( '_NamespaceType' );
734 if ( $nsType == 'site-name' ) {
735 $name = $this->getVar( 'wgSitename' );
736 // Sanitize for namespace
737 // This algorithm should match the JS one in WebInstallerOutput.php
738 $name = preg_replace( '/[\[\]\{\}|#<>%+? ]/', '_', $name );
739 $name = str_replace( '&', '&', $name );
740 $name = preg_replace( '/__+/', '_', $name );
741 $name = ucfirst( trim( $name, '_' ) );
742 } elseif ( $nsType == 'generic' ) {
743 $name = wfMessage( 'config-ns-generic' )->text();
745 $name = $this->getVar( 'wgMetaNamespace' );
748 // Validate namespace
749 if ( strpos( $name, ':' ) !== false ) {
752 // Title-style validation
753 $title = Title
::newFromText( $name );
755 $good = $nsType == 'site-name';
757 $name = $title->getDBkey();
762 $this->parent
->showError( 'config-ns-invalid', $name );
766 // Make sure it won't conflict with any existing namespaces
768 $nsIndex = $wgContLang->getNsIndex( $name );
769 if ( $nsIndex !== false && $nsIndex !== NS_PROJECT
) {
770 $this->parent
->showError( 'config-ns-conflict', $name );
774 $this->setVar( 'wgMetaNamespace', $name );
776 // Validate username for creation
777 $name = $this->getVar( '_AdminName' );
778 if ( strval( $name ) === '' ) {
779 $this->parent
->showError( 'config-admin-name-blank' );
783 $cname = User
::getCanonicalName( $name, 'creatable' );
784 if ( $cname === false ) {
785 $this->parent
->showError( 'config-admin-name-invalid', $name );
788 $this->setVar( '_AdminName', $cname );
794 $pwd = $this->getVar( '_AdminPassword' );
795 $user = User
::newFromName( $cname );
796 $valid = $user && $user->getPasswordValidity( $pwd );
797 if ( strval( $pwd ) === '' ) {
798 # $user->getPasswordValidity just checks for $wgMinimalPasswordLength.
799 # This message is more specific and helpful.
800 $msg = 'config-admin-password-blank';
801 } elseif ( $pwd !== $this->getVar( '_AdminPassword2' ) ) {
802 $msg = 'config-admin-password-mismatch';
803 } elseif ( $valid !== true ) {
804 # As of writing this will only catch the username being e.g. 'FOO' and
808 if ( $msg !== false ) {
809 call_user_func_array( array( $this->parent
, 'showError' ), (array)$msg );
810 $this->setVar( '_AdminPassword', '' );
811 $this->setVar( '_AdminPassword2', '' );
815 // Validate e-mail if provided
816 $email = $this->getVar( '_AdminEmail' );
817 if ( $email && !Sanitizer
::validateEmail( $email ) ) {
818 $this->parent
->showError( 'config-admin-error-bademail' );
821 // If they asked to subscribe to mediawiki-announce but didn't give
822 // an e-mail, show an error. Bug 29332
823 if ( !$email && $this->getVar( '_Subscribe' ) ) {
824 $this->parent
->showError( 'config-subscribe-noemail' );
833 class WebInstaller_Options
extends WebInstallerPage
{
835 public function execute() {
836 if ( $this->getVar( '_SkipOptional' ) == 'skip' ) {
839 if ( $this->parent
->request
->wasPosted() ) {
840 if ( $this->submit() ) {
845 $emailwrapperStyle = $this->getVar( 'wgEnableEmail' ) ?
'' : 'display: none';
849 // getRadioSet() builds a set of labeled radio buttons.
850 // For grep: The following messages are used as the item labels:
851 // config-profile-wiki, config-profile-no-anon, config-profile-fishbowl, config-profile-private
852 $this->parent
->getRadioSet( array(
853 'var' => '_RightsProfile',
854 'label' => 'config-profile',
855 'itemLabelPrefix' => 'config-profile-',
856 'values' => array_keys( $this->parent
->rightsProfiles
),
858 $this->parent
->getInfoBox( wfMessage( 'config-profile-help' )->plain() ) .
861 // getRadioSet() builds a set of labeled radio buttons.
862 // For grep: The following messages are used as the item labels:
863 // config-license-cc-by, config-license-cc-by-sa, config-license-cc-by-nc-sa,
864 // config-license-cc-0, config-license-pd, config-license-gfdl,
865 // config-license-none, config-license-cc-choose
866 $this->parent
->getRadioSet( array(
867 'var' => '_LicenseCode',
868 'label' => 'config-license',
869 'itemLabelPrefix' => 'config-license-',
870 'values' => array_keys( $this->parent
->licenses
),
871 'commonAttribs' => array( 'class' => 'licenseRadio' ),
873 $this->getCCChooser() .
874 $this->parent
->getHelpBox( 'config-license-help' ) .
877 $this->getFieldSetStart( 'config-email-settings' ) .
878 $this->parent
->getCheckBox( array(
879 'var' => 'wgEnableEmail',
880 'label' => 'config-enable-email',
881 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'emailwrapper' ),
883 $this->parent
->getHelpBox( 'config-enable-email-help' ) .
884 "<div id=\"emailwrapper\" style=\"$emailwrapperStyle\">" .
885 $this->parent
->getTextBox( array(
886 'var' => 'wgPasswordSender',
887 'label' => 'config-email-sender'
889 $this->parent
->getHelpBox( 'config-email-sender-help' ) .
890 $this->parent
->getCheckBox( array(
891 'var' => 'wgEnableUserEmail',
892 'label' => 'config-email-user',
894 $this->parent
->getHelpBox( 'config-email-user-help' ) .
895 $this->parent
->getCheckBox( array(
896 'var' => 'wgEnotifUserTalk',
897 'label' => 'config-email-usertalk',
899 $this->parent
->getHelpBox( 'config-email-usertalk-help' ) .
900 $this->parent
->getCheckBox( array(
901 'var' => 'wgEnotifWatchlist',
902 'label' => 'config-email-watchlist',
904 $this->parent
->getHelpBox( 'config-email-watchlist-help' ) .
905 $this->parent
->getCheckBox( array(
906 'var' => 'wgEmailAuthentication',
907 'label' => 'config-email-auth',
909 $this->parent
->getHelpBox( 'config-email-auth-help' ) .
911 $this->getFieldSetEnd()
914 $extensions = $this->parent
->findExtensions();
917 $extHtml = $this->getFieldSetStart( 'config-extensions' );
919 foreach ( $extensions as $ext ) {
920 $extHtml .= $this->parent
->getCheckBox( array(
926 $extHtml .= $this->parent
->getHelpBox( 'config-extensions-help' ) .
927 $this->getFieldSetEnd();
928 $this->addHTML( $extHtml );
931 // Having / in paths in Windows looks funny :)
932 $this->setVar( 'wgDeletedDirectory',
934 '/', DIRECTORY_SEPARATOR
,
935 $this->getVar( 'wgDeletedDirectory' )
938 // If we're using the default, let the user set it relative to $wgScriptPath
939 $curLogo = $this->getVar( 'wgLogo' );
940 $logoString = ( $curLogo == "/wiki/skins/common/images/wiki.png" ) ?
941 '$wgStylePath/common/images/wiki.png' : $curLogo;
943 $uploadwrapperStyle = $this->getVar( 'wgEnableUploads' ) ?
'' : 'display: none';
946 $this->getFieldSetStart( 'config-upload-settings' ) .
947 $this->parent
->getCheckBox( array(
948 'var' => 'wgEnableUploads',
949 'label' => 'config-upload-enable',
950 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'uploadwrapper' ),
951 'help' => $this->parent
->getHelpBox( 'config-upload-help' )
953 '<div id="uploadwrapper" style="' . $uploadwrapperStyle . '">' .
954 $this->parent
->getTextBox( array(
955 'var' => 'wgDeletedDirectory',
956 'label' => 'config-upload-deleted',
957 'attribs' => array( 'dir' => 'ltr' ),
958 'help' => $this->parent
->getHelpBox( 'config-upload-deleted-help' )
961 $this->parent
->getTextBox( array(
963 'value' => $logoString,
964 'label' => 'config-logo',
965 'attribs' => array( 'dir' => 'ltr' ),
966 'help' => $this->parent
->getHelpBox( 'config-logo-help' )
970 $this->parent
->getCheckBox( array(
971 'var' => 'wgUseInstantCommons',
972 'label' => 'config-instantcommons',
973 'help' => $this->parent
->getHelpBox( 'config-instantcommons-help' )
975 $this->getFieldSetEnd()
978 $caches = array( 'none' );
979 if ( count( $this->getVar( '_Caches' ) ) ) {
982 $caches[] = 'memcached';
984 // We'll hide/show this on demand when the value changes, see config.js.
985 $cacheval = $this->getVar( 'wgMainCacheType' );
987 // We need to set a default here; but don't hardcode it
988 // or we lose it every time we reload the page for validation
992 $hidden = ( $cacheval == 'memcached' ) ?
'' : 'display: none';
995 $this->getFieldSetStart( 'config-advanced-settings' ) .
996 # Object cache settings
997 // getRadioSet() builds a set of labeled radio buttons.
998 // For grep: The following messages are used as the item labels:
999 // config-cache-none, config-cache-accel, config-cache-memcached
1000 $this->parent
->getRadioSet( array(
1001 'var' => 'wgMainCacheType',
1002 'label' => 'config-cache-options',
1003 'itemLabelPrefix' => 'config-cache-',
1004 'values' => $caches,
1005 'value' => $cacheval,
1007 $this->parent
->getHelpBox( 'config-cache-help' ) .
1008 "<div id=\"config-memcachewrapper\" style=\"$hidden\">" .
1009 $this->parent
->getTextArea( array(
1010 'var' => '_MemCachedServers',
1011 'label' => 'config-memcached-servers',
1012 'help' => $this->parent
->getHelpBox( 'config-memcached-help' )
1015 $this->getFieldSetEnd()
1023 public function getCCPartnerUrl() {
1024 $server = $this->getVar( 'wgServer' );
1025 $exitUrl = $server . $this->parent
->getUrl( array(
1026 'page' => 'Options',
1027 'SubmitCC' => 'indeed',
1028 'config__LicenseCode' => 'cc',
1029 'config_wgRightsUrl' => '[license_url]',
1030 'config_wgRightsText' => '[license_name]',
1031 'config_wgRightsIcon' => '[license_button]',
1033 $styleUrl = $server . dirname( dirname( $this->parent
->getUrl() ) ) .
1034 '/skins/common/config-cc.css';
1035 $iframeUrl = 'http://creativecommons.org/license/?' .
1036 wfArrayToCgi( array(
1037 'partner' => 'MediaWiki',
1038 'exit_url' => $exitUrl,
1039 'lang' => $this->getVar( '_UserLang' ),
1040 'stylesheet' => $styleUrl,
1045 public function getCCChooser() {
1046 $iframeAttribs = array(
1047 'class' => 'config-cc-iframe',
1048 'name' => 'config-cc-iframe',
1049 'id' => 'config-cc-iframe',
1054 if ( $this->getVar( '_CCDone' ) ) {
1055 $iframeAttribs['src'] = $this->parent
->getUrl( array( 'ShowCC' => 'yes' ) );
1057 $iframeAttribs['src'] = $this->getCCPartnerUrl();
1059 $wrapperStyle = ( $this->getVar( '_LicenseCode' ) == 'cc-choose' ) ?
'' : 'display: none';
1061 return "<div class=\"config-cc-wrapper\" id=\"config-cc-wrapper\" style=\"$wrapperStyle\">\n" .
1062 Html
::element( 'iframe', $iframeAttribs, '', false /* not short */ ) .
1066 public function getCCDoneBox() {
1067 $js = "parent.document.getElementById('config-cc-wrapper').style.height = '$1';";
1068 // If you change this height, also change it in config.css
1069 $expandJs = str_replace( '$1', '54em', $js );
1070 $reduceJs = str_replace( '$1', '70px', $js );
1072 Html
::element( 'img', array( 'src' => $this->getVar( 'wgRightsIcon' ) ) ) .
1074 htmlspecialchars( $this->getVar( 'wgRightsText' ) ) .
1076 "<p style=\"text-align: center\">" .
1079 'href' => $this->getCCPartnerUrl(),
1080 'onclick' => $expandJs,
1082 wfMessage( 'config-cc-again' )->text()
1085 "<script type=\"text/javascript\">\n" .
1086 # Reduce the wrapper div height
1087 htmlspecialchars( $reduceJs ) .
1092 public function submitCC() {
1093 $newValues = $this->parent
->setVarsFromRequest(
1094 array( 'wgRightsUrl', 'wgRightsText', 'wgRightsIcon' ) );
1095 if ( count( $newValues ) != 3 ) {
1096 $this->parent
->showError( 'config-cc-error' );
1099 $this->setVar( '_CCDone', true );
1100 $this->addHTML( $this->getCCDoneBox() );
1103 public function submit() {
1104 $this->parent
->setVarsFromRequest( array( '_RightsProfile', '_LicenseCode',
1105 'wgEnableEmail', 'wgPasswordSender', 'wgEnableUploads', 'wgLogo',
1106 'wgEnableUserEmail', 'wgEnotifUserTalk', 'wgEnotifWatchlist',
1107 'wgEmailAuthentication', 'wgMainCacheType', '_MemCachedServers',
1108 'wgUseInstantCommons' ) );
1110 if ( !in_array( $this->getVar( '_RightsProfile' ),
1111 array_keys( $this->parent
->rightsProfiles
) ) )
1113 reset( $this->parent
->rightsProfiles
);
1114 $this->setVar( '_RightsProfile', key( $this->parent
->rightsProfiles
) );
1117 $code = $this->getVar( '_LicenseCode' );
1118 if ( $code == 'cc-choose' ) {
1119 if ( !$this->getVar( '_CCDone' ) ) {
1120 $this->parent
->showError( 'config-cc-not-chosen' );
1123 } elseif ( in_array( $code, array_keys( $this->parent
->licenses
) ) ) {
1124 // Give grep a chance to find the usages:
1125 // config-license-cc-by, config-license-cc-by-sa, config-license-cc-by-nc-sa,
1126 // config-license-cc-0, config-license-pd, config-license-gfdl,
1127 // config-license-none, config-license-cc-choose
1128 $entry = $this->parent
->licenses
[$code];
1129 if ( isset( $entry['text'] ) ) {
1130 $this->setVar( 'wgRightsText', $entry['text'] );
1132 $this->setVar( 'wgRightsText', wfMessage( 'config-license-' . $code )->text() );
1134 $this->setVar( 'wgRightsUrl', $entry['url'] );
1135 $this->setVar( 'wgRightsIcon', $entry['icon'] );
1137 $this->setVar( 'wgRightsText', '' );
1138 $this->setVar( 'wgRightsUrl', '' );
1139 $this->setVar( 'wgRightsIcon', '' );
1142 $extsAvailable = $this->parent
->findExtensions();
1143 $extsToInstall = array();
1144 foreach ( $extsAvailable as $ext ) {
1145 if ( $this->parent
->request
->getCheck( 'config_ext-' . $ext ) ) {
1146 $extsToInstall[] = $ext;
1149 $this->parent
->setVar( '_Extensions', $extsToInstall );
1151 if ( $this->getVar( 'wgMainCacheType' ) == 'memcached' ) {
1152 $memcServers = explode( "\n", $this->getVar( '_MemCachedServers' ) );
1153 if ( !$memcServers ) {
1154 $this->parent
->showError( 'config-memcache-needservers' );
1158 foreach ( $memcServers as $server ) {
1159 $memcParts = explode( ":", $server, 2 );
1160 if ( !isset( $memcParts[0] )
1161 ||
( !IP
::isValid( $memcParts[0] )
1162 && ( gethostbyname( $memcParts[0] ) == $memcParts[0] ) ) ) {
1163 $this->parent
->showError( 'config-memcache-badip', $memcParts[0] );
1165 } elseif ( !isset( $memcParts[1] ) ) {
1166 $this->parent
->showError( 'config-memcache-noport', $memcParts[0] );
1168 } elseif ( $memcParts[1] < 1 ||
$memcParts[1] > 65535 ) {
1169 $this->parent
->showError( 'config-memcache-badport', 1, 65535 );
1179 class WebInstaller_Install
extends WebInstallerPage
{
1180 public function isSlow() {
1184 public function execute() {
1185 if ( $this->getVar( '_UpgradeDone' ) ) {
1187 } elseif ( $this->getVar( '_InstallDone' ) ) {
1189 } elseif ( $this->parent
->request
->wasPosted() ) {
1191 $this->addHTML( "<ul>" );
1192 $results = $this->parent
->performInstallation(
1193 array( $this, 'startStage' ),
1194 array( $this, 'endStage' )
1196 $this->addHTML( "</ul>" );
1197 // PerformInstallation bails on a fatal, so make sure the last item
1198 // completed before giving 'next.' Likewise, only provide back on failure
1199 $lastStep = end( $results );
1200 $continue = $lastStep->isOK() ?
'continue' : false;
1201 $back = $lastStep->isOK() ?
false : 'back';
1202 $this->endForm( $continue, $back );
1205 $this->addHTML( $this->parent
->getInfoBox( wfMessage( 'config-install-begin' )->plain() ) );
1211 public function startStage( $step ) {
1212 $this->addHTML( "<li>" . wfMessage( "config-install-$step" )->escaped() . wfMessage( 'ellipsis' )->escaped() );
1213 if ( $step == 'extension-tables' ) {
1214 $this->startLiveBox();
1220 * @param $status Status
1222 public function endStage( $step, $status ) {
1223 if ( $step == 'extension-tables' ) {
1224 $this->endLiveBox();
1226 $msg = $status->isOk() ?
'config-install-step-done' : 'config-install-step-failed';
1227 $html = wfMessage( 'word-separator' )->escaped() . wfMessage( $msg )->escaped();
1228 if ( !$status->isOk() ) {
1229 $html = "<span class=\"error\">$html</span>";
1231 $this->addHTML( $html . "</li>\n" );
1232 if ( !$status->isGood() ) {
1233 $this->parent
->showStatusBox( $status );
1239 class WebInstaller_Complete
extends WebInstallerPage
{
1241 public function execute() {
1242 // Pop up a dialog box, to make it difficult for the user to forget
1243 // to download the file
1244 $lsUrl = $this->getVar( 'wgServer' ) . $this->parent
->getURL( array( 'localsettings' => 1 ) );
1245 if ( isset( $_SERVER['HTTP_USER_AGENT'] ) &&
1246 strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE' ) !== false ) {
1247 // JS appears the only method that works consistently with IE7+
1248 $this->addHtml( "\n<script type=\"" . $GLOBALS['wgJsMimeType'] .
1249 '">jQuery( document ).ready( function() { document.location=' .
1250 Xml
::encodeJsVar( $lsUrl ) . "; } );</script>\n" );
1252 $this->parent
->request
->response()->header( "Refresh: 0;url=$lsUrl" );
1256 $this->parent
->disableLinkPopups();
1258 $this->parent
->getInfoBox(
1259 wfMessage( 'config-install-done',
1261 $this->getVar( 'wgServer' ) .
1262 $this->getVar( 'wgScriptPath' ) . '/index' .
1263 $this->getVar( 'wgScriptExtension' ),
1265 )->plain(), 'tick-32.png'
1268 $this->parent
->restoreLinkPopups();
1269 $this->endForm( false, false );
1273 class WebInstaller_Restart
extends WebInstallerPage
{
1275 public function execute() {
1276 $r = $this->parent
->request
;
1277 if ( $r->wasPosted() ) {
1278 $really = $r->getVal( 'submit-restart' );
1280 $this->parent
->reset();
1286 $s = $this->parent
->getWarningBox( wfMessage( 'config-help-restart' )->plain() );
1287 $this->addHTML( $s );
1288 $this->endForm( 'restart' );
1293 abstract class WebInstaller_Document
extends WebInstallerPage
{
1295 abstract protected function getFileName();
1297 public function execute() {
1298 $text = $this->getFileContents();
1299 $text = InstallDocFormatter
::format( $text );
1300 $this->parent
->output
->addWikiText( $text );
1302 $this->endForm( false );
1305 public function getFileContents() {
1306 $file = __DIR__
. '/../../' . $this->getFileName();
1307 if ( ! file_exists( $file ) ) {
1308 return wfMessage( 'config-nofile', $file )->plain();
1310 return file_get_contents( $file );
1315 class WebInstaller_Readme
extends WebInstaller_Document
{
1316 protected function getFileName() {
1321 class WebInstaller_ReleaseNotes
extends WebInstaller_Document
{
1322 protected function getFileName() {
1325 if ( !preg_match( '/^(\d+)\.(\d+).*/i', $wgVersion, $result ) ) {
1326 throw new MWException( 'Variable $wgVersion has an invalid value.' );
1329 return 'RELEASE-NOTES-' . $result[1] . '.' . $result[2];
1333 class WebInstaller_UpgradeDoc
extends WebInstaller_Document
{
1334 protected function getFileName() {
1339 class WebInstaller_Copying
extends WebInstaller_Document
{
1340 protected function getFileName() {