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