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