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