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