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