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