Followup r78786: pass $fname in the raw SQL case too
[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 /**
600 * Uncomment this feature once we've got some sort of API to mailman
601 * to handle these subscriptions. Some dummy wrapper script on the
602 * mailman box that shell's out to mailman/bin/add_members would do
603 $this->parent->getCheckBox( array(
604 'var' => '_Subscribe',
605 'label' => 'config-subscribe',
606 'help' => $this->parent->getHelpBox( 'config-subscribe-help' )
607 ) ) .
608 */
609 $this->getFieldSetEnd() .
610 $this->parent->getInfoBox( wfMsg( 'config-almost-done' ) ) .
611 $this->parent->getRadioSet( array(
612 'var' => '_SkipOptional',
613 'itemLabelPrefix' => 'config-optional-',
614 'values' => array( 'continue', 'skip' )
615 ) )
616 );
617
618 // Restore the default value
619 $this->setVar( 'wgMetaNamespace', $metaNS );
620
621 $this->endForm();
622 return 'output';
623 }
624
625 public function submit() {
626 $retVal = true;
627 $this->parent->setVarsFromRequest( array( 'wgSitename', '_NamespaceType',
628 '_AdminName', '_AdminPassword', '_AdminPassword2', '_AdminEmail',
629 '_Subscribe', '_SkipOptional' ) );
630
631 // Validate site name
632 if ( strval( $this->getVar( 'wgSitename' ) ) === '' ) {
633 $this->parent->showError( 'config-site-name-blank' );
634 $retVal = false;
635 }
636
637 // Fetch namespace
638 $nsType = $this->getVar( '_NamespaceType' );
639 if ( $nsType == 'site-name' ) {
640 $name = $this->getVar( 'wgSitename' );
641 // Sanitize for namespace
642 // This algorithm should match the JS one in WebInstallerOutput.php
643 $name = preg_replace( '/[\[\]\{\}|#<>%+? ]/', '_', $name );
644 $name = str_replace( '&', '&amp;', $name );
645 $name = preg_replace( '/__+/', '_', $name );
646 $name = ucfirst( trim( $name, '_' ) );
647 } elseif ( $nsType == 'generic' ) {
648 $name = wfMsg( 'config-ns-generic' );
649 } else { // other
650 $name = $this->getVar( 'wgMetaNamespace' );
651 }
652
653 // Validate namespace
654 if ( strpos( $name, ':' ) !== false ) {
655 $good = false;
656 } else {
657 // Title-style validation
658 $title = Title::newFromText( $name );
659 if ( !$title ) {
660 $good = $nsType == 'site-name';
661 } else {
662 $name = $title->getDBkey();
663 $good = true;
664 }
665 }
666 if ( !$good ) {
667 $this->parent->showError( 'config-ns-invalid', $name );
668 $retVal = false;
669 }
670 $this->setVar( 'wgMetaNamespace', $name );
671
672 // Validate username for creation
673 $name = $this->getVar( '_AdminName' );
674 if ( strval( $name ) === '' ) {
675 $this->parent->showError( 'config-admin-name-blank' );
676 $cname = $name;
677 $retVal = false;
678 } else {
679 $cname = User::getCanonicalName( $name, 'creatable' );
680 if ( $cname === false ) {
681 $this->parent->showError( 'config-admin-name-invalid', $name );
682 $retVal = false;
683 } else {
684 $this->setVar( '_AdminName', $cname );
685 }
686 }
687
688 // Validate password
689 $msg = false;
690 $valid = false;
691 $pwd = $this->getVar( '_AdminPassword' );
692 $user = User::newFromName( $cname );
693 $valid = $user && $user->getPasswordValidity( $pwd );
694 if ( strval( $pwd ) === '' ) {
695 # $user->getPasswordValidity just checks for $wgMinimalPasswordLength.
696 # This message is more specific and helpful.
697 $msg = 'config-admin-password-blank';
698 } elseif ( $pwd !== $this->getVar( '_AdminPassword2' ) ) {
699 $msg = 'config-admin-password-mismatch';
700 } elseif ( $valid !== true ) {
701 # As of writing this will only catch the username being e.g. 'FOO' and
702 # the password 'foo'
703 $msg = $valid;
704 }
705 if ( $msg !== false ) {
706 $this->parent->showError( $msg );
707 $this->setVar( '_AdminPassword', '' );
708 $this->setVar( '_AdminPassword2', '' );
709 $retVal = false;
710 }
711 return $retVal;
712 }
713
714 }
715
716 class WebInstaller_Options extends WebInstallerPage {
717
718 public function execute() {
719 if ( $this->getVar( '_SkipOptional' ) == 'skip' ) {
720 return 'skip';
721 }
722 if ( $this->parent->request->wasPosted() ) {
723 if ( $this->submit() ) {
724 return 'continue';
725 }
726 }
727
728 $this->startForm();
729 $this->addHTML(
730 # User Rights
731 $this->parent->getRadioSet( array(
732 'var' => '_RightsProfile',
733 'label' => 'config-profile',
734 'itemLabelPrefix' => 'config-profile-',
735 'values' => array_keys( $this->parent->rightsProfiles ),
736 ) ) .
737 $this->parent->getHelpBox( 'config-profile-help' ) .
738
739 # Licensing
740 $this->parent->getRadioSet( array(
741 'var' => '_LicenseCode',
742 'label' => 'config-license',
743 'itemLabelPrefix' => 'config-license-',
744 'values' => array_keys( $this->parent->licenses ),
745 'commonAttribs' => array( 'class' => 'licenseRadio' ),
746 ) ) .
747 $this->getCCChooser() .
748 $this->parent->getHelpBox( 'config-license-help' ) .
749
750 # E-mail
751 $this->getFieldSetStart( 'config-email-settings' ) .
752 $this->parent->getCheckBox( array(
753 'var' => 'wgEnableEmail',
754 'label' => 'config-enable-email',
755 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'emailwrapper' ),
756 ) ) .
757 $this->parent->getHelpBox( 'config-enable-email-help' ) .
758 "<div id=\"emailwrapper\">" .
759 $this->parent->getTextBox( array(
760 'var' => 'wgPasswordSender',
761 'label' => 'config-email-sender'
762 ) ) .
763 $this->parent->getHelpBox( 'config-email-sender-help' ) .
764 $this->parent->getCheckBox( array(
765 'var' => 'wgEnableUserEmail',
766 'label' => 'config-email-user',
767 ) ) .
768 $this->parent->getHelpBox( 'config-email-user-help' ) .
769 $this->parent->getCheckBox( array(
770 'var' => 'wgEnotifUserTalk',
771 'label' => 'config-email-usertalk',
772 ) ) .
773 $this->parent->getHelpBox( 'config-email-usertalk-help' ) .
774 $this->parent->getCheckBox( array(
775 'var' => 'wgEnotifWatchlist',
776 'label' => 'config-email-watchlist',
777 ) ) .
778 $this->parent->getHelpBox( 'config-email-watchlist-help' ) .
779 $this->parent->getCheckBox( array(
780 'var' => 'wgEmailAuthentication',
781 'label' => 'config-email-auth',
782 ) ) .
783 $this->parent->getHelpBox( 'config-email-auth-help' ) .
784 "</div>" .
785 $this->getFieldSetEnd()
786 );
787
788 $extensions = $this->parent->findExtensions();
789
790 if( $extensions ) {
791 $extHtml = $this->getFieldSetStart( 'config-extensions' );
792
793 foreach( $extensions as $ext ) {
794 $extHtml .= $this->parent->getCheckBox( array(
795 'var' => "ext-$ext",
796 'rawtext' => $ext,
797 ) );
798 }
799
800 $extHtml .= $this->parent->getHelpBox( 'config-extensions-help' ) .
801 $this->getFieldSetEnd();
802 $this->addHTML( $extHtml );
803 }
804
805 $this->addHTML(
806 # Uploading
807 $this->getFieldSetStart( 'config-upload-settings' ) .
808 $this->parent->getCheckBox( array(
809 'var' => 'wgEnableUploads',
810 'label' => 'config-upload-enable',
811 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'uploadwrapper' ),
812 'help' => $this->parent->getHelpBox( 'config-upload-help' )
813 ) ) .
814 '<div id="uploadwrapper" style="display: none;">' .
815 $this->parent->getTextBox( array(
816 'var' => 'wgDeletedDirectory',
817 'label' => 'config-upload-deleted',
818 'help' => $this->parent->getHelpBox( 'config-upload-deleted-help' )
819 ) ) .
820 '</div>' .
821 $this->parent->getTextBox( array(
822 'var' => 'wgLogo',
823 'label' => 'config-logo',
824 'help' => $this->parent->getHelpBox( 'config-logo-help' )
825 ) )
826 );
827 $this->addHTML(
828 $this->parent->getCheckBox( array(
829 'var' => 'wgUseInstantCommons',
830 'label' => 'config-instantcommons',
831 'help' => $this->parent->getHelpBox( 'config-instantcommons-help' )
832 ) ) .
833 $this->getFieldSetEnd()
834 );
835
836 $caches = array( 'none' );
837 if( count( $this->getVar( '_Caches' ) ) ) {
838 $caches[] = 'accel';
839 }
840 $caches[] = 'memcached';
841
842 $this->addHTML(
843 # Advanced settings
844 $this->getFieldSetStart( 'config-advanced-settings' ) .
845 # Object cache settings
846 $this->parent->getRadioSet( array(
847 'var' => 'wgMainCacheType',
848 'label' => 'config-cache-options',
849 'itemLabelPrefix' => 'config-cache-',
850 'values' => $caches,
851 'value' => 'none',
852 ) ) .
853 $this->parent->getHelpBox( 'config-cache-help' ) .
854 '<div id="config-memcachewrapper">' .
855 $this->parent->getTextBox( array(
856 'var' => '_MemCachedServers',
857 'label' => 'config-memcached-servers',
858 'help' => $this->parent->getHelpBox( 'config-memcached-help' )
859 ) ) .
860 '</div>' .
861 $this->getFieldSetEnd()
862 );
863 $this->endForm();
864 }
865
866 public function getCCPartnerUrl() {
867 global $wgServer;
868 $exitUrl = $wgServer . $this->parent->getUrl( array(
869 'page' => 'Options',
870 'SubmitCC' => 'indeed',
871 'config__LicenseCode' => 'cc',
872 'config_wgRightsUrl' => '[license_url]',
873 'config_wgRightsText' => '[license_name]',
874 'config_wgRightsIcon' => '[license_button]',
875 ) );
876 $styleUrl = $wgServer . dirname( dirname( $this->parent->getUrl() ) ) .
877 '/skins/common/config-cc.css';
878 $iframeUrl = 'http://creativecommons.org/license/?' .
879 wfArrayToCGI( array(
880 'partner' => 'MediaWiki',
881 'exit_url' => $exitUrl,
882 'lang' => $this->getVar( '_UserLang' ),
883 'stylesheet' => $styleUrl,
884 ) );
885 return $iframeUrl;
886 }
887
888 public function getCCChooser() {
889 $iframeAttribs = array(
890 'class' => 'config-cc-iframe',
891 'name' => 'config-cc-iframe',
892 'id' => 'config-cc-iframe',
893 'frameborder' => 0,
894 'width' => '100%',
895 'height' => '100%',
896 );
897 if ( $this->getVar( '_CCDone' ) ) {
898 $iframeAttribs['src'] = $this->parent->getUrl( array( 'ShowCC' => 'yes' ) );
899 } else {
900 $iframeAttribs['src'] = $this->getCCPartnerUrl();
901 }
902
903 return
904 "<div class=\"config-cc-wrapper\" id=\"config-cc-wrapper\" style=\"display: none;\">\n" .
905 Html::element( 'iframe', $iframeAttribs, '', false /* not short */ ) .
906 "</div>\n";
907 }
908
909 public function getCCDoneBox() {
910 $js = "parent.document.getElementById('config-cc-wrapper').style.height = '$1';";
911 // If you change this height, also change it in config.css
912 $expandJs = str_replace( '$1', '54em', $js );
913 $reduceJs = str_replace( '$1', '70px', $js );
914 return
915 '<p>'.
916 Html::element( 'img', array( 'src' => $this->getVar( 'wgRightsIcon' ) ) ) .
917 '&#160;&#160;' .
918 htmlspecialchars( $this->getVar( 'wgRightsText' ) ) .
919 "</p>\n" .
920 "<p style=\"text-align: center\">" .
921 Html::element( 'a',
922 array(
923 'href' => $this->getCCPartnerUrl(),
924 'onclick' => $expandJs,
925 ),
926 wfMsg( 'config-cc-again' )
927 ) .
928 "</p>\n" .
929 "<script type=\"text/javascript\">\n" .
930 # Reduce the wrapper div height
931 htmlspecialchars( $reduceJs ) .
932 "\n" .
933 "</script>\n";
934 }
935
936 public function submitCC() {
937 $newValues = $this->parent->setVarsFromRequest(
938 array( 'wgRightsUrl', 'wgRightsText', 'wgRightsIcon' ) );
939 if ( count( $newValues ) != 3 ) {
940 $this->parent->showError( 'config-cc-error' );
941 return;
942 }
943 $this->setVar( '_CCDone', true );
944 $this->addHTML( $this->getCCDoneBox() );
945 }
946
947 public function submit() {
948 $this->parent->setVarsFromRequest( array( '_RightsProfile', '_LicenseCode',
949 'wgEnableEmail', 'wgPasswordSender', 'wgEnableUploads', 'wgLogo',
950 'wgEnableUserEmail', 'wgEnotifUserTalk', 'wgEnotifWatchlist',
951 'wgEmailAuthentication', 'wgMainCacheType', '_MemCachedServers',
952 'wgUseInstantCommons' ) );
953
954 if ( !in_array( $this->getVar( '_RightsProfile' ),
955 array_keys( $this->parent->rightsProfiles ) ) )
956 {
957 reset( $this->parent->rightsProfiles );
958 $this->setVar( '_RightsProfile', key( $this->parent->rightsProfiles ) );
959 }
960
961 $code = $this->getVar( '_LicenseCode' );
962 if ( $code == 'cc-choose' ) {
963 if ( !$this->getVar( '_CCDone' ) ) {
964 $this->parent->showError( 'config-cc-not-chosen' );
965 return false;
966 }
967 } elseif ( in_array( $code, array_keys( $this->parent->licenses ) ) ) {
968 $entry = $this->parent->licenses[$code];
969 if ( isset( $entry['text'] ) ) {
970 $this->setVar( 'wgRightsText', $entry['text'] );
971 } else {
972 $this->setVar( 'wgRightsText', wfMsg( 'config-license-' . $code ) );
973 }
974 $this->setVar( 'wgRightsUrl', $entry['url'] );
975 $this->setVar( 'wgRightsIcon', $entry['icon'] );
976 } else {
977 $this->setVar( 'wgRightsText', '' );
978 $this->setVar( 'wgRightsUrl', '' );
979 $this->setVar( 'wgRightsIcon', '' );
980 }
981
982 $extsAvailable = $this->parent->findExtensions();
983 $extsToInstall = array();
984 foreach( $extsAvailable as $ext ) {
985 if( $this->parent->request->getCheck( 'config_ext-' . $ext ) ) {
986 $extsToInstall[] = $ext;
987 }
988 }
989 $this->parent->setVar( '_Extensions', $extsToInstall );
990 return true;
991 }
992
993 }
994
995 class WebInstaller_Install extends WebInstallerPage {
996
997 public function execute() {
998 if( $this->parent->request->wasPosted() ) {
999 return 'continue';
1000 } elseif( $this->getVar( '_InstallDone' ) ) {
1001 $this->startForm();
1002 $status = new Status();
1003 $status->warning( 'config-install-alreadydone' );
1004 $this->parent->showStatusBox( $status );
1005 } elseif( $this->getVar( '_UpgradeDone' ) ) {
1006 return 'skip';
1007 } else {
1008 $this->startForm();
1009 $this->addHTML("<ul>");
1010 $this->parent->performInstallation(
1011 array( $this, 'startStage'),
1012 array( $this, 'endStage' )
1013 );
1014 $this->addHTML("</ul>");
1015 }
1016 $this->endForm();
1017 return true;
1018 }
1019
1020 public function startStage( $step ) {
1021 $this->addHTML( "<li>" . wfMsgHtml( "config-install-$step" ) . wfMsg( 'ellipsis') );
1022 }
1023
1024 public function endStage( $step, $status ) {
1025 $msg = $status->isOk() ? 'config-install-step-done' : 'config-install-step-failed';
1026 $html = wfMsgHtml( 'word-separator' ) . wfMsgHtml( $msg );
1027 if ( !$status->isOk() ) {
1028 $html = "<span class=\"error\">$html</span>";
1029 }
1030 $this->addHTML( $html . "</li>\n" );
1031 if( !$status->isGood() ) {
1032 $this->parent->showStatusBox( $status );
1033 }
1034 }
1035
1036 }
1037
1038 class WebInstaller_Complete extends WebInstallerPage {
1039
1040 public function execute() {
1041 // Pop up a dialog box, to make it difficult for the user to forget
1042 // to download the file
1043 $lsUrl = $GLOBALS['wgServer'] . $this->parent->getURL( array( 'localsettings' => 1 ) );
1044 $this->parent->request->response()->header( "Refresh: 0;$lsUrl" );
1045
1046 $this->startForm();
1047 $this->parent->disableLinkPopups();
1048 $this->addHTML(
1049 $this->parent->getInfoBox(
1050 wfMsgNoTrans( 'config-install-done',
1051 $lsUrl,
1052 $GLOBALS['wgServer'] .
1053 $this->getVar( 'wgScriptPath' ) . '/index' .
1054 $this->getVar( 'wgScriptExtension' ),
1055 '<downloadlink/>'
1056 ), 'tick-32.png'
1057 )
1058 );
1059 $this->parent->restoreLinkPopups();
1060 $this->endForm( false, false );
1061 }
1062 }
1063
1064 class WebInstaller_Restart extends WebInstallerPage {
1065
1066 public function execute() {
1067 $r = $this->parent->request;
1068 if ( $r->wasPosted() ) {
1069 $really = $r->getVal( 'submit-restart' );
1070 if ( $really ) {
1071 $this->parent->session = array();
1072 $this->parent->happyPages = array();
1073 $this->parent->settings = array();
1074 }
1075 return 'continue';
1076 }
1077
1078 $this->startForm();
1079 $s = $this->parent->getWarningBox( wfMsgNoTrans( 'config-help-restart' ) );
1080 $this->addHTML( $s );
1081 $this->endForm( 'restart' );
1082 }
1083
1084 }
1085
1086 abstract class WebInstaller_Document extends WebInstallerPage {
1087
1088 protected abstract function getFileName();
1089
1090 public function execute() {
1091 $text = $this->getFileContents();
1092 $text = $this->formatTextFile( $text );
1093 $this->parent->output->addWikiText( $text );
1094 $this->startForm();
1095 $this->endForm( false );
1096 }
1097
1098 public function getFileContents() {
1099 return file_get_contents( dirname( __FILE__ ) . '/../../' . $this->getFileName() );
1100 }
1101
1102 protected function formatTextFile( $text ) {
1103 // Use Unix line endings, escape some wikitext stuff
1104 $text = str_replace( array( '<', '{{', '[[', "\r" ),
1105 array( '&lt;', '&#123;&#123;', '&#91;&#91;', '' ), $text );
1106 // join word-wrapped lines into one
1107 do {
1108 $prev = $text;
1109 $text = preg_replace( "/\n([\\*#\t])([^\n]*?)\n([^\n#\\*:]+)/", "\n\\1\\2 \\3", $text );
1110 } while ( $text != $prev );
1111 // Replace tab indents with colons
1112 $text = preg_replace( '/^\t\t/m', '::', $text );
1113 $text = preg_replace( '/^\t/m', ':', $text );
1114 // turn (bug nnnn) into links
1115 $text = preg_replace_callback('/bug (\d+)/', array( $this, 'replaceBugLinks' ), $text );
1116 // add links to manual to every global variable mentioned
1117 $text = preg_replace_callback('/(\$wg[a-z0-9_]+)/i', array( $this, 'replaceConfigLinks' ), $text );
1118 return $text;
1119 }
1120
1121 private function replaceBugLinks( $matches ) {
1122 return '<span class="config-plainlink">[https://bugzilla.wikimedia.org/' .
1123 $matches[1] . ' bug ' . $matches[1] . ']</span>';
1124 }
1125
1126 private function replaceConfigLinks( $matches ) {
1127 return '<span class="config-plainlink">[http://www.mediawiki.org/wiki/Manual:' .
1128 $matches[1] . ' ' . $matches[1] . ']</span>';
1129 }
1130
1131 }
1132
1133 class WebInstaller_Readme extends WebInstaller_Document {
1134 protected function getFileName() { return 'README'; }
1135 }
1136
1137 class WebInstaller_ReleaseNotes extends WebInstaller_Document {
1138 protected function getFileName() { return 'RELEASE-NOTES'; }
1139 }
1140
1141 class WebInstaller_UpgradeDoc extends WebInstaller_Document {
1142 protected function getFileName() { return 'UPGRADE'; }
1143 }
1144
1145 class WebInstaller_Copying extends WebInstaller_Document {
1146 protected function getFileName() { return 'COPYING'; }
1147 }
1148