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