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] ) ) continue;
258 $s .= "\n" . Xml
::option( "$code - $lang", $code, $code == $selectedCode );
260 $s .= "\n</select>\n";
261 return $this->parent
->label( $label, $name, $s );
266 class WebInstaller_ExistingWiki
extends WebInstallerPage
{
267 public function execute() {
268 // If there is no LocalSettings.php, continue to the installer welcome page
269 $vars = Installer
::getExistingLocalSettings();
274 // Check if the upgrade key supplied to the user has appeared in LocalSettings.php
275 if ( $vars['wgUpgradeKey'] !== false
276 && $this->getVar( '_UpgradeKeySupplied' )
277 && $this->getVar( 'wgUpgradeKey' ) === $vars['wgUpgradeKey'] )
279 // It's there, so the user is authorized
280 $status = $this->handleExistingUpgrade( $vars );
281 if ( $status->isOK() ) {
285 $this->parent
->showStatusBox( $status );
286 $this->endForm( 'continue' );
291 // If there is no $wgUpgradeKey, tell the user to add one to LocalSettings.php
292 if ( $vars['wgUpgradeKey'] === false ) {
293 if ( $this->getVar( 'wgUpgradeKey', false ) === false ) {
294 $secretKey = $this->getVar( 'wgSecretKey' ); // preserve $wgSecretKey
295 $this->parent
->generateKeys();
296 $this->setVar( 'wgSecretKey', $secretKey );
297 $this->setVar( '_UpgradeKeySupplied', true );
300 $this->addHTML( $this->parent
->getInfoBox(
301 wfMessage( 'config-upgrade-key-missing', "<pre dir=\"ltr\">\$wgUpgradeKey = '" .
302 $this->getVar( 'wgUpgradeKey' ) . "';</pre>" )->plain()
304 $this->endForm( 'continue' );
308 // If there is an upgrade key, but it wasn't supplied, prompt the user to enter it
310 $r = $this->parent
->request
;
311 if ( $r->wasPosted() ) {
312 $key = $r->getText( 'config_wgUpgradeKey' );
313 if( !$key ||
$key !== $vars['wgUpgradeKey'] ) {
314 $this->parent
->showError( 'config-localsettings-badkey' );
315 $this->showKeyForm();
319 $status = $this->handleExistingUpgrade( $vars );
320 if ( $status->isOK() ) {
323 $this->parent
->showStatusBox( $status );
324 $this->showKeyForm();
328 $this->showKeyForm();
334 * Show the "enter key" form
336 protected function showKeyForm() {
339 $this->parent
->getInfoBox( wfMessage( 'config-localsettings-upgrade' )->plain() ).
341 $this->parent
->getTextBox( array(
342 'var' => 'wgUpgradeKey',
343 'label' => 'config-localsettings-key',
344 'attribs' => array( 'autocomplete' => 'off' ),
347 $this->endForm( 'continue' );
350 protected function importVariables( $names, $vars ) {
351 $status = Status
::newGood();
352 foreach ( $names as $name ) {
353 if ( !isset( $vars[$name] ) ) {
354 $status->fatal( 'config-localsettings-incomplete', $name );
356 $this->setVar( $name, $vars[$name] );
362 * Initiate an upgrade of the existing database
363 * @param array $vars Variables from LocalSettings.php and AdminSettings.php
366 protected function handleExistingUpgrade( $vars ) {
368 if ( !isset( $vars['wgDBtype'] ) ||
369 !in_array( $vars['wgDBtype'], Installer
::getDBTypes() ) ) {
370 return Status
::newFatal( 'config-localsettings-connection-error', '' );
373 // Set the relevant variables from LocalSettings.php
374 $requiredVars = array( 'wgDBtype' );
375 $status = $this->importVariables( $requiredVars, $vars );
376 $installer = $this->parent
->getDBInstaller();
377 $status->merge( $this->importVariables( $installer->getGlobalNames(), $vars ) );
378 if ( !$status->isOK() ) {
382 if ( isset( $vars['wgDBadminuser'] ) ) {
383 $this->setVar( '_InstallUser', $vars['wgDBadminuser'] );
385 $this->setVar( '_InstallUser', $vars['wgDBuser'] );
387 if ( isset( $vars['wgDBadminpassword'] ) ) {
388 $this->setVar( '_InstallPassword', $vars['wgDBadminpassword'] );
390 $this->setVar( '_InstallPassword', $vars['wgDBpassword'] );
393 // Test the database connection
394 $status = $installer->getConnection();
395 if ( !$status->isOK() ) {
396 // Adjust the error message to explain things correctly
397 $status->replaceMessage( 'config-connection-error',
398 'config-localsettings-connection-error' );
403 $this->setVar( '_ExistingDBSettings', true );
408 class WebInstaller_Welcome
extends WebInstallerPage
{
410 public function execute() {
411 if ( $this->parent
->request
->wasPosted() ) {
412 if ( $this->getVar( '_Environment' ) ) {
416 $this->parent
->output
->addWikiText( wfMessage( 'config-welcome' )->plain() );
417 $status = $this->parent
->doEnvironmentChecks();
418 if ( $status->isGood() ) {
419 $this->parent
->output
->addHTML( '<span class="success-message">' .
420 wfMessage( 'config-env-good' )->escaped() . '</span>' );
421 $this->parent
->output
->addWikiText( wfMessage( 'config-copyright',
422 SpecialVersion
::getCopyrightAndAuthorList() )->plain() );
426 $this->parent
->showStatusMessage( $status );
433 class WebInstaller_DBConnect
extends WebInstallerPage
{
435 public function execute() {
436 if ( $this->getVar( '_ExistingDBSettings' ) ) {
440 $r = $this->parent
->request
;
441 if ( $r->wasPosted() ) {
442 $status = $this->submit();
444 if ( $status->isGood() ) {
445 $this->setVar( '_UpgradeDone', false );
448 $this->parent
->showStatusBox( $status );
454 $types = "<ul class=\"config-settings-block\">\n";
456 $defaultType = $this->getVar( 'wgDBtype' );
458 // Give grep a chance to find the usages:
459 // config-support-mysql, config-support-postgres, config-support-oracle, config-support-sqlite
461 foreach( $this->parent
->getDBTypes() as $type ) {
462 $link = DatabaseBase
::factory( $type )->getSoftwareLink();
463 $dbSupport .= wfMessage( "config-support-$type", $link )->plain() . "\n";
465 $this->addHTML( $this->parent
->getInfoBox(
466 wfMessage( 'config-support-info', trim( $dbSupport ) )->text() ) );
468 foreach ( $this->parent
->getVar( '_CompiledDBs' ) as $type ) {
469 $installer = $this->parent
->getDBInstaller( $type );
473 $installer->getReadableName(),
477 $type == $defaultType,
478 array( 'class' => 'dbRadio', 'rel' => "DB_wrapper_$type" )
482 // Give grep a chance to find the usages:
483 // config-header-mysql, config-header-postgres, config-header-oracle, config-header-sqlite
485 Html
::openElement( 'div', array( 'id' => 'DB_wrapper_' . $type,
486 'class' => 'dbWrapper' ) ) .
487 Html
::element( 'h3', array(), wfMessage( 'config-header-' . $type )->text() ) .
488 $installer->getConnectForm() .
491 $types .= "</ul><br style=\"clear: left\"/>\n";
494 $this->parent
->label( 'config-db-type', false, $types ) .
501 public function submit() {
502 $r = $this->parent
->request
;
503 $type = $r->getVal( 'DBType' );
504 $this->setVar( 'wgDBtype', $type );
505 $installer = $this->parent
->getDBInstaller( $type );
507 return Status
::newFatal( 'config-invalid-db-type' );
509 return $installer->submitConnectForm();
514 class WebInstaller_Upgrade
extends WebInstallerPage
{
515 public function isSlow() {
519 public function execute() {
520 if ( $this->getVar( '_UpgradeDone' ) ) {
521 // Allow regeneration of LocalSettings.php, unless we are working
522 // from a pre-existing LocalSettings.php file and we want to avoid
523 // leaking its contents
524 if ( $this->parent
->request
->wasPosted() && !$this->getVar( '_ExistingDBSettings' ) ) {
525 // Done message acknowledged
529 // Show the done message again
530 // Make them click back again if they want to do the upgrade again
531 $this->showDoneMessage();
536 // wgDBtype is generally valid here because otherwise the previous page
537 // (connect) wouldn't have declared its happiness
538 $type = $this->getVar( 'wgDBtype' );
539 $installer = $this->parent
->getDBInstaller( $type );
541 if ( !$installer->needsUpgrade() ) {
545 if ( $this->parent
->request
->wasPosted() ) {
546 $installer->preUpgrade();
548 $this->startLiveBox();
549 $result = $installer->doUpgrade();
553 // If they're going to possibly regenerate LocalSettings, we
554 // need to create the upgrade/secret keys. Bug 26481
555 if( !$this->getVar( '_ExistingDBSettings' ) ) {
556 $this->parent
->generateKeys();
558 $this->setVar( '_UpgradeDone', true );
559 $this->showDoneMessage();
565 $this->addHTML( $this->parent
->getInfoBox(
566 wfMessage( 'config-can-upgrade', $GLOBALS['wgVersion'] )->plain() ) );
570 public function showDoneMessage() {
572 $regenerate = !$this->getVar( '_ExistingDBSettings' );
574 $msg = 'config-upgrade-done';
576 $msg = 'config-upgrade-done-no-regenerate';
578 $this->parent
->disableLinkPopups();
580 $this->parent
->getInfoBox(
582 $this->getVar( 'wgServer' ) .
583 $this->getVar( 'wgScriptPath' ) . '/index' .
584 $this->getVar( 'wgScriptExtension' )
585 )->plain(), 'tick-32.png'
588 $this->parent
->restoreLinkPopups();
589 $this->endForm( $regenerate ?
'regenerate' : false, false );
594 class WebInstaller_DBSettings
extends WebInstallerPage
{
596 public function execute() {
597 $installer = $this->parent
->getDBInstaller( $this->getVar( 'wgDBtype' ) );
599 $r = $this->parent
->request
;
600 if ( $r->wasPosted() ) {
601 $status = $installer->submitSettingsForm();
602 if ( $status === false ) {
604 } elseif ( $status->isGood() ) {
607 $this->parent
->showStatusBox( $status );
611 $form = $installer->getSettingsForm();
612 if ( $form === false ) {
617 $this->addHTML( $form );
623 class WebInstaller_Name
extends WebInstallerPage
{
625 public function execute() {
626 $r = $this->parent
->request
;
627 if ( $r->wasPosted() ) {
628 if ( $this->submit() ) {
635 // Encourage people to not name their site 'MediaWiki' by blanking the
636 // field. I think that was the intent with the original $GLOBALS['wgSitename']
637 // but these two always were the same so had the effect of making the
638 // installer forget $wgSitename when navigating back to this page.
639 if ( $this->getVar( 'wgSitename' ) == 'MediaWiki' ) {
640 $this->setVar( 'wgSitename', '' );
643 // Set wgMetaNamespace to something valid before we show the form.
644 // $wgMetaNamespace defaults to $wgSiteName which is 'MediaWiki'
645 $metaNS = $this->getVar( 'wgMetaNamespace' );
648 wfMessage( 'config-ns-other-default' )->inContentLanguage()->text()
652 $this->parent
->getTextBox( array(
653 'var' => 'wgSitename',
654 'label' => 'config-site-name',
655 'help' => $this->parent
->getHelpBox( 'config-site-name-help' )
657 // getRadioSet() builds a set of labeled radio buttons.
658 // For grep: The following messages are used as the item labels:
659 // config-ns-site-name, config-ns-generic, config-ns-other
660 $this->parent
->getRadioSet( array(
661 'var' => '_NamespaceType',
662 'label' => 'config-project-namespace',
663 'itemLabelPrefix' => 'config-ns-',
664 'values' => array( 'site-name', 'generic', 'other' ),
665 'commonAttribs' => array( 'class' => 'enableForOther',
666 'rel' => 'config_wgMetaNamespace' ),
667 'help' => $this->parent
->getHelpBox( 'config-project-namespace-help' )
669 $this->parent
->getTextBox( array(
670 'var' => 'wgMetaNamespace',
671 'label' => '', //TODO: Needs a label?
672 'attribs' => array( 'readonly' => 'readonly', 'class' => 'enabledByOther' ),
675 $this->getFieldSetStart( 'config-admin-box' ) .
676 $this->parent
->getTextBox( array(
677 'var' => '_AdminName',
678 'label' => 'config-admin-name',
679 'help' => $this->parent
->getHelpBox( 'config-admin-help' )
681 $this->parent
->getPasswordBox( array(
682 'var' => '_AdminPassword',
683 'label' => 'config-admin-password',
685 $this->parent
->getPasswordBox( array(
686 'var' => '_AdminPassword2',
687 'label' => 'config-admin-password-confirm'
689 $this->parent
->getTextBox( array(
690 'var' => '_AdminEmail',
691 'label' => 'config-admin-email',
692 'help' => $this->parent
->getHelpBox( 'config-admin-email-help' )
694 $this->parent
->getCheckBox( array(
695 'var' => '_Subscribe',
696 'label' => 'config-subscribe',
697 'help' => $this->parent
->getHelpBox( 'config-subscribe-help' )
699 $this->getFieldSetEnd() .
700 $this->parent
->getInfoBox( wfMessage( 'config-almost-done' )->text() ) .
701 // getRadioSet() builds a set of labeled radio buttons.
702 // For grep: The following messages are used as the item labels:
703 // config-optional-continue, config-optional-skip
704 $this->parent
->getRadioSet( array(
705 'var' => '_SkipOptional',
706 'itemLabelPrefix' => 'config-optional-',
707 'values' => array( 'continue', 'skip' )
711 // Restore the default value
712 $this->setVar( 'wgMetaNamespace', $metaNS );
718 public function submit() {
720 $this->parent
->setVarsFromRequest( array( 'wgSitename', '_NamespaceType',
721 '_AdminName', '_AdminPassword', '_AdminPassword2', '_AdminEmail',
722 '_Subscribe', '_SkipOptional', 'wgMetaNamespace' ) );
724 // Validate site name
725 if ( strval( $this->getVar( 'wgSitename' ) ) === '' ) {
726 $this->parent
->showError( 'config-site-name-blank' );
731 $nsType = $this->getVar( '_NamespaceType' );
732 if ( $nsType == 'site-name' ) {
733 $name = $this->getVar( 'wgSitename' );
734 // Sanitize for namespace
735 // This algorithm should match the JS one in WebInstallerOutput.php
736 $name = preg_replace( '/[\[\]\{\}|#<>%+? ]/', '_', $name );
737 $name = str_replace( '&', '&', $name );
738 $name = preg_replace( '/__+/', '_', $name );
739 $name = ucfirst( trim( $name, '_' ) );
740 } elseif ( $nsType == 'generic' ) {
741 $name = wfMessage( 'config-ns-generic' )->text();
743 $name = $this->getVar( 'wgMetaNamespace' );
746 // Validate namespace
747 if ( strpos( $name, ':' ) !== false ) {
750 // Title-style validation
751 $title = Title
::newFromText( $name );
753 $good = $nsType == 'site-name';
755 $name = $title->getDBkey();
760 $this->parent
->showError( 'config-ns-invalid', $name );
764 // Make sure it won't conflict with any existing namespaces
766 $nsIndex = $wgContLang->getNsIndex( $name );
767 if( $nsIndex !== false && $nsIndex !== NS_PROJECT
) {
768 $this->parent
->showError( 'config-ns-conflict', $name );
772 $this->setVar( 'wgMetaNamespace', $name );
774 // Validate username for creation
775 $name = $this->getVar( '_AdminName' );
776 if ( strval( $name ) === '' ) {
777 $this->parent
->showError( 'config-admin-name-blank' );
781 $cname = User
::getCanonicalName( $name, 'creatable' );
782 if ( $cname === false ) {
783 $this->parent
->showError( 'config-admin-name-invalid', $name );
786 $this->setVar( '_AdminName', $cname );
792 $pwd = $this->getVar( '_AdminPassword' );
793 $user = User
::newFromName( $cname );
794 $valid = $user && $user->getPasswordValidity( $pwd );
795 if ( strval( $pwd ) === '' ) {
796 # $user->getPasswordValidity just checks for $wgMinimalPasswordLength.
797 # This message is more specific and helpful.
798 $msg = 'config-admin-password-blank';
799 } elseif ( $pwd !== $this->getVar( '_AdminPassword2' ) ) {
800 $msg = 'config-admin-password-mismatch';
801 } elseif ( $valid !== true ) {
802 # As of writing this will only catch the username being e.g. 'FOO' and
806 if ( $msg !== false ) {
807 call_user_func_array( array( $this->parent
, 'showError' ), (array)$msg );
808 $this->setVar( '_AdminPassword', '' );
809 $this->setVar( '_AdminPassword2', '' );
813 // Validate e-mail if provided
814 $email = $this->getVar( '_AdminEmail' );
815 if( $email && !Sanitizer
::validateEmail( $email ) ) {
816 $this->parent
->showError( 'config-admin-error-bademail' );
819 // If they asked to subscribe to mediawiki-announce but didn't give
820 // an e-mail, show an error. Bug 29332
821 if( !$email && $this->getVar( '_Subscribe' ) ) {
822 $this->parent
->showError( 'config-subscribe-noemail' );
831 class WebInstaller_Options
extends WebInstallerPage
{
833 public function execute() {
834 if ( $this->getVar( '_SkipOptional' ) == 'skip' ) {
837 if ( $this->parent
->request
->wasPosted() ) {
838 if ( $this->submit() ) {
843 $emailwrapperStyle = $this->getVar( 'wgEnableEmail' ) ?
'' : 'display: none';
847 // getRadioSet() builds a set of labeled radio buttons.
848 // For grep: The following messages are used as the item labels:
849 // config-profile-wiki, config-profile-no-anon, config-profile-fishbowl, config-profile-private
850 $this->parent
->getRadioSet( array(
851 'var' => '_RightsProfile',
852 'label' => 'config-profile',
853 'itemLabelPrefix' => 'config-profile-',
854 'values' => array_keys( $this->parent
->rightsProfiles
),
856 $this->parent
->getInfoBox( wfMessage( 'config-profile-help' )->plain() ) .
859 // getRadioSet() builds a set of labeled radio buttons.
860 // For grep: The following messages are used as the item labels:
861 // config-license-cc-by, config-license-cc-by-sa, config-license-cc-by-nc-sa,
862 // config-license-cc-0, config-license-pd, config-license-gfdl,
863 // config-license-none, config-license-cc-choose
864 $this->parent
->getRadioSet( array(
865 'var' => '_LicenseCode',
866 'label' => 'config-license',
867 'itemLabelPrefix' => 'config-license-',
868 'values' => array_keys( $this->parent
->licenses
),
869 'commonAttribs' => array( 'class' => 'licenseRadio' ),
871 $this->getCCChooser() .
872 $this->parent
->getHelpBox( 'config-license-help' ) .
875 $this->getFieldSetStart( 'config-email-settings' ) .
876 $this->parent
->getCheckBox( array(
877 'var' => 'wgEnableEmail',
878 'label' => 'config-enable-email',
879 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'emailwrapper' ),
881 $this->parent
->getHelpBox( 'config-enable-email-help' ) .
882 "<div id=\"emailwrapper\" style=\"$emailwrapperStyle\">" .
883 $this->parent
->getTextBox( array(
884 'var' => 'wgPasswordSender',
885 'label' => 'config-email-sender'
887 $this->parent
->getHelpBox( 'config-email-sender-help' ) .
888 $this->parent
->getCheckBox( array(
889 'var' => 'wgEnableUserEmail',
890 'label' => 'config-email-user',
892 $this->parent
->getHelpBox( 'config-email-user-help' ) .
893 $this->parent
->getCheckBox( array(
894 'var' => 'wgEnotifUserTalk',
895 'label' => 'config-email-usertalk',
897 $this->parent
->getHelpBox( 'config-email-usertalk-help' ) .
898 $this->parent
->getCheckBox( array(
899 'var' => 'wgEnotifWatchlist',
900 'label' => 'config-email-watchlist',
902 $this->parent
->getHelpBox( 'config-email-watchlist-help' ) .
903 $this->parent
->getCheckBox( array(
904 'var' => 'wgEmailAuthentication',
905 'label' => 'config-email-auth',
907 $this->parent
->getHelpBox( 'config-email-auth-help' ) .
909 $this->getFieldSetEnd()
912 $extensions = $this->parent
->findExtensions();
915 $extHtml = $this->getFieldSetStart( 'config-extensions' );
917 foreach( $extensions as $ext ) {
918 $extHtml .= $this->parent
->getCheckBox( array(
924 $extHtml .= $this->parent
->getHelpBox( 'config-extensions-help' ) .
925 $this->getFieldSetEnd();
926 $this->addHTML( $extHtml );
929 // Having / in paths in Windows looks funny :)
930 $this->setVar( 'wgDeletedDirectory',
932 '/', DIRECTORY_SEPARATOR
,
933 $this->getVar( 'wgDeletedDirectory' )
937 $uploadwrapperStyle = $this->getVar( 'wgEnableUploads' ) ?
'' : 'display: none';
940 $this->getFieldSetStart( 'config-upload-settings' ) .
941 $this->parent
->getCheckBox( array(
942 'var' => 'wgEnableUploads',
943 'label' => 'config-upload-enable',
944 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'uploadwrapper' ),
945 'help' => $this->parent
->getHelpBox( 'config-upload-help' )
947 '<div id="uploadwrapper" style="' . $uploadwrapperStyle . '">' .
948 $this->parent
->getTextBox( array(
949 'var' => 'wgDeletedDirectory',
950 'label' => 'config-upload-deleted',
951 'attribs' => array( 'dir' => 'ltr' ),
952 'help' => $this->parent
->getHelpBox( 'config-upload-deleted-help' )
955 $this->parent
->getTextBox( array(
957 'label' => 'config-logo',
958 'attribs' => array( 'dir' => 'ltr' ),
959 'help' => $this->parent
->getHelpBox( 'config-logo-help' )
963 $this->parent
->getCheckBox( array(
964 'var' => 'wgUseInstantCommons',
965 'label' => 'config-instantcommons',
966 'help' => $this->parent
->getHelpBox( 'config-instantcommons-help' )
968 $this->getFieldSetEnd()
971 $caches = array( 'none' );
972 if( count( $this->getVar( '_Caches' ) ) ) {
975 $caches[] = 'memcached';
977 // We'll hide/show this on demand when the value changes, see config.js.
978 $cacheval = $this->getVar( 'wgMainCacheType' );
980 // We need to set a default here; but don't hardcode it
981 // or we lose it every time we reload the page for validation
985 $hidden = ($cacheval == 'memcached') ?
'' : 'display: none';
988 $this->getFieldSetStart( 'config-advanced-settings' ) .
989 # Object cache settings
990 // getRadioSet() builds a set of labeled radio buttons.
991 // For grep: The following messages are used as the item labels:
992 // config-cache-none, config-cache-accel, config-cache-memcached
993 $this->parent
->getRadioSet( array(
994 'var' => 'wgMainCacheType',
995 'label' => 'config-cache-options',
996 'itemLabelPrefix' => 'config-cache-',
998 'value' => $cacheval,
1000 $this->parent
->getHelpBox( 'config-cache-help' ) .
1001 "<div id=\"config-memcachewrapper\" style=\"$hidden\">" .
1002 $this->parent
->getTextArea( array(
1003 'var' => '_MemCachedServers',
1004 'label' => 'config-memcached-servers',
1005 'help' => $this->parent
->getHelpBox( 'config-memcached-help' )
1008 $this->getFieldSetEnd()
1016 public function getCCPartnerUrl() {
1017 $server = $this->getVar( 'wgServer' );
1018 $exitUrl = $server . $this->parent
->getUrl( array(
1019 'page' => 'Options',
1020 'SubmitCC' => 'indeed',
1021 'config__LicenseCode' => 'cc',
1022 'config_wgRightsUrl' => '[license_url]',
1023 'config_wgRightsText' => '[license_name]',
1024 'config_wgRightsIcon' => '[license_button]',
1026 $styleUrl = $server . dirname( dirname( $this->parent
->getUrl() ) ) .
1027 '/skins/common/config-cc.css';
1028 $iframeUrl = 'http://creativecommons.org/license/?' .
1029 wfArrayToCgi( array(
1030 'partner' => 'MediaWiki',
1031 'exit_url' => $exitUrl,
1032 'lang' => $this->getVar( '_UserLang' ),
1033 'stylesheet' => $styleUrl,
1038 public function getCCChooser() {
1039 $iframeAttribs = array(
1040 'class' => 'config-cc-iframe',
1041 'name' => 'config-cc-iframe',
1042 'id' => 'config-cc-iframe',
1047 if ( $this->getVar( '_CCDone' ) ) {
1048 $iframeAttribs['src'] = $this->parent
->getUrl( array( 'ShowCC' => 'yes' ) );
1050 $iframeAttribs['src'] = $this->getCCPartnerUrl();
1052 $wrapperStyle = ($this->getVar( '_LicenseCode' ) == 'cc-choose') ?
'' : 'display: none';
1055 "<div class=\"config-cc-wrapper\" id=\"config-cc-wrapper\" style=\"$wrapperStyle\">\n" .
1056 Html
::element( 'iframe', $iframeAttribs, '', false /* not short */ ) .
1060 public function getCCDoneBox() {
1061 $js = "parent.document.getElementById('config-cc-wrapper').style.height = '$1';";
1062 // If you change this height, also change it in config.css
1063 $expandJs = str_replace( '$1', '54em', $js );
1064 $reduceJs = str_replace( '$1', '70px', $js );
1067 Html
::element( 'img', array( 'src' => $this->getVar( 'wgRightsIcon' ) ) ) .
1069 htmlspecialchars( $this->getVar( 'wgRightsText' ) ) .
1071 "<p style=\"text-align: center\">" .
1074 'href' => $this->getCCPartnerUrl(),
1075 'onclick' => $expandJs,
1077 wfMessage( 'config-cc-again' )->text()
1080 "<script type=\"text/javascript\">\n" .
1081 # Reduce the wrapper div height
1082 htmlspecialchars( $reduceJs ) .
1087 public function submitCC() {
1088 $newValues = $this->parent
->setVarsFromRequest(
1089 array( 'wgRightsUrl', 'wgRightsText', 'wgRightsIcon' ) );
1090 if ( count( $newValues ) != 3 ) {
1091 $this->parent
->showError( 'config-cc-error' );
1094 $this->setVar( '_CCDone', true );
1095 $this->addHTML( $this->getCCDoneBox() );
1098 public function submit() {
1099 $this->parent
->setVarsFromRequest( array( '_RightsProfile', '_LicenseCode',
1100 'wgEnableEmail', 'wgPasswordSender', 'wgEnableUploads', 'wgLogo',
1101 'wgEnableUserEmail', 'wgEnotifUserTalk', 'wgEnotifWatchlist',
1102 'wgEmailAuthentication', 'wgMainCacheType', '_MemCachedServers',
1103 'wgUseInstantCommons' ) );
1105 if ( !in_array( $this->getVar( '_RightsProfile' ),
1106 array_keys( $this->parent
->rightsProfiles
) ) )
1108 reset( $this->parent
->rightsProfiles
);
1109 $this->setVar( '_RightsProfile', key( $this->parent
->rightsProfiles
) );
1112 $code = $this->getVar( '_LicenseCode' );
1113 if ( $code == 'cc-choose' ) {
1114 if ( !$this->getVar( '_CCDone' ) ) {
1115 $this->parent
->showError( 'config-cc-not-chosen' );
1118 } elseif ( in_array( $code, array_keys( $this->parent
->licenses
) ) ) {
1119 // Give grep a chance to find the usages:
1120 // config-license-cc-by, config-license-cc-by-sa, config-license-cc-by-nc-sa,
1121 // config-license-cc-0, config-license-pd, config-license-gfdl,
1122 // config-license-none, config-license-cc-choose
1123 $entry = $this->parent
->licenses
[$code];
1124 if ( isset( $entry['text'] ) ) {
1125 $this->setVar( 'wgRightsText', $entry['text'] );
1127 $this->setVar( 'wgRightsText', wfMessage( 'config-license-' . $code )->text() );
1129 $this->setVar( 'wgRightsUrl', $entry['url'] );
1130 $this->setVar( 'wgRightsIcon', $entry['icon'] );
1132 $this->setVar( 'wgRightsText', '' );
1133 $this->setVar( 'wgRightsUrl', '' );
1134 $this->setVar( 'wgRightsIcon', '' );
1137 $extsAvailable = $this->parent
->findExtensions();
1138 $extsToInstall = array();
1139 foreach( $extsAvailable as $ext ) {
1140 if( $this->parent
->request
->getCheck( 'config_ext-' . $ext ) ) {
1141 $extsToInstall[] = $ext;
1144 $this->parent
->setVar( '_Extensions', $extsToInstall );
1146 if( $this->getVar( 'wgMainCacheType' ) == 'memcached' ) {
1147 $memcServers = explode( "\n", $this->getVar( '_MemCachedServers' ) );
1148 if( !$memcServers ) {
1149 $this->parent
->showError( 'config-memcache-needservers' );
1153 foreach( $memcServers as $server ) {
1154 $memcParts = explode( ":", $server, 2 );
1155 if ( !isset( $memcParts[0] )
1156 ||
( !IP
::isValid( $memcParts[0] )
1157 && ( gethostbyname( $memcParts[0] ) == $memcParts[0] ) ) ) {
1158 $this->parent
->showError( 'config-memcache-badip', $memcParts[0] );
1160 } elseif( !isset( $memcParts[1] ) ) {
1161 $this->parent
->showError( 'config-memcache-noport', $memcParts[0] );
1163 } elseif( $memcParts[1] < 1 ||
$memcParts[1] > 65535 ) {
1164 $this->parent
->showError( 'config-memcache-badport', 1, 65535 );
1174 class WebInstaller_Install
extends WebInstallerPage
{
1175 public function isSlow() {
1179 public function execute() {
1180 if( $this->getVar( '_UpgradeDone' ) ) {
1182 } elseif( $this->getVar( '_InstallDone' ) ) {
1184 } elseif( $this->parent
->request
->wasPosted() ) {
1186 $this->addHTML( "<ul>" );
1187 $results = $this->parent
->performInstallation(
1188 array( $this, 'startStage' ),
1189 array( $this, 'endStage' )
1191 $this->addHTML( "</ul>" );
1192 // PerformInstallation bails on a fatal, so make sure the last item
1193 // completed before giving 'next.' Likewise, only provide back on failure
1194 $lastStep = end( $results );
1195 $continue = $lastStep->isOK() ?
'continue' : false;
1196 $back = $lastStep->isOK() ?
false : 'back';
1197 $this->endForm( $continue, $back );
1200 $this->addHTML( $this->parent
->getInfoBox( wfMessage( 'config-install-begin' )->plain() ) );
1206 public function startStage( $step ) {
1207 $this->addHTML( "<li>" . wfMessage( "config-install-$step" )->escaped() . wfMessage( 'ellipsis' )->escaped() );
1208 if ( $step == 'extension-tables' ) {
1209 $this->startLiveBox();
1215 * @param $status Status
1217 public function endStage( $step, $status ) {
1218 if ( $step == 'extension-tables' ) {
1219 $this->endLiveBox();
1221 $msg = $status->isOk() ?
'config-install-step-done' : 'config-install-step-failed';
1222 $html = wfMessage( 'word-separator' )->escaped() . wfMessage( $msg )->escaped();
1223 if ( !$status->isOk() ) {
1224 $html = "<span class=\"error\">$html</span>";
1226 $this->addHTML( $html . "</li>\n" );
1227 if( !$status->isGood() ) {
1228 $this->parent
->showStatusBox( $status );
1234 class WebInstaller_Complete
extends WebInstallerPage
{
1236 public function execute() {
1237 // Pop up a dialog box, to make it difficult for the user to forget
1238 // to download the file
1239 $lsUrl = $this->getVar( 'wgServer' ) . $this->parent
->getURL( array( 'localsettings' => 1 ) );
1240 if ( isset( $_SERVER['HTTP_USER_AGENT'] ) &&
1241 strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE' ) !== false ) {
1242 // JS appears the only method that works consistently with IE7+
1243 $this->addHtml( "\n<script type=\"" . $GLOBALS['wgJsMimeType'] .
1244 '">jQuery( document ).ready( function() { document.location=' .
1245 Xml
::encodeJsVar( $lsUrl) . "; } );</script>\n" );
1247 $this->parent
->request
->response()->header( "Refresh: 0;url=$lsUrl" );
1251 $this->parent
->disableLinkPopups();
1253 $this->parent
->getInfoBox(
1254 wfMessage( 'config-install-done',
1256 $this->getVar( 'wgServer' ) .
1257 $this->getVar( 'wgScriptPath' ) . '/index' .
1258 $this->getVar( 'wgScriptExtension' ),
1260 )->plain(), 'tick-32.png'
1263 $this->parent
->restoreLinkPopups();
1264 $this->endForm( false, false );
1268 class WebInstaller_Restart
extends WebInstallerPage
{
1270 public function execute() {
1271 $r = $this->parent
->request
;
1272 if ( $r->wasPosted() ) {
1273 $really = $r->getVal( 'submit-restart' );
1275 $this->parent
->reset();
1281 $s = $this->parent
->getWarningBox( wfMessage( 'config-help-restart' )->plain() );
1282 $this->addHTML( $s );
1283 $this->endForm( 'restart' );
1288 abstract class WebInstaller_Document
extends WebInstallerPage
{
1290 abstract protected function getFileName();
1292 public function execute() {
1293 $text = $this->getFileContents();
1294 $text = InstallDocFormatter
::format( $text );
1295 $this->parent
->output
->addWikiText( $text );
1297 $this->endForm( false );
1300 public function getFileContents() {
1301 $file = __DIR__
. '/../../' . $this->getFileName();
1302 if( ! file_exists( $file ) ) {
1303 return wfMessage( 'config-nofile', $file )->plain();
1305 return file_get_contents( $file );
1310 class WebInstaller_Readme
extends WebInstaller_Document
{
1311 protected function getFileName() { return 'README'; }
1314 class WebInstaller_ReleaseNotes
extends WebInstaller_Document
{
1315 protected function getFileName() {
1318 if( !preg_match( '/^(\d+)\.(\d+).*/i', $wgVersion, $result ) ) {
1319 throw new MWException( 'Variable $wgVersion has an invalid value.' );
1322 return 'RELEASE-NOTES-' . $result[1] . '.' . $result[2];
1326 class WebInstaller_UpgradeDoc
extends WebInstaller_Document
{
1327 protected function getFileName() { return 'UPGRADE'; }
1330 class WebInstaller_Copying
extends WebInstaller_Document
{
1331 protected function getFileName() { return 'COPYING'; }