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