3 * Base code for web installer pages.
10 * Abstract class to define pages for the web installer.
15 abstract class WebInstallerPage
{
18 * The WebInstaller object this WebInstallerPage belongs to.
24 public abstract function execute();
29 * @param $parent WebInstaller
31 public function __construct( WebInstaller
$parent ) {
32 $this->parent
= $parent;
35 public function addHTML( $html ) {
36 $this->parent
->output
->addHTML( $html );
39 public function startForm() {
41 "<div class=\"config-section\">\n" .
46 'action' => $this->parent
->getUrl( array( 'page' => $this->getName() ) )
52 public function endForm( $continue = 'continue' ) {
53 $this->parent
->output
->outputWarnings();
54 $s = "<div class=\"config-submit\">\n";
57 if ( $id === false ) {
58 $s .= Html
::hidden( 'lastPage', $this->parent
->request
->getVal( 'lastPage' ) );
62 // Fake submit button for enter keypress
63 $s .= Xml
::submitButton( wfMsg( "config-$continue" ),
64 array( 'name' => "enter-$continue", 'style' => 'display:none' ) ) . "\n";
68 $s .= Xml
::submitButton( wfMsg( 'config-back' ),
70 'name' => 'submit-back',
71 'tabindex' => $this->parent
->nextTabIndex()
76 $s .= Xml
::submitButton( wfMsg( "config-$continue" ),
78 'name' => "submit-$continue",
79 'tabindex' => $this->parent
->nextTabIndex(),
83 $s .= "</div></form></div>\n";
87 public function getName() {
88 return str_replace( 'WebInstaller_', '', get_class( $this ) );
91 public function getId() {
92 return array_search( $this->getName(), $this->parent
->pageSequence
);
95 public function getVar( $var ) {
96 return $this->parent
->getVar( $var );
99 public function setVar( $name, $value ) {
100 $this->parent
->setVar( $name, $value );
104 * Get the starting tags of a fieldset.
106 * @param $legend String: message name
108 protected function getFieldsetStart( $legend ) {
109 return "\n<fieldset><legend>" . wfMsgHtml( $legend ) . "</legend>\n";
113 * Get the end tag of a fieldset.
115 protected function getFieldsetEnd() {
116 return "</fieldset>\n";
120 class WebInstaller_Locked
extends WebInstallerPage
{
122 // The status of Installer::getLocalSettingsStatus()
125 public function setLocalSettingsStatus( Status
$s ) {
129 public function execute() {
130 $r = $this->parent
->request
;
131 if( !$r->wasPosted() ||
!$this->status
->isOK() ) {
135 $key = $r->getText( 'config_wpUpgradeKey' );
136 if( !$key ||
$key !== $this->getVar( '_UpgradeKey' ) ) {
137 $this->parent
->showError( 'config-localsettings-badkey' );
141 $this->setVar( '_LocalSettingsLocked', false );
148 * Display stuff to the end user
150 private function display() {
152 $this->parent
->showStatusBox( $this->status
);
153 if( $this->status
->isOK() && !$this->status
->isGood() ) {
154 $this->addHTML( "<br />" .
155 $this->parent
->getTextBox( array(
156 'var' => 'wpUpgradeKey',
157 'label' => 'config-localsettings-key',
165 class WebInstaller_Language
extends WebInstallerPage
{
167 public function execute() {
169 $r = $this->parent
->request
;
170 $userLang = $r->getVal( 'UserLang' );
171 $contLang = $r->getVal( 'ContLang' );
173 $lifetime = intval( ini_get( 'session.gc_maxlifetime' ) );
175 $lifetime = 1440; // PHP default
178 if ( $r->wasPosted() ) {
180 if ( $this->parent
->getSession( 'test' ) === null ) {
181 $requestTime = $r->getVal( 'LanguageRequestTime' );
182 if ( !$requestTime ) {
183 // The most likely explanation is that the user was knocked back
184 // from another page on POST due to session expiry
185 $msg = 'config-session-expired';
186 } elseif ( time() - $requestTime > $lifetime ) {
187 $msg = 'config-session-expired';
189 $msg = 'config-no-session';
191 $this->parent
->showError( $msg, $wgLang->formatTimePeriod( $lifetime ) );
193 $languages = Language
::getLanguageNames();
194 if ( isset( $languages[$userLang] ) ) {
195 $this->setVar( '_UserLang', $userLang );
197 if ( isset( $languages[$contLang] ) ) {
198 $this->setVar( 'wgLanguageCode', $contLang );
200 $this->setVar( '_ExternalHTTP', $r->getBool( 'config__ExternalHTTP' ) );
203 } elseif ( $this->parent
->showSessionWarning
) {
204 # The user was knocked back from another page to the start
205 # This probably indicates a session expiry
206 $this->parent
->showError( 'config-session-expired', $wgLang->formatTimePeriod( $lifetime ) );
209 $this->parent
->setSession( 'test', true );
211 if ( !isset( $languages[$userLang] ) ) {
212 $userLang = $this->getVar( '_UserLang', 'en' );
214 if ( !isset( $languages[$contLang] ) ) {
215 $contLang = $this->getVar( 'wgLanguageCode', 'en' );
218 $s = Html
::hidden( 'LanguageRequestTime', time() ) .
219 $this->getLanguageSelector( 'UserLang', 'config-your-language', $userLang, $this->parent
->getHelpBox( 'config-your-language-help' ) ) .
220 $this->getLanguageSelector( 'ContLang', 'config-wiki-language', $contLang, $this->parent
->getHelpBox( 'config-wiki-language-help' ) ) .
221 $this->parent
->getCheckBox(
223 'var' => '_ExternalHTTP',
224 'label' => 'config-allow-requests',
225 'help' => $this->parent
->getHelpBox( 'config-allow-requests-help' )
229 $this->addHTML( $s );
234 * Get a <select> for selecting languages.
236 public function getLanguageSelector( $name, $label, $selectedCode ) {
237 global $wgDummyLanguageCodes;
238 $s = Xml
::openElement( 'select', array( 'id' => $name, 'name' => $name ) ) . "\n";
240 $languages = Language
::getLanguageNames();
242 $dummies = array_flip( $wgDummyLanguageCodes );
243 foreach ( $languages as $code => $lang ) {
244 if ( isset( $dummies[$code] ) ) continue;
245 $s .= "\n" . Xml
::option( "$code - $lang", $code, $code == $selectedCode );
247 $s .= "\n</select>\n";
248 return $this->parent
->label( $label, $name, $s );
253 class WebInstaller_Welcome
extends WebInstallerPage
{
255 public function execute() {
256 if ( $this->parent
->request
->wasPosted() ) {
257 if ( $this->getVar( '_Environment' ) ) {
261 $this->parent
->output
->addWikiText( wfMsgNoTrans( 'config-welcome' ) );
262 $status = $this->parent
->doEnvironmentChecks();
264 $this->parent
->output
->addWikiText( wfMsgNoTrans( 'config-copyright',
265 SpecialVersion
::getCopyrightAndAuthorList() ) );
273 class WebInstaller_DBConnect
extends WebInstallerPage
{
275 public function execute() {
276 $r = $this->parent
->request
;
277 if ( $r->wasPosted() ) {
278 $status = $this->submit();
279 if ( $status->isGood() ) {
280 $this->setVar( '_UpgradeDone', false );
283 $this->parent
->showStatusBox( $status );
289 $types = "<ul class=\"config-settings-block\">\n";
291 $defaultType = $this->getVar( 'wgDBtype' );
294 foreach( $this->parent
->getDBTypes() as $type ) {
295 $db = 'Database' . ucfirst( $type );
296 $dbSupport .= wfMsgNoTrans( "config-support-$type",
297 call_user_func( array( $db, 'getSoftwareLink' ) ) ) . "\n";
299 $this->addHTML( $this->parent
->getInfoBox(
300 wfMsg( 'config-support-info', $dbSupport ) ) );
302 foreach ( $this->parent
->getVar( '_CompiledDBs' ) as $type ) {
303 $installer = $this->parent
->getDBInstaller( $type );
307 $installer->getReadableName(),
311 $type == $defaultType,
312 array( 'class' => 'dbRadio', 'rel' => "DB_wrapper_$type" )
317 Xml
::openElement( 'div', array( 'id' => 'DB_wrapper_' . $type, 'class' => 'dbWrapper' ) ) .
318 Xml
::element( 'h3', array(), wfMsg( 'config-header-' . $type ) ) .
319 $installer->getConnectForm() .
322 $types .= "</ul><br clear=\"left\"/>\n";
325 $this->parent
->label( 'config-db-type', false, $types ) .
332 public function submit() {
333 $r = $this->parent
->request
;
334 $type = $r->getVal( 'DBType' );
335 $this->setVar( 'wgDBtype', $type );
336 $installer = $this->parent
->getDBInstaller( $type );
338 return Status
::newFatal( 'config-invalid-db-type' );
340 return $installer->submitConnectForm();
345 class WebInstaller_Upgrade
extends WebInstallerPage
{
347 public function execute() {
348 if ( $this->getVar( '_UpgradeDone' ) ) {
349 if ( $this->parent
->request
->wasPosted() ) {
350 // Done message acknowledged
354 // Show the done message again
355 // Make them click back again if they want to do the upgrade again
356 $this->showDoneMessage();
361 // wgDBtype is generally valid here because otherwise the previous page
362 // (connect) wouldn't have declared its happiness
363 $type = $this->getVar( 'wgDBtype' );
364 $installer = $this->parent
->getDBInstaller( $type );
366 if ( !$installer->needsUpgrade() ) {
370 if ( $this->parent
->request
->wasPosted() ) {
371 $installer->preUpgrade();
373 '<div id="config-spinner" style="display:none;"><img src="../skins/common/images/ajax-loader.gif" /></div>' .
374 '<script>jQuery( "#config-spinner" )[0].style.display = "block";</script>' .
375 '<textarea id="config-update-log" name="UpdateLog" rows="10" readonly="readonly">'
377 $this->parent
->output
->flush();
378 $result = $installer->doUpgrade();
379 $this->addHTML( '</textarea>
380 <script>jQuery( "#config-spinner" )[0].style.display = "none";</script>' );
381 $this->parent
->output
->flush();
383 $this->setVar( '_UpgradeDone', true );
384 $this->showDoneMessage();
390 $this->addHTML( $this->parent
->getInfoBox(
391 wfMsgNoTrans( 'config-can-upgrade', $GLOBALS['wgVersion'] ) ) );
395 public function showDoneMessage() {
398 $this->parent
->getInfoBox(
399 wfMsgNoTrans( 'config-upgrade-done',
400 $GLOBALS['wgServer'] .
401 $this->getVar( 'wgScriptPath' ) . '/index' .
402 $this->getVar( 'wgScriptExtension' )
406 $this->endForm( 'regenerate' );
411 class WebInstaller_DBSettings
extends WebInstallerPage
{
413 public function execute() {
414 $installer = $this->parent
->getDBInstaller( $this->getVar( 'wgDBtype' ) );
416 $r = $this->parent
->request
;
417 if ( $r->wasPosted() ) {
418 $status = $installer->submitSettingsForm();
419 if ( $status === false ) {
421 } elseif ( $status->isGood() ) {
424 $this->parent
->showStatusBox( $status );
428 $form = $installer->getSettingsForm();
429 if ( $form === false ) {
434 $this->addHTML( $form );
440 class WebInstaller_Name
extends WebInstallerPage
{
442 public function execute() {
443 $r = $this->parent
->request
;
444 if ( $r->wasPosted() ) {
445 if ( $this->submit() ) {
452 if ( $this->getVar( 'wgSitename' ) == $GLOBALS['wgSitename'] ) {
453 $this->setVar( 'wgSitename', '' );
456 // Set wgMetaNamespace to something valid before we show the form.
457 // $wgMetaNamespace defaults to $wgSiteName which is 'MediaWiki'
458 $metaNS = $this->getVar( 'wgMetaNamespace' );
459 $this->setVar( 'wgMetaNamespace', wfMsgForContent( 'config-ns-other-default' ) );
462 $this->parent
->getTextBox( array(
463 'var' => 'wgSitename',
464 'label' => 'config-site-name',
465 'help' => $this->parent
->getHelpBox( 'config-site-name-help' )
467 $this->parent
->getRadioSet( array(
468 'var' => '_NamespaceType',
469 'label' => 'config-project-namespace',
470 'itemLabelPrefix' => 'config-ns-',
471 'values' => array( 'site-name', 'generic', 'other' ),
472 'commonAttribs' => array( 'class' => 'enableForOther', 'rel' => 'config_wgMetaNamespace' ),
473 'help' => $this->parent
->getHelpBox( 'config-project-namespace-help' )
475 $this->parent
->getTextBox( array(
476 'var' => 'wgMetaNamespace',
478 'attribs' => array( 'disabled' => '' ),
481 $this->getFieldSetStart( 'config-admin-box' ) .
482 $this->parent
->getTextBox( array(
483 'var' => '_AdminName',
484 'label' => 'config-admin-name'
486 $this->parent
->getPasswordBox( array(
487 'var' => '_AdminPassword',
488 'label' => 'config-admin-password',
489 'help' => $this->parent
->getHelpBox( 'config-admin-help' )
491 $this->parent
->getPasswordBox( array(
492 'var' => '_AdminPassword2',
493 'label' => 'config-admin-password-confirm'
495 $this->parent
->getTextBox( array(
496 'var' => '_AdminEmail',
497 'label' => 'config-admin-email',
498 'help' => $this->parent
->getHelpBox( 'config-admin-email-help' )
500 $this->parent
->getCheckBox( array(
501 'var' => '_Subscribe',
502 'label' => 'config-subscribe',
503 'help' => $this->parent
->getHelpBox( 'config-subscribe-help' )
505 $this->getFieldSetEnd() .
506 $this->parent
->getInfoBox( wfMsg( 'config-almost-done' ) ) .
507 $this->parent
->getRadioSet( array(
508 'var' => '_SkipOptional',
509 'itemLabelPrefix' => 'config-optional-',
510 'values' => array( 'continue', 'skip' )
514 // Restore the default value
515 $this->setVar( 'wgMetaNamespace', $metaNS );
521 public function submit() {
523 $this->parent
->setVarsFromRequest( array( 'wgSitename', '_NamespaceType',
524 '_AdminName', '_AdminPassword', '_AdminPassword2', '_AdminEmail',
525 '_Subscribe', '_SkipOptional' ) );
527 // Validate site name
528 if ( strval( $this->getVar( 'wgSitename' ) ) === '' ) {
529 $this->parent
->showError( 'config-site-name-blank' );
534 $nsType = $this->getVar( '_NamespaceType' );
535 if ( $nsType == 'site-name' ) {
536 $name = $this->getVar( 'wgSitename' );
537 // Sanitize for namespace
538 // This algorithm should match the JS one in WebInstallerOutput.php
539 $name = preg_replace( '/[\[\]\{\}|#<>%+? ]/', '_', $name );
540 $name = str_replace( '&', '&', $name );
541 $name = preg_replace( '/__+/', '_', $name );
542 $name = ucfirst( trim( $name, '_' ) );
543 } elseif ( $nsType == 'generic' ) {
544 $name = wfMsg( 'config-ns-generic' );
546 $name = $this->getVar( 'wgMetaNamespace' );
549 // Validate namespace
550 if ( strpos( $name, ':' ) !== false ) {
553 // Title-style validation
554 $title = Title
::newFromText( $name );
556 $good = $nsType == 'site-name';
558 $name = $title->getDBkey();
563 $this->parent
->showError( 'config-ns-invalid', $name );
566 $this->setVar( 'wgMetaNamespace', $name );
568 // Validate username for creation
569 $name = $this->getVar( '_AdminName' );
570 if ( strval( $name ) === '' ) {
571 $this->parent
->showError( 'config-admin-name-blank' );
575 $cname = User
::getCanonicalName( $name, 'creatable' );
576 if ( $cname === false ) {
577 $this->parent
->showError( 'config-admin-name-invalid', $name );
580 $this->setVar( '_AdminName', $cname );
587 $pwd = $this->getVar( '_AdminPassword' );
588 $user = User
::newFromName( $cname );
589 if ( ( isset ( $pwd ) ) && ( $user != null ) ) {
590 $valid = $user->getPasswordValidity( $pwd );
592 if ( strval( $pwd ) === '' ) {
593 # $user->getPasswordValidity just checks for $wgMinimalPasswordLength.
594 # This message is more specific and helpful.
595 $msg = 'config-admin-password-blank';
596 } elseif ( $pwd !== $this->getVar( '_AdminPassword2' ) ) {
597 $msg = 'config-admin-password-mismatch';
598 } elseif ( $valid !== true ) {
599 # As of writing this will only catch the username being e.g. 'FOO' and
603 if ( $msg !== false ) {
604 $this->parent
->showError( $msg );
605 $this->setVar( '_AdminPassword', '' );
606 $this->setVar( '_AdminPassword2', '' );
614 class WebInstaller_Options
extends WebInstallerPage
{
616 public function execute() {
617 if ( $this->getVar( '_SkipOptional' ) == 'skip' ) {
620 if ( $this->parent
->request
->wasPosted() ) {
621 if ( $this->submit() ) {
629 $this->parent
->getRadioSet( array(
630 'var' => '_RightsProfile',
631 'label' => 'config-profile',
632 'itemLabelPrefix' => 'config-profile-',
633 'values' => array_keys( $this->parent
->rightsProfiles
),
635 $this->parent
->getHelpBox( 'config-profile-help' ) .
638 $this->parent
->getRadioSet( array(
639 'var' => '_LicenseCode',
640 'label' => 'config-license',
641 'itemLabelPrefix' => 'config-license-',
642 'values' => array_keys( $this->parent
->licenses
),
643 'commonAttribs' => array( 'class' => 'licenseRadio' ),
645 $this->getCCChooser() .
646 $this->parent
->getHelpBox( 'config-license-help' ) .
649 $this->getFieldSetStart( 'config-email-settings' ) .
650 $this->parent
->getCheckBox( array(
651 'var' => 'wgEnableEmail',
652 'label' => 'config-enable-email',
653 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'emailwrapper' ),
655 $this->parent
->getHelpBox( 'config-enable-email-help' ) .
656 "<div id=\"emailwrapper\">" .
657 $this->parent
->getTextBox( array(
658 'var' => 'wgPasswordSender',
659 'label' => 'config-email-sender'
661 $this->parent
->getHelpBox( 'config-email-sender-help' ) .
662 $this->parent
->getCheckBox( array(
663 'var' => 'wgEnableUserEmail',
664 'label' => 'config-email-user',
666 $this->parent
->getHelpBox( 'config-email-user-help' ) .
667 $this->parent
->getCheckBox( array(
668 'var' => 'wgEnotifUserTalk',
669 'label' => 'config-email-usertalk',
671 $this->parent
->getHelpBox( 'config-email-usertalk-help' ) .
672 $this->parent
->getCheckBox( array(
673 'var' => 'wgEnotifWatchlist',
674 'label' => 'config-email-watchlist',
676 $this->parent
->getHelpBox( 'config-email-watchlist-help' ) .
677 $this->parent
->getCheckBox( array(
678 'var' => 'wgEmailAuthentication',
679 'label' => 'config-email-auth',
681 $this->parent
->getHelpBox( 'config-email-auth-help' ) .
683 $this->getFieldSetEnd()
686 $extensions = $this->parent
->findExtensions();
689 $extHtml = $this->getFieldSetStart( 'config-extensions' );
691 foreach( $extensions as $ext ) {
692 $extHtml .= $this->parent
->getCheckBox( array(
698 $extHtml .= $this->parent
->getHelpBox( 'config-extensions-help' ) .
699 $this->getFieldSetEnd();
700 $this->addHTML( $extHtml );
705 $this->getFieldSetStart( 'config-upload-settings' ) .
706 $this->parent
->getCheckBox( array(
707 'var' => 'wgEnableUploads',
708 'label' => 'config-upload-enable',
709 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'uploadwrapper' ),
710 'help' => $this->parent
->getHelpBox( 'config-upload-help' )
712 '<div id="uploadwrapper" style="display: none;">' .
713 $this->parent
->getTextBox( array(
714 'var' => 'wgDeletedDirectory',
715 'label' => 'config-upload-deleted',
716 'help' => $this->parent
->getHelpBox( 'config-upload-deleted-help' )
719 $this->parent
->getTextBox( array(
721 'label' => 'config-logo',
722 'help' => $this->parent
->getHelpBox( 'config-logo-help' )
725 $canUse = $this->getVar( '_ExternalHTTP' ) ?
726 'config-instantcommons-good' : 'config-instantcommons-bad';
728 $this->parent
->getCheckBox( array(
729 'var' => 'wgUseInstantCommons',
730 'label' => 'config-instantcommons',
731 'help' => $this->parent
->getHelpBox( 'config-instantcommons-help', wfMsgNoTrans( $canUse ) )
733 $this->getFieldSetEnd()
736 $caches = array( 'none' );
737 if( count( $this->getVar( '_Caches' ) ) ) {
740 $caches[] = 'memcached';
744 $this->getFieldSetStart( 'config-advanced-settings' ) .
745 # Object cache settings
746 $this->parent
->getRadioSet( array(
747 'var' => 'wgMainCacheType',
748 'label' => 'config-cache-options',
749 'itemLabelPrefix' => 'config-cache-',
753 $this->parent
->getHelpBox( 'config-cache-help' ) .
754 '<div id="config-memcachewrapper">' .
755 $this->parent
->getTextBox( array(
756 'var' => '_MemCachedServers',
757 'label' => 'config-memcached-servers',
758 'help' => $this->parent
->getHelpBox( 'config-memcached-help' )
761 $this->getFieldSetEnd()
766 public function getCCPartnerUrl() {
768 $exitUrl = $wgServer . $this->parent
->getUrl( array(
770 'SubmitCC' => 'indeed',
771 'config__LicenseCode' => 'cc',
772 'config_wgRightsUrl' => '[license_url]',
773 'config_wgRightsText' => '[license_name]',
774 'config_wgRightsIcon' => '[license_button]',
776 $styleUrl = $wgServer . dirname( dirname( $this->parent
->getUrl() ) ) .
777 '/skins/common/config-cc.css';
778 $iframeUrl = 'http://creativecommons.org/license/?' .
780 'partner' => 'MediaWiki',
781 'exit_url' => $exitUrl,
782 'lang' => $this->getVar( '_UserLang' ),
783 'stylesheet' => $styleUrl,
788 public function getCCChooser() {
789 $iframeAttribs = array(
790 'class' => 'config-cc-iframe',
791 'name' => 'config-cc-iframe',
792 'id' => 'config-cc-iframe',
797 if ( $this->getVar( '_CCDone' ) ) {
798 $iframeAttribs['src'] = $this->parent
->getUrl( array( 'ShowCC' => 'yes' ) );
800 $iframeAttribs['src'] = $this->getCCPartnerUrl();
804 "<div class=\"config-cc-wrapper\" id=\"config-cc-wrapper\" style=\"display: none;\">\n" .
805 Xml
::element( 'iframe', $iframeAttribs, '', false /* not short */ ) .
809 public function getCCDoneBox() {
810 $js = "parent.document.getElementById('config-cc-wrapper').style.height = '$1';";
811 // If you change this height, also change it in config.css
812 $expandJs = str_replace( '$1', '54em', $js );
813 $reduceJs = str_replace( '$1', '70px', $js );
816 Xml
::element( 'img', array( 'src' => $this->getVar( 'wgRightsIcon' ) ) ) .
818 htmlspecialchars( $this->getVar( 'wgRightsText' ) ) .
820 "<p style=\"text-align: center\">" .
823 'href' => $this->getCCPartnerUrl(),
824 'onclick' => $expandJs,
826 wfMsg( 'config-cc-again' )
829 "<script type=\"text/javascript\">\n" .
830 # Reduce the wrapper div height
831 htmlspecialchars( $reduceJs ) .
836 public function submitCC() {
837 $newValues = $this->parent
->setVarsFromRequest(
838 array( 'wgRightsUrl', 'wgRightsText', 'wgRightsIcon' ) );
839 if ( count( $newValues ) != 3 ) {
840 $this->parent
->showError( 'config-cc-error' );
843 $this->setVar( '_CCDone', true );
844 $this->addHTML( $this->getCCDoneBox() );
847 public function submit() {
848 $this->parent
->setVarsFromRequest( array( '_RightsProfile', '_LicenseCode',
849 'wgEnableEmail', 'wgPasswordSender', 'wgEnableUploads', 'wgLogo',
850 'wgEnableUserEmail', 'wgEnotifUserTalk', 'wgEnotifWatchlist',
851 'wgEmailAuthentication', 'wgMainCacheType', '_MemCachedServers',
852 'wgUseInstantCommons' ) );
854 if ( !in_array( $this->getVar( '_RightsProfile' ),
855 array_keys( $this->parent
->rightsProfiles
) ) )
857 reset( $this->parent
->rightsProfiles
);
858 $this->setVar( '_RightsProfile', key( $this->parent
->rightsProfiles
) );
861 $code = $this->getVar( '_LicenseCode' );
862 if ( $code == 'cc-choose' ) {
863 if ( !$this->getVar( '_CCDone' ) ) {
864 $this->parent
->showError( 'config-cc-not-chosen' );
867 } elseif ( in_array( $code, array_keys( $this->parent
->licenses
) ) ) {
868 $entry = $this->parent
->licenses
[$code];
869 if ( isset( $entry['text'] ) ) {
870 $this->setVar( 'wgRightsText', $entry['text'] );
872 $this->setVar( 'wgRightsText', wfMsg( 'config-license-' . $code ) );
874 $this->setVar( 'wgRightsUrl', $entry['url'] );
875 $this->setVar( 'wgRightsIcon', $entry['icon'] );
877 $this->setVar( 'wgRightsText', '' );
878 $this->setVar( 'wgRightsUrl', '' );
879 $this->setVar( 'wgRightsIcon', '' );
882 $extsAvailable = $this->parent
->findExtensions();
883 $extsToInstall = array();
884 foreach( $extsAvailable as $ext ) {
885 if( $this->parent
->request
->getCheck( 'config_ext-' . $ext ) ) {
886 $extsToInstall[] = $ext;
889 $this->parent
->setVar( '_Extensions', $extsToInstall );
895 class WebInstaller_Install
extends WebInstallerPage
{
897 public function execute() {
898 if( $this->parent
->request
->wasPosted() ) {
900 } elseif( $this->getVar( '_InstallDone' ) ) {
902 $status = new Status();
903 $status->warning( 'config-install-alreadydone' );
904 $this->parent
->showStatusBox( $status );
905 } elseif( $this->getVar( '_UpgradeDone' ) ) {
909 $this->addHTML("<ul>");
910 $this->parent
->performInstallation(
911 array( $this, 'startStage'),
912 array( $this, 'endStage' )
914 $this->addHTML("</ul>");
920 public function startStage( $step ) {
921 $this->addHTML( "<li>" . wfMsgHtml( "config-install-$step" ) . wfMsg( 'ellipsis') );
924 public function endStage( $step, $status ) {
925 $msg = $status->isOk() ?
'config-install-step-done' : 'config-install-step-failed';
926 $html = wfMsgHtml( 'word-separator' ) . wfMsgHtml( $msg );
927 if ( !$status->isOk() ) {
928 $html = "<span class=\"error\">$html</span>";
930 $this->addHTML( $html . "</li>\n" );
931 if( !$status->isGood() ) {
932 $this->parent
->showStatusBox( $status );
938 class WebInstaller_Complete
extends WebInstallerPage
{
940 public function execute() {
943 $this->parent
->getInfoBox(
944 wfMsgNoTrans( 'config-install-done',
945 $GLOBALS['wgServer'] . $this->parent
->getURL( array( 'localsettings' => 1 ) ),
946 $GLOBALS['wgServer'] .
947 $this->getVar( 'wgScriptPath' ) . '/index' .
948 $this->getVar( 'wgScriptExtension' )
952 $this->endForm( false );
956 class WebInstaller_Restart
extends WebInstallerPage
{
958 public function execute() {
959 $r = $this->parent
->request
;
960 if ( $r->wasPosted() ) {
961 $really = $r->getVal( 'submit-restart' );
963 $this->parent
->session
= array();
964 $this->parent
->happyPages
= array();
965 $this->parent
->settings
= array();
971 $s = $this->parent
->getWarningBox( wfMsgNoTrans( 'config-help-restart' ) );
972 $this->addHTML( $s );
973 $this->endForm( 'restart' );
978 abstract class WebInstaller_Document
extends WebInstallerPage
{
980 protected abstract function getFileName();
982 public function execute() {
983 $text = $this->getFileContents();
984 $this->parent
->output
->addWikiText( $text );
986 $this->endForm( false );
989 public function getFileContents() {
990 return file_get_contents( dirname( __FILE__
) . '/../../' . $this->getFileName() );
993 protected function formatTextFile( $text ) {
994 $text = str_replace( array( '<', '{{', '[[' ),
995 array( '<', '{{', '[[' ), $text );
996 // replace numbering with [1], [2], etc with MW-style numbering
997 $text = preg_replace( "/\r?\n(\r?\n)?\\[\\d+\\]/m", "\\1#", $text );
998 // join word-wrapped lines into one
1001 $text = preg_replace( "/\n([\\*#])([^\r\n]*?)\r?\n([^\r\n#\\*:]+)/", "\n\\1\\2 \\3", $text );
1002 } while ( $text != $prev );
1003 // turn (bug nnnn) into links
1004 $text = preg_replace_callback('/bug (\d+)/', array( $this, 'replaceBugLinks' ), $text );
1005 // add links to manual to every global variable mentioned
1006 $text = preg_replace_callback('/(\$wg[a-z0-9_]+)/i', array( $this, 'replaceConfigLinks' ), $text );
1007 // special case for <pre> - formatted links
1010 $text = preg_replace( '/^([^\\s].*?)\r?\n[\\s]+(https?:\/\/)/m', "\\1\n:\\2", $text );
1011 } while ( $text != $prev );
1015 private function replaceBugLinks( $matches ) {
1016 return '<span class="config-plainlink">[https://bugzilla.wikimedia.org/' .
1017 $matches[1] . ' bug ' . $matches[1] . ']</span>';
1020 private function replaceConfigLinks( $matches ) {
1021 return '<span class="config-plainlink">[http://www.mediawiki.org/wiki/Manual:' .
1022 $matches[1] . ' ' . $matches[1] . ']</span>';
1027 class WebInstaller_Readme
extends WebInstaller_Document
{
1029 protected function getFileName() { return 'README'; }
1031 public function getFileContents() {
1032 return $this->formatTextFile( parent
::getFileContents() );
1037 class WebInstaller_ReleaseNotes
extends WebInstaller_Document
{
1039 protected function getFileName() { return 'RELEASE-NOTES'; }
1041 public function getFileContents() {
1042 return $this->formatTextFile( parent
::getFileContents() );
1047 class WebInstaller_UpgradeDoc
extends WebInstaller_Document
{
1049 protected function getFileName() { return 'UPGRADE'; }
1051 public function getFileContents() {
1052 return $this->formatTextFile( parent
::getFileContents() );
1057 class WebInstaller_Copying
extends WebInstaller_Document
{
1059 protected function getFileName() { return 'COPYING'; }
1061 public function getFileContents() {
1062 $text = parent
::getFileContents();
1063 $text = str_replace( "\x0C", '', $text );
1064 $text = preg_replace_callback( '/\n[ \t]+/m', array( 'WebInstaller_Copying', 'replaceLeadingSpaces' ), $text );
1065 $text = '<tt>' . nl2br( $text ) . '</tt>';
1069 private static function replaceLeadingSpaces( $matches ) {
1070 return "\n" . str_repeat( ' ', strlen( $matches[0] ) );