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