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