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