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' )
936 // If we're using the default, let the user set it relative to $wgScriptPath
937 $curLogo = $this->getVar( 'wgLogo' );
938 $logoString = ( $curLogo == "/wiki/skins/common/images/wiki.png" ) ?
939 '$wgStylePath/common/images/wiki.png' : $curLogo;
941 $uploadwrapperStyle = $this->getVar( 'wgEnableUploads' ) ?
'' : 'display: none';
944 $this->getFieldSetStart( 'config-upload-settings' ) .
945 $this->parent
->getCheckBox( array(
946 'var' => 'wgEnableUploads',
947 'label' => 'config-upload-enable',
948 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'uploadwrapper' ),
949 'help' => $this->parent
->getHelpBox( 'config-upload-help' )
951 '<div id="uploadwrapper" style="' . $uploadwrapperStyle . '">' .
952 $this->parent
->getTextBox( array(
953 'var' => 'wgDeletedDirectory',
954 'label' => 'config-upload-deleted',
955 'attribs' => array( 'dir' => 'ltr' ),
956 'help' => $this->parent
->getHelpBox( 'config-upload-deleted-help' )
959 $this->parent
->getTextBox( array(
961 'value' => $logoString,
962 'label' => 'config-logo',
963 'attribs' => array( 'dir' => 'ltr' ),
964 'help' => $this->parent
->getHelpBox( 'config-logo-help' )
968 $this->parent
->getCheckBox( array(
969 'var' => 'wgUseInstantCommons',
970 'label' => 'config-instantcommons',
971 'help' => $this->parent
->getHelpBox( 'config-instantcommons-help' )
973 $this->getFieldSetEnd()
976 $caches = array( 'none' );
977 if( count( $this->getVar( '_Caches' ) ) ) {
980 $caches[] = 'memcached';
982 // We'll hide/show this on demand when the value changes, see config.js.
983 $cacheval = $this->getVar( 'wgMainCacheType' );
985 // We need to set a default here; but don't hardcode it
986 // or we lose it every time we reload the page for validation
990 $hidden = ($cacheval == 'memcached') ?
'' : 'display: none';
993 $this->getFieldSetStart( 'config-advanced-settings' ) .
994 # Object cache settings
995 // getRadioSet() builds a set of labeled radio buttons.
996 // For grep: The following messages are used as the item labels:
997 // config-cache-none, config-cache-accel, config-cache-memcached
998 $this->parent
->getRadioSet( array(
999 'var' => 'wgMainCacheType',
1000 'label' => 'config-cache-options',
1001 'itemLabelPrefix' => 'config-cache-',
1002 'values' => $caches,
1003 'value' => $cacheval,
1005 $this->parent
->getHelpBox( 'config-cache-help' ) .
1006 "<div id=\"config-memcachewrapper\" style=\"$hidden\">" .
1007 $this->parent
->getTextArea( array(
1008 'var' => '_MemCachedServers',
1009 'label' => 'config-memcached-servers',
1010 'help' => $this->parent
->getHelpBox( 'config-memcached-help' )
1013 $this->getFieldSetEnd()
1021 public function getCCPartnerUrl() {
1022 $server = $this->getVar( 'wgServer' );
1023 $exitUrl = $server . $this->parent
->getUrl( array(
1024 'page' => 'Options',
1025 'SubmitCC' => 'indeed',
1026 'config__LicenseCode' => 'cc',
1027 'config_wgRightsUrl' => '[license_url]',
1028 'config_wgRightsText' => '[license_name]',
1029 'config_wgRightsIcon' => '[license_button]',
1031 $styleUrl = $server . dirname( dirname( $this->parent
->getUrl() ) ) .
1032 '/skins/common/config-cc.css';
1033 $iframeUrl = 'http://creativecommons.org/license/?' .
1034 wfArrayToCgi( array(
1035 'partner' => 'MediaWiki',
1036 'exit_url' => $exitUrl,
1037 'lang' => $this->getVar( '_UserLang' ),
1038 'stylesheet' => $styleUrl,
1043 public function getCCChooser() {
1044 $iframeAttribs = array(
1045 'class' => 'config-cc-iframe',
1046 'name' => 'config-cc-iframe',
1047 'id' => 'config-cc-iframe',
1052 if ( $this->getVar( '_CCDone' ) ) {
1053 $iframeAttribs['src'] = $this->parent
->getUrl( array( 'ShowCC' => 'yes' ) );
1055 $iframeAttribs['src'] = $this->getCCPartnerUrl();
1057 $wrapperStyle = ($this->getVar( '_LicenseCode' ) == 'cc-choose') ?
'' : 'display: none';
1059 return "<div class=\"config-cc-wrapper\" id=\"config-cc-wrapper\" style=\"$wrapperStyle\">\n" .
1060 Html
::element( 'iframe', $iframeAttribs, '', false /* not short */ ) .
1064 public function getCCDoneBox() {
1065 $js = "parent.document.getElementById('config-cc-wrapper').style.height = '$1';";
1066 // If you change this height, also change it in config.css
1067 $expandJs = str_replace( '$1', '54em', $js );
1068 $reduceJs = str_replace( '$1', '70px', $js );
1070 Html
::element( 'img', array( 'src' => $this->getVar( 'wgRightsIcon' ) ) ) .
1072 htmlspecialchars( $this->getVar( 'wgRightsText' ) ) .
1074 "<p style=\"text-align: center\">" .
1077 'href' => $this->getCCPartnerUrl(),
1078 'onclick' => $expandJs,
1080 wfMessage( 'config-cc-again' )->text()
1083 "<script type=\"text/javascript\">\n" .
1084 # Reduce the wrapper div height
1085 htmlspecialchars( $reduceJs ) .
1090 public function submitCC() {
1091 $newValues = $this->parent
->setVarsFromRequest(
1092 array( 'wgRightsUrl', 'wgRightsText', 'wgRightsIcon' ) );
1093 if ( count( $newValues ) != 3 ) {
1094 $this->parent
->showError( 'config-cc-error' );
1097 $this->setVar( '_CCDone', true );
1098 $this->addHTML( $this->getCCDoneBox() );
1101 public function submit() {
1102 $this->parent
->setVarsFromRequest( array( '_RightsProfile', '_LicenseCode',
1103 'wgEnableEmail', 'wgPasswordSender', 'wgEnableUploads', 'wgLogo',
1104 'wgEnableUserEmail', 'wgEnotifUserTalk', 'wgEnotifWatchlist',
1105 'wgEmailAuthentication', 'wgMainCacheType', '_MemCachedServers',
1106 'wgUseInstantCommons' ) );
1108 if ( !in_array( $this->getVar( '_RightsProfile' ),
1109 array_keys( $this->parent
->rightsProfiles
) ) )
1111 reset( $this->parent
->rightsProfiles
);
1112 $this->setVar( '_RightsProfile', key( $this->parent
->rightsProfiles
) );
1115 $code = $this->getVar( '_LicenseCode' );
1116 if ( $code == 'cc-choose' ) {
1117 if ( !$this->getVar( '_CCDone' ) ) {
1118 $this->parent
->showError( 'config-cc-not-chosen' );
1121 } elseif ( in_array( $code, array_keys( $this->parent
->licenses
) ) ) {
1122 // Give grep a chance to find the usages:
1123 // config-license-cc-by, config-license-cc-by-sa, config-license-cc-by-nc-sa,
1124 // config-license-cc-0, config-license-pd, config-license-gfdl,
1125 // config-license-none, config-license-cc-choose
1126 $entry = $this->parent
->licenses
[$code];
1127 if ( isset( $entry['text'] ) ) {
1128 $this->setVar( 'wgRightsText', $entry['text'] );
1130 $this->setVar( 'wgRightsText', wfMessage( 'config-license-' . $code )->text() );
1132 $this->setVar( 'wgRightsUrl', $entry['url'] );
1133 $this->setVar( 'wgRightsIcon', $entry['icon'] );
1135 $this->setVar( 'wgRightsText', '' );
1136 $this->setVar( 'wgRightsUrl', '' );
1137 $this->setVar( 'wgRightsIcon', '' );
1140 $extsAvailable = $this->parent
->findExtensions();
1141 $extsToInstall = array();
1142 foreach( $extsAvailable as $ext ) {
1143 if( $this->parent
->request
->getCheck( 'config_ext-' . $ext ) ) {
1144 $extsToInstall[] = $ext;
1147 $this->parent
->setVar( '_Extensions', $extsToInstall );
1149 if( $this->getVar( 'wgMainCacheType' ) == 'memcached' ) {
1150 $memcServers = explode( "\n", $this->getVar( '_MemCachedServers' ) );
1151 if( !$memcServers ) {
1152 $this->parent
->showError( 'config-memcache-needservers' );
1156 foreach( $memcServers as $server ) {
1157 $memcParts = explode( ":", $server, 2 );
1158 if ( !isset( $memcParts[0] )
1159 ||
( !IP
::isValid( $memcParts[0] )
1160 && ( gethostbyname( $memcParts[0] ) == $memcParts[0] ) ) ) {
1161 $this->parent
->showError( 'config-memcache-badip', $memcParts[0] );
1163 } elseif( !isset( $memcParts[1] ) ) {
1164 $this->parent
->showError( 'config-memcache-noport', $memcParts[0] );
1166 } elseif( $memcParts[1] < 1 ||
$memcParts[1] > 65535 ) {
1167 $this->parent
->showError( 'config-memcache-badport', 1, 65535 );
1177 class WebInstaller_Install
extends WebInstallerPage
{
1178 public function isSlow() {
1182 public function execute() {
1183 if( $this->getVar( '_UpgradeDone' ) ) {
1185 } elseif( $this->getVar( '_InstallDone' ) ) {
1187 } elseif( $this->parent
->request
->wasPosted() ) {
1189 $this->addHTML( "<ul>" );
1190 $results = $this->parent
->performInstallation(
1191 array( $this, 'startStage' ),
1192 array( $this, 'endStage' )
1194 $this->addHTML( "</ul>" );
1195 // PerformInstallation bails on a fatal, so make sure the last item
1196 // completed before giving 'next.' Likewise, only provide back on failure
1197 $lastStep = end( $results );
1198 $continue = $lastStep->isOK() ?
'continue' : false;
1199 $back = $lastStep->isOK() ?
false : 'back';
1200 $this->endForm( $continue, $back );
1203 $this->addHTML( $this->parent
->getInfoBox( wfMessage( 'config-install-begin' )->plain() ) );
1209 public function startStage( $step ) {
1210 $this->addHTML( "<li>" . wfMessage( "config-install-$step" )->escaped() . wfMessage( 'ellipsis' )->escaped() );
1211 if ( $step == 'extension-tables' ) {
1212 $this->startLiveBox();
1218 * @param $status Status
1220 public function endStage( $step, $status ) {
1221 if ( $step == 'extension-tables' ) {
1222 $this->endLiveBox();
1224 $msg = $status->isOk() ?
'config-install-step-done' : 'config-install-step-failed';
1225 $html = wfMessage( 'word-separator' )->escaped() . wfMessage( $msg )->escaped();
1226 if ( !$status->isOk() ) {
1227 $html = "<span class=\"error\">$html</span>";
1229 $this->addHTML( $html . "</li>\n" );
1230 if( !$status->isGood() ) {
1231 $this->parent
->showStatusBox( $status );
1237 class WebInstaller_Complete
extends WebInstallerPage
{
1239 public function execute() {
1240 // Pop up a dialog box, to make it difficult for the user to forget
1241 // to download the file
1242 $lsUrl = $this->getVar( 'wgServer' ) . $this->parent
->getURL( array( 'localsettings' => 1 ) );
1243 if ( isset( $_SERVER['HTTP_USER_AGENT'] ) &&
1244 strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE' ) !== false ) {
1245 // JS appears the only method that works consistently with IE7+
1246 $this->addHtml( "\n<script type=\"" . $GLOBALS['wgJsMimeType'] .
1247 '">jQuery( document ).ready( function() { document.location=' .
1248 Xml
::encodeJsVar( $lsUrl ) . "; } );</script>\n" );
1250 $this->parent
->request
->response()->header( "Refresh: 0;url=$lsUrl" );
1254 $this->parent
->disableLinkPopups();
1256 $this->parent
->getInfoBox(
1257 wfMessage( 'config-install-done',
1259 $this->getVar( 'wgServer' ) .
1260 $this->getVar( 'wgScriptPath' ) . '/index' .
1261 $this->getVar( 'wgScriptExtension' ),
1263 )->plain(), 'tick-32.png'
1266 $this->parent
->restoreLinkPopups();
1267 $this->endForm( false, false );
1271 class WebInstaller_Restart
extends WebInstallerPage
{
1273 public function execute() {
1274 $r = $this->parent
->request
;
1275 if ( $r->wasPosted() ) {
1276 $really = $r->getVal( 'submit-restart' );
1278 $this->parent
->reset();
1284 $s = $this->parent
->getWarningBox( wfMessage( 'config-help-restart' )->plain() );
1285 $this->addHTML( $s );
1286 $this->endForm( 'restart' );
1291 abstract class WebInstaller_Document
extends WebInstallerPage
{
1293 abstract protected function getFileName();
1295 public function execute() {
1296 $text = $this->getFileContents();
1297 $text = InstallDocFormatter
::format( $text );
1298 $this->parent
->output
->addWikiText( $text );
1300 $this->endForm( false );
1303 public function getFileContents() {
1304 $file = __DIR__
. '/../../' . $this->getFileName();
1305 if( ! file_exists( $file ) ) {
1306 return wfMessage( 'config-nofile', $file )->plain();
1308 return file_get_contents( $file );
1313 class WebInstaller_Readme
extends WebInstaller_Document
{
1314 protected function getFileName() {
1319 class WebInstaller_ReleaseNotes
extends WebInstaller_Document
{
1320 protected function getFileName() {
1323 if( !preg_match( '/^(\d+)\.(\d+).*/i', $wgVersion, $result ) ) {
1324 throw new MWException( 'Variable $wgVersion has an invalid value.' );
1327 return 'RELEASE-NOTES-' . $result[1] . '.' . $result[2];
1331 class WebInstaller_UpgradeDoc
extends WebInstaller_Document
{
1332 protected function getFileName() {
1337 class WebInstaller_Copying
extends WebInstaller_Document
{
1338 protected function getFileName() {