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