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