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