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 public abstract 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 $s .= Xml
::submitButton( wfMessage( "config-$continue" )->text(),
88 array( 'name' => "enter-$continue", 'style' =>
89 'visibility:hidden;overflow:hidden;width:1px;margin:0' ) ) . "\n";
93 $s .= Xml
::submitButton( wfMessage( "config-$back" )->text(),
95 'name' => "submit-$back",
96 'tabindex' => $this->parent
->nextTabIndex()
101 $s .= Xml
::submitButton( wfMessage( "config-$continue" )->text(),
103 'name' => "submit-$continue",
104 'tabindex' => $this->parent
->nextTabIndex(),
108 $s .= "</div></form></div>\n";
109 $this->addHTML( $s );
112 public function getName() {
113 return str_replace( 'WebInstaller_', '', get_class( $this ) );
116 protected function getId() {
117 return array_search( $this->getName(), $this->parent
->pageSequence
);
120 public function getVar( $var ) {
121 return $this->parent
->getVar( $var );
124 public function setVar( $name, $value ) {
125 $this->parent
->setVar( $name, $value );
129 * Get the starting tags of a fieldset.
131 * @param $legend String: message name
135 protected function getFieldsetStart( $legend ) {
136 return "\n<fieldset><legend>" . wfMessage( $legend )->escaped() . "</legend>\n";
140 * Get the end tag of a fieldset.
144 protected function getFieldsetEnd() {
145 return "</fieldset>\n";
149 * Opens a textarea used to display the progress of a long operation
151 protected function startLiveBox() {
153 '<div id="config-spinner" style="display:none;">' .
154 '<img src="../skins/common/images/ajax-loader.gif" /></div>' .
155 '<script>jQuery( "#config-spinner" ).show();</script>' .
156 '<div id="config-live-log">' .
157 '<textarea name="LiveLog" rows="10" cols="30" readonly="readonly">'
159 $this->parent
->output
->flush();
163 * Opposite to startLiveBox()
165 protected function endLiveBox() {
166 $this->addHTML( '</textarea></div>
167 <script>jQuery( "#config-spinner" ).hide()</script>' );
168 $this->parent
->output
->flush();
172 class WebInstaller_Language
extends WebInstallerPage
{
174 public function execute() {
176 $r = $this->parent
->request
;
177 $userLang = $r->getVal( 'uselang' );
178 $contLang = $r->getVal( 'ContLang' );
180 $languages = Language
::fetchLanguageNames();
181 $lifetime = intval( ini_get( 'session.gc_maxlifetime' ) );
183 $lifetime = 1440; // PHP default
186 if ( $r->wasPosted() ) {
188 if ( $this->parent
->getSession( 'test' ) === null ) {
189 $requestTime = $r->getVal( 'LanguageRequestTime' );
190 if ( !$requestTime ) {
191 // The most likely explanation is that the user was knocked back
192 // from another page on POST due to session expiry
193 $msg = 'config-session-expired';
194 } elseif ( time() - $requestTime > $lifetime ) {
195 $msg = 'config-session-expired';
197 $msg = 'config-no-session';
199 $this->parent
->showError( $msg, $wgLang->formatTimePeriod( $lifetime ) );
201 if ( isset( $languages[$userLang] ) ) {
202 $this->setVar( '_UserLang', $userLang );
204 if ( isset( $languages[$contLang] ) ) {
205 $this->setVar( 'wgLanguageCode', $contLang );
209 } elseif ( $this->parent
->showSessionWarning
) {
210 # The user was knocked back from another page to the start
211 # This probably indicates a session expiry
212 $this->parent
->showError( 'config-session-expired',
213 $wgLang->formatTimePeriod( $lifetime ) );
216 $this->parent
->setSession( 'test', true );
218 if ( !isset( $languages[$userLang] ) ) {
219 $userLang = $this->getVar( '_UserLang', 'en' );
221 if ( !isset( $languages[$contLang] ) ) {
222 $contLang = $this->getVar( 'wgLanguageCode', 'en' );
225 $s = Html
::hidden( 'LanguageRequestTime', time() ) .
226 $this->getLanguageSelector( 'uselang', 'config-your-language', $userLang,
227 $this->parent
->getHelpBox( 'config-your-language-help' ) ) .
228 $this->getLanguageSelector( 'ContLang', 'config-wiki-language', $contLang,
229 $this->parent
->getHelpBox( 'config-wiki-language-help' ) );
230 $this->addHTML( $s );
231 $this->endForm( 'continue', false );
235 * Get a "<select>" for selecting languages.
239 * @param $selectedCode
240 * @param $helpHtml string
243 public function getLanguageSelector( $name, $label, $selectedCode, $helpHtml = '' ) {
244 global $wgDummyLanguageCodes;
248 $s .= Html
::openElement( 'select', array( 'id' => $name, 'name' => $name,
249 'tabindex' => $this->parent
->nextTabIndex() ) ) . "\n";
251 $languages = Language
::fetchLanguageNames();
253 foreach ( $languages as $code => $lang ) {
254 if ( isset( $wgDummyLanguageCodes[$code] ) ) continue;
255 $s .= "\n" . Xml
::option( "$code - $lang", $code, $code == $selectedCode );
257 $s .= "\n</select>\n";
258 return $this->parent
->label( $label, $name, $s );
263 class WebInstaller_ExistingWiki
extends WebInstallerPage
{
264 public function execute() {
265 // If there is no LocalSettings.php, continue to the installer welcome page
266 $vars = Installer
::getExistingLocalSettings();
271 // Check if the upgrade key supplied to the user has appeared in LocalSettings.php
272 if ( $vars['wgUpgradeKey'] !== false
273 && $this->getVar( '_UpgradeKeySupplied' )
274 && $this->getVar( 'wgUpgradeKey' ) === $vars['wgUpgradeKey'] )
276 // It's there, so the user is authorized
277 $status = $this->handleExistingUpgrade( $vars );
278 if ( $status->isOK() ) {
282 $this->parent
->showStatusBox( $status );
283 $this->endForm( 'continue' );
288 // If there is no $wgUpgradeKey, tell the user to add one to LocalSettings.php
289 if ( $vars['wgUpgradeKey'] === false ) {
290 if ( $this->getVar( 'wgUpgradeKey', false ) === false ) {
291 $secretKey = $this->getVar( 'wgSecretKey' ); // preserve $wgSecretKey
292 $this->parent
->generateKeys();
293 $this->setVar( 'wgSecretKey', $secretKey );
294 $this->setVar( '_UpgradeKeySupplied', true );
297 $this->addHTML( $this->parent
->getInfoBox(
298 wfMessage( 'config-upgrade-key-missing', "<pre dir=\"ltr\">\$wgUpgradeKey = '" .
299 $this->getVar( 'wgUpgradeKey' ) . "';</pre>" )->plain()
301 $this->endForm( 'continue' );
305 // If there is an upgrade key, but it wasn't supplied, prompt the user to enter it
307 $r = $this->parent
->request
;
308 if ( $r->wasPosted() ) {
309 $key = $r->getText( 'config_wgUpgradeKey' );
310 if( !$key ||
$key !== $vars['wgUpgradeKey'] ) {
311 $this->parent
->showError( 'config-localsettings-badkey' );
312 $this->showKeyForm();
316 $status = $this->handleExistingUpgrade( $vars );
317 if ( $status->isOK() ) {
320 $this->parent
->showStatusBox( $status );
321 $this->showKeyForm();
325 $this->showKeyForm();
331 * Show the "enter key" form
333 protected function showKeyForm() {
336 $this->parent
->getInfoBox( wfMessage( 'config-localsettings-upgrade' )->plain() ).
338 $this->parent
->getTextBox( array(
339 'var' => 'wgUpgradeKey',
340 'label' => 'config-localsettings-key',
341 'attribs' => array( 'autocomplete' => 'off' ),
344 $this->endForm( 'continue' );
347 protected function importVariables( $names, $vars ) {
348 $status = Status
::newGood();
349 foreach ( $names as $name ) {
350 if ( !isset( $vars[$name] ) ) {
351 $status->fatal( 'config-localsettings-incomplete', $name );
353 $this->setVar( $name, $vars[$name] );
359 * Initiate an upgrade of the existing database
360 * @param $vars array Variables from LocalSettings.php and AdminSettings.php
363 protected function handleExistingUpgrade( $vars ) {
365 if ( !isset( $vars['wgDBtype'] ) ||
366 !in_array( $vars['wgDBtype'], Installer
::getDBTypes() ) ) {
367 return Status
::newFatal( 'config-localsettings-connection-error', '' );
370 // Set the relevant variables from LocalSettings.php
371 $requiredVars = array( 'wgDBtype' );
372 $status = $this->importVariables( $requiredVars , $vars );
373 $installer = $this->parent
->getDBInstaller();
374 $status->merge( $this->importVariables( $installer->getGlobalNames(), $vars ) );
375 if ( !$status->isOK() ) {
379 if ( isset( $vars['wgDBadminuser'] ) ) {
380 $this->setVar( '_InstallUser', $vars['wgDBadminuser'] );
382 $this->setVar( '_InstallUser', $vars['wgDBuser'] );
384 if ( isset( $vars['wgDBadminpassword'] ) ) {
385 $this->setVar( '_InstallPassword', $vars['wgDBadminpassword'] );
387 $this->setVar( '_InstallPassword', $vars['wgDBpassword'] );
390 // Test the database connection
391 $status = $installer->getConnection();
392 if ( !$status->isOK() ) {
393 // Adjust the error message to explain things correctly
394 $status->replaceMessage( 'config-connection-error',
395 'config-localsettings-connection-error' );
400 $this->setVar( '_ExistingDBSettings', true );
405 class WebInstaller_Welcome
extends WebInstallerPage
{
407 public function execute() {
408 if ( $this->parent
->request
->wasPosted() ) {
409 if ( $this->getVar( '_Environment' ) ) {
413 $this->parent
->output
->addWikiText( wfMessage( 'config-welcome' )->plain() );
414 $status = $this->parent
->doEnvironmentChecks();
415 if ( $status->isGood() ) {
416 $this->parent
->output
->addHTML( '<span class="success-message">' .
417 wfMessage( 'config-env-good' )->escaped() . '</span>' );
418 $this->parent
->output
->addWikiText( wfMessage( 'config-copyright',
419 SpecialVersion
::getCopyrightAndAuthorList() )->plain() );
423 $this->parent
->showStatusMessage( $status );
429 class WebInstaller_DBConnect
extends WebInstallerPage
{
431 public function execute() {
432 if ( $this->getVar( '_ExistingDBSettings' ) ) {
436 $r = $this->parent
->request
;
437 if ( $r->wasPosted() ) {
438 $status = $this->submit();
440 if ( $status->isGood() ) {
441 $this->setVar( '_UpgradeDone', false );
444 $this->parent
->showStatusBox( $status );
450 $types = "<ul class=\"config-settings-block\">\n";
452 $defaultType = $this->getVar( 'wgDBtype' );
455 foreach( $this->parent
->getDBTypes() as $type ) {
456 $link = DatabaseBase
::factory( $type )->getSoftwareLink();
457 $dbSupport .= wfMessage( "config-support-$type", $link )->plain() . "\n";
459 $this->addHTML( $this->parent
->getInfoBox(
460 wfMessage( 'config-support-info', trim( $dbSupport ) )->text() ) );
462 foreach ( $this->parent
->getVar( '_CompiledDBs' ) as $type ) {
463 $installer = $this->parent
->getDBInstaller( $type );
467 $installer->getReadableName(),
471 $type == $defaultType,
472 array( 'class' => 'dbRadio', 'rel' => "DB_wrapper_$type" )
477 Html
::openElement( 'div', array( 'id' => 'DB_wrapper_' . $type,
478 'class' => 'dbWrapper' ) ) .
479 Html
::element( 'h3', array(), wfMessage( 'config-header-' . $type )->text() ) .
480 $installer->getConnectForm() .
483 $types .= "</ul><br style=\"clear: left\"/>\n";
486 $this->parent
->label( 'config-db-type', false, $types ) .
493 public function submit() {
494 $r = $this->parent
->request
;
495 $type = $r->getVal( 'DBType' );
496 $this->setVar( 'wgDBtype', $type );
497 $installer = $this->parent
->getDBInstaller( $type );
499 return Status
::newFatal( 'config-invalid-db-type' );
501 return $installer->submitConnectForm();
506 class WebInstaller_Upgrade
extends WebInstallerPage
{
507 public function isSlow() {
511 public function execute() {
512 if ( $this->getVar( '_UpgradeDone' ) ) {
513 // Allow regeneration of LocalSettings.php, unless we are working
514 // from a pre-existing LocalSettings.php file and we want to avoid
515 // leaking its contents
516 if ( $this->parent
->request
->wasPosted() && !$this->getVar( '_ExistingDBSettings' ) ) {
517 // Done message acknowledged
521 // Show the done message again
522 // Make them click back again if they want to do the upgrade again
523 $this->showDoneMessage();
528 // wgDBtype is generally valid here because otherwise the previous page
529 // (connect) wouldn't have declared its happiness
530 $type = $this->getVar( 'wgDBtype' );
531 $installer = $this->parent
->getDBInstaller( $type );
533 if ( !$installer->needsUpgrade() ) {
537 if ( $this->parent
->request
->wasPosted() ) {
538 $installer->preUpgrade();
540 $this->startLiveBox();
541 $result = $installer->doUpgrade();
545 // If they're going to possibly regenerate LocalSettings, we
546 // need to create the upgrade/secret keys. Bug 26481
547 if( !$this->getVar( '_ExistingDBSettings' ) ) {
548 $this->parent
->generateKeys();
550 $this->setVar( '_UpgradeDone', true );
551 $this->showDoneMessage();
557 $this->addHTML( $this->parent
->getInfoBox(
558 wfMessage( 'config-can-upgrade', $GLOBALS['wgVersion'] )->plain() ) );
562 public function showDoneMessage() {
564 $regenerate = !$this->getVar( '_ExistingDBSettings' );
566 $msg = 'config-upgrade-done';
568 $msg = 'config-upgrade-done-no-regenerate';
570 $this->parent
->disableLinkPopups();
572 $this->parent
->getInfoBox(
574 $this->getVar( 'wgServer' ) .
575 $this->getVar( 'wgScriptPath' ) . '/index' .
576 $this->getVar( 'wgScriptExtension' )
577 )->plain(), 'tick-32.png'
580 $this->parent
->restoreLinkPopups();
581 $this->endForm( $regenerate ?
'regenerate' : false, false );
586 class WebInstaller_DBSettings
extends WebInstallerPage
{
588 public function execute() {
589 $installer = $this->parent
->getDBInstaller( $this->getVar( 'wgDBtype' ) );
591 $r = $this->parent
->request
;
592 if ( $r->wasPosted() ) {
593 $status = $installer->submitSettingsForm();
594 if ( $status === false ) {
596 } elseif ( $status->isGood() ) {
599 $this->parent
->showStatusBox( $status );
603 $form = $installer->getSettingsForm();
604 if ( $form === false ) {
609 $this->addHTML( $form );
615 class WebInstaller_Name
extends WebInstallerPage
{
617 public function execute() {
618 $r = $this->parent
->request
;
619 if ( $r->wasPosted() ) {
620 if ( $this->submit() ) {
627 // Encourage people to not name their site 'MediaWiki' by blanking the
628 // field. I think that was the intent with the original $GLOBALS['wgSitename']
629 // but these two always were the same so had the effect of making the
630 // installer forget $wgSitename when navigating back to this page.
631 if ( $this->getVar( 'wgSitename' ) == 'MediaWiki' ) {
632 $this->setVar( 'wgSitename', '' );
635 // Set wgMetaNamespace to something valid before we show the form.
636 // $wgMetaNamespace defaults to $wgSiteName which is 'MediaWiki'
637 $metaNS = $this->getVar( 'wgMetaNamespace' );
640 wfMessage( 'config-ns-other-default' )->inContentLanguage()->text()
644 $this->parent
->getTextBox( array(
645 'var' => 'wgSitename',
646 'label' => 'config-site-name',
647 'help' => $this->parent
->getHelpBox( 'config-site-name-help' )
649 $this->parent
->getRadioSet( array(
650 'var' => '_NamespaceType',
651 'label' => 'config-project-namespace',
652 'itemLabelPrefix' => 'config-ns-',
653 'values' => array( 'site-name', 'generic', 'other' ),
654 'commonAttribs' => array( 'class' => 'enableForOther',
655 'rel' => 'config_wgMetaNamespace' ),
656 'help' => $this->parent
->getHelpBox( 'config-project-namespace-help' )
658 $this->parent
->getTextBox( array(
659 'var' => 'wgMetaNamespace',
660 'label' => '', //TODO: Needs a label?
661 'attribs' => array( 'readonly' => 'readonly', 'class' => 'enabledByOther' ),
664 $this->getFieldSetStart( 'config-admin-box' ) .
665 $this->parent
->getTextBox( array(
666 'var' => '_AdminName',
667 'label' => 'config-admin-name',
668 'help' => $this->parent
->getHelpBox( 'config-admin-help' )
670 $this->parent
->getPasswordBox( array(
671 'var' => '_AdminPassword',
672 'label' => 'config-admin-password',
674 $this->parent
->getPasswordBox( array(
675 'var' => '_AdminPassword2',
676 'label' => 'config-admin-password-confirm'
678 $this->parent
->getTextBox( array(
679 'var' => '_AdminEmail',
680 'label' => 'config-admin-email',
681 'help' => $this->parent
->getHelpBox( 'config-admin-email-help' )
683 $this->parent
->getCheckBox( array(
684 'var' => '_Subscribe',
685 'label' => 'config-subscribe',
686 'help' => $this->parent
->getHelpBox( 'config-subscribe-help' )
688 $this->getFieldSetEnd() .
689 $this->parent
->getInfoBox( wfMessage( 'config-almost-done' )->text() ) .
690 $this->parent
->getRadioSet( array(
691 'var' => '_SkipOptional',
692 'itemLabelPrefix' => 'config-optional-',
693 'values' => array( 'continue', 'skip' )
697 // Restore the default value
698 $this->setVar( 'wgMetaNamespace', $metaNS );
704 public function submit() {
706 $this->parent
->setVarsFromRequest( array( 'wgSitename', '_NamespaceType',
707 '_AdminName', '_AdminPassword', '_AdminPassword2', '_AdminEmail',
708 '_Subscribe', '_SkipOptional', 'wgMetaNamespace' ) );
710 // Validate site name
711 if ( strval( $this->getVar( 'wgSitename' ) ) === '' ) {
712 $this->parent
->showError( 'config-site-name-blank' );
717 $nsType = $this->getVar( '_NamespaceType' );
718 if ( $nsType == 'site-name' ) {
719 $name = $this->getVar( 'wgSitename' );
720 // Sanitize for namespace
721 // This algorithm should match the JS one in WebInstallerOutput.php
722 $name = preg_replace( '/[\[\]\{\}|#<>%+? ]/', '_', $name );
723 $name = str_replace( '&', '&', $name );
724 $name = preg_replace( '/__+/', '_', $name );
725 $name = ucfirst( trim( $name, '_' ) );
726 } elseif ( $nsType == 'generic' ) {
727 $name = wfMessage( 'config-ns-generic' )->text();
729 $name = $this->getVar( 'wgMetaNamespace' );
732 // Validate namespace
733 if ( strpos( $name, ':' ) !== false ) {
736 // Title-style validation
737 $title = Title
::newFromText( $name );
739 $good = $nsType == 'site-name';
741 $name = $title->getDBkey();
746 $this->parent
->showError( 'config-ns-invalid', $name );
750 // Make sure it won't conflict with any existing namespaces
752 $nsIndex = $wgContLang->getNsIndex( $name );
753 if( $nsIndex !== false && $nsIndex !== NS_PROJECT
) {
754 $this->parent
->showError( 'config-ns-conflict', $name );
758 $this->setVar( 'wgMetaNamespace', $name );
760 // Validate username for creation
761 $name = $this->getVar( '_AdminName' );
762 if ( strval( $name ) === '' ) {
763 $this->parent
->showError( 'config-admin-name-blank' );
767 $cname = User
::getCanonicalName( $name, 'creatable' );
768 if ( $cname === false ) {
769 $this->parent
->showError( 'config-admin-name-invalid', $name );
772 $this->setVar( '_AdminName', $cname );
778 $pwd = $this->getVar( '_AdminPassword' );
779 $user = User
::newFromName( $cname );
780 $valid = $user && $user->getPasswordValidity( $pwd );
781 if ( strval( $pwd ) === '' ) {
782 # $user->getPasswordValidity just checks for $wgMinimalPasswordLength.
783 # This message is more specific and helpful.
784 $msg = 'config-admin-password-blank';
785 } elseif ( $pwd !== $this->getVar( '_AdminPassword2' ) ) {
786 $msg = 'config-admin-password-mismatch';
787 } elseif ( $valid !== true ) {
788 # As of writing this will only catch the username being e.g. 'FOO' and
792 if ( $msg !== false ) {
793 call_user_func_array( array( $this->parent
, 'showError' ), (array)$msg );
794 $this->setVar( '_AdminPassword', '' );
795 $this->setVar( '_AdminPassword2', '' );
799 // Validate e-mail if provided
800 $email = $this->getVar( '_AdminEmail' );
801 if( $email && !Sanitizer
::validateEmail( $email ) ) {
802 $this->parent
->showError( 'config-admin-error-bademail' );
805 // If they asked to subscribe to mediawiki-announce but didn't give
806 // an e-mail, show an error. Bug 29332
807 if( !$email && $this->getVar( '_Subscribe' ) ) {
808 $this->parent
->showError( 'config-subscribe-noemail' );
817 class WebInstaller_Options
extends WebInstallerPage
{
819 public function execute() {
820 if ( $this->getVar( '_SkipOptional' ) == 'skip' ) {
823 if ( $this->parent
->request
->wasPosted() ) {
824 if ( $this->submit() ) {
829 $emailwrapperStyle = $this->getVar( 'wgEnableEmail' ) ?
'' : 'display: none';
833 $this->parent
->getRadioSet( array(
834 'var' => '_RightsProfile',
835 'label' => 'config-profile',
836 'itemLabelPrefix' => 'config-profile-',
837 'values' => array_keys( $this->parent
->rightsProfiles
),
839 $this->parent
->getInfoBox( wfMessage( 'config-profile-help' )->plain() ) .
842 $this->parent
->getRadioSet( array(
843 'var' => '_LicenseCode',
844 'label' => 'config-license',
845 'itemLabelPrefix' => 'config-license-',
846 'values' => array_keys( $this->parent
->licenses
),
847 'commonAttribs' => array( 'class' => 'licenseRadio' ),
849 $this->getCCChooser() .
850 $this->parent
->getHelpBox( 'config-license-help' ) .
853 $this->getFieldSetStart( 'config-email-settings' ) .
854 $this->parent
->getCheckBox( array(
855 'var' => 'wgEnableEmail',
856 'label' => 'config-enable-email',
857 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'emailwrapper' ),
859 $this->parent
->getHelpBox( 'config-enable-email-help' ) .
860 "<div id=\"emailwrapper\" style=\"$emailwrapperStyle\">" .
861 $this->parent
->getTextBox( array(
862 'var' => 'wgPasswordSender',
863 'label' => 'config-email-sender'
865 $this->parent
->getHelpBox( 'config-email-sender-help' ) .
866 $this->parent
->getCheckBox( array(
867 'var' => 'wgEnableUserEmail',
868 'label' => 'config-email-user',
870 $this->parent
->getHelpBox( 'config-email-user-help' ) .
871 $this->parent
->getCheckBox( array(
872 'var' => 'wgEnotifUserTalk',
873 'label' => 'config-email-usertalk',
875 $this->parent
->getHelpBox( 'config-email-usertalk-help' ) .
876 $this->parent
->getCheckBox( array(
877 'var' => 'wgEnotifWatchlist',
878 'label' => 'config-email-watchlist',
880 $this->parent
->getHelpBox( 'config-email-watchlist-help' ) .
881 $this->parent
->getCheckBox( array(
882 'var' => 'wgEmailAuthentication',
883 'label' => 'config-email-auth',
885 $this->parent
->getHelpBox( 'config-email-auth-help' ) .
887 $this->getFieldSetEnd()
890 $extensions = $this->parent
->findExtensions();
893 $extHtml = $this->getFieldSetStart( 'config-extensions' );
895 foreach( $extensions as $ext ) {
896 $extHtml .= $this->parent
->getCheckBox( array(
902 $extHtml .= $this->parent
->getHelpBox( 'config-extensions-help' ) .
903 $this->getFieldSetEnd();
904 $this->addHTML( $extHtml );
907 // Having / in paths in Windows looks funny :)
908 $this->setVar( 'wgDeletedDirectory',
910 '/', DIRECTORY_SEPARATOR
,
911 $this->getVar( 'wgDeletedDirectory' )
915 $uploadwrapperStyle = $this->getVar( 'wgEnableUploads' ) ?
'' : 'display: none';
918 $this->getFieldSetStart( 'config-upload-settings' ) .
919 $this->parent
->getCheckBox( array(
920 'var' => 'wgEnableUploads',
921 'label' => 'config-upload-enable',
922 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'uploadwrapper' ),
923 'help' => $this->parent
->getHelpBox( 'config-upload-help' )
925 '<div id="uploadwrapper" style="' . $uploadwrapperStyle . '">' .
926 $this->parent
->getTextBox( array(
927 'var' => 'wgDeletedDirectory',
928 'label' => 'config-upload-deleted',
929 'attribs' => array( 'dir' => 'ltr' ),
930 'help' => $this->parent
->getHelpBox( 'config-upload-deleted-help' )
933 $this->parent
->getTextBox( array(
935 'label' => 'config-logo',
936 'attribs' => array( 'dir' => 'ltr' ),
937 'help' => $this->parent
->getHelpBox( 'config-logo-help' )
941 $this->parent
->getCheckBox( array(
942 'var' => 'wgUseInstantCommons',
943 'label' => 'config-instantcommons',
944 'help' => $this->parent
->getHelpBox( 'config-instantcommons-help' )
946 $this->getFieldSetEnd()
949 $caches = array( 'none' );
950 if( count( $this->getVar( '_Caches' ) ) ) {
953 $caches[] = 'memcached';
955 // We'll hide/show this on demand when the value changes, see config.js.
956 $cacheval = $this->getVar( 'wgMainCacheType' );
958 // We need to set a default here; but don't hardcode it
959 // or we lose it every time we reload the page for validation
963 $hidden = ($cacheval == 'memcached') ?
'' : 'display: none';
966 $this->getFieldSetStart( 'config-advanced-settings' ) .
967 # Object cache settings
968 $this->parent
->getRadioSet( array(
969 'var' => 'wgMainCacheType',
970 'label' => 'config-cache-options',
971 'itemLabelPrefix' => 'config-cache-',
973 'value' => $cacheval,
975 $this->parent
->getHelpBox( 'config-cache-help' ) .
976 "<div id=\"config-memcachewrapper\" style=\"$hidden\">" .
977 $this->parent
->getTextArea( array(
978 'var' => '_MemCachedServers',
979 'label' => 'config-memcached-servers',
980 'help' => $this->parent
->getHelpBox( 'config-memcached-help' )
983 $this->getFieldSetEnd()
991 public function getCCPartnerUrl() {
992 $server = $this->getVar( 'wgServer' );
993 $exitUrl = $server . $this->parent
->getUrl( array(
995 'SubmitCC' => 'indeed',
996 'config__LicenseCode' => 'cc',
997 'config_wgRightsUrl' => '[license_url]',
998 'config_wgRightsText' => '[license_name]',
999 'config_wgRightsIcon' => '[license_button]',
1001 $styleUrl = $server . dirname( dirname( $this->parent
->getUrl() ) ) .
1002 '/skins/common/config-cc.css';
1003 $iframeUrl = 'http://creativecommons.org/license/?' .
1004 wfArrayToCGI( array(
1005 'partner' => 'MediaWiki',
1006 'exit_url' => $exitUrl,
1007 'lang' => $this->getVar( '_UserLang' ),
1008 'stylesheet' => $styleUrl,
1013 public function getCCChooser() {
1014 $iframeAttribs = array(
1015 'class' => 'config-cc-iframe',
1016 'name' => 'config-cc-iframe',
1017 'id' => 'config-cc-iframe',
1022 if ( $this->getVar( '_CCDone' ) ) {
1023 $iframeAttribs['src'] = $this->parent
->getUrl( array( 'ShowCC' => 'yes' ) );
1025 $iframeAttribs['src'] = $this->getCCPartnerUrl();
1027 $wrapperStyle = ($this->getVar('_LicenseCode') == 'cc-choose') ?
'' : 'display: none';
1030 "<div class=\"config-cc-wrapper\" id=\"config-cc-wrapper\" style=\"$wrapperStyle\">\n" .
1031 Html
::element( 'iframe', $iframeAttribs, '', false /* not short */ ) .
1035 public function getCCDoneBox() {
1036 $js = "parent.document.getElementById('config-cc-wrapper').style.height = '$1';";
1037 // If you change this height, also change it in config.css
1038 $expandJs = str_replace( '$1', '54em', $js );
1039 $reduceJs = str_replace( '$1', '70px', $js );
1042 Html
::element( 'img', array( 'src' => $this->getVar( 'wgRightsIcon' ) ) ) .
1044 htmlspecialchars( $this->getVar( 'wgRightsText' ) ) .
1046 "<p style=\"text-align: center\">" .
1049 'href' => $this->getCCPartnerUrl(),
1050 'onclick' => $expandJs,
1052 wfMessage( 'config-cc-again' )->text()
1055 "<script type=\"text/javascript\">\n" .
1056 # Reduce the wrapper div height
1057 htmlspecialchars( $reduceJs ) .
1062 public function submitCC() {
1063 $newValues = $this->parent
->setVarsFromRequest(
1064 array( 'wgRightsUrl', 'wgRightsText', 'wgRightsIcon' ) );
1065 if ( count( $newValues ) != 3 ) {
1066 $this->parent
->showError( 'config-cc-error' );
1069 $this->setVar( '_CCDone', true );
1070 $this->addHTML( $this->getCCDoneBox() );
1073 public function submit() {
1074 $this->parent
->setVarsFromRequest( array( '_RightsProfile', '_LicenseCode',
1075 'wgEnableEmail', 'wgPasswordSender', 'wgEnableUploads', 'wgLogo',
1076 'wgEnableUserEmail', 'wgEnotifUserTalk', 'wgEnotifWatchlist',
1077 'wgEmailAuthentication', 'wgMainCacheType', '_MemCachedServers',
1078 'wgUseInstantCommons' ) );
1080 if ( !in_array( $this->getVar( '_RightsProfile' ),
1081 array_keys( $this->parent
->rightsProfiles
) ) )
1083 reset( $this->parent
->rightsProfiles
);
1084 $this->setVar( '_RightsProfile', key( $this->parent
->rightsProfiles
) );
1087 $code = $this->getVar( '_LicenseCode' );
1088 if ( $code == 'cc-choose' ) {
1089 if ( !$this->getVar( '_CCDone' ) ) {
1090 $this->parent
->showError( 'config-cc-not-chosen' );
1093 } elseif ( in_array( $code, array_keys( $this->parent
->licenses
) ) ) {
1094 $entry = $this->parent
->licenses
[$code];
1095 if ( isset( $entry['text'] ) ) {
1096 $this->setVar( 'wgRightsText', $entry['text'] );
1098 $this->setVar( 'wgRightsText', wfMessage( 'config-license-' . $code )->text() );
1100 $this->setVar( 'wgRightsUrl', $entry['url'] );
1101 $this->setVar( 'wgRightsIcon', $entry['icon'] );
1103 $this->setVar( 'wgRightsText', '' );
1104 $this->setVar( 'wgRightsUrl', '' );
1105 $this->setVar( 'wgRightsIcon', '' );
1108 $extsAvailable = $this->parent
->findExtensions();
1109 $extsToInstall = array();
1110 foreach( $extsAvailable as $ext ) {
1111 if( $this->parent
->request
->getCheck( 'config_ext-' . $ext ) ) {
1112 $extsToInstall[] = $ext;
1115 $this->parent
->setVar( '_Extensions', $extsToInstall );
1117 if( $this->getVar( 'wgMainCacheType' ) == 'memcached' ) {
1118 $memcServers = explode( "\n", $this->getVar( '_MemCachedServers' ) );
1119 if( !$memcServers ) {
1120 $this->parent
->showError( 'config-memcache-needservers' );
1124 foreach( $memcServers as $server ) {
1125 $memcParts = explode( ":", $server, 2 );
1126 if ( !isset( $memcParts[0] )
1127 ||
( !IP
::isValid( $memcParts[0] )
1128 && ( gethostbyname( $memcParts[0] ) == $memcParts[0] ) ) ) {
1129 $this->parent
->showError( 'config-memcache-badip', $memcParts[0] );
1131 } elseif( !isset( $memcParts[1] ) ) {
1132 $this->parent
->showError( 'config-memcache-noport', $memcParts[0] );
1134 } elseif( $memcParts[1] < 1 ||
$memcParts[1] > 65535 ) {
1135 $this->parent
->showError( 'config-memcache-badport', 1, 65535 );
1145 class WebInstaller_Install
extends WebInstallerPage
{
1146 public function isSlow() {
1150 public function execute() {
1151 if( $this->getVar( '_UpgradeDone' ) ) {
1153 } elseif( $this->getVar( '_InstallDone' ) ) {
1155 } elseif( $this->parent
->request
->wasPosted() ) {
1157 $this->addHTML("<ul>");
1158 $results = $this->parent
->performInstallation(
1159 array( $this, 'startStage'),
1160 array( $this, 'endStage' )
1162 $this->addHTML("</ul>");
1163 // PerformInstallation bails on a fatal, so make sure the last item
1164 // completed before giving 'next.' Likewise, only provide back on failure
1165 $lastStep = end( $results );
1166 $continue = $lastStep->isOK() ?
'continue' : false;
1167 $back = $lastStep->isOK() ?
false : 'back';
1168 $this->endForm( $continue, $back );
1171 $this->addHTML( $this->parent
->getInfoBox( wfMessage( 'config-install-begin' )->plain() ) );
1177 public function startStage( $step ) {
1178 $this->addHTML( "<li>" . wfMessage( "config-install-$step" )->escaped() . wfMessage( 'ellipsis')->escaped() );
1179 if ( $step == 'extension-tables' ) {
1180 $this->startLiveBox();
1186 * @param $status Status
1188 public function endStage( $step, $status ) {
1189 if ( $step == 'extension-tables' ) {
1190 $this->endLiveBox();
1192 $msg = $status->isOk() ?
'config-install-step-done' : 'config-install-step-failed';
1193 $html = wfMessage( 'word-separator' )->escaped() . wfMessage( $msg )->escaped();
1194 if ( !$status->isOk() ) {
1195 $html = "<span class=\"error\">$html</span>";
1197 $this->addHTML( $html . "</li>\n" );
1198 if( !$status->isGood() ) {
1199 $this->parent
->showStatusBox( $status );
1205 class WebInstaller_Complete
extends WebInstallerPage
{
1207 public function execute() {
1208 // Pop up a dialog box, to make it difficult for the user to forget
1209 // to download the file
1210 $lsUrl = $this->getVar( 'wgServer' ) . $this->parent
->getURL( array( 'localsettings' => 1 ) );
1211 if ( isset( $_SERVER['HTTP_USER_AGENT'] ) &&
1212 strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE' ) !== false ) {
1213 // JS appears the only method that works consistently with IE7+
1214 $this->addHtml( "\n<script type=\"" . $GLOBALS['wgJsMimeType'] .
1215 '">jQuery( document ).ready( function() { document.location=' .
1216 Xml
::encodeJsVar( $lsUrl) . "; } );</script>\n" );
1218 $this->parent
->request
->response()->header( "Refresh: 0;url=$lsUrl" );
1222 $this->parent
->disableLinkPopups();
1224 $this->parent
->getInfoBox(
1225 wfMessage( 'config-install-done',
1227 $this->getVar( 'wgServer' ) .
1228 $this->getVar( 'wgScriptPath' ) . '/index' .
1229 $this->getVar( 'wgScriptExtension' ),
1231 )->plain(), 'tick-32.png'
1234 $this->parent
->restoreLinkPopups();
1235 $this->endForm( false, false );
1239 class WebInstaller_Restart
extends WebInstallerPage
{
1241 public function execute() {
1242 $r = $this->parent
->request
;
1243 if ( $r->wasPosted() ) {
1244 $really = $r->getVal( 'submit-restart' );
1246 $this->parent
->reset();
1252 $s = $this->parent
->getWarningBox( wfMessage( 'config-help-restart' )->plain() );
1253 $this->addHTML( $s );
1254 $this->endForm( 'restart' );
1259 abstract class WebInstaller_Document
extends WebInstallerPage
{
1261 protected abstract function getFileName();
1263 public function execute() {
1264 $text = $this->getFileContents();
1265 $text = InstallDocFormatter
::format( $text );
1266 $this->parent
->output
->addWikiText( $text );
1268 $this->endForm( false );
1271 public function getFileContents() {
1272 $file = __DIR__
. '/../../' . $this->getFileName();
1273 if( ! file_exists( $file ) ) {
1274 return wfMessage( 'config-nofile', $file )->plain();
1276 return file_get_contents( $file );
1281 class WebInstaller_Readme
extends WebInstaller_Document
{
1282 protected function getFileName() { return 'README'; }
1285 class WebInstaller_ReleaseNotes
extends WebInstaller_Document
{
1286 protected function getFileName() {
1289 if(! preg_match( '/^(\d+)\.(\d+).*/i', $wgVersion, $result ) ) {
1290 throw new MWException('Variable $wgVersion has an invalid value.');
1293 return 'RELEASE-NOTES-' . $result[1] . '.' . $result[2];
1297 class WebInstaller_UpgradeDoc
extends WebInstaller_Document
{
1298 protected function getFileName() { return 'UPGRADE'; }
1301 class WebInstaller_Copying
extends WebInstaller_Document
{
1302 protected function getFileName() { return 'COPYING'; }