0edd7350d2618f1516ae3933188bf08f6314f2b9
[lhc/web/wiklou.git] / includes / installer / WebInstaller.php
1 <?php
2
3 class WebInstaller extends Installer {
4 /** WebRequest object */
5 var $request;
6
7 /** Cached session array */
8 var $session;
9
10 /** Captured PHP error text. Temporary.
11 */
12 var $phpErrors;
13
14 /**
15 * The main sequence of page names. These will be displayed in turn.
16 * To add one:
17 * * Add it here
18 * * Add a config-page-<name> message
19 * * Add a WebInstaller_<name> class
20 */
21 var $pageSequence = array(
22 'Language',
23 'Welcome',
24 'DBConnect',
25 'Upgrade',
26 'DBSettings',
27 'Name',
28 'Options',
29 'Install',
30 'Complete',
31 );
32
33 /**
34 * Out of sequence pages, selectable by the user at any time
35 */
36 var $otherPages = array(
37 'Restart',
38 'Readme',
39 'ReleaseNotes',
40 'Copying',
41 'UpgradeDoc', // Can't use Upgrade due to Upgrade step
42 );
43
44 /**
45 * Array of pages which have declared that they have been submitted, have validated
46 * their input, and need no further processing
47 */
48 var $happyPages;
49
50 /**
51 * List of "skipped" pages. These are pages that will automatically continue
52 * to the next page on any GET request. To avoid breaking the "back" button,
53 * they need to be skipped during a back operation.
54 */
55 var $skippedPages;
56
57 /**
58 * Flag indicating that session data may have been lost
59 */
60 var $showSessionWarning = false;
61
62 var $helpId = 0;
63 var $tabIndex = 1;
64
65 var $currentPageName;
66
67 /** Constructor */
68 function __construct( $request ) {
69 parent::__construct();
70 $this->output = new WebInstallerOutput( $this );
71 $this->request = $request;
72 }
73
74 /**
75 * Main entry point.
76 * @param $session Array: initial session array
77 * @return Array: new session array
78 */
79 function execute( $session ) {
80 $this->session = $session;
81 if ( isset( $session['settings'] ) ) {
82 $this->settings = $session['settings'] + $this->settings;
83 }
84 $this->exportVars();
85 $this->setupLanguage();
86
87 if ( isset( $session['happyPages'] ) ) {
88 $this->happyPages = $session['happyPages'];
89 } else {
90 $this->happyPages = array();
91 }
92 if ( isset( $session['skippedPages'] ) ) {
93 $this->skippedPages = $session['skippedPages'];
94 } else {
95 $this->skippedPages = array();
96 }
97 $lowestUnhappy = $this->getLowestUnhappy();
98
99 # Special case for Creative Commons partner chooser box
100 if ( $this->request->getVal( 'SubmitCC' ) ) {
101 $page = $this->getPageByName( 'Options' );
102 $this->output->useShortHeader();
103 $page->submitCC();
104 return $this->finish();
105 }
106 if ( $this->request->getVal( 'ShowCC' ) ) {
107 $page = $this->getPageByName( 'Options' );
108 $this->output->useShortHeader();
109 $this->output->addHTML( $page->getCCDoneBox() );
110 return $this->finish();
111 }
112
113 # Get the page name
114 $pageName = $this->request->getVal( 'page' );
115
116 if ( in_array( $pageName, $this->otherPages ) ) {
117 # Out of sequence
118 $pageId = false;
119 $page = $this->getPageByName( $pageName );
120 } else {
121 # Main sequence
122 if ( !$pageName || !in_array( $pageName, $this->pageSequence ) ) {
123 $pageId = $lowestUnhappy;
124 } else {
125 $pageId = array_search( $pageName, $this->pageSequence );
126 }
127
128 # If necessary, move back to the lowest-numbered unhappy page
129 if ( $pageId > $lowestUnhappy ) {
130 $pageId = $lowestUnhappy;
131 if ( $lowestUnhappy == 0 ) {
132 # Knocked back to start, possible loss of session data
133 $this->showSessionWarning = true;
134 }
135 }
136 $pageName = $this->pageSequence[$pageId];
137 $page = $this->getPageByName( $pageName );
138 }
139
140 # If a back button was submitted, go back without submitting the form data
141 if ( $this->request->wasPosted() && $this->request->getBool( 'submit-back' ) ) {
142 if ( $this->request->getVal( 'lastPage' ) ) {
143 $nextPage = $this->request->getVal( 'lastPage' );
144 } elseif ( $pageId !== false ) {
145 # Main sequence page
146 # Skip the skipped pages
147 $nextPageId = $pageId;
148 do {
149 $nextPageId--;
150 $nextPage = $this->pageSequence[$nextPageId];
151 } while( isset( $this->skippedPages[$nextPage] ) );
152 } else {
153 $nextPage = $this->pageSequence[$lowestUnhappy];
154 }
155 $this->output->redirect( $this->getUrl( array( 'page' => $nextPage ) ) );
156 return $this->finish();
157 }
158
159 # Execute the page
160 $this->currentPageName = $page->getName();
161 $this->startPageWrapper( $pageName );
162 $result = $page->execute();
163 $this->endPageWrapper();
164
165 if ( $result == 'skip' ) {
166 # Page skipped without explicit submission
167 # Skip it when we click "back" so that we don't just go forward again
168 $this->skippedPages[$pageName] = true;
169 $result = 'continue';
170 } else {
171 unset( $this->skippedPages[$pageName] );
172 }
173
174 # If it was posted, the page can request a continue to the next page
175 if ( $result === 'continue' && !$this->output->headerDone() ) {
176 if ( $pageId !== false ) {
177 $this->happyPages[$pageId] = true;
178 }
179 $lowestUnhappy = $this->getLowestUnhappy();
180
181 if ( $this->request->getVal( 'lastPage' ) ) {
182 $nextPage = $this->request->getVal( 'lastPage' );
183 } elseif ( $pageId !== false ) {
184 $nextPage = $this->pageSequence[$pageId + 1];
185 } else {
186 $nextPage = $this->pageSequence[$lowestUnhappy];
187 }
188 if ( array_search( $nextPage, $this->pageSequence ) > $lowestUnhappy ) {
189 $nextPage = $this->pageSequence[$lowestUnhappy];
190 }
191 $this->output->redirect( $this->getUrl( array( 'page' => $nextPage ) ) );
192 }
193 return $this->finish();
194 }
195
196 function getLowestUnhappy() {
197 if ( count( $this->happyPages ) == 0 ) {
198 return 0;
199 } else {
200 return max( array_keys( $this->happyPages ) ) + 1;
201 }
202 }
203
204 /**
205 * Start the PHP session. This may be called before execute() to start the PHP session.
206 */
207 function startSession() {
208 $sessPath = $this->getSessionSavePath();
209 if( $sessPath != '' ) {
210 if( !is_dir( $sessPath ) || !is_writeable( $sessPath ) ) {
211 $this->showError( 'config-session-path-bad', $sessPath );
212 return false;
213 }
214 } else {
215 // If the path is unset it'll default to some system bit, which *probably* is ok...
216 // not sure how to actually get what will be used.
217 }
218 if( wfIniGetBool( 'session.auto_start' ) || session_id() ) {
219 // Done already
220 return true;
221 }
222
223 $this->phpErrors = array();
224 set_error_handler( array( $this, 'errorHandler' ) );
225 session_start();
226 restore_error_handler();
227 if ( $this->phpErrors ) {
228 $this->showError( 'config-session-error', $this->phpErrors[0] );
229 return false;
230 }
231 return true;
232 }
233
234 /**
235 * Get the value of session.save_path
236 *
237 * Per http://www.php.net/manual/en/ref.session.php#ini.session.save-path,
238 * this might have some additional preceding parts which need to be
239 * ditched
240 *
241 * @return String
242 */
243 private function getSessionSavePath() {
244 $path = ini_get( 'session.save_path' );
245 $path = ltrim( substr( $path, strrpos( $path, ';' ) ), ';');
246
247 return $path;
248 }
249
250 /**
251 * Show an error message in a box. Parameters are like wfMsg().
252 */
253 function showError( $msg /*...*/ ) {
254 $args = func_get_args();
255 array_shift( $args );
256 $args = array_map( 'htmlspecialchars', $args );
257 $msg = wfMsgReal( $msg, $args, false, false, false );
258 $this->output->addHTML( $this->getErrorBox( $msg ) );
259 }
260
261 /**
262 * Temporary error handler for session start debugging
263 */
264 function errorHandler( $errno, $errstr ) {
265 $this->phpErrors[] = $errstr;
266 }
267
268 /**
269 * Clean up from execute()
270 * @private.
271 */
272 function finish() {
273 $this->output->output();
274 $this->session['happyPages'] = $this->happyPages;
275 $this->session['skippedPages'] = $this->skippedPages;
276 $this->session['settings'] = $this->settings;
277 return $this->session;
278 }
279
280 /**
281 * Get a URL for submission back to the same script
282 */
283 function getUrl( $query = array() ) {
284 $url = $this->request->getRequestURL();
285 # Remove existing query
286 $url = preg_replace( '/\?.*$/', '', $url );
287 if ( $query ) {
288 $url .= '?' . wfArrayToCGI( $query );
289 }
290 return $url;
291 }
292
293 /**
294 * Get a WebInstallerPage from the main sequence, by ID
295 */
296 function getPageById( $id ) {
297 $pageName = $this->pageSequence[$id];
298 $pageClass = 'WebInstaller_' . $pageName;
299 return new $pageClass( $this );
300 }
301
302 /**
303 * Get a WebInstallerPage by name
304 */
305 function getPageByName( $pageName ) {
306 $pageClass = 'WebInstaller_' . $pageName;
307 return new $pageClass( $this );
308 }
309
310 /**
311 * Get a session variable
312 */
313 function getSession( $name, $default = null ) {
314 if ( !isset( $this->session[$name] ) ) {
315 return $default;
316 } else {
317 return $this->session[$name];
318 }
319 }
320
321 /**
322 * Set a session variable
323 */
324 function setSession( $name, $value ) {
325 $this->session[$name] = $value;
326 }
327
328 /**
329 * Get the next tabindex attribute value
330 */
331 function nextTabIndex() {
332 return $this->tabIndex++;
333 }
334
335 /**
336 * Initializes language-related variables
337 */
338 function setupLanguage() {
339 global $wgLang, $wgContLang, $wgLanguageCode;
340 if ( $this->getSession( 'test' ) === null && !$this->request->wasPosted() ) {
341 $wgLanguageCode = $this->getAcceptLanguage();
342 $wgLang = $wgContLang = Language::factory( $wgLanguageCode );
343 $this->setVar( 'wgLanguageCode', $wgLanguageCode );
344 $this->setVar( '_UserLang', $wgLanguageCode );
345 } else {
346 $wgLanguageCode = $this->getVar( 'wgLanguageCode' );
347 $wgLang = Language::factory( $this->getVar( '_UserLang' ) );
348 $wgContLang = Language::factory( $wgLanguageCode );
349 }
350 }
351
352 /**
353 * Retrieves MediaWiki language from Accept-Language HTTP header
354 */
355 function getAcceptLanguage() {
356 global $wgLanguageCode;
357
358 $mwLanguages = Language::getLanguageNames();
359 $langs = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
360 foreach ( explode( ';', $langs ) as $splitted ) {
361 foreach ( explode( ',', $splitted ) as $lang ) {
362 $lang = trim( strtolower( $lang ) );
363 if ( $lang == '' || $lang[0] == 'q' ) {
364 continue;
365 }
366 if ( isset( $mwLanguages[$lang] ) ) {
367 return $lang;
368 }
369 $lang = preg_replace( '/^(.*?)(?=-[^-]*)$/', '\\1', $lang );
370 if ( $lang != '' && isset( $mwLanguages[$lang] ) ) {
371 return $lang;
372 }
373 }
374 }
375 return $wgLanguageCode;
376 }
377
378 /**
379 * Called by execute() before page output starts, to show a page list
380 */
381 function startPageWrapper( $currentPageName ) {
382 $s = "<div class=\"config-page-wrapper\">\n" .
383 "<div class=\"config-page-list\"><ul>\n";
384 $lastHappy = -1;
385 foreach ( $this->pageSequence as $id => $pageName ) {
386 $happy = !empty( $this->happyPages[$id] );
387 $s .= $this->getPageListItem( $pageName,
388 $happy || $lastHappy == $id - 1, $currentPageName );
389 if ( $happy ) {
390 $lastHappy = $id;
391 }
392 }
393 $s .= "</ul><br/><ul>\n";
394 foreach ( $this->otherPages as $pageName ) {
395 $s .= $this->getPageListItem( $pageName, true, $currentPageName );
396 }
397 $s .= "</ul></div>\n". // end list pane
398 "<div class=\"config-page\">\n" .
399 Xml::element( 'h2', array(),
400 wfMsg( 'config-page-' . strtolower( $currentPageName ) ) );
401
402 $this->output->addHTMLNoFlush( $s );
403 }
404
405 /**
406 * Get a list item for the page list
407 */
408 function getPageListItem( $pageName, $enabled, $currentPageName ) {
409 $s = "<li class=\"config-page-list-item\">";
410 $name = wfMsg( 'config-page-' . strtolower( $pageName ) );
411 if ( $enabled ) {
412 $query = array( 'page' => $pageName );
413 if ( !in_array( $pageName, $this->pageSequence ) ) {
414 if ( in_array( $currentPageName, $this->pageSequence ) ) {
415 $query['lastPage'] = $currentPageName;
416 }
417 $link = Xml::element( 'a',
418 array(
419 'href' => $this->getUrl( $query )
420 ),
421 $name
422 );
423 } else {
424 $link = htmlspecialchars( $name );
425 }
426 if ( $pageName == $currentPageName ) {
427 $s .= "<span class=\"config-page-current\">$link</span>";
428 } else {
429 $s .= $link;
430 }
431 } else {
432 $s .= Xml::element( 'span',
433 array(
434 'class' => 'config-page-disabled'
435 ),
436 $name
437 );
438 }
439 $s .= "</li>\n";
440 return $s;
441 }
442
443 /**
444 * Output some stuff after a page is finished
445 */
446 function endPageWrapper() {
447 $this->output->addHTMLNoFlush(
448 "</div>\n" .
449 "<br style=\"clear:both\"/>\n" .
450 "</div>" );
451 }
452
453 /**
454 * Get HTML for an error box with an icon
455 *
456 * @param $text String: wikitext, get this with wfMsgNoTrans()
457 */
458 function getErrorBox( $text ) {
459 return $this->getInfoBox( $text, 'critical-32.png', 'config-error-box' );
460 }
461
462 /**
463 * Get HTML for a warning box with an icon
464 *
465 * @param $text String: wikitext, get this with wfMsgNoTrans()
466 */
467 function getWarningBox( $text ) {
468 return $this->getInfoBox( $text, 'warning-32.png', 'config-warning-box' );
469 }
470
471 /**
472 * Get HTML for an info box with an icon
473 *
474 * @param $text String: wikitext, get this with wfMsgNoTrans()
475 * @param $icon String: icon name, file in skins/common/images
476 * @param $class String: additional class name to add to the wrapper div
477 */
478 function getInfoBox( $text, $icon = 'info-32.png', $class = false ) {
479 $s =
480 "<div class=\"config-info $class\">\n" .
481 "<div class=\"config-info-left\">\n" .
482 Xml::element( 'img',
483 array(
484 'src' => '../skins/common/images/' . $icon,
485 'alt' => wfMsg( 'config-information' ),
486 )
487 ) . "\n" .
488 "</div>\n" .
489 "<div class=\"config-info-right\">\n" .
490 $this->parse( $text ) . "\n" .
491 "</div>\n" .
492 "<div style=\"clear: left;\"></div>\n" .
493 "</div>\n";
494 return $s;
495 }
496
497 /**
498 * Get small text indented help for a preceding form field.
499 * Parameters like wfMsg().
500 */
501 function getHelpBox( $msg /*, ... */ ) {
502 $args = func_get_args();
503 array_shift( $args );
504 $args = array_map( 'htmlspecialchars', $args );
505 $text = wfMsgReal( $msg, $args, false, false, false );
506 $html = $this->parse( $text, true );
507 $id = $this->helpId++;
508 $alt = wfMsg( 'help' );
509
510 return
511 "<div class=\"config-help-wrapper\">\n" .
512 "<div class=\"config-help-message\">\n" .
513 $html .
514 "</div>\n" .
515 "<div class=\"config-show-help\">\n" .
516 "<a href=\"#\">" .
517 wfMsgHtml( 'config-show-help' ) .
518 "</a></div>\n" .
519 "<div class=\"config-hide-help\">\n" .
520 "<a href=\"#\">" .
521 wfMsgHtml( 'config-hide-help' ) .
522 "</a></div>\n</div>\n";
523 }
524
525 /**
526 * Output a help box
527 */
528 function showHelpBox( $msg /*, ... */ ) {
529 $args = func_get_args();
530 $html = call_user_func_array( array( $this, 'getHelpBox' ), $args );
531 $this->output->addHTML( $html );
532 }
533
534 /**
535 * Show a short informational message
536 * Output looks like a list.
537 */
538 function showMessage( $msg /*, ... */ ) {
539 $args = func_get_args();
540 array_shift( $args );
541 $html = '<div class="config-message">' .
542 $this->parse( wfMsgReal( $msg, $args, false, false, false ) ) .
543 "</div>\n";
544 $this->output->addHTML( $html );
545 }
546
547 /**
548 * Label a control by wrapping a config-input div around it and putting a
549 * label before it
550 */
551 function label( $msg, $forId, $contents ) {
552 if ( strval( $msg ) == '' ) {
553 $labelText = '&nbsp;';
554 } else {
555 $labelText = wfMsgHtml( $msg );
556 }
557 $attributes = array( 'class' => 'config-label' );
558 if ( $forId ) {
559 $attributes['for'] = $forId;
560 }
561 return
562 "<div class=\"config-input\">\n" .
563 Xml::tags( 'label',
564 $attributes,
565 $labelText ) . "\n" .
566 $contents .
567 "</div>\n";
568 }
569
570 /**
571 * Get a labelled text box to configure a variable
572 *
573 * @param $params Array
574 * Parameters are:
575 * var: The variable to be configured (required)
576 * label: The message name for the label (required)
577 * attribs: Additional attributes for the input element (optional)
578 * controlName: The name for the input element (optional)
579 * value: The current value of the variable (optional)
580 */
581 function getTextBox( $params ) {
582 if ( !isset( $params['controlName'] ) ) {
583 $params['controlName'] = 'config_' . $params['var'];
584 }
585 if ( !isset( $params['value'] ) ) {
586 $params['value'] = $this->getVar( $params['var'] );
587 }
588 if ( !isset( $params['attribs'] ) ) {
589 $params['attribs'] = array();
590 }
591 return
592 $this->label(
593 $params['label'],
594 $params['controlName'],
595 Xml::input(
596 $params['controlName'],
597 30, // intended to be overridden by CSS
598 $params['value'],
599 $params['attribs'] + array(
600 'id' => $params['controlName'],
601 'class' => 'config-input-text',
602 'tabindex' => $this->nextTabIndex()
603 )
604 )
605 );
606 }
607
608 /**
609 * Get a labelled password box to configure a variable
610 *
611 * Implements password hiding
612 * @param $params Array
613 * Parameters are:
614 * var: The variable to be configured (required)
615 * label: The message name for the label (required)
616 * attribs: Additional attributes for the input element (optional)
617 * controlName: The name for the input element (optional)
618 * value: The current value of the variable (optional)
619 */
620 function getPasswordBox( $params ) {
621 if ( !isset( $params['value'] ) ) {
622 $params['value'] = $this->getVar( $params['var'] );
623 }
624 if ( !isset( $params['attribs'] ) ) {
625 $params['attribs'] = array();
626 }
627 $params['value'] = $this->getFakePassword( $params['value'] );
628 $params['attribs']['type'] = 'password';
629 return $this->getTextBox( $params );
630 }
631
632 /**
633 * Get a labelled checkbox to configure a boolean variable
634 *
635 * @param $params Array
636 * Parameters are:
637 * var: The variable to be configured (required)
638 * label: The message name for the label (required)
639 * attribs: Additional attributes for the input element (optional)
640 * controlName: The name for the input element (optional)
641 * value: The current value of the variable (optional)
642 */
643 function getCheckBox( $params ) {
644 if ( !isset( $params['controlName'] ) ) {
645 $params['controlName'] = 'config_' . $params['var'];
646 }
647 if ( !isset( $params['value'] ) ) {
648 $params['value'] = $this->getVar( $params['var'] );
649 }
650 if ( !isset( $params['attribs'] ) ) {
651 $params['attribs'] = array();
652 }
653 if( isset( $params['rawtext'] ) ) {
654 $labelText = $params['rawtext'];
655 } else {
656 $labelText = $this->parse( wfMsg( $params['label'] ) );
657 }
658 return
659 "<div class=\"config-input-check\">\n" .
660 "<label>\n" .
661 Xml::check(
662 $params['controlName'],
663 $params['value'],
664 $params['attribs'] + array(
665 'id' => $params['controlName'],
666 'class' => 'config-input-text',
667 'tabindex' => $this->nextTabIndex(),
668 )
669 ) .
670 $labelText . "\n" .
671 "</label>\n" .
672 "</div>\n";
673 }
674
675 /**
676 * Get a set of labelled radio buttons
677 *
678 * @param $params Array
679 * Parameters are:
680 * var: The variable to be configured (required)
681 * label: The message name for the label (required)
682 * itemLabelPrefix: The message name prefix for the item labels (required)
683 * values: List of allowed values (required)
684 * itemAttribs Array of attribute arrays, outer key is the value name (optional)
685 * commonAttribs Attribute array applied to all items
686 * controlName: The name for the input element (optional)
687 * value: The current value of the variable (optional)
688 */
689 function getRadioSet( $params ) {
690 if ( !isset( $params['controlName'] ) ) {
691 $params['controlName'] = 'config_' . $params['var'];
692 }
693 if ( !isset( $params['value'] ) ) {
694 $params['value'] = $this->getVar( $params['var'] );
695 }
696 if ( !isset( $params['label'] ) ) {
697 $label = '';
698 } else {
699 $label = $this->parse( wfMsgNoTrans( $params['label'] ) );
700 }
701 $s = "<label class=\"config-label\">\n" .
702 $label .
703 "</label>\n" .
704 "<ul class=\"config-settings-block\">\n";
705 foreach ( $params['values'] as $value ) {
706 $itemAttribs = array();
707 if ( isset( $params['commonAttribs'] ) ) {
708 $itemAttribs = $params['commonAttribs'];
709 }
710 if ( isset( $params['itemAttribs'][$value] ) ) {
711 $itemAttribs = $params['itemAttribs'][$value] + $itemAttribs;
712 }
713 $checked = $value == $params['value'];
714 $id = $params['controlName'] . '_' . $value;
715 $itemAttribs['id'] = $id;
716 $itemAttribs['tabindex'] = $this->nextTabIndex();
717 $s .=
718 '<li>' .
719 Xml::radio( $params['controlName'], $value, $checked, $itemAttribs ) .
720 '&nbsp;' .
721 Xml::tags( 'label', array( 'for' => $id ), $this->parse(
722 wfMsgNoTrans( $params['itemLabelPrefix'] . strtolower( $value ) )
723 ) ) .
724 "</li>\n";
725 }
726 $s .= "</ul>\n";
727 return $s;
728 }
729
730 /**
731 * Output an error box using a Status object
732 */
733 function showStatusErrorBox( $status ) {
734 $text = $status->getWikiText();
735 $this->output->addHTML( $this->getErrorBox( $text ) );
736 }
737
738 function showStatusError( $status ) {
739 $text = $status->getWikiText();
740 $this->output->addWikiText(
741 "<div class=\"config-message\">\n" .
742 $text .
743 "</div>"
744 );
745 }
746
747 /**
748 * Convenience function to set variables based on form data.
749 * Assumes that variables containing "password" in the name are (potentially
750 * fake) passwords.
751 *
752 * @param $varNames Array
753 * @param $prefix String: the prefix added to variables to obtain form names
754 */
755 function setVarsFromRequest( $varNames, $prefix = 'config_' ) {
756 $newValues = array();
757 foreach ( $varNames as $name ) {
758 $value = trim( $this->request->getVal( $prefix . $name ) );
759 $newValues[$name] = $value;
760 if ( $value === null ) {
761 // Checkbox?
762 $this->setVar( $name, false );
763 } else {
764 if ( stripos( $name, 'password' ) !== false ) {
765 $this->setPassword( $name, $value );
766 } else {
767 $this->setVar( $name, $value );
768 }
769 }
770 }
771 return $newValues;
772 }
773
774 /**
775 * Get the starting tags of a fieldset
776 *
777 * @param $legend String: message name
778 */
779 function getFieldsetStart( $legend ) {
780 return "\n<fieldset><legend>" . wfMsgHtml( $legend ) . "</legend>\n";
781 }
782
783 /**
784 * Get the end tag of a fieldset
785 */
786 function getFieldsetEnd() {
787 return "</fieldset>\n";
788 }
789
790 /**
791 * Helper for Installer::docLink()
792 */
793 function getDocUrl( $page ) {
794 $url = "{$_SERVER['PHP_SELF']}?page=" . urlencode( $page );
795 if ( in_array( $this->currentPageName, $this->pageSequence ) ) {
796 $url .= '&lastPage=' . urlencode( $this->currentPageName );
797 }
798 return $url;
799 }
800 }
801
802 class WebInstallerPage {
803 function __construct( $parent ) {
804 $this->parent = $parent;
805 }
806
807 function addHTML( $html ) {
808 $this->parent->output->addHTML( $html );
809 }
810
811 function startForm() {
812 $this->addHTML(
813 "<div class=\"config-section\">\n" .
814 Xml::openElement(
815 'form',
816 array(
817 'method' => 'post',
818 'action' => $this->parent->getUrl( array( 'page' => $this->getName() ) )
819 )
820 ) . "\n"
821 );
822 }
823
824 function endForm( $continue = 'continue' ) {
825 $this->parent->output->outputWarnings();
826 $s = "<div class=\"config-submit\">\n";
827 $id = $this->getId();
828 if ( $id === false ) {
829 $s .= Xml::hidden( 'lastPage', $this->parent->request->getVal( 'lastPage' ) );
830 }
831 if ( $continue ) {
832 // Fake submit button for enter keypress
833 $s .= Xml::submitButton( wfMsg( "config-$continue" ),
834 array( 'name' => "enter-$continue", 'style' => 'display:none' ) ) . "\n";
835 }
836 if ( $id !== 0 ) {
837 $s .= Xml::submitButton( wfMsg( 'config-back' ),
838 array(
839 'name' => 'submit-back',
840 'tabindex' => $this->parent->nextTabIndex()
841 ) ) . "\n";
842 }
843 if ( $continue ) {
844 $s .= Xml::submitButton( wfMsg( "config-$continue" ),
845 array(
846 'name' => "submit-$continue",
847 'tabindex' => $this->parent->nextTabIndex(),
848 ) ) . "\n";
849 }
850 $s .= "</div></form></div>\n";
851 $this->addHTML( $s );
852 }
853
854 function getName() {
855 return str_replace( 'WebInstaller_', '', get_class( $this ) );
856 }
857
858 function getId() {
859 return array_search( $this->getName(), $this->parent->pageSequence );
860 }
861
862 function execute() {
863 if ( $this->parent->request->wasPosted() ) {
864 return 'continue';
865 } else {
866 $this->startForm();
867 $this->addHTML( 'Mockup' );
868 $this->endForm();
869 }
870 }
871
872 function getVar( $var ) {
873 return $this->parent->getVar( $var );
874 }
875
876 function setVar( $name, $value ) {
877 $this->parent->setVar( $name, $value );
878 }
879 }
880
881 class WebInstaller_Language extends WebInstallerPage {
882 function execute() {
883 global $wgLang;
884 $r = $this->parent->request;
885 $userLang = $r->getVal( 'UserLang' );
886 $contLang = $r->getVal( 'ContLang' );
887
888 $lifetime = intval( ini_get( 'session.gc_maxlifetime' ) );
889 if ( !$lifetime ) {
890 $lifetime = 1440; // PHP default
891 }
892
893 if ( $r->wasPosted() ) {
894 # Do session test
895 if ( $this->parent->getSession( 'test' ) === null ) {
896 $requestTime = $r->getVal( 'LanguageRequestTime' );
897 if ( !$requestTime ) {
898 // The most likely explanation is that the user was knocked back
899 // from another page on POST due to session expiry
900 $msg = 'config-session-expired';
901 } elseif ( time() - $requestTime > $lifetime ) {
902 $msg = 'config-session-expired';
903 } else {
904 $msg = 'config-no-session';
905 }
906 $this->parent->showError( $msg, $wgLang->formatTimePeriod( $lifetime ) );
907 } else {
908 $languages = Language::getLanguageNames();
909 if ( isset( $languages[$userLang] ) ) {
910 $this->setVar( '_UserLang', $userLang );
911 }
912 if ( isset( $languages[$contLang] ) ) {
913 $this->setVar( 'wgLanguageCode', $contLang );
914 if ( $this->getVar( '_AdminName' ) === null ) {
915 // Load localised sysop username in *content* language
916 $this->setVar( '_AdminName', wfMsgForContent( 'config-admin-default-username' ) );
917 }
918 }
919 return 'continue';
920 }
921 } elseif ( $this->parent->showSessionWarning ) {
922 # The user was knocked back from another page to the start
923 # This probably indicates a session expiry
924 $this->parent->showError( 'config-session-expired', $wgLang->formatTimePeriod( $lifetime ) );
925 }
926
927 $this->parent->setSession( 'test', true );
928
929 if ( !isset( $languages[$userLang] ) ) {
930 $userLang = $this->getVar( '_UserLang', 'en' );
931 }
932 if ( !isset( $languages[$contLang] ) ) {
933 $contLang = $this->getVar( 'wgLanguageCode', 'en' );
934 }
935 $this->startForm();
936 $s =
937 Xml::hidden( 'LanguageRequestTime', time() ) .
938 $this->getLanguageSelector( 'UserLang', 'config-your-language', $userLang ) .
939 $this->parent->getHelpBox( 'config-your-language-help' ) .
940 $this->getLanguageSelector( 'ContLang', 'config-wiki-language', $contLang ) .
941 $this->parent->getHelpBox( 'config-wiki-language-help' );
942
943
944 $this->addHTML( $s );
945 $this->endForm();
946 }
947
948 /**
949 * Get a <select> for selecting languages
950 */
951 function getLanguageSelector( $name, $label, $selectedCode ) {
952 global $wgDummyLanguageCodes;
953 $s = Xml::openElement( 'select', array( 'id' => $name, 'name' => $name ) ) . "\n";
954
955 $languages = Language::getLanguageNames();
956 ksort( $languages );
957 $dummies = array_flip( $wgDummyLanguageCodes );
958 foreach ( $languages as $code => $lang ) {
959 if ( isset( $dummies[$code] ) ) continue;
960 $s .= "\n" . Xml::option( "$code - $lang", $code, $code == $selectedCode );
961 }
962 $s .= "\n</select>\n";
963 return $this->parent->label( $label, $name, $s );
964 }
965 }
966
967 class WebInstaller_Welcome extends WebInstallerPage {
968 function execute() {
969 if ( $this->parent->request->wasPosted() ) {
970 if ( $this->getVar( '_Environment' ) ) {
971 return 'continue';
972 }
973 }
974 $this->parent->output->addWikiText( wfMsgNoTrans( 'config-welcome' ) );
975 $status = $this->parent->doEnvironmentChecks();
976 if ( $status ) {
977 $this->parent->output->addWikiText( wfMsgNoTrans( 'config-copyright', wfMsg( 'config-authors' ) ) );
978 $this->startForm();
979 $this->endForm();
980 }
981 }
982 }
983
984 class WebInstaller_DBConnect extends WebInstallerPage {
985 function execute() {
986 $r = $this->parent->request;
987 if ( $r->wasPosted() ) {
988 $status = $this->submit();
989 if ( $status->isGood() ) {
990 $this->setVar( '_UpgradeDone', false );
991 return 'continue';
992 } else {
993 $this->parent->showStatusErrorBox( $status );
994 }
995 }
996
997
998 $this->startForm();
999
1000 $types = "<ul class=\"config-settings-block\">\n";
1001 $settings = '';
1002 $defaultType = $this->getVar( 'wgDBtype' );
1003 foreach ( $this->parent->getVar( '_CompiledDBs' ) as $type ) {
1004 $installer = $this->parent->getDBInstaller( $type );
1005 $types .=
1006 '<li>' .
1007 Xml::radioLabel(
1008 $installer->getReadableName(),
1009 'DBType',
1010 $type,
1011 "DBType_$type",
1012 $type == $defaultType,
1013 array( 'class' => 'dbRadio', 'rel' => "DB_wrapper_$type" )
1014 ) .
1015 "</li>\n";
1016
1017 $settings .=
1018 Xml::openElement( 'div', array( 'id' => 'DB_wrapper_' . $type, 'class' => 'dbWrapper' ) ) .
1019 Xml::element( 'h3', array(), wfMsg( 'config-header-' . $type ) ) .
1020 $installer->getConnectForm() .
1021 "</div>\n";
1022 }
1023 $types .= "</ul><br clear=\"left\"/>\n";
1024
1025 $this->addHTML(
1026 $this->parent->label( 'config-db-type', false, $types ) .
1027 $settings
1028 );
1029
1030 $this->endForm();
1031 }
1032
1033 function submit() {
1034 $r = $this->parent->request;
1035 $type = $r->getVal( 'DBType' );
1036 $this->setVar( 'wgDBtype', $type );
1037 $installer = $this->parent->getDBInstaller( $type );
1038 if ( !$installer ) {
1039 return Status::newFatal( 'config-invalid-db-type' );
1040 }
1041 return $installer->submitConnectForm();
1042 }
1043 }
1044
1045 class WebInstaller_Upgrade extends WebInstallerPage {
1046 function execute() {
1047 if ( $this->getVar( '_UpgradeDone' ) ) {
1048 if ( $this->parent->request->wasPosted() ) {
1049 // Done message acknowledged
1050 return 'continue';
1051 } else {
1052 // Back button click
1053 // Show the done message again
1054 // Make them click back again if they want to do the upgrade again
1055 $this->showDoneMessage();
1056 return 'output';
1057 }
1058 }
1059
1060 // wgDBtype is generally valid here because otherwise the previous page
1061 // (connect) wouldn't have declared its happiness
1062 $type = $this->getVar( 'wgDBtype' );
1063 $installer = $this->parent->getDBInstaller( $type );
1064
1065 if ( !$installer->needsUpgrade() ) {
1066 return 'skip';
1067 }
1068
1069 if ( $this->parent->request->wasPosted() ) {
1070 $this->addHTML(
1071 '<div id="config-spinner" style="display:none;"><img src="../skins/common/images/ajax-loader.gif" /></div>' .
1072 '<script>jQuery( "#config-spinner" )[0].style.display = "block";</script>' .
1073 '<textarea id="config-update-log" name="UpdateLog" rows="10" readonly="readonly">'
1074 );
1075 $this->parent->output->flush();
1076 $result = $installer->doUpgrade();
1077 $this->addHTML( '</textarea>
1078 <script>jQuery( "#config-spinner" )[0].style.display = "none";</script>' );
1079 $this->parent->output->flush();
1080 if ( $result ) {
1081 $this->setVar( '_UpgradeDone', true );
1082 $this->showDoneMessage();
1083 return 'output';
1084 }
1085 }
1086
1087 $this->startForm();
1088 $this->addHTML( $this->parent->getInfoBox(
1089 wfMsgNoTrans( 'config-can-upgrade', $GLOBALS['wgVersion'] ) ) );
1090 $this->endForm();
1091 }
1092
1093 function showDoneMessage() {
1094 $this->startForm();
1095 $this->addHTML(
1096 $this->parent->getInfoBox(
1097 wfMsgNoTrans( 'config-upgrade-done',
1098 $GLOBALS['wgServer'] .
1099 $this->getVar( 'wgScriptPath' ) . '/index' .
1100 $this->getVar( 'wgScriptExtension' )
1101 ), 'tick-32.png'
1102 )
1103 );
1104 $this->endForm( 'regenerate' );
1105 }
1106 }
1107
1108 class WebInstaller_DBSettings extends WebInstallerPage {
1109 function execute() {
1110 $installer = $this->parent->getDBInstaller( $this->getVar( 'wgDBtype' ) );
1111
1112 $r = $this->parent->request;
1113 if ( $r->wasPosted() ) {
1114 $status = $installer->submitSettingsForm();
1115 if ( $status === false ) {
1116 return 'skip';
1117 } elseif ( $status->isGood() ) {
1118 return 'continue';
1119 } else {
1120 $this->parent->showStatusErrorBox( $status );
1121 }
1122 }
1123
1124 $form = $installer->getSettingsForm();
1125 if ( $form === false ) {
1126 return 'skip';
1127 }
1128
1129 $this->startForm();
1130 $this->addHTML( $form );
1131 $this->endForm();
1132 }
1133
1134 }
1135
1136 class WebInstaller_Name extends WebInstallerPage {
1137 function execute() {
1138 $r = $this->parent->request;
1139 if ( $r->wasPosted() ) {
1140 if ( $this->submit() ) {
1141 return 'continue';
1142 }
1143 }
1144
1145 $this->startForm();
1146
1147 if ( $this->getVar( 'wgSitename' ) == $GLOBALS['wgSitename'] ) {
1148 $this->setVar( 'wgSitename', '' );
1149 }
1150
1151 // Set wgMetaNamespace to something valid before we show the form.
1152 // $wgMetaNamespace defaults to $wgSiteName which is 'MediaWiki'
1153 $metaNS = $this->getVar( 'wgMetaNamespace' );
1154 $this->setVar( 'wgMetaNamespace', wfMsgForContent( 'config-ns-other-default' ) );
1155
1156 $this->addHTML(
1157 $this->parent->getTextBox( array(
1158 'var' => 'wgSitename',
1159 'label' => 'config-site-name',
1160 ) ) .
1161 $this->parent->getHelpBox( 'config-site-name-help' ) .
1162 $this->parent->getRadioSet( array(
1163 'var' => '_NamespaceType',
1164 'label' => 'config-project-namespace',
1165 'itemLabelPrefix' => 'config-ns-',
1166 'values' => array( 'site-name', 'generic', 'other' ),
1167 'commonAttribs' => array( 'class' => 'enableForOther', 'rel' => 'config_wgMetaNamespace' ),
1168 ) ) .
1169 $this->parent->getTextBox( array(
1170 'var' => 'wgMetaNamespace',
1171 'label' => '',
1172 'attribs' => array( 'disabled' => '' ),
1173 ) ) .
1174 $this->parent->getHelpBox( 'config-project-namespace-help' ) .
1175 $this->parent->getFieldsetStart( 'config-admin-box' ) .
1176 $this->parent->getTextBox( array(
1177 'var' => '_AdminName',
1178 'label' => 'config-admin-name'
1179 ) ) .
1180 $this->parent->getPasswordBox( array(
1181 'var' => '_AdminPassword',
1182 'label' => 'config-admin-password',
1183 ) ) .
1184 $this->parent->getPasswordBox( array(
1185 'var' => '_AdminPassword2',
1186 'label' => 'config-admin-password-confirm'
1187 ) ) .
1188 $this->parent->getHelpBox( 'config-admin-help' ) .
1189 $this->parent->getTextBox( array(
1190 'var' => '_AdminEmail',
1191 'label' => 'config-admin-email'
1192 ) ) .
1193 $this->parent->getHelpBox( 'config-admin-email-help' ) .
1194 $this->parent->getCheckBox( array(
1195 'var' => '_Subscribe',
1196 'label' => 'config-subscribe'
1197 ) ) .
1198 $this->parent->getHelpBox( 'config-subscribe-help' ) .
1199 $this->parent->getFieldsetEnd() .
1200 $this->parent->getInfoBox( wfMsg( 'config-almost-done' ) ) .
1201 $this->parent->getRadioSet( array(
1202 'var' => '_SkipOptional',
1203 'itemLabelPrefix' => 'config-optional-',
1204 'values' => array( 'continue', 'skip' )
1205 ) )
1206 );
1207
1208 // Restore the default value
1209 $this->setVar( 'wgMetaNamespace', $metaNS );
1210
1211 $this->endForm();
1212 return 'output';
1213 }
1214
1215 function submit() {
1216 $retVal = true;
1217 $this->parent->setVarsFromRequest( array( 'wgSitename', '_NamespaceType',
1218 '_AdminName', '_AdminPassword', '_AdminPassword2', '_AdminEmail',
1219 '_Subscribe', '_SkipOptional' ) );
1220
1221 // Validate site name
1222 if ( strval( $this->getVar( 'wgSitename' ) ) === '' ) {
1223 $this->parent->showError( 'config-site-name-blank' );
1224 $retVal = false;
1225 }
1226
1227 // Fetch namespace
1228 $nsType = $this->getVar( '_NamespaceType' );
1229 if ( $nsType == 'site-name' ) {
1230 $name = $this->getVar( 'wgSitename' );
1231 // Sanitize for namespace
1232 // This algorithm should match the JS one in WebInstallerOutput.php
1233 $name = preg_replace( '/[\[\]\{\}|#<>%+? ]/', '_', $name );
1234 $name = str_replace( '&', '&amp;', $name );
1235 $name = preg_replace( '/__+/', '_', $name );
1236 $name = ucfirst( trim( $name, '_' ) );
1237 } elseif ( $nsType == 'generic' ) {
1238 $name = wfMsg( 'config-ns-generic' );
1239 } else { // other
1240 $name = $this->getVar( 'wgMetaNamespace' );
1241 }
1242
1243 // Validate namespace
1244 if ( strpos( $name, ':' ) !== false ) {
1245 $good = false;
1246 } else {
1247 // Title-style validation
1248 $title = Title::newFromText( $name );
1249 if ( !$title ) {
1250 $good = $nsType == 'site-name' ? true : false;
1251 } else {
1252 $name = $title->getDBkey();
1253 $good = true;
1254 }
1255 }
1256 if ( !$good ) {
1257 $this->parent->showError( 'config-ns-invalid', $name );
1258 $retVal = false;
1259 }
1260 $this->setVar( 'wgMetaNamespace', $name );
1261
1262 // Validate username for creation
1263 $name = $this->getVar( '_AdminName' );
1264 if ( strval( $name ) === '' ) {
1265 $this->parent->showError( 'config-admin-name-blank' );
1266 $cname = $name;
1267 $retVal = false;
1268 } else {
1269 $cname = User::getCanonicalName( $name, 'creatable' );
1270 if ( $cname === false ) {
1271 $this->parent->showError( 'config-admin-name-invalid', $name );
1272 $retVal = false;
1273 } else {
1274 $this->setVar( '_AdminName', $cname );
1275 }
1276 }
1277
1278 // Validate password
1279 $msg = false;
1280 $pwd = $this->getVar( '_AdminPassword' );
1281 $user = User::newFromName( $cname );
1282 $valid = $user->getPasswordValidity( $pwd );
1283 if ( strval( $pwd ) === '' ) {
1284 # $user->getPasswordValidity just checks for $wgMinimalPasswordLength.
1285 # This message is more specific and helpful.
1286 $msg = 'config-admin-password-blank';
1287 } elseif ( $pwd !== $this->getVar( '_AdminPassword2' ) ) {
1288 $msg = 'config-admin-password-mismatch';
1289 } elseif ( $valid !== true ) {
1290 # As of writing this will only catch the username being e.g. 'FOO' and
1291 # the password 'foo'
1292 $msg = $valid;
1293 }
1294 if ( $msg !== false ) {
1295 $this->parent->showError( $msg );
1296 $this->setVar( '_AdminPassword', '' );
1297 $this->setVar( '_AdminPassword2', '' );
1298 $retVal = false;
1299 }
1300 return $retVal;
1301 }
1302 }
1303
1304 class WebInstaller_Options extends WebInstallerPage {
1305 function execute() {
1306 if ( $this->getVar( '_SkipOptional' ) == 'skip' ) {
1307 return 'skip';
1308 }
1309 if ( $this->parent->request->wasPosted() ) {
1310 if ( $this->submit() ) {
1311 return 'continue';
1312 }
1313 }
1314
1315 $this->startForm();
1316 $this->addHTML(
1317 # User Rights
1318 $this->parent->getRadioSet( array(
1319 'var' => '_RightsProfile',
1320 'label' => 'config-profile',
1321 'itemLabelPrefix' => 'config-profile-',
1322 'values' => array_keys( $this->parent->rightsProfiles ),
1323 ) ) .
1324 $this->parent->getHelpBox( 'config-profile-help' ) .
1325
1326 # Licensing
1327 $this->parent->getRadioSet( array(
1328 'var' => '_LicenseCode',
1329 'label' => 'config-license',
1330 'itemLabelPrefix' => 'config-license-',
1331 'values' => array_keys( $this->parent->licenses ),
1332 'commonAttribs' => array( 'class' => 'licenseRadio' ),
1333 ) ) .
1334 $this->getCCChooser() .
1335 $this->parent->getHelpBox( 'config-license-help' ) .
1336
1337 # E-mail
1338 $this->parent->getFieldsetStart( 'config-email-settings' ) .
1339 $this->parent->getCheckBox( array(
1340 'var' => 'wgEnableEmail',
1341 'label' => 'config-enable-email',
1342 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'emailwrapper' ),
1343 ) ) .
1344 $this->parent->getHelpBox( 'config-enable-email-help' ) .
1345 "<div id=\"emailwrapper\">" .
1346 $this->parent->getTextBox( array(
1347 'var' => 'wgPasswordSender',
1348 'label' => 'config-email-sender'
1349 ) ) .
1350 $this->parent->getHelpBox( 'config-email-sender-help' ) .
1351 $this->parent->getCheckBox( array(
1352 'var' => 'wgEnableUserEmail',
1353 'label' => 'config-email-user',
1354 ) ) .
1355 $this->parent->getHelpBox( 'config-email-user-help' ) .
1356 $this->parent->getCheckBox( array(
1357 'var' => 'wgEnotifUserTalk',
1358 'label' => 'config-email-usertalk',
1359 ) ) .
1360 $this->parent->getHelpBox( 'config-email-usertalk-help' ) .
1361 $this->parent->getCheckBox( array(
1362 'var' => 'wgEnotifWatchlist',
1363 'label' => 'config-email-watchlist',
1364 ) ) .
1365 $this->parent->getHelpBox( 'config-email-watchlist-help' ) .
1366 $this->parent->getCheckBox( array(
1367 'var' => 'wgEmailAuthentication',
1368 'label' => 'config-email-auth',
1369 ) ) .
1370 $this->parent->getHelpBox( 'config-email-auth-help' ) .
1371 "</div>" .
1372 $this->parent->getFieldsetEnd()
1373 );
1374
1375 $extensions = $this->parent->findExtensions();
1376 if( $extensions ) {
1377 $extHtml = $this->parent->getFieldsetStart( 'config-extensions' );
1378 foreach( $extensions as $ext ) {
1379 $extHtml .= $this->parent->getCheckBox( array(
1380 'var' => "ext-$ext",
1381 'rawtext' => $ext,
1382 ) );
1383 }
1384 $extHtml .= $this->parent->getHelpBox( 'config-extensions-help' ) .
1385 $this->parent->getFieldsetEnd();
1386 $this->addHTML( $extHtml );
1387 }
1388
1389 $this->addHTML(
1390 # Uploading
1391 $this->parent->getFieldsetStart( 'config-upload-settings' ) .
1392 $this->parent->getCheckBox( array(
1393 'var' => 'wgEnableUploads',
1394 'label' => 'config-upload-enable',
1395 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'uploadwrapper' ),
1396 ) ) .
1397 $this->parent->getHelpBox( 'config-upload-help' ) .
1398 '<div id="uploadwrapper" style="display: none;">' .
1399 $this->parent->getTextBox( array(
1400 'var' => 'wgDeletedDirectory',
1401 'label' => 'config-upload-deleted',
1402 ) ) .
1403 $this->parent->getHelpBox( 'config-upload-deleted-help' ) .
1404 $this->parent->getTextBox( array(
1405 'var' => 'wgLogo',
1406 'label' => 'config-logo'
1407 ) ) .
1408 $this->parent->getHelpBox( 'config-logo-help' ) .
1409 '</div>' .
1410 $this->parent->getFieldsetEnd()
1411 );
1412
1413 $caches = array( 'none', 'anything', 'db' );
1414 $selected = 'db';
1415 if( count( $this->getVar( '_Caches' ) ) ) {
1416 $caches[] = 'accel';
1417 $selected = 'accel';
1418 }
1419 $caches[] = 'memcached';
1420
1421 $this->addHTML(
1422 # Advanced settings
1423 $this->parent->getFieldsetStart( 'config-advanced-settings' ) .
1424 # Object cache settings
1425 $this->parent->getRadioSet( array(
1426 'var' => 'wgMainCacheType',
1427 'label' => 'config-cache-options',
1428 'itemLabelPrefix' => 'config-cache-',
1429 'values' => $caches,
1430 'value' => $selected,
1431 ) ) .
1432 $this->parent->getHelpBox( 'config-cache-help' ) .
1433 '<div id="config-memcachewrapper">' .
1434 $this->parent->getTextBox( array(
1435 'var' => '_MemCachedServers',
1436 'label' => 'config-memcached-servers',
1437 ) ) .
1438 $this->parent->getHelpBox( 'config-memcached-help' ) . '</div>' .
1439 $this->parent->getFieldsetEnd()
1440 );
1441 $this->endForm();
1442 }
1443
1444 function getCCPartnerUrl() {
1445 global $wgServer;
1446 $exitUrl = $wgServer . $this->parent->getUrl( array(
1447 'page' => 'Options',
1448 'SubmitCC' => 'indeed',
1449 'config__LicenseCode' => 'cc',
1450 'config_wgRightsUrl' => '[license_url]',
1451 'config_wgRightsText' => '[license_name]',
1452 'config_wgRightsIcon' => '[license_button]',
1453 ) );
1454 $styleUrl = $wgServer . dirname( dirname( $this->parent->getUrl() ) ) .
1455 '/skins/common/config-cc.css';
1456 $iframeUrl = 'http://creativecommons.org/license/?' .
1457 wfArrayToCGI( array(
1458 'partner' => 'MediaWiki',
1459 'exit_url' => $exitUrl,
1460 'lang' => $this->getVar( '_UserLang' ),
1461 'stylesheet' => $styleUrl,
1462 ) );
1463 return $iframeUrl;
1464 }
1465
1466 function getCCChooser() {
1467 $iframeAttribs = array(
1468 'class' => 'config-cc-iframe',
1469 'name' => 'config-cc-iframe',
1470 'id' => 'config-cc-iframe',
1471 'frameborder' => 0,
1472 'width' => '100%',
1473 'height' => '100%',
1474 );
1475 if ( $this->getVar( '_CCDone' ) ) {
1476 $iframeAttribs['src'] = $this->parent->getUrl( array( 'ShowCC' => 'yes' ) );
1477 } else {
1478 $iframeAttribs['src'] = $this->getCCPartnerUrl();
1479 }
1480
1481 return
1482 "<div class=\"config-cc-wrapper\" id=\"config-cc-wrapper\" style=\"display: none;\">\n" .
1483 Xml::element( 'iframe', $iframeAttribs, '', false /* not short */ ) .
1484 "</div>\n";
1485 }
1486
1487 function getCCDoneBox() {
1488 $js = "parent.document.getElementById('config-cc-wrapper').style.height = '$1';";
1489 // If you change this height, also change it in config.css
1490 $expandJs = str_replace( '$1', '54em', $js );
1491 $reduceJs = str_replace( '$1', '70px', $js );
1492 return
1493 '<p>'.
1494 Xml::element( 'img', array( 'src' => $this->getVar( 'wgRightsIcon' ) ) ) .
1495 '&nbsp;&nbsp;' .
1496 htmlspecialchars( $this->getVar( 'wgRightsText' ) ) .
1497 "</p>\n" .
1498 "<p style=\"text-align: center\">" .
1499 Xml::element( 'a',
1500 array(
1501 'href' => $this->getCCPartnerUrl(),
1502 'onclick' => $expandJs,
1503 ),
1504 wfMsg( 'config-cc-again' )
1505 ) .
1506 "</p>\n" .
1507 "<script type=\"text/javascript\">\n" .
1508 # Reduce the wrapper div height
1509 htmlspecialchars( $reduceJs ) .
1510 "\n" .
1511 "</script>\n";
1512 }
1513
1514
1515 function submitCC() {
1516 $newValues = $this->parent->setVarsFromRequest(
1517 array( 'wgRightsUrl', 'wgRightsText', 'wgRightsIcon' ) );
1518 if ( count( $newValues ) != 3 ) {
1519 $this->parent->showError( 'config-cc-error' );
1520 return;
1521 }
1522 $this->setVar( '_CCDone', true );
1523 $this->addHTML( $this->getCCDoneBox() );
1524 }
1525
1526 function submit() {
1527 $this->parent->setVarsFromRequest( array( '_RightsProfile', '_LicenseCode',
1528 'wgEnableEmail', 'wgPasswordSender', 'wgEnableUpload', 'wgLogo',
1529 'wgEnableUserEmail', 'wgEnotifUserTalk', 'wgEnotifWatchlist',
1530 'wgEmailAuthentication', 'wgMainCacheType', '_MemCachedServers' ) );
1531
1532 if ( !in_array( $this->getVar( '_RightsProfile' ),
1533 array_keys( $this->parent->rightsProfiles ) ) )
1534 {
1535 reset( $this->parent->rightsProfiles );
1536 $this->setVar( '_RightsProfile', key( $this->parent->rightsProfiles ) );
1537 }
1538
1539 $code = $this->getVar( '_LicenseCode' );
1540 if ( $code == 'cc-choose' ) {
1541 if ( !$this->getVar( '_CCDone' ) ) {
1542 $this->parent->showError( 'config-cc-not-chosen' );
1543 return false;
1544 }
1545 } elseif ( in_array( $code, array_keys( $this->parent->licenses ) ) ) {
1546 $entry = $this->parent->licenses[$code];
1547 if ( isset( $entry['text'] ) ) {
1548 $this->setVar( 'wgRightsText', $entry['text'] );
1549 } else {
1550 $this->setVar( 'wgRightsText', wfMsg( 'config-license-' . $code ) );
1551 }
1552 $this->setVar( 'wgRightsUrl', $entry['url'] );
1553 $this->setVar( 'wgRightsIcon', $entry['icon'] );
1554 } else {
1555 $this->setVar( 'wgRightsText', '' );
1556 $this->setVar( 'wgRightsUrl', '' );
1557 $this->setVar( 'wgRightsIcon', '' );
1558 }
1559
1560 $exts = $this->parent->getVar( '_Extensions' );
1561 foreach( $exts as $key => $ext ) {
1562 if( !$this->parent->request->getCheck( 'config_ext-' . $ext ) ) {
1563 unset( $exts[$key] );
1564 }
1565 }
1566 $this->parent->setVar( '_Extensions', $exts );
1567 return true;
1568 }
1569 }
1570
1571 class WebInstaller_Install extends WebInstallerPage {
1572
1573 function execute() {
1574 if( $this->parent->request->wasPosted() ) {
1575 return 'continue';
1576 }
1577 $this->startForm();
1578 $this->addHTML("<ul>");
1579 foreach( $this->parent->getInstallSteps() as $step ) {
1580 $this->startStage( "config-install-$step" );
1581 $func = 'install' . ucfirst( $step );
1582 $status = $this->parent->{$func}();
1583 $ok = $status->isGood();
1584 if ( !$ok ) {
1585 $this->parent->showStatusErrorBox( $status );
1586 }
1587 $this->endStage( $ok );
1588 }
1589 $this->addHTML("</ul>");
1590 $this->endForm();
1591 return true;
1592
1593 }
1594
1595 private function startStage( $msg ) {
1596 $this->addHTML( "<li>" . wfMsgHtml( $msg ) . wfMsg( 'ellipsis') );
1597 }
1598
1599 private function endStage( $success = true ) {
1600 $msg = $success ? 'config-install-step-done' : 'config-install-step-failed';
1601 $html = wfMsgHtml( 'word-separator' ) . wfMsgHtml( $msg );
1602 if ( !$success ) {
1603 $html = "<span class=\"error\">$html</span>";
1604 }
1605 $this->addHTML( $html . "</li>\n" );
1606 }
1607 }
1608
1609 class WebInstaller_Complete extends WebInstallerPage {
1610 public function execute() {
1611 global $IP;
1612 $this->startForm();
1613 $msg = file_exists( "$IP/LocalSettings.php" ) ? 'config-install-done-moved' : 'config-install-done';
1614 $this->addHTML(
1615 $this->parent->getInfoBox(
1616 wfMsgNoTrans( $msg,
1617 $GLOBALS['wgServer'] .
1618 $this->getVar( 'wgScriptPath' ) . '/index' .
1619 $this->getVar( 'wgScriptExtension' )
1620 ), 'tick-32.png'
1621 )
1622 );
1623 $this->endForm( false );
1624 }
1625 }
1626
1627 class WebInstaller_Restart extends WebInstallerPage {
1628 function execute() {
1629 $r = $this->parent->request;
1630 if ( $r->wasPosted() ) {
1631 $really = $r->getVal( 'submit-restart' );
1632 if ( $really ) {
1633 $this->parent->session = array();
1634 $this->parent->happyPages = array();
1635 $this->parent->settings = array();
1636 }
1637 return 'continue';
1638 }
1639
1640 $this->startForm();
1641 $s = $this->parent->getWarningBox( wfMsgNoTrans( 'config-help-restart' ) );
1642 $this->addHTML( $s );
1643 $this->endForm( 'restart' );
1644 }
1645 }
1646
1647 abstract class WebInstaller_Document extends WebInstallerPage {
1648 abstract function getFileName();
1649
1650 function execute() {
1651 $text = $this->getFileContents();
1652 $this->parent->output->addWikiText( $text );
1653 $this->startForm();
1654 $this->endForm( false );
1655 }
1656
1657 function getFileContents() {
1658 return file_get_contents( dirname( __FILE__ ) . '/../../' . $this->getFileName() );
1659 }
1660
1661 protected function formatTextFile( $text ) {
1662 // replace numbering with [1], [2], etc with MW-style numbering
1663 $text = preg_replace( "/\r?\n(\r?\n)?\\[\\d+\\]/m", "\\1#", $text );
1664 // join word-wrapped lines into one
1665 do {
1666 $prev = $text;
1667 $text = preg_replace( "/\n([\\*#])([^\r\n]*?)\r?\n([^\r\n#\\*:]+)/", "\n\\1\\2 \\3", $text );
1668 } while ( $text != $prev );
1669 // turn (bug nnnn) into links
1670 $text = preg_replace_callback('/bug (\d+)/', array( $this, 'replaceBugLinks' ), $text );
1671 // add links to manual to every global variable mentioned
1672 $text = preg_replace_callback('/(\$wg[a-z0-9_]+)/i', array( $this, 'replaceConfigLinks' ), $text );
1673 // special case for <pre> - formatted links
1674 do {
1675 $prev = $text;
1676 $text = preg_replace( '/^([^\\s].*?)\r?\n[\\s]+(https?:\/\/)/m', "\\1\n:\\2", $text );
1677 } while ( $text != $prev );
1678 return $text;
1679 }
1680
1681 private function replaceBugLinks( $matches ) {
1682 return '<span class="config-plainlink">[https://bugzilla.wikimedia.org/' .
1683 $matches[1] . ' bug ' . $matches[1] . ']</span>';
1684 }
1685
1686 private function replaceConfigLinks( $matches ) {
1687 return '<span class="config-plainlink">[http://www.mediawiki.org/wiki/Manual:' .
1688 $matches[1] . ' ' . $matches[1] . ']</span>';
1689 }
1690 }
1691
1692 class WebInstaller_Readme extends WebInstaller_Document {
1693 function getFileName() { return 'README'; }
1694
1695 function getFileContents() {
1696 return $this->formatTextFile( parent::getFileContents() );
1697 }
1698 }
1699
1700 class WebInstaller_ReleaseNotes extends WebInstaller_Document {
1701 function getFileName() { return 'RELEASE-NOTES'; }
1702
1703 function getFileContents() {
1704 return $this->formatTextFile( parent::getFileContents() );
1705 }
1706 }
1707
1708 class WebInstaller_UpgradeDoc extends WebInstaller_Document {
1709 function getFileName() { return 'UPGRADE'; }
1710
1711 function getFileContents() {
1712 return $this->formatTextFile( parent::getFileContents() );
1713 }
1714 }
1715
1716 class WebInstaller_Copying extends WebInstaller_Document {
1717 function getFileName() { return 'COPYING'; }
1718
1719 function getFileContents() {
1720 $text = parent::getFileContents();
1721 $text = str_replace( "\x0C", '', $text );
1722 $text = preg_replace_callback( '/\n[ \t]+/m', array( 'WebInstaller_Copying', 'replaceLeadingSpaces' ), $text );
1723 $text = '<tt>' . nl2br( $text ) . '</tt>';
1724 return $text;
1725 }
1726
1727 private static function replaceLeadingSpaces( $matches ) {
1728 return "\n" . str_repeat( '&nbsp;', strlen( $matches[0] ) );
1729 }
1730 }