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