a630b5d18158034fa61a4bf8346a6d067396ae1b
[lhc/web/wiklou.git] / includes / installer / WebInstallerPage.php
1 <?php
2
3 /**
4 * Abstract class to define pages for the web installer.
5 */
6 abstract class WebInstallerPage {
7
8 /**
9 * The WebInstaller object this WebInstallerPage belongs to.
10 *
11 * @var WebInstaller
12 */
13 public $parent;
14
15 public abstract function execute();
16
17 /**
18 * Constructor.
19 *
20 * @param WebInstaller $parent
21 */
22 public function __construct( WebInstaller $parent ) {
23 $this->parent = $parent;
24 }
25
26 public function addHTML( $html ) {
27 $this->parent->output->addHTML( $html );
28 }
29
30 public function startForm() {
31 $this->addHTML(
32 "<div class=\"config-section\">\n" .
33 Xml::openElement(
34 'form',
35 array(
36 'method' => 'post',
37 'action' => $this->parent->getUrl( array( 'page' => $this->getName() ) )
38 )
39 ) . "\n"
40 );
41 }
42
43 public function endForm( $continue = 'continue' ) {
44 $this->parent->output->outputWarnings();
45 $s = "<div class=\"config-submit\">\n";
46 $id = $this->getId();
47
48 if ( $id === false ) {
49 $s .= Xml::hidden( 'lastPage', $this->parent->request->getVal( 'lastPage' ) );
50 }
51
52 if ( $continue ) {
53 // Fake submit button for enter keypress
54 $s .= Xml::submitButton( wfMsg( "config-$continue" ),
55 array( 'name' => "enter-$continue", 'style' => 'display:none' ) ) . "\n";
56 }
57
58 if ( $id !== 0 ) {
59 $s .= Xml::submitButton( wfMsg( 'config-back' ),
60 array(
61 'name' => 'submit-back',
62 'tabindex' => $this->parent->nextTabIndex()
63 ) ) . "\n";
64 }
65
66 if ( $continue ) {
67 $s .= Xml::submitButton( wfMsg( "config-$continue" ),
68 array(
69 'name' => "submit-$continue",
70 'tabindex' => $this->parent->nextTabIndex(),
71 ) ) . "\n";
72 }
73
74 $s .= "</div></form></div>\n";
75 $this->addHTML( $s );
76 }
77
78 public function getName() {
79 return str_replace( 'WebInstaller_', '', get_class( $this ) );
80 }
81
82 public function getId() {
83 return array_search( $this->getName(), $this->parent->pageSequence );
84 }
85
86 public function getVar( $var ) {
87 return $this->parent->getVar( $var );
88 }
89
90 public function setVar( $name, $value ) {
91 $this->parent->setVar( $name, $value );
92 }
93
94 }
95
96 class WebInstaller_Language extends WebInstallerPage {
97
98 public function execute() {
99 global $wgLang;
100 $r = $this->parent->request;
101 $userLang = $r->getVal( 'UserLang' );
102 $contLang = $r->getVal( 'ContLang' );
103
104 $lifetime = intval( ini_get( 'session.gc_maxlifetime' ) );
105 if ( !$lifetime ) {
106 $lifetime = 1440; // PHP default
107 }
108
109 if ( $r->wasPosted() ) {
110 # Do session test
111 if ( $this->parent->getSession( 'test' ) === null ) {
112 $requestTime = $r->getVal( 'LanguageRequestTime' );
113 if ( !$requestTime ) {
114 // The most likely explanation is that the user was knocked back
115 // from another page on POST due to session expiry
116 $msg = 'config-session-expired';
117 } elseif ( time() - $requestTime > $lifetime ) {
118 $msg = 'config-session-expired';
119 } else {
120 $msg = 'config-no-session';
121 }
122 $this->parent->showError( $msg, $wgLang->formatTimePeriod( $lifetime ) );
123 } else {
124 $languages = Language::getLanguageNames();
125 if ( isset( $languages[$userLang] ) ) {
126 $this->setVar( '_UserLang', $userLang );
127 }
128 if ( isset( $languages[$contLang] ) ) {
129 $this->setVar( 'wgLanguageCode', $contLang );
130 }
131 return 'continue';
132 }
133 } elseif ( $this->parent->showSessionWarning ) {
134 # The user was knocked back from another page to the start
135 # This probably indicates a session expiry
136 $this->parent->showError( 'config-session-expired', $wgLang->formatTimePeriod( $lifetime ) );
137 }
138
139 $this->parent->setSession( 'test', true );
140
141 if ( !isset( $languages[$userLang] ) ) {
142 $userLang = $this->getVar( '_UserLang', 'en' );
143 }
144 if ( !isset( $languages[$contLang] ) ) {
145 $contLang = $this->getVar( 'wgLanguageCode', 'en' );
146 }
147 $this->startForm();
148 $s =
149 Xml::hidden( 'LanguageRequestTime', time() ) .
150 $this->getLanguageSelector( 'UserLang', 'config-your-language', $userLang ) .
151 $this->parent->getHelpBox( 'config-your-language-help' ) .
152 $this->getLanguageSelector( 'ContLang', 'config-wiki-language', $contLang ) .
153 $this->parent->getHelpBox( 'config-wiki-language-help' );
154
155
156 $this->addHTML( $s );
157 $this->endForm();
158 }
159
160 /**
161 * Get a <select> for selecting languages.
162 */
163 public function getLanguageSelector( $name, $label, $selectedCode ) {
164 global $wgDummyLanguageCodes;
165 $s = Xml::openElement( 'select', array( 'id' => $name, 'name' => $name ) ) . "\n";
166
167 $languages = Language::getLanguageNames();
168 ksort( $languages );
169 $dummies = array_flip( $wgDummyLanguageCodes );
170 foreach ( $languages as $code => $lang ) {
171 if ( isset( $dummies[$code] ) ) continue;
172 $s .= "\n" . Xml::option( "$code - $lang", $code, $code == $selectedCode );
173 }
174 $s .= "\n</select>\n";
175 return $this->parent->label( $label, $name, $s );
176 }
177
178 }
179
180 class WebInstaller_Welcome extends WebInstallerPage {
181
182 public function execute() {
183 if ( $this->parent->request->wasPosted() ) {
184 if ( $this->getVar( '_Environment' ) ) {
185 return 'continue';
186 }
187 }
188 $this->parent->output->addWikiText( wfMsgNoTrans( 'config-welcome' ) );
189 $status = $this->parent->doEnvironmentChecks();
190 if ( $status ) {
191 $this->parent->output->addWikiText( wfMsgNoTrans( 'config-copyright', wfMsg( 'config-authors' ) ) );
192 $this->startForm();
193 $this->endForm();
194 }
195 }
196
197 }
198
199 class WebInstaller_DBConnect extends WebInstallerPage {
200
201 public function execute() {
202 $r = $this->parent->request;
203 if ( $r->wasPosted() ) {
204 $status = $this->submit();
205 if ( $status->isGood() ) {
206 $this->setVar( '_UpgradeDone', false );
207 return 'continue';
208 } else {
209 $this->parent->showStatusBox( $status );
210 }
211 }
212
213 $this->startForm();
214
215 $types = "<ul class=\"config-settings-block\">\n";
216 $settings = '';
217 $defaultType = $this->getVar( 'wgDBtype' );
218 foreach ( $this->parent->getVar( '_CompiledDBs' ) as $type ) {
219 $installer = $this->parent->getDBInstaller( $type );
220 $types .=
221 '<li>' .
222 Xml::radioLabel(
223 $installer->getReadableName(),
224 'DBType',
225 $type,
226 "DBType_$type",
227 $type == $defaultType,
228 array( 'class' => 'dbRadio', 'rel' => "DB_wrapper_$type" )
229 ) .
230 "</li>\n";
231
232 $settings .=
233 Xml::openElement( 'div', array( 'id' => 'DB_wrapper_' . $type, 'class' => 'dbWrapper' ) ) .
234 Xml::element( 'h3', array(), wfMsg( 'config-header-' . $type ) ) .
235 $installer->getConnectForm() .
236 "</div>\n";
237 }
238 $types .= "</ul><br clear=\"left\"/>\n";
239
240 $this->addHTML(
241 $this->parent->label( 'config-db-type', false, $types ) .
242 $settings
243 );
244
245 $this->endForm();
246 }
247
248 public function submit() {
249 $r = $this->parent->request;
250 $type = $r->getVal( 'DBType' );
251 $this->setVar( 'wgDBtype', $type );
252 $installer = $this->parent->getDBInstaller( $type );
253 if ( !$installer ) {
254 return Status::newFatal( 'config-invalid-db-type' );
255 }
256 return $installer->submitConnectForm();
257 }
258
259 }
260
261 class WebInstaller_Upgrade extends WebInstallerPage {
262
263 public function execute() {
264 if ( $this->getVar( '_UpgradeDone' ) ) {
265 if ( $this->parent->request->wasPosted() ) {
266 // Done message acknowledged
267 return 'continue';
268 } else {
269 // Back button click
270 // Show the done message again
271 // Make them click back again if they want to do the upgrade again
272 $this->showDoneMessage();
273 return 'output';
274 }
275 }
276
277 // wgDBtype is generally valid here because otherwise the previous page
278 // (connect) wouldn't have declared its happiness
279 $type = $this->getVar( 'wgDBtype' );
280 $installer = $this->parent->getDBInstaller( $type );
281
282 if ( !$installer->needsUpgrade() ) {
283 return 'skip';
284 }
285
286 if ( $this->parent->request->wasPosted() ) {
287 $this->addHTML(
288 '<div id="config-spinner" style="display:none;"><img src="../skins/common/images/ajax-loader.gif" /></div>' .
289 '<script>jQuery( "#config-spinner" )[0].style.display = "block";</script>' .
290 '<textarea id="config-update-log" name="UpdateLog" rows="10" readonly="readonly">'
291 );
292 $this->parent->output->flush();
293 $result = $installer->doUpgrade();
294 $this->addHTML( '</textarea>
295 <script>jQuery( "#config-spinner" )[0].style.display = "none";</script>' );
296 $this->parent->output->flush();
297 if ( $result ) {
298 $this->setVar( '_UpgradeDone', true );
299 $this->showDoneMessage();
300 return 'output';
301 }
302 }
303
304 $this->startForm();
305 $this->addHTML( $this->parent->getInfoBox(
306 wfMsgNoTrans( 'config-can-upgrade', $GLOBALS['wgVersion'] ) ) );
307 $this->endForm();
308 }
309
310 public function showDoneMessage() {
311 $this->startForm();
312 $this->addHTML(
313 $this->parent->getInfoBox(
314 wfMsgNoTrans( 'config-upgrade-done',
315 $GLOBALS['wgServer'] .
316 $this->getVar( 'wgScriptPath' ) . '/index' .
317 $this->getVar( 'wgScriptExtension' )
318 ), 'tick-32.png'
319 )
320 );
321 $this->endForm( 'regenerate' );
322 }
323
324 }
325
326 class WebInstaller_DBSettings extends WebInstallerPage {
327
328 public function execute() {
329 $installer = $this->parent->getDBInstaller( $this->getVar( 'wgDBtype' ) );
330
331 $r = $this->parent->request;
332 if ( $r->wasPosted() ) {
333 $status = $installer->submitSettingsForm();
334 if ( $status === false ) {
335 return 'skip';
336 } elseif ( $status->isGood() ) {
337 return 'continue';
338 } else {
339 $this->parent->showStatusBox( $status );
340 }
341 }
342
343 $form = $installer->getSettingsForm();
344 if ( $form === false ) {
345 return 'skip';
346 }
347
348 $this->startForm();
349 $this->addHTML( $form );
350 $this->endForm();
351 }
352
353 }
354
355 class WebInstaller_Name extends WebInstallerPage {
356
357 public function execute() {
358 $r = $this->parent->request;
359 if ( $r->wasPosted() ) {
360 if ( $this->submit() ) {
361 return 'continue';
362 }
363 }
364
365 $this->startForm();
366
367 if ( $this->getVar( 'wgSitename' ) == $GLOBALS['wgSitename'] ) {
368 $this->setVar( 'wgSitename', '' );
369 }
370
371 // Set wgMetaNamespace to something valid before we show the form.
372 // $wgMetaNamespace defaults to $wgSiteName which is 'MediaWiki'
373 $metaNS = $this->getVar( 'wgMetaNamespace' );
374 $this->setVar( 'wgMetaNamespace', wfMsgForContent( 'config-ns-other-default' ) );
375
376 $this->addHTML(
377 $this->parent->getTextBox( array(
378 'var' => 'wgSitename',
379 'label' => 'config-site-name',
380 ) ) .
381 $this->parent->getHelpBox( 'config-site-name-help' ) .
382 $this->parent->getRadioSet( array(
383 'var' => '_NamespaceType',
384 'label' => 'config-project-namespace',
385 'itemLabelPrefix' => 'config-ns-',
386 'values' => array( 'site-name', 'generic', 'other' ),
387 'commonAttribs' => array( 'class' => 'enableForOther', 'rel' => 'config_wgMetaNamespace' ),
388 ) ) .
389 $this->parent->getTextBox( array(
390 'var' => 'wgMetaNamespace',
391 'label' => '',
392 'attribs' => array( 'disabled' => '' ),
393 ) ) .
394 $this->parent->getHelpBox( 'config-project-namespace-help' ) .
395 $this->parent->getFieldsetStart( 'config-admin-box' ) .
396 $this->parent->getTextBox( array(
397 'var' => '_AdminName',
398 'label' => 'config-admin-name'
399 ) ) .
400 $this->parent->getPasswordBox( array(
401 'var' => '_AdminPassword',
402 'label' => 'config-admin-password',
403 ) ) .
404 $this->parent->getPasswordBox( array(
405 'var' => '_AdminPassword2',
406 'label' => 'config-admin-password-confirm'
407 ) ) .
408 $this->parent->getHelpBox( 'config-admin-help' ) .
409 $this->parent->getTextBox( array(
410 'var' => '_AdminEmail',
411 'label' => 'config-admin-email'
412 ) ) .
413 $this->parent->getHelpBox( 'config-admin-email-help' ) .
414 $this->parent->getCheckBox( array(
415 'var' => '_Subscribe',
416 'label' => 'config-subscribe'
417 ) ) .
418 $this->parent->getHelpBox( 'config-subscribe-help' ) .
419 $this->parent->getFieldsetEnd() .
420 $this->parent->getInfoBox( wfMsg( 'config-almost-done' ) ) .
421 $this->parent->getRadioSet( array(
422 'var' => '_SkipOptional',
423 'itemLabelPrefix' => 'config-optional-',
424 'values' => array( 'continue', 'skip' )
425 ) )
426 );
427
428 // Restore the default value
429 $this->setVar( 'wgMetaNamespace', $metaNS );
430
431 $this->endForm();
432 return 'output';
433 }
434
435 public function submit() {
436 $retVal = true;
437 $this->parent->setVarsFromRequest( array( 'wgSitename', '_NamespaceType',
438 '_AdminName', '_AdminPassword', '_AdminPassword2', '_AdminEmail',
439 '_Subscribe', '_SkipOptional' ) );
440
441 // Validate site name
442 if ( strval( $this->getVar( 'wgSitename' ) ) === '' ) {
443 $this->parent->showError( 'config-site-name-blank' );
444 $retVal = false;
445 }
446
447 // Fetch namespace
448 $nsType = $this->getVar( '_NamespaceType' );
449 if ( $nsType == 'site-name' ) {
450 $name = $this->getVar( 'wgSitename' );
451 // Sanitize for namespace
452 // This algorithm should match the JS one in WebInstallerOutput.php
453 $name = preg_replace( '/[\[\]\{\}|#<>%+? ]/', '_', $name );
454 $name = str_replace( '&', '&amp;', $name );
455 $name = preg_replace( '/__+/', '_', $name );
456 $name = ucfirst( trim( $name, '_' ) );
457 } elseif ( $nsType == 'generic' ) {
458 $name = wfMsg( 'config-ns-generic' );
459 } else { // other
460 $name = $this->getVar( 'wgMetaNamespace' );
461 }
462
463 // Validate namespace
464 if ( strpos( $name, ':' ) !== false ) {
465 $good = false;
466 } else {
467 // Title-style validation
468 $title = Title::newFromText( $name );
469 if ( !$title ) {
470 $good = $nsType == 'site-name' ? true : false;
471 } else {
472 $name = $title->getDBkey();
473 $good = true;
474 }
475 }
476 if ( !$good ) {
477 $this->parent->showError( 'config-ns-invalid', $name );
478 $retVal = false;
479 }
480 $this->setVar( 'wgMetaNamespace', $name );
481
482 // Validate username for creation
483 $name = $this->getVar( '_AdminName' );
484 if ( strval( $name ) === '' ) {
485 $this->parent->showError( 'config-admin-name-blank' );
486 $cname = $name;
487 $retVal = false;
488 } else {
489 $cname = User::getCanonicalName( $name, 'creatable' );
490 if ( $cname === false ) {
491 $this->parent->showError( 'config-admin-name-invalid', $name );
492 $retVal = false;
493 } else {
494 $this->setVar( '_AdminName', $cname );
495 }
496 }
497
498 // Validate password
499 $msg = false;
500 $pwd = $this->getVar( '_AdminPassword' );
501 $user = User::newFromName( $cname );
502 $valid = $user->getPasswordValidity( $pwd );
503 if ( strval( $pwd ) === '' ) {
504 # $user->getPasswordValidity just checks for $wgMinimalPasswordLength.
505 # This message is more specific and helpful.
506 $msg = 'config-admin-password-blank';
507 } elseif ( $pwd !== $this->getVar( '_AdminPassword2' ) ) {
508 $msg = 'config-admin-password-mismatch';
509 } elseif ( $valid !== true ) {
510 # As of writing this will only catch the username being e.g. 'FOO' and
511 # the password 'foo'
512 $msg = $valid;
513 }
514 if ( $msg !== false ) {
515 $this->parent->showError( $msg );
516 $this->setVar( '_AdminPassword', '' );
517 $this->setVar( '_AdminPassword2', '' );
518 $retVal = false;
519 }
520 return $retVal;
521 }
522
523 }
524
525 class WebInstaller_Options extends WebInstallerPage {
526
527 public function execute() {
528 if ( $this->getVar( '_SkipOptional' ) == 'skip' ) {
529 return 'skip';
530 }
531 if ( $this->parent->request->wasPosted() ) {
532 if ( $this->submit() ) {
533 return 'continue';
534 }
535 }
536
537 $this->startForm();
538 $this->addHTML(
539 # User Rights
540 $this->parent->getRadioSet( array(
541 'var' => '_RightsProfile',
542 'label' => 'config-profile',
543 'itemLabelPrefix' => 'config-profile-',
544 'values' => array_keys( $this->parent->rightsProfiles ),
545 ) ) .
546 $this->parent->getHelpBox( 'config-profile-help' ) .
547
548 # Licensing
549 $this->parent->getRadioSet( array(
550 'var' => '_LicenseCode',
551 'label' => 'config-license',
552 'itemLabelPrefix' => 'config-license-',
553 'values' => array_keys( $this->parent->licenses ),
554 'commonAttribs' => array( 'class' => 'licenseRadio' ),
555 ) ) .
556 $this->getCCChooser() .
557 $this->parent->getHelpBox( 'config-license-help' ) .
558
559 # E-mail
560 $this->parent->getFieldsetStart( 'config-email-settings' ) .
561 $this->parent->getCheckBox( array(
562 'var' => 'wgEnableEmail',
563 'label' => 'config-enable-email',
564 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'emailwrapper' ),
565 ) ) .
566 $this->parent->getHelpBox( 'config-enable-email-help' ) .
567 "<div id=\"emailwrapper\">" .
568 $this->parent->getTextBox( array(
569 'var' => 'wgPasswordSender',
570 'label' => 'config-email-sender'
571 ) ) .
572 $this->parent->getHelpBox( 'config-email-sender-help' ) .
573 $this->parent->getCheckBox( array(
574 'var' => 'wgEnableUserEmail',
575 'label' => 'config-email-user',
576 ) ) .
577 $this->parent->getHelpBox( 'config-email-user-help' ) .
578 $this->parent->getCheckBox( array(
579 'var' => 'wgEnotifUserTalk',
580 'label' => 'config-email-usertalk',
581 ) ) .
582 $this->parent->getHelpBox( 'config-email-usertalk-help' ) .
583 $this->parent->getCheckBox( array(
584 'var' => 'wgEnotifWatchlist',
585 'label' => 'config-email-watchlist',
586 ) ) .
587 $this->parent->getHelpBox( 'config-email-watchlist-help' ) .
588 $this->parent->getCheckBox( array(
589 'var' => 'wgEmailAuthentication',
590 'label' => 'config-email-auth',
591 ) ) .
592 $this->parent->getHelpBox( 'config-email-auth-help' ) .
593 "</div>" .
594 $this->parent->getFieldsetEnd()
595 );
596
597 $extensions = $this->parent->findExtensions();
598
599 if( $extensions ) {
600 $extHtml = $this->parent->getFieldsetStart( 'config-extensions' );
601
602 foreach( $extensions as $ext ) {
603 $extHtml .= $this->parent->getCheckBox( array(
604 'var' => "ext-$ext",
605 'rawtext' => $ext,
606 ) );
607 }
608
609 $extHtml .= $this->parent->getHelpBox( 'config-extensions-help' ) .
610 $this->parent->getFieldsetEnd();
611 $this->addHTML( $extHtml );
612 }
613
614 $this->addHTML(
615 # Uploading
616 $this->parent->getFieldsetStart( 'config-upload-settings' ) .
617 $this->parent->getCheckBox( array(
618 'var' => 'wgEnableUploads',
619 'label' => 'config-upload-enable',
620 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'uploadwrapper' ),
621 ) ) .
622 $this->parent->getHelpBox( 'config-upload-help' ) .
623 '<div id="uploadwrapper" style="display: none;">' .
624 $this->parent->getTextBox( array(
625 'var' => 'wgDeletedDirectory',
626 'label' => 'config-upload-deleted',
627 ) ) .
628 $this->parent->getHelpBox( 'config-upload-deleted-help' ) .
629 '</div>' .
630 $this->parent->getTextBox( array(
631 'var' => 'wgLogo',
632 'label' => 'config-logo'
633 ) ) .
634 $this->parent->getHelpBox( 'config-logo-help' )
635 );
636 $canUse = $this->getVar( '_ExternalHTTP' ) ?
637 'config-instantcommons-good' : 'config-instantcommons-bad';
638 $this->addHTML(
639 $this->parent->getCheckBox( array(
640 'var' => 'wgUseInstantCommons',
641 'label' => 'config-instantcommons',
642 ) ) .
643 $this->parent->getHelpBox( 'config-instantcommons-help', wfMsgNoTrans( $canUse ) ) .
644 $this->parent->getFieldsetEnd()
645 );
646
647 $caches = array( 'none' );
648 if( count( $this->getVar( '_Caches' ) ) ) {
649 $caches[] = 'accel';
650 }
651 $caches[] = 'memcached';
652
653 $this->addHTML(
654 # Advanced settings
655 $this->parent->getFieldsetStart( 'config-advanced-settings' ) .
656 # Object cache settings
657 $this->parent->getRadioSet( array(
658 'var' => 'wgMainCacheType',
659 'label' => 'config-cache-options',
660 'itemLabelPrefix' => 'config-cache-',
661 'values' => $caches,
662 'value' => 'none',
663 ) ) .
664 $this->parent->getHelpBox( 'config-cache-help' ) .
665 '<div id="config-memcachewrapper">' .
666 $this->parent->getTextBox( array(
667 'var' => '_MemCachedServers',
668 'label' => 'config-memcached-servers',
669 ) ) .
670 $this->parent->getHelpBox( 'config-memcached-help' ) . '</div>' .
671 $this->parent->getFieldsetEnd()
672 );
673 $this->endForm();
674 }
675
676 public function getCCPartnerUrl() {
677 global $wgServer;
678 $exitUrl = $wgServer . $this->parent->getUrl( array(
679 'page' => 'Options',
680 'SubmitCC' => 'indeed',
681 'config__LicenseCode' => 'cc',
682 'config_wgRightsUrl' => '[license_url]',
683 'config_wgRightsText' => '[license_name]',
684 'config_wgRightsIcon' => '[license_button]',
685 ) );
686 $styleUrl = $wgServer . dirname( dirname( $this->parent->getUrl() ) ) .
687 '/skins/common/config-cc.css';
688 $iframeUrl = 'http://creativecommons.org/license/?' .
689 wfArrayToCGI( array(
690 'partner' => 'MediaWiki',
691 'exit_url' => $exitUrl,
692 'lang' => $this->getVar( '_UserLang' ),
693 'stylesheet' => $styleUrl,
694 ) );
695 return $iframeUrl;
696 }
697
698 public function getCCChooser() {
699 $iframeAttribs = array(
700 'class' => 'config-cc-iframe',
701 'name' => 'config-cc-iframe',
702 'id' => 'config-cc-iframe',
703 'frameborder' => 0,
704 'width' => '100%',
705 'height' => '100%',
706 );
707 if ( $this->getVar( '_CCDone' ) ) {
708 $iframeAttribs['src'] = $this->parent->getUrl( array( 'ShowCC' => 'yes' ) );
709 } else {
710 $iframeAttribs['src'] = $this->getCCPartnerUrl();
711 }
712
713 return
714 "<div class=\"config-cc-wrapper\" id=\"config-cc-wrapper\" style=\"display: none;\">\n" .
715 Xml::element( 'iframe', $iframeAttribs, '', false /* not short */ ) .
716 "</div>\n";
717 }
718
719 public function getCCDoneBox() {
720 $js = "parent.document.getElementById('config-cc-wrapper').style.height = '$1';";
721 // If you change this height, also change it in config.css
722 $expandJs = str_replace( '$1', '54em', $js );
723 $reduceJs = str_replace( '$1', '70px', $js );
724 return
725 '<p>'.
726 Xml::element( 'img', array( 'src' => $this->getVar( 'wgRightsIcon' ) ) ) .
727 '&#160;&#160;' .
728 htmlspecialchars( $this->getVar( 'wgRightsText' ) ) .
729 "</p>\n" .
730 "<p style=\"text-align: center\">" .
731 Xml::element( 'a',
732 array(
733 'href' => $this->getCCPartnerUrl(),
734 'onclick' => $expandJs,
735 ),
736 wfMsg( 'config-cc-again' )
737 ) .
738 "</p>\n" .
739 "<script type=\"text/javascript\">\n" .
740 # Reduce the wrapper div height
741 htmlspecialchars( $reduceJs ) .
742 "\n" .
743 "</script>\n";
744 }
745
746 public function submitCC() {
747 $newValues = $this->parent->setVarsFromRequest(
748 array( 'wgRightsUrl', 'wgRightsText', 'wgRightsIcon' ) );
749 if ( count( $newValues ) != 3 ) {
750 $this->parent->showError( 'config-cc-error' );
751 return;
752 }
753 $this->setVar( '_CCDone', true );
754 $this->addHTML( $this->getCCDoneBox() );
755 }
756
757 public function submit() {
758 $this->parent->setVarsFromRequest( array( '_RightsProfile', '_LicenseCode',
759 'wgEnableEmail', 'wgPasswordSender', 'wgEnableUpload', 'wgLogo',
760 'wgEnableUserEmail', 'wgEnotifUserTalk', 'wgEnotifWatchlist',
761 'wgEmailAuthentication', 'wgMainCacheType', '_MemCachedServers',
762 'wgUseInstantCommons' ) );
763
764 if ( !in_array( $this->getVar( '_RightsProfile' ),
765 array_keys( $this->parent->rightsProfiles ) ) )
766 {
767 reset( $this->parent->rightsProfiles );
768 $this->setVar( '_RightsProfile', key( $this->parent->rightsProfiles ) );
769 }
770
771 $code = $this->getVar( '_LicenseCode' );
772 if ( $code == 'cc-choose' ) {
773 if ( !$this->getVar( '_CCDone' ) ) {
774 $this->parent->showError( 'config-cc-not-chosen' );
775 return false;
776 }
777 } elseif ( in_array( $code, array_keys( $this->parent->licenses ) ) ) {
778 $entry = $this->parent->licenses[$code];
779 if ( isset( $entry['text'] ) ) {
780 $this->setVar( 'wgRightsText', $entry['text'] );
781 } else {
782 $this->setVar( 'wgRightsText', wfMsg( 'config-license-' . $code ) );
783 }
784 $this->setVar( 'wgRightsUrl', $entry['url'] );
785 $this->setVar( 'wgRightsIcon', $entry['icon'] );
786 } else {
787 $this->setVar( 'wgRightsText', '' );
788 $this->setVar( 'wgRightsUrl', '' );
789 $this->setVar( 'wgRightsIcon', '' );
790 }
791
792 $exts = $this->parent->getVar( '_Extensions' );
793 foreach( $exts as $key => $ext ) {
794 if( !$this->parent->request->getCheck( 'config_ext-' . $ext ) ) {
795 unset( $exts[$key] );
796 }
797 }
798 $this->parent->setVar( '_Extensions', $exts );
799 return true;
800 }
801
802 }
803
804 class WebInstaller_Install extends WebInstallerPage {
805
806 public function execute() {
807 if( $this->parent->request->wasPosted() ) {
808 return 'continue';
809 } elseif( $this->getVar( '_InstallDone' ) ) {
810 $this->startForm();
811 $status = new Status();
812 $status->warning( 'config-install-alreadydone' );
813 $this->parent->showStatusBox( $status );
814 } else {
815 $this->startForm();
816 $this->addHTML("<ul>");
817 $this->parent->performInstallation(
818 array( $this, 'startStage'),
819 array( $this, 'endStage' )
820 );
821 $this->addHTML("</ul>");
822 }
823 $this->endForm();
824 return true;
825 }
826
827 public function startStage( $step ) {
828 $this->addHTML( "<li>" . wfMsgHtml( "config-install-$step" ) . wfMsg( 'ellipsis') );
829 }
830
831 public function endStage( $step, $status ) {
832 $success = $status->isGood();
833 $msg = $success ? 'config-install-step-done' : 'config-install-step-failed';
834 $html = wfMsgHtml( 'word-separator' ) . wfMsgHtml( $msg );
835 if ( !$success ) {
836 $html = "<span class=\"error\">$html</span>";
837 }
838 $this->addHTML( $html . "</li>\n" );
839 if( !$success ) {
840 $this->parent->showStatusBox( $status );
841 }
842 }
843
844 }
845
846 class WebInstaller_Complete extends WebInstallerPage {
847
848 public function execute() {
849 $this->startForm();
850 $this->addHTML(
851 $this->parent->getInfoBox(
852 wfMsgNoTrans( 'config-install-done',
853 $GLOBALS['wgServer'] . $this->parent->getURL( array( 'localsettings' => 1 ) ),
854 $GLOBALS['wgServer'] .
855 $this->getVar( 'wgScriptPath' ) . '/index' .
856 $this->getVar( 'wgScriptExtension' )
857 ), 'tick-32.png'
858 )
859 );
860 $this->endForm( false );
861 }
862 }
863
864 class WebInstaller_Restart extends WebInstallerPage {
865
866 public function execute() {
867 $r = $this->parent->request;
868 if ( $r->wasPosted() ) {
869 $really = $r->getVal( 'submit-restart' );
870 if ( $really ) {
871 $this->parent->session = array();
872 $this->parent->happyPages = array();
873 $this->parent->settings = array();
874 }
875 return 'continue';
876 }
877
878 $this->startForm();
879 $s = $this->parent->getWarningBox( wfMsgNoTrans( 'config-help-restart' ) );
880 $this->addHTML( $s );
881 $this->endForm( 'restart' );
882 }
883
884 }
885
886 abstract class WebInstaller_Document extends WebInstallerPage {
887
888 protected abstract function getFileName();
889
890 public function execute() {
891 $text = $this->getFileContents();
892 $this->parent->output->addWikiText( $text );
893 $this->startForm();
894 $this->endForm( false );
895 }
896
897 public function getFileContents() {
898 return file_get_contents( dirname( __FILE__ ) . '/../../' . $this->getFileName() );
899 }
900
901 protected function formatTextFile( $text ) {
902 $text = str_replace( array( '<', '{{', '[[' ),
903 array( '&lt;', '&#123;&#123;', '&#91;&#91;' ), $text );
904 // replace numbering with [1], [2], etc with MW-style numbering
905 $text = preg_replace( "/\r?\n(\r?\n)?\\[\\d+\\]/m", "\\1#", $text );
906 // join word-wrapped lines into one
907 do {
908 $prev = $text;
909 $text = preg_replace( "/\n([\\*#])([^\r\n]*?)\r?\n([^\r\n#\\*:]+)/", "\n\\1\\2 \\3", $text );
910 } while ( $text != $prev );
911 // turn (bug nnnn) into links
912 $text = preg_replace_callback('/bug (\d+)/', array( $this, 'replaceBugLinks' ), $text );
913 // add links to manual to every global variable mentioned
914 $text = preg_replace_callback('/(\$wg[a-z0-9_]+)/i', array( $this, 'replaceConfigLinks' ), $text );
915 // special case for <pre> - formatted links
916 do {
917 $prev = $text;
918 $text = preg_replace( '/^([^\\s].*?)\r?\n[\\s]+(https?:\/\/)/m', "\\1\n:\\2", $text );
919 } while ( $text != $prev );
920 return $text;
921 }
922
923 private function replaceBugLinks( $matches ) {
924 return '<span class="config-plainlink">[https://bugzilla.wikimedia.org/' .
925 $matches[1] . ' bug ' . $matches[1] . ']</span>';
926 }
927
928 private function replaceConfigLinks( $matches ) {
929 return '<span class="config-plainlink">[http://www.mediawiki.org/wiki/Manual:' .
930 $matches[1] . ' ' . $matches[1] . ']</span>';
931 }
932
933 }
934
935 class WebInstaller_Readme extends WebInstaller_Document {
936
937 protected function getFileName() { return 'README'; }
938
939 public function getFileContents() {
940 return $this->formatTextFile( parent::getFileContents() );
941 }
942
943 }
944
945 class WebInstaller_ReleaseNotes extends WebInstaller_Document {
946
947 protected function getFileName() { return 'RELEASE-NOTES'; }
948
949 public function getFileContents() {
950 return $this->formatTextFile( parent::getFileContents() );
951 }
952
953 }
954
955 class WebInstaller_UpgradeDoc extends WebInstaller_Document {
956
957 protected function getFileName() { return 'UPGRADE'; }
958
959 public function getFileContents() {
960 return $this->formatTextFile( parent::getFileContents() );
961 }
962
963 }
964
965 class WebInstaller_Copying extends WebInstaller_Document {
966
967 protected function getFileName() { return 'COPYING'; }
968
969 public function getFileContents() {
970 $text = parent::getFileContents();
971 $text = str_replace( "\x0C", '', $text );
972 $text = preg_replace_callback( '/\n[ \t]+/m', array( 'WebInstaller_Copying', 'replaceLeadingSpaces' ), $text );
973 $text = '<tt>' . nl2br( $text ) . '</tt>';
974 return $text;
975 }
976
977 private static function replaceLeadingSpaces( $matches ) {
978 return "\n" . str_repeat( '&#160;', strlen( $matches[0] ) );
979 }
980
981 }