revert r103691 that makes update.php output garbage
[lhc/web/wiklou.git] / includes / installer / WebInstallerPage.php
1 <?php
2 /**
3 * Base code for web installer pages.
4 *
5 * @file
6 * @ingroup Deployment
7 */
8
9 /**
10 * Abstract class to define pages for the web installer.
11 *
12 * @ingroup Deployment
13 * @since 1.17
14 */
15 abstract class WebInstallerPage {
16
17 /**
18 * The WebInstaller object this WebInstallerPage belongs to.
19 *
20 * @var WebInstaller
21 */
22 public $parent;
23
24 public abstract function execute();
25
26 /**
27 * Constructor.
28 *
29 * @param $parent WebInstaller
30 */
31 public function __construct( WebInstaller $parent ) {
32 $this->parent = $parent;
33 }
34
35 /**
36 * Is this a slow-running page in the installer? If so, WebInstaller will
37 * set_time_limit(0) before calling execute(). Right now this only applies
38 * to Install and Upgrade pages
39 */
40 public function isSlow() {
41 return false;
42 }
43
44 public function addHTML( $html ) {
45 $this->parent->output->addHTML( $html );
46 }
47
48 public function startForm() {
49 $this->addHTML(
50 "<div class=\"config-section\">\n" .
51 Html::openElement(
52 'form',
53 array(
54 'method' => 'post',
55 'action' => $this->parent->getUrl( array( 'page' => $this->getName() ) )
56 )
57 ) . "\n"
58 );
59 }
60
61 public function endForm( $continue = 'continue', $back = 'back' ) {
62 $s = "<div class=\"config-submit\">\n";
63 $id = $this->getId();
64
65 if ( $id === false ) {
66 $s .= Html::hidden( 'lastPage', $this->parent->request->getVal( 'lastPage' ) );
67 }
68
69 if ( $continue ) {
70 // Fake submit button for enter keypress (bug 26267)
71 $s .= Xml::submitButton( wfMsg( "config-$continue" ),
72 array( 'name' => "enter-$continue", 'style' =>
73 'visibility:hidden;overflow:hidden;width:1px;margin:0' ) ) . "\n";
74 }
75
76 if ( $back ) {
77 $s .= Xml::submitButton( wfMsg( "config-$back" ),
78 array(
79 'name' => "submit-$back",
80 'tabindex' => $this->parent->nextTabIndex()
81 ) ) . "\n";
82 }
83
84 if ( $continue ) {
85 $s .= Xml::submitButton( wfMsg( "config-$continue" ),
86 array(
87 'name' => "submit-$continue",
88 'tabindex' => $this->parent->nextTabIndex(),
89 ) ) . "\n";
90 }
91
92 $s .= "</div></form></div>\n";
93 $this->addHTML( $s );
94 }
95
96 public function getName() {
97 return str_replace( 'WebInstaller_', '', get_class( $this ) );
98 }
99
100 protected function getId() {
101 return array_search( $this->getName(), $this->parent->pageSequence );
102 }
103
104 public function getVar( $var ) {
105 return $this->parent->getVar( $var );
106 }
107
108 public function setVar( $name, $value ) {
109 $this->parent->setVar( $name, $value );
110 }
111
112 /**
113 * Get the starting tags of a fieldset.
114 *
115 * @param $legend String: message name
116 *
117 * @return string
118 */
119 protected function getFieldsetStart( $legend ) {
120 return "\n<fieldset><legend>" . wfMsgHtml( $legend ) . "</legend>\n";
121 }
122
123 /**
124 * Get the end tag of a fieldset.
125 *
126 * @return string
127 */
128 protected function getFieldsetEnd() {
129 return "</fieldset>\n";
130 }
131
132 /**
133 * Opens a textarea used to display the progress of a long operation
134 */
135 protected function startLiveBox() {
136 $this->addHTML(
137 '<div id="config-spinner" style="display:none;">' .
138 '<img src="../skins/common/images/ajax-loader.gif" /></div>' .
139 '<script>jQuery( "#config-spinner" ).show();</script>' .
140 '<div id="config-live-log">' .
141 '<textarea name="LiveLog" rows="10" cols="30" readonly="readonly">'
142 );
143 $this->parent->output->flush();
144 }
145
146 /**
147 * Opposite to startLiveBox()
148 */
149 protected function endLiveBox() {
150 $this->addHTML( '</textarea></div>
151 <script>jQuery( "#config-spinner" ).hide()</script>' );
152 $this->parent->output->flush();
153 }
154 }
155
156 class WebInstaller_Language extends WebInstallerPage {
157
158 public function execute() {
159 global $wgLang;
160 $r = $this->parent->request;
161 $userLang = $r->getVal( 'userlang' );
162 $contLang = $r->getVal( 'ContLang' );
163
164 $lifetime = intval( ini_get( 'session.gc_maxlifetime' ) );
165 if ( !$lifetime ) {
166 $lifetime = 1440; // PHP default
167 }
168
169 if ( $r->wasPosted() ) {
170 # Do session test
171 if ( $this->parent->getSession( 'test' ) === null ) {
172 $requestTime = $r->getVal( 'LanguageRequestTime' );
173 if ( !$requestTime ) {
174 // The most likely explanation is that the user was knocked back
175 // from another page on POST due to session expiry
176 $msg = 'config-session-expired';
177 } elseif ( time() - $requestTime > $lifetime ) {
178 $msg = 'config-session-expired';
179 } else {
180 $msg = 'config-no-session';
181 }
182 $this->parent->showError( $msg, $wgLang->formatTimePeriod( $lifetime ) );
183 } else {
184 $languages = Language::getLanguageNames();
185 if ( isset( $languages[$userLang] ) ) {
186 $this->setVar( '_UserLang', $userLang );
187 }
188 if ( isset( $languages[$contLang] ) ) {
189 $this->setVar( 'wgLanguageCode', $contLang );
190 }
191 return 'continue';
192 }
193 } elseif ( $this->parent->showSessionWarning ) {
194 # The user was knocked back from another page to the start
195 # This probably indicates a session expiry
196 $this->parent->showError( 'config-session-expired',
197 $wgLang->formatTimePeriod( $lifetime ) );
198 }
199
200 $this->parent->setSession( 'test', true );
201
202 if ( !isset( $languages[$userLang] ) ) {
203 $userLang = $this->getVar( '_UserLang', 'en' );
204 }
205 if ( !isset( $languages[$contLang] ) ) {
206 $contLang = $this->getVar( 'wgLanguageCode', 'en' );
207 }
208 $this->startForm();
209 $s = Html::hidden( 'LanguageRequestTime', time() ) .
210 $this->getLanguageSelector( 'userlang', 'config-your-language', $userLang,
211 $this->parent->getHelpBox( 'config-your-language-help' ) ) .
212 $this->getLanguageSelector( 'ContLang', 'config-wiki-language', $contLang,
213 $this->parent->getHelpBox( 'config-wiki-language-help' ) );
214 $this->addHTML( $s );
215 $this->endForm( 'continue', false );
216 }
217
218 /**
219 * Get a <select> for selecting languages.
220 *
221 * @param $name
222 * @param $label
223 * @param $selectedCode
224 * @param $helpHtml string
225 * @return string
226 */
227 public function getLanguageSelector( $name, $label, $selectedCode, $helpHtml = '' ) {
228 global $wgDummyLanguageCodes;
229
230 $s = $helpHtml;
231
232 $s .= Html::openElement( 'select', array( 'id' => $name, 'name' => $name,
233 'tabindex' => $this->parent->nextTabIndex() ) ) . "\n";
234
235 $languages = Language::getLanguageNames();
236 ksort( $languages );
237 foreach ( $languages as $code => $lang ) {
238 if ( isset( $wgDummyLanguageCodes[$code] ) ) continue;
239 $s .= "\n" . Xml::option( "$code - $lang", $code, $code == $selectedCode );
240 }
241 $s .= "\n</select>\n";
242 return $this->parent->label( $label, $name, $s );
243 }
244
245 }
246
247 class WebInstaller_ExistingWiki extends WebInstallerPage {
248 public function execute() {
249 // If there is no LocalSettings.php, continue to the installer welcome page
250 $vars = Installer::getExistingLocalSettings();
251 if ( !$vars ) {
252 return 'skip';
253 }
254
255 // Check if the upgrade key supplied to the user has appeared in LocalSettings.php
256 if ( $vars['wgUpgradeKey'] !== false
257 && $this->getVar( '_UpgradeKeySupplied' )
258 && $this->getVar( 'wgUpgradeKey' ) === $vars['wgUpgradeKey'] )
259 {
260 // It's there, so the user is authorized
261 $status = $this->handleExistingUpgrade( $vars );
262 if ( $status->isOK() ) {
263 return 'skip';
264 } else {
265 $this->startForm();
266 $this->parent->showStatusBox( $status );
267 $this->endForm( 'continue' );
268 return 'output';
269 }
270 }
271
272 // If there is no $wgUpgradeKey, tell the user to add one to LocalSettings.php
273 if ( $vars['wgUpgradeKey'] === false ) {
274 if ( $this->getVar( 'wgUpgradeKey', false ) === false ) {
275 $secretKey = $this->getVar( 'wgSecretKey' ); // preserve $wgSecretKey
276 $this->parent->generateKeys();
277 $this->setVar( 'wgSecretKey', $secretKey );
278 $this->setVar( '_UpgradeKeySupplied', true );
279 }
280 $this->startForm();
281 $this->addHTML( $this->parent->getInfoBox(
282 wfMsgNoTrans( 'config-upgrade-key-missing',
283 "<pre>\$wgUpgradeKey = '" . $this->getVar( 'wgUpgradeKey' ) . "';</pre>" )
284 ) );
285 $this->endForm( 'continue' );
286 return 'output';
287 }
288
289 // If there is an upgrade key, but it wasn't supplied, prompt the user to enter it
290
291 $r = $this->parent->request;
292 if ( $r->wasPosted() ) {
293 $key = $r->getText( 'config_wgUpgradeKey' );
294 if( !$key || $key !== $vars['wgUpgradeKey'] ) {
295 $this->parent->showError( 'config-localsettings-badkey' );
296 $this->showKeyForm();
297 return 'output';
298 }
299 // Key was OK
300 $status = $this->handleExistingUpgrade( $vars );
301 if ( $status->isOK() ) {
302 return 'continue';
303 } else {
304 $this->parent->showStatusBox( $status );
305 $this->showKeyForm();
306 return 'output';
307 }
308 } else {
309 $this->showKeyForm();
310 return 'output';
311 }
312 }
313
314 /**
315 * Show the "enter key" form
316 */
317 protected function showKeyForm() {
318 $this->startForm();
319 $this->addHTML(
320 $this->parent->getInfoBox( wfMsgNoTrans( 'config-localsettings-upgrade' ) ).
321 '<br />' .
322 $this->parent->getTextBox( array(
323 'var' => 'wgUpgradeKey',
324 'label' => 'config-localsettings-key',
325 'attribs' => array( 'autocomplete' => 'off' ),
326 ) )
327 );
328 $this->endForm( 'continue' );
329 }
330
331 protected function importVariables( $names, $vars ) {
332 $status = Status::newGood();
333 foreach ( $names as $name ) {
334 if ( !isset( $vars[$name] ) ) {
335 $status->fatal( 'config-localsettings-incomplete', $name );
336 }
337 $this->setVar( $name, $vars[$name] );
338 }
339 return $status;
340 }
341
342 /**
343 * Initiate an upgrade of the existing database
344 * @param $vars Variables from LocalSettings.php and AdminSettings.php
345 * @return Status
346 */
347 protected function handleExistingUpgrade( $vars ) {
348 // Check $wgDBtype
349 if ( !isset( $vars['wgDBtype'] ) ||
350 !in_array( $vars['wgDBtype'], Installer::getDBTypes() ) ) {
351 return Status::newFatal( 'config-localsettings-connection-error', '' );
352 }
353
354 // Set the relevant variables from LocalSettings.php
355 $requiredVars = array( 'wgDBtype' );
356 $status = $this->importVariables( $requiredVars , $vars );
357 $installer = $this->parent->getDBInstaller();
358 $status->merge( $this->importVariables( $installer->getGlobalNames(), $vars ) );
359 if ( !$status->isOK() ) {
360 return $status;
361 }
362
363 if ( isset( $vars['wgDBadminuser'] ) ) {
364 $this->setVar( '_InstallUser', $vars['wgDBadminuser'] );
365 } else {
366 $this->setVar( '_InstallUser', $vars['wgDBuser'] );
367 }
368 if ( isset( $vars['wgDBadminpassword'] ) ) {
369 $this->setVar( '_InstallPassword', $vars['wgDBadminpassword'] );
370 } else {
371 $this->setVar( '_InstallPassword', $vars['wgDBpassword'] );
372 }
373
374 // Test the database connection
375 $status = $installer->getConnection();
376 if ( !$status->isOK() ) {
377 // Adjust the error message to explain things correctly
378 $status->replaceMessage( 'config-connection-error',
379 'config-localsettings-connection-error' );
380 return $status;
381 }
382
383 // All good
384 $this->setVar( '_ExistingDBSettings', true );
385 return $status;
386 }
387 }
388
389 class WebInstaller_Welcome extends WebInstallerPage {
390
391 public function execute() {
392 if ( $this->parent->request->wasPosted() ) {
393 if ( $this->getVar( '_Environment' ) ) {
394 return 'continue';
395 }
396 }
397 $this->parent->output->addWikiText( wfMsgNoTrans( 'config-welcome' ) );
398 $status = $this->parent->doEnvironmentChecks();
399 if ( $status->isGood() ) {
400 $this->parent->output->addHTML( '<span class="success-message">' .
401 wfMsgHtml( 'config-env-good' ) . '</span>' );
402 $this->parent->output->addWikiText( wfMsgNoTrans( 'config-copyright',
403 SpecialVersion::getCopyrightAndAuthorList() ) );
404 $this->startForm();
405 $this->endForm();
406 } else {
407 $this->parent->showStatusMessage( $status );
408 }
409 }
410
411 }
412
413 class WebInstaller_DBConnect extends WebInstallerPage {
414
415 public function execute() {
416 if ( $this->getVar( '_ExistingDBSettings' ) ) {
417 return 'skip';
418 }
419
420 $r = $this->parent->request;
421 if ( $r->wasPosted() ) {
422 $status = $this->submit();
423
424 if ( $status->isGood() ) {
425 $this->setVar( '_UpgradeDone', false );
426 return 'continue';
427 } else {
428 $this->parent->showStatusBox( $status );
429 }
430 }
431
432 $this->startForm();
433
434 $types = "<ul class=\"config-settings-block\">\n";
435 $settings = '';
436 $defaultType = $this->getVar( 'wgDBtype' );
437
438 $dbSupport = '';
439 foreach( $this->parent->getDBTypes() as $type ) {
440 $link = DatabaseBase::factory( $type )->getSoftwareLink();
441 $dbSupport .= wfMsgNoTrans( "config-support-$type", $link ) . "\n";
442 }
443 $this->addHTML( $this->parent->getInfoBox(
444 wfMsg( 'config-support-info', $dbSupport ) ) );
445
446 foreach ( $this->parent->getVar( '_CompiledDBs' ) as $type ) {
447 $installer = $this->parent->getDBInstaller( $type );
448 $types .=
449 '<li>' .
450 Xml::radioLabel(
451 $installer->getReadableName(),
452 'DBType',
453 $type,
454 "DBType_$type",
455 $type == $defaultType,
456 array( 'class' => 'dbRadio', 'rel' => "DB_wrapper_$type" )
457 ) .
458 "</li>\n";
459
460 $settings .=
461 Html::openElement( 'div', array( 'id' => 'DB_wrapper_' . $type,
462 'class' => 'dbWrapper' ) ) .
463 Html::element( 'h3', array(), wfMsg( 'config-header-' . $type ) ) .
464 $installer->getConnectForm() .
465 "</div>\n";
466 }
467 $types .= "</ul><br style=\"clear: left\"/>\n";
468
469 $this->addHTML(
470 $this->parent->label( 'config-db-type', false, $types ) .
471 $settings
472 );
473
474 $this->endForm();
475 }
476
477 public function submit() {
478 $r = $this->parent->request;
479 $type = $r->getVal( 'DBType' );
480 $this->setVar( 'wgDBtype', $type );
481 $installer = $this->parent->getDBInstaller( $type );
482 if ( !$installer ) {
483 return Status::newFatal( 'config-invalid-db-type' );
484 }
485 return $installer->submitConnectForm();
486 }
487
488 }
489
490 class WebInstaller_Upgrade extends WebInstallerPage {
491 public function isSlow() {
492 return true;
493 }
494
495 public function execute() {
496 if ( $this->getVar( '_UpgradeDone' ) ) {
497 // Allow regeneration of LocalSettings.php, unless we are working
498 // from a pre-existing LocalSettings.php file and we want to avoid
499 // leaking its contents
500 if ( $this->parent->request->wasPosted() && !$this->getVar( '_ExistingDBSettings' ) ) {
501 // Done message acknowledged
502 return 'continue';
503 } else {
504 // Back button click
505 // Show the done message again
506 // Make them click back again if they want to do the upgrade again
507 $this->showDoneMessage();
508 return 'output';
509 }
510 }
511
512 // wgDBtype is generally valid here because otherwise the previous page
513 // (connect) wouldn't have declared its happiness
514 $type = $this->getVar( 'wgDBtype' );
515 $installer = $this->parent->getDBInstaller( $type );
516
517 if ( !$installer->needsUpgrade() ) {
518 return 'skip';
519 }
520
521 if ( $this->parent->request->wasPosted() ) {
522 $installer->preUpgrade();
523
524 $this->startLiveBox();
525 $result = $installer->doUpgrade();
526 $this->endLiveBox();
527
528 if ( $result ) {
529 // If they're going to possibly regenerate LocalSettings, we
530 // need to create the upgrade/secret keys. Bug 26481
531 if( !$this->getVar( '_ExistingDBSettings' ) ) {
532 $this->parent->generateKeys();
533 }
534 $this->setVar( '_UpgradeDone', true );
535 $this->showDoneMessage();
536 return 'output';
537 }
538 }
539
540 $this->startForm();
541 $this->addHTML( $this->parent->getInfoBox(
542 wfMsgNoTrans( 'config-can-upgrade', $GLOBALS['wgVersion'] ) ) );
543 $this->endForm();
544 }
545
546 public function showDoneMessage() {
547 $this->startForm();
548 $regenerate = !$this->getVar( '_ExistingDBSettings' );
549 if ( $regenerate ) {
550 $msg = 'config-upgrade-done';
551 } else {
552 $msg = 'config-upgrade-done-no-regenerate';
553 }
554 $this->parent->disableLinkPopups();
555 $this->addHTML(
556 $this->parent->getInfoBox(
557 wfMsgNoTrans( $msg,
558 $this->getVar( 'wgServer' ) .
559 $this->getVar( 'wgScriptPath' ) . '/index' .
560 $this->getVar( 'wgScriptExtension' )
561 ), 'tick-32.png'
562 )
563 );
564 $this->parent->restoreLinkPopups();
565 $this->endForm( $regenerate ? 'regenerate' : false, false );
566 }
567
568 }
569
570 class WebInstaller_DBSettings extends WebInstallerPage {
571
572 public function execute() {
573 $installer = $this->parent->getDBInstaller( $this->getVar( 'wgDBtype' ) );
574
575 $r = $this->parent->request;
576 if ( $r->wasPosted() ) {
577 $status = $installer->submitSettingsForm();
578 if ( $status === false ) {
579 return 'skip';
580 } elseif ( $status->isGood() ) {
581 return 'continue';
582 } else {
583 $this->parent->showStatusBox( $status );
584 }
585 }
586
587 $form = $installer->getSettingsForm();
588 if ( $form === false ) {
589 return 'skip';
590 }
591
592 $this->startForm();
593 $this->addHTML( $form );
594 $this->endForm();
595 }
596
597 }
598
599 class WebInstaller_Name extends WebInstallerPage {
600
601 public function execute() {
602 $r = $this->parent->request;
603 if ( $r->wasPosted() ) {
604 if ( $this->submit() ) {
605 return 'continue';
606 }
607 }
608
609 $this->startForm();
610
611 // Encourage people to not name their site 'MediaWiki' by blanking the
612 // field. I think that was the intent with the original $GLOBALS['wgSitename']
613 // but these two always were the same so had the effect of making the
614 // installer forget $wgSitename when navigating back to this page.
615 if ( $this->getVar( 'wgSitename' ) == 'MediaWiki' ) {
616 $this->setVar( 'wgSitename', '' );
617 }
618
619 // Set wgMetaNamespace to something valid before we show the form.
620 // $wgMetaNamespace defaults to $wgSiteName which is 'MediaWiki'
621 $metaNS = $this->getVar( 'wgMetaNamespace' );
622 $this->setVar( 'wgMetaNamespace', wfMsgForContent( 'config-ns-other-default' ) );
623
624 $this->addHTML(
625 $this->parent->getTextBox( array(
626 'var' => 'wgSitename',
627 'label' => 'config-site-name',
628 'help' => $this->parent->getHelpBox( 'config-site-name-help' )
629 ) ) .
630 $this->parent->getRadioSet( array(
631 'var' => '_NamespaceType',
632 'label' => 'config-project-namespace',
633 'itemLabelPrefix' => 'config-ns-',
634 'values' => array( 'site-name', 'generic', 'other' ),
635 'commonAttribs' => array( 'class' => 'enableForOther',
636 'rel' => 'config_wgMetaNamespace' ),
637 'help' => $this->parent->getHelpBox( 'config-project-namespace-help' )
638 ) ) .
639 $this->parent->getTextBox( array(
640 'var' => 'wgMetaNamespace',
641 'label' => '', //TODO: Needs a label?
642 'attribs' => array( 'readonly' => 'readonly', 'class' => 'enabledByOther' ),
643
644 ) ) .
645 $this->getFieldSetStart( 'config-admin-box' ) .
646 $this->parent->getTextBox( array(
647 'var' => '_AdminName',
648 'label' => 'config-admin-name',
649 'help' => $this->parent->getHelpBox( 'config-admin-help' )
650 ) ) .
651 $this->parent->getPasswordBox( array(
652 'var' => '_AdminPassword',
653 'label' => 'config-admin-password',
654 ) ) .
655 $this->parent->getPasswordBox( array(
656 'var' => '_AdminPassword2',
657 'label' => 'config-admin-password-confirm'
658 ) ) .
659 $this->parent->getTextBox( array(
660 'var' => '_AdminEmail',
661 'label' => 'config-admin-email',
662 'help' => $this->parent->getHelpBox( 'config-admin-email-help' )
663 ) ) .
664 $this->parent->getCheckBox( array(
665 'var' => '_Subscribe',
666 'label' => 'config-subscribe',
667 'help' => $this->parent->getHelpBox( 'config-subscribe-help' )
668 ) ) .
669 $this->getFieldSetEnd() .
670 $this->parent->getInfoBox( wfMsg( 'config-almost-done' ) ) .
671 $this->parent->getRadioSet( array(
672 'var' => '_SkipOptional',
673 'itemLabelPrefix' => 'config-optional-',
674 'values' => array( 'continue', 'skip' )
675 ) )
676 );
677
678 // Restore the default value
679 $this->setVar( 'wgMetaNamespace', $metaNS );
680
681 $this->endForm();
682 return 'output';
683 }
684
685 public function submit() {
686 $retVal = true;
687 $this->parent->setVarsFromRequest( array( 'wgSitename', '_NamespaceType',
688 '_AdminName', '_AdminPassword', '_AdminPassword2', '_AdminEmail',
689 '_Subscribe', '_SkipOptional', 'wgMetaNamespace' ) );
690
691 // Validate site name
692 if ( strval( $this->getVar( 'wgSitename' ) ) === '' ) {
693 $this->parent->showError( 'config-site-name-blank' );
694 $retVal = false;
695 }
696
697 // Fetch namespace
698 $nsType = $this->getVar( '_NamespaceType' );
699 if ( $nsType == 'site-name' ) {
700 $name = $this->getVar( 'wgSitename' );
701 // Sanitize for namespace
702 // This algorithm should match the JS one in WebInstallerOutput.php
703 $name = preg_replace( '/[\[\]\{\}|#<>%+? ]/', '_', $name );
704 $name = str_replace( '&', '&amp;', $name );
705 $name = preg_replace( '/__+/', '_', $name );
706 $name = ucfirst( trim( $name, '_' ) );
707 } elseif ( $nsType == 'generic' ) {
708 $name = wfMsg( 'config-ns-generic' );
709 } else { // other
710 $name = $this->getVar( 'wgMetaNamespace' );
711 }
712
713 // Validate namespace
714 if ( strpos( $name, ':' ) !== false ) {
715 $good = false;
716 } else {
717 // Title-style validation
718 $title = Title::newFromText( $name );
719 if ( !$title ) {
720 $good = $nsType == 'site-name';
721 } else {
722 $name = $title->getDBkey();
723 $good = true;
724 }
725 }
726 if ( !$good ) {
727 $this->parent->showError( 'config-ns-invalid', $name );
728 $retVal = false;
729 }
730
731 // Make sure it won't conflict with any existing namespaces
732 global $wgContLang;
733 $nsIndex = $wgContLang->getNsIndex( $name );
734 if( $nsIndex !== false && $nsIndex !== NS_PROJECT ) {
735 $this->parent->showError( 'config-ns-conflict', $name );
736 $retVal = false;
737 }
738
739 $this->setVar( 'wgMetaNamespace', $name );
740
741 // Validate username for creation
742 $name = $this->getVar( '_AdminName' );
743 if ( strval( $name ) === '' ) {
744 $this->parent->showError( 'config-admin-name-blank' );
745 $cname = $name;
746 $retVal = false;
747 } else {
748 $cname = User::getCanonicalName( $name, 'creatable' );
749 if ( $cname === false ) {
750 $this->parent->showError( 'config-admin-name-invalid', $name );
751 $retVal = false;
752 } else {
753 $this->setVar( '_AdminName', $cname );
754 }
755 }
756
757 // Validate password
758 $msg = false;
759 $pwd = $this->getVar( '_AdminPassword' );
760 $user = User::newFromName( $cname );
761 $valid = $user && $user->getPasswordValidity( $pwd );
762 if ( strval( $pwd ) === '' ) {
763 # $user->getPasswordValidity just checks for $wgMinimalPasswordLength.
764 # This message is more specific and helpful.
765 $msg = 'config-admin-password-blank';
766 } elseif ( $pwd !== $this->getVar( '_AdminPassword2' ) ) {
767 $msg = 'config-admin-password-mismatch';
768 } elseif ( $valid !== true ) {
769 # As of writing this will only catch the username being e.g. 'FOO' and
770 # the password 'foo'
771 $msg = $valid;
772 }
773 if ( $msg !== false ) {
774 call_user_func_array( array( $this->parent, 'showError' ), (array)$msg );
775 $this->setVar( '_AdminPassword', '' );
776 $this->setVar( '_AdminPassword2', '' );
777 $retVal = false;
778 }
779
780 // Validate e-mail if provided
781 $email = $this->getVar( '_AdminEmail' );
782 if( $email && !Sanitizer::validateEmail( $email ) ) {
783 $this->parent->showError( 'config-admin-error-bademail' );
784 $retVal = false;
785 }
786 // If they asked to subscribe to mediawiki-announce but didn't give
787 // an e-mail, show an error. Bug 29332
788 if( !$email && $this->getVar( '_Subscribe' ) ) {
789 $this->parent->showError( 'config-subscribe-noemail' );
790 $retVal = false;
791 }
792
793 return $retVal;
794 }
795
796 }
797
798 class WebInstaller_Options extends WebInstallerPage {
799
800 public function execute() {
801 if ( $this->getVar( '_SkipOptional' ) == 'skip' ) {
802 return 'skip';
803 }
804 if ( $this->parent->request->wasPosted() ) {
805 if ( $this->submit() ) {
806 return 'continue';
807 }
808 }
809
810 $emailwrapperStyle = $this->getVar( 'wgEnableEmail' ) ? '' : 'display: none';
811 $this->startForm();
812 $this->addHTML(
813 # User Rights
814 $this->parent->getRadioSet( array(
815 'var' => '_RightsProfile',
816 'label' => 'config-profile',
817 'itemLabelPrefix' => 'config-profile-',
818 'values' => array_keys( $this->parent->rightsProfiles ),
819 ) ) .
820 $this->parent->getInfoBox( wfMsgNoTrans( 'config-profile-help' ) ) .
821
822 # Licensing
823 $this->parent->getRadioSet( array(
824 'var' => '_LicenseCode',
825 'label' => 'config-license',
826 'itemLabelPrefix' => 'config-license-',
827 'values' => array_keys( $this->parent->licenses ),
828 'commonAttribs' => array( 'class' => 'licenseRadio' ),
829 ) ) .
830 $this->getCCChooser() .
831 $this->parent->getHelpBox( 'config-license-help' ) .
832
833 # E-mail
834 $this->getFieldSetStart( 'config-email-settings' ) .
835 $this->parent->getCheckBox( array(
836 'var' => 'wgEnableEmail',
837 'label' => 'config-enable-email',
838 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'emailwrapper' ),
839 ) ) .
840 $this->parent->getHelpBox( 'config-enable-email-help' ) .
841 "<div id=\"emailwrapper\" style=\"$emailwrapperStyle\">" .
842 $this->parent->getTextBox( array(
843 'var' => 'wgPasswordSender',
844 'label' => 'config-email-sender'
845 ) ) .
846 $this->parent->getHelpBox( 'config-email-sender-help' ) .
847 $this->parent->getCheckBox( array(
848 'var' => 'wgEnableUserEmail',
849 'label' => 'config-email-user',
850 ) ) .
851 $this->parent->getHelpBox( 'config-email-user-help' ) .
852 $this->parent->getCheckBox( array(
853 'var' => 'wgEnotifUserTalk',
854 'label' => 'config-email-usertalk',
855 ) ) .
856 $this->parent->getHelpBox( 'config-email-usertalk-help' ) .
857 $this->parent->getCheckBox( array(
858 'var' => 'wgEnotifWatchlist',
859 'label' => 'config-email-watchlist',
860 ) ) .
861 $this->parent->getHelpBox( 'config-email-watchlist-help' ) .
862 $this->parent->getCheckBox( array(
863 'var' => 'wgEmailAuthentication',
864 'label' => 'config-email-auth',
865 ) ) .
866 $this->parent->getHelpBox( 'config-email-auth-help' ) .
867 "</div>" .
868 $this->getFieldSetEnd()
869 );
870
871 $extensions = $this->parent->findExtensions();
872
873 if( $extensions ) {
874 $extHtml = $this->getFieldSetStart( 'config-extensions' );
875
876 foreach( $extensions as $ext ) {
877 $extHtml .= $this->parent->getCheckBox( array(
878 'var' => "ext-$ext",
879 'rawtext' => $ext,
880 ) );
881 }
882
883 $extHtml .= $this->parent->getHelpBox( 'config-extensions-help' ) .
884 $this->getFieldSetEnd();
885 $this->addHTML( $extHtml );
886 }
887
888 // Having / in paths in Windows looks funny :)
889 $this->setVar( 'wgDeletedDirectory',
890 str_replace(
891 '/', DIRECTORY_SEPARATOR,
892 $this->getVar( 'wgDeletedDirectory' )
893 )
894 );
895
896 $uploadwrapperStyle = $this->getVar( 'wgEnableUploads' ) ? '' : 'display: none';
897 $this->addHTML(
898 # Uploading
899 $this->getFieldSetStart( 'config-upload-settings' ) .
900 $this->parent->getCheckBox( array(
901 'var' => 'wgEnableUploads',
902 'label' => 'config-upload-enable',
903 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'uploadwrapper' ),
904 'help' => $this->parent->getHelpBox( 'config-upload-help' )
905 ) ) .
906 '<div id="uploadwrapper" style="' . $uploadwrapperStyle . '">' .
907 $this->parent->getTextBox( array(
908 'var' => 'wgDeletedDirectory',
909 'label' => 'config-upload-deleted',
910 'attribs' => array( 'dir' => 'ltr' ),
911 'help' => $this->parent->getHelpBox( 'config-upload-deleted-help' )
912 ) ) .
913 '</div>' .
914 $this->parent->getTextBox( array(
915 'var' => 'wgLogo',
916 'label' => 'config-logo',
917 'attribs' => array( 'dir' => 'ltr' ),
918 'help' => $this->parent->getHelpBox( 'config-logo-help' )
919 ) )
920 );
921 $this->addHTML(
922 $this->parent->getCheckBox( array(
923 'var' => 'wgUseInstantCommons',
924 'label' => 'config-instantcommons',
925 'help' => $this->parent->getHelpBox( 'config-instantcommons-help' )
926 ) ) .
927 $this->getFieldSetEnd()
928 );
929
930 $caches = array( 'none' );
931 if( count( $this->getVar( '_Caches' ) ) ) {
932 $caches[] = 'accel';
933 }
934 $caches[] = 'memcached';
935
936 // We'll hide/show this on demand when the value changes, see config.js.
937 $cacheval = $this->getVar( 'wgMainCacheType' );
938 if (!$cacheval) {
939 // We need to set a default here; but don't hardcode it
940 // or we lose it every time we reload the page for validation
941 // or going back!
942 $cacheval = 'none';
943 }
944 $hidden = ($cacheval == 'memcached') ? '' : 'display: none';
945 $this->addHTML(
946 # Advanced settings
947 $this->getFieldSetStart( 'config-advanced-settings' ) .
948 # Object cache settings
949 $this->parent->getRadioSet( array(
950 'var' => 'wgMainCacheType',
951 'label' => 'config-cache-options',
952 'itemLabelPrefix' => 'config-cache-',
953 'values' => $caches,
954 'value' => $cacheval,
955 ) ) .
956 $this->parent->getHelpBox( 'config-cache-help' ) .
957 "<div id=\"config-memcachewrapper\" style=\"$hidden\">" .
958 $this->parent->getTextArea( array(
959 'var' => '_MemCachedServers',
960 'label' => 'config-memcached-servers',
961 'help' => $this->parent->getHelpBox( 'config-memcached-help' )
962 ) ) .
963 '</div>' .
964 $this->getFieldSetEnd()
965 );
966 $this->endForm();
967 }
968
969 /**
970 * @return string
971 */
972 public function getCCPartnerUrl() {
973 $server = $this->getVar( 'wgServer' );
974 $exitUrl = $server . $this->parent->getUrl( array(
975 'page' => 'Options',
976 'SubmitCC' => 'indeed',
977 'config__LicenseCode' => 'cc',
978 'config_wgRightsUrl' => '[license_url]',
979 'config_wgRightsText' => '[license_name]',
980 'config_wgRightsIcon' => '[license_button]',
981 ) );
982 $styleUrl = $server . dirname( dirname( $this->parent->getUrl() ) ) .
983 '/skins/common/config-cc.css';
984 $iframeUrl = 'http://creativecommons.org/license/?' .
985 wfArrayToCGI( array(
986 'partner' => 'MediaWiki',
987 'exit_url' => $exitUrl,
988 'lang' => $this->getVar( '_UserLang' ),
989 'stylesheet' => $styleUrl,
990 ) );
991 return $iframeUrl;
992 }
993
994 public function getCCChooser() {
995 $iframeAttribs = array(
996 'class' => 'config-cc-iframe',
997 'name' => 'config-cc-iframe',
998 'id' => 'config-cc-iframe',
999 'frameborder' => 0,
1000 'width' => '100%',
1001 'height' => '100%',
1002 );
1003 if ( $this->getVar( '_CCDone' ) ) {
1004 $iframeAttribs['src'] = $this->parent->getUrl( array( 'ShowCC' => 'yes' ) );
1005 } else {
1006 $iframeAttribs['src'] = $this->getCCPartnerUrl();
1007 }
1008 $wrapperStyle = ($this->getVar('_LicenseCode') == 'cc-choose') ? '' : 'display: none';
1009
1010 return
1011 "<div class=\"config-cc-wrapper\" id=\"config-cc-wrapper\" style=\"$wrapperStyle\">\n" .
1012 Html::element( 'iframe', $iframeAttribs, '', false /* not short */ ) .
1013 "</div>\n";
1014 }
1015
1016 public function getCCDoneBox() {
1017 $js = "parent.document.getElementById('config-cc-wrapper').style.height = '$1';";
1018 // If you change this height, also change it in config.css
1019 $expandJs = str_replace( '$1', '54em', $js );
1020 $reduceJs = str_replace( '$1', '70px', $js );
1021 return
1022 '<p>'.
1023 Html::element( 'img', array( 'src' => $this->getVar( 'wgRightsIcon' ) ) ) .
1024 '&#160;&#160;' .
1025 htmlspecialchars( $this->getVar( 'wgRightsText' ) ) .
1026 "</p>\n" .
1027 "<p style=\"text-align: center\">" .
1028 Html::element( 'a',
1029 array(
1030 'href' => $this->getCCPartnerUrl(),
1031 'onclick' => $expandJs,
1032 ),
1033 wfMsg( 'config-cc-again' )
1034 ) .
1035 "</p>\n" .
1036 "<script type=\"text/javascript\">\n" .
1037 # Reduce the wrapper div height
1038 htmlspecialchars( $reduceJs ) .
1039 "\n" .
1040 "</script>\n";
1041 }
1042
1043 public function submitCC() {
1044 $newValues = $this->parent->setVarsFromRequest(
1045 array( 'wgRightsUrl', 'wgRightsText', 'wgRightsIcon' ) );
1046 if ( count( $newValues ) != 3 ) {
1047 $this->parent->showError( 'config-cc-error' );
1048 return;
1049 }
1050 $this->setVar( '_CCDone', true );
1051 $this->addHTML( $this->getCCDoneBox() );
1052 }
1053
1054 public function submit() {
1055 $this->parent->setVarsFromRequest( array( '_RightsProfile', '_LicenseCode',
1056 'wgEnableEmail', 'wgPasswordSender', 'wgEnableUploads', 'wgLogo',
1057 'wgEnableUserEmail', 'wgEnotifUserTalk', 'wgEnotifWatchlist',
1058 'wgEmailAuthentication', 'wgMainCacheType', '_MemCachedServers',
1059 'wgUseInstantCommons' ) );
1060
1061 if ( !in_array( $this->getVar( '_RightsProfile' ),
1062 array_keys( $this->parent->rightsProfiles ) ) )
1063 {
1064 reset( $this->parent->rightsProfiles );
1065 $this->setVar( '_RightsProfile', key( $this->parent->rightsProfiles ) );
1066 }
1067
1068 $code = $this->getVar( '_LicenseCode' );
1069 if ( $code == 'cc-choose' ) {
1070 if ( !$this->getVar( '_CCDone' ) ) {
1071 $this->parent->showError( 'config-cc-not-chosen' );
1072 return false;
1073 }
1074 } elseif ( in_array( $code, array_keys( $this->parent->licenses ) ) ) {
1075 $entry = $this->parent->licenses[$code];
1076 if ( isset( $entry['text'] ) ) {
1077 $this->setVar( 'wgRightsText', $entry['text'] );
1078 } else {
1079 $this->setVar( 'wgRightsText', wfMsg( 'config-license-' . $code ) );
1080 }
1081 $this->setVar( 'wgRightsUrl', $entry['url'] );
1082 $this->setVar( 'wgRightsIcon', $entry['icon'] );
1083 } else {
1084 $this->setVar( 'wgRightsText', '' );
1085 $this->setVar( 'wgRightsUrl', '' );
1086 $this->setVar( 'wgRightsIcon', '' );
1087 }
1088
1089 $extsAvailable = $this->parent->findExtensions();
1090 $extsToInstall = array();
1091 foreach( $extsAvailable as $ext ) {
1092 if( $this->parent->request->getCheck( 'config_ext-' . $ext ) ) {
1093 $extsToInstall[] = $ext;
1094 }
1095 }
1096 $this->parent->setVar( '_Extensions', $extsToInstall );
1097
1098 if( $this->getVar( 'wgMainCacheType' ) == 'memcached' ) {
1099 $memcServers = explode( "\n", $this->getVar( '_MemCachedServers' ) );
1100 if( !$memcServers ) {
1101 $this->parent->showError( 'config-memcache-needservers' );
1102 return false;
1103 }
1104
1105 foreach( $memcServers as $server ) {
1106 $memcParts = explode( ":", $server, 2 );
1107 if ( !isset( $memcParts[0] )
1108 || ( !IP::isValid( $memcParts[0] )
1109 && ( gethostbyname( $memcParts[0] ) == $memcParts[0] ) ) ) {
1110 $this->parent->showError( 'config-memcache-badip', $memcParts[0] );
1111 return false;
1112 } elseif( !isset( $memcParts[1] ) ) {
1113 $this->parent->showError( 'config-memcache-noport', $memcParts[0] );
1114 return false;
1115 } elseif( $memcParts[1] < 1 || $memcParts[1] > 65535 ) {
1116 $this->parent->showError( 'config-memcache-badport', 1, 65535 );
1117 return false;
1118 }
1119 }
1120 }
1121 return true;
1122 }
1123
1124 }
1125
1126 class WebInstaller_Install extends WebInstallerPage {
1127 public function isSlow() {
1128 return true;
1129 }
1130
1131 public function execute() {
1132 if( $this->getVar( '_UpgradeDone' ) ) {
1133 return 'skip';
1134 } elseif( $this->getVar( '_InstallDone' ) ) {
1135 return 'continue';
1136 } elseif( $this->parent->request->wasPosted() ) {
1137 $this->startForm();
1138 $this->addHTML("<ul>");
1139 $results = $this->parent->performInstallation(
1140 array( $this, 'startStage'),
1141 array( $this, 'endStage' )
1142 );
1143 $this->addHTML("</ul>");
1144 // PerformInstallation bails on a fatal, so make sure the last item
1145 // completed before giving 'next.' Likewise, only provide back on failure
1146 $lastStep = end( $results );
1147 $continue = $lastStep->isOK() ? 'continue' : false;
1148 $back = $lastStep->isOK() ? false : 'back';
1149 $this->endForm( $continue, $back );
1150 } else {
1151 $this->startForm();
1152 $this->addHTML( $this->parent->getInfoBox( wfMsgNoTrans( 'config-install-begin' ) ) );
1153 $this->endForm();
1154 }
1155 return true;
1156 }
1157
1158 public function startStage( $step ) {
1159 $this->addHTML( "<li>" . wfMsgHtml( "config-install-$step" ) . wfMsg( 'ellipsis') );
1160 if ( $step == 'extension-tables' ) {
1161 $this->startLiveBox();
1162 }
1163 }
1164
1165 /**
1166 * @param $step
1167 * @param $status Status
1168 */
1169 public function endStage( $step, $status ) {
1170 if ( $step == 'extension-tables' ) {
1171 $this->endLiveBox();
1172 }
1173 $msg = $status->isOk() ? 'config-install-step-done' : 'config-install-step-failed';
1174 $html = wfMsgHtml( 'word-separator' ) . wfMsgHtml( $msg );
1175 if ( !$status->isOk() ) {
1176 $html = "<span class=\"error\">$html</span>";
1177 }
1178 $this->addHTML( $html . "</li>\n" );
1179 if( !$status->isGood() ) {
1180 $this->parent->showStatusBox( $status );
1181 }
1182 }
1183
1184 }
1185
1186 class WebInstaller_Complete extends WebInstallerPage {
1187
1188 public function execute() {
1189 // Pop up a dialog box, to make it difficult for the user to forget
1190 // to download the file
1191 $lsUrl = $this->getVar( 'wgServer' ) . $this->parent->getURL( array( 'localsettings' => 1 ) );
1192 if ( isset( $_SERVER['HTTP_USER_AGENT'] ) &&
1193 strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE' ) !== false ) {
1194 // JS appears the only method that works consistently with IE7+
1195 $this->addHtml( "\n<script type=\"" . $GLOBALS['wgJsMimeType'] .
1196 '">jQuery( document ).ready( function() { document.location=' .
1197 Xml::encodeJsVar( $lsUrl) . "; } );</script>\n" );
1198 } else {
1199 $this->parent->request->response()->header( "Refresh: 0;url=$lsUrl" );
1200 }
1201
1202 $this->startForm();
1203 $this->parent->disableLinkPopups();
1204 $this->addHTML(
1205 $this->parent->getInfoBox(
1206 wfMsgNoTrans( 'config-install-done',
1207 $lsUrl,
1208 $this->getVar( 'wgServer' ) .
1209 $this->getVar( 'wgScriptPath' ) . '/index' .
1210 $this->getVar( 'wgScriptExtension' ),
1211 '<downloadlink/>'
1212 ), 'tick-32.png'
1213 )
1214 );
1215 $this->parent->restoreLinkPopups();
1216 $this->endForm( false, false );
1217 }
1218 }
1219
1220 class WebInstaller_Restart extends WebInstallerPage {
1221
1222 public function execute() {
1223 $r = $this->parent->request;
1224 if ( $r->wasPosted() ) {
1225 $really = $r->getVal( 'submit-restart' );
1226 if ( $really ) {
1227 $this->parent->reset();
1228 }
1229 return 'continue';
1230 }
1231
1232 $this->startForm();
1233 $s = $this->parent->getWarningBox( wfMsgNoTrans( 'config-help-restart' ) );
1234 $this->addHTML( $s );
1235 $this->endForm( 'restart' );
1236 }
1237
1238 }
1239
1240 abstract class WebInstaller_Document extends WebInstallerPage {
1241
1242 protected abstract function getFileName();
1243
1244 public function execute() {
1245 $text = $this->getFileContents();
1246 $text = InstallDocFormatter::format( $text );
1247 $this->parent->output->addWikiText( $text );
1248 $this->startForm();
1249 $this->endForm( false );
1250 }
1251
1252 public function getFileContents() {
1253 return file_get_contents( dirname( __FILE__ ) . '/../../' . $this->getFileName() );
1254 }
1255
1256 }
1257
1258 class WebInstaller_Readme extends WebInstaller_Document {
1259 protected function getFileName() { return 'README'; }
1260 }
1261
1262 class WebInstaller_ReleaseNotes extends WebInstaller_Document {
1263 protected function getFileName() { return 'RELEASE-NOTES'; }
1264 }
1265
1266 class WebInstaller_UpgradeDoc extends WebInstaller_Document {
1267 protected function getFileName() { return 'UPGRADE'; }
1268 }
1269
1270 class WebInstaller_Copying extends WebInstaller_Document {
1271 protected function getFileName() { return 'COPYING'; }
1272 }
1273