Typofix r77949
[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 return 'continue';
205 }
206 } elseif ( $this->parent->showSessionWarning ) {
207 # The user was knocked back from another page to the start
208 # This probably indicates a session expiry
209 $this->parent->showError( 'config-session-expired', $wgLang->formatTimePeriod( $lifetime ) );
210 }
211
212 $this->parent->setSession( 'test', true );
213
214 if ( !isset( $languages[$userLang] ) ) {
215 $userLang = $this->getVar( '_UserLang', 'en' );
216 }
217 if ( !isset( $languages[$contLang] ) ) {
218 $contLang = $this->getVar( 'wgLanguageCode', 'en' );
219 }
220 $this->startForm();
221 $s = Html::hidden( 'LanguageRequestTime', time() ) .
222 $this->getLanguageSelector( 'UserLang', 'config-your-language', $userLang, $this->parent->getHelpBox( 'config-your-language-help' ) ) .
223 $this->getLanguageSelector( 'ContLang', 'config-wiki-language', $contLang, $this->parent->getHelpBox( 'config-wiki-language-help' ) );
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 = Html::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 Html::openElement( 'div', array( 'id' => 'DB_wrapper_' . $type, 'class' => 'dbWrapper' ) ) .
313 Html::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 'help' => $this->parent->getHelpBox( 'config-site-name-help' )
461 ) ) .
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 'help' => $this->parent->getHelpBox( 'config-project-namespace-help' )
469 ) ) .
470 $this->parent->getTextBox( array(
471 'var' => 'wgMetaNamespace',
472 'label' => '', //TODO: Needs a label?
473 'attribs' => array( 'readonly' => 'readonly', 'class' => 'enabledByOther' ),
474
475 ) ) .
476 $this->getFieldSetStart( 'config-admin-box' ) .
477 $this->parent->getTextBox( array(
478 'var' => '_AdminName',
479 'label' => 'config-admin-name',
480 'help' => $this->parent->getHelpBox( 'config-admin-help' )
481 ) ) .
482 $this->parent->getPasswordBox( array(
483 'var' => '_AdminPassword',
484 'label' => 'config-admin-password',
485 ) ) .
486 $this->parent->getPasswordBox( array(
487 'var' => '_AdminPassword2',
488 'label' => 'config-admin-password-confirm'
489 ) ) .
490 $this->parent->getTextBox( array(
491 'var' => '_AdminEmail',
492 'label' => 'config-admin-email',
493 'help' => $this->parent->getHelpBox( 'config-admin-email-help' )
494 ) ) .
495 $this->parent->getCheckBox( array(
496 'var' => '_Subscribe',
497 'label' => 'config-subscribe',
498 'help' => $this->parent->getHelpBox( 'config-subscribe-help' )
499 ) ) .
500 $this->getFieldSetEnd() .
501 $this->parent->getInfoBox( wfMsg( 'config-almost-done' ) ) .
502 $this->parent->getRadioSet( array(
503 'var' => '_SkipOptional',
504 'itemLabelPrefix' => 'config-optional-',
505 'values' => array( 'continue', 'skip' )
506 ) )
507 );
508
509 // Restore the default value
510 $this->setVar( 'wgMetaNamespace', $metaNS );
511
512 $this->endForm();
513 return 'output';
514 }
515
516 public function submit() {
517 $retVal = true;
518 $this->parent->setVarsFromRequest( array( 'wgSitename', '_NamespaceType',
519 '_AdminName', '_AdminPassword', '_AdminPassword2', '_AdminEmail',
520 '_Subscribe', '_SkipOptional' ) );
521
522 // Validate site name
523 if ( strval( $this->getVar( 'wgSitename' ) ) === '' ) {
524 $this->parent->showError( 'config-site-name-blank' );
525 $retVal = false;
526 }
527
528 // Fetch namespace
529 $nsType = $this->getVar( '_NamespaceType' );
530 if ( $nsType == 'site-name' ) {
531 $name = $this->getVar( 'wgSitename' );
532 // Sanitize for namespace
533 // This algorithm should match the JS one in WebInstallerOutput.php
534 $name = preg_replace( '/[\[\]\{\}|#<>%+? ]/', '_', $name );
535 $name = str_replace( '&', '&amp;', $name );
536 $name = preg_replace( '/__+/', '_', $name );
537 $name = ucfirst( trim( $name, '_' ) );
538 } elseif ( $nsType == 'generic' ) {
539 $name = wfMsg( 'config-ns-generic' );
540 } else { // other
541 $name = $this->getVar( 'wgMetaNamespace' );
542 }
543
544 // Validate namespace
545 if ( strpos( $name, ':' ) !== false ) {
546 $good = false;
547 } else {
548 // Title-style validation
549 $title = Title::newFromText( $name );
550 if ( !$title ) {
551 $good = $nsType == 'site-name';
552 } else {
553 $name = $title->getDBkey();
554 $good = true;
555 }
556 }
557 if ( !$good ) {
558 $this->parent->showError( 'config-ns-invalid', $name );
559 $retVal = false;
560 }
561 $this->setVar( 'wgMetaNamespace', $name );
562
563 // Validate username for creation
564 $name = $this->getVar( '_AdminName' );
565 if ( strval( $name ) === '' ) {
566 $this->parent->showError( 'config-admin-name-blank' );
567 $cname = $name;
568 $retVal = false;
569 } else {
570 $cname = User::getCanonicalName( $name, 'creatable' );
571 if ( $cname === false ) {
572 $this->parent->showError( 'config-admin-name-invalid', $name );
573 $retVal = false;
574 } else {
575 $this->setVar( '_AdminName', $cname );
576 }
577 }
578
579 // Validate password
580 $msg = false;
581 $valid = false;
582 $pwd = $this->getVar( '_AdminPassword' );
583 $user = User::newFromName( $cname );
584 $valid = $user && $user->getPasswordValidity( $pwd );
585 if ( strval( $pwd ) === '' ) {
586 # $user->getPasswordValidity just checks for $wgMinimalPasswordLength.
587 # This message is more specific and helpful.
588 $msg = 'config-admin-password-blank';
589 } elseif ( $pwd !== $this->getVar( '_AdminPassword2' ) ) {
590 $msg = 'config-admin-password-mismatch';
591 } elseif ( $valid !== true ) {
592 # As of writing this will only catch the username being e.g. 'FOO' and
593 # the password 'foo'
594 $msg = $valid;
595 }
596 if ( $msg !== false ) {
597 $this->parent->showError( $msg );
598 $this->setVar( '_AdminPassword', '' );
599 $this->setVar( '_AdminPassword2', '' );
600 $retVal = false;
601 }
602 return $retVal;
603 }
604
605 }
606
607 class WebInstaller_Options extends WebInstallerPage {
608
609 public function execute() {
610 if ( $this->getVar( '_SkipOptional' ) == 'skip' ) {
611 return 'skip';
612 }
613 if ( $this->parent->request->wasPosted() ) {
614 if ( $this->submit() ) {
615 return 'continue';
616 }
617 }
618
619 $this->startForm();
620 $this->addHTML(
621 # User Rights
622 $this->parent->getRadioSet( array(
623 'var' => '_RightsProfile',
624 'label' => 'config-profile',
625 'itemLabelPrefix' => 'config-profile-',
626 'values' => array_keys( $this->parent->rightsProfiles ),
627 ) ) .
628 $this->parent->getHelpBox( 'config-profile-help' ) .
629
630 # Licensing
631 $this->parent->getRadioSet( array(
632 'var' => '_LicenseCode',
633 'label' => 'config-license',
634 'itemLabelPrefix' => 'config-license-',
635 'values' => array_keys( $this->parent->licenses ),
636 'commonAttribs' => array( 'class' => 'licenseRadio' ),
637 ) ) .
638 $this->getCCChooser() .
639 $this->parent->getHelpBox( 'config-license-help' ) .
640
641 # E-mail
642 $this->getFieldSetStart( 'config-email-settings' ) .
643 $this->parent->getCheckBox( array(
644 'var' => 'wgEnableEmail',
645 'label' => 'config-enable-email',
646 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'emailwrapper' ),
647 ) ) .
648 $this->parent->getHelpBox( 'config-enable-email-help' ) .
649 "<div id=\"emailwrapper\">" .
650 $this->parent->getTextBox( array(
651 'var' => 'wgPasswordSender',
652 'label' => 'config-email-sender'
653 ) ) .
654 $this->parent->getHelpBox( 'config-email-sender-help' ) .
655 $this->parent->getCheckBox( array(
656 'var' => 'wgEnableUserEmail',
657 'label' => 'config-email-user',
658 ) ) .
659 $this->parent->getHelpBox( 'config-email-user-help' ) .
660 $this->parent->getCheckBox( array(
661 'var' => 'wgEnotifUserTalk',
662 'label' => 'config-email-usertalk',
663 ) ) .
664 $this->parent->getHelpBox( 'config-email-usertalk-help' ) .
665 $this->parent->getCheckBox( array(
666 'var' => 'wgEnotifWatchlist',
667 'label' => 'config-email-watchlist',
668 ) ) .
669 $this->parent->getHelpBox( 'config-email-watchlist-help' ) .
670 $this->parent->getCheckBox( array(
671 'var' => 'wgEmailAuthentication',
672 'label' => 'config-email-auth',
673 ) ) .
674 $this->parent->getHelpBox( 'config-email-auth-help' ) .
675 "</div>" .
676 $this->getFieldSetEnd()
677 );
678
679 $extensions = $this->parent->findExtensions();
680
681 if( $extensions ) {
682 $extHtml = $this->getFieldSetStart( 'config-extensions' );
683
684 foreach( $extensions as $ext ) {
685 $extHtml .= $this->parent->getCheckBox( array(
686 'var' => "ext-$ext",
687 'rawtext' => $ext,
688 ) );
689 }
690
691 $extHtml .= $this->parent->getHelpBox( 'config-extensions-help' ) .
692 $this->getFieldSetEnd();
693 $this->addHTML( $extHtml );
694 }
695
696 $this->addHTML(
697 # Uploading
698 $this->getFieldSetStart( 'config-upload-settings' ) .
699 $this->parent->getCheckBox( array(
700 'var' => 'wgEnableUploads',
701 'label' => 'config-upload-enable',
702 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'uploadwrapper' ),
703 'help' => $this->parent->getHelpBox( 'config-upload-help' )
704 ) ) .
705 '<div id="uploadwrapper" style="display: none;">' .
706 $this->parent->getTextBox( array(
707 'var' => 'wgDeletedDirectory',
708 'label' => 'config-upload-deleted',
709 'help' => $this->parent->getHelpBox( 'config-upload-deleted-help' )
710 ) ) .
711 '</div>' .
712 $this->parent->getTextBox( array(
713 'var' => 'wgLogo',
714 'label' => 'config-logo',
715 'help' => $this->parent->getHelpBox( 'config-logo-help' )
716 ) )
717 );
718 $this->addHTML(
719 $this->parent->getCheckBox( array(
720 'var' => 'wgUseInstantCommons',
721 'label' => 'config-instantcommons',
722 'help' => $this->parent->getHelpBox( 'config-instantcommons-help' )
723 ) ) .
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 'help' => $this->parent->getHelpBox( 'config-memcached-help' )
750 ) ) .
751 '</div>' .
752 $this->getFieldSetEnd()
753 );
754 $this->endForm();
755 }
756
757 public function getCCPartnerUrl() {
758 global $wgServer;
759 $exitUrl = $wgServer . $this->parent->getUrl( array(
760 'page' => 'Options',
761 'SubmitCC' => 'indeed',
762 'config__LicenseCode' => 'cc',
763 'config_wgRightsUrl' => '[license_url]',
764 'config_wgRightsText' => '[license_name]',
765 'config_wgRightsIcon' => '[license_button]',
766 ) );
767 $styleUrl = $wgServer . dirname( dirname( $this->parent->getUrl() ) ) .
768 '/skins/common/config-cc.css';
769 $iframeUrl = 'http://creativecommons.org/license/?' .
770 wfArrayToCGI( array(
771 'partner' => 'MediaWiki',
772 'exit_url' => $exitUrl,
773 'lang' => $this->getVar( '_UserLang' ),
774 'stylesheet' => $styleUrl,
775 ) );
776 return $iframeUrl;
777 }
778
779 public function getCCChooser() {
780 $iframeAttribs = array(
781 'class' => 'config-cc-iframe',
782 'name' => 'config-cc-iframe',
783 'id' => 'config-cc-iframe',
784 'frameborder' => 0,
785 'width' => '100%',
786 'height' => '100%',
787 );
788 if ( $this->getVar( '_CCDone' ) ) {
789 $iframeAttribs['src'] = $this->parent->getUrl( array( 'ShowCC' => 'yes' ) );
790 } else {
791 $iframeAttribs['src'] = $this->getCCPartnerUrl();
792 }
793
794 return
795 "<div class=\"config-cc-wrapper\" id=\"config-cc-wrapper\" style=\"display: none;\">\n" .
796 Html::element( 'iframe', $iframeAttribs, '', false /* not short */ ) .
797 "</div>\n";
798 }
799
800 public function getCCDoneBox() {
801 $js = "parent.document.getElementById('config-cc-wrapper').style.height = '$1';";
802 // If you change this height, also change it in config.css
803 $expandJs = str_replace( '$1', '54em', $js );
804 $reduceJs = str_replace( '$1', '70px', $js );
805 return
806 '<p>'.
807 Html::element( 'img', array( 'src' => $this->getVar( 'wgRightsIcon' ) ) ) .
808 '&#160;&#160;' .
809 htmlspecialchars( $this->getVar( 'wgRightsText' ) ) .
810 "</p>\n" .
811 "<p style=\"text-align: center\">" .
812 Html::element( 'a',
813 array(
814 'href' => $this->getCCPartnerUrl(),
815 'onclick' => $expandJs,
816 ),
817 wfMsg( 'config-cc-again' )
818 ) .
819 "</p>\n" .
820 "<script type=\"text/javascript\">\n" .
821 # Reduce the wrapper div height
822 htmlspecialchars( $reduceJs ) .
823 "\n" .
824 "</script>\n";
825 }
826
827 public function submitCC() {
828 $newValues = $this->parent->setVarsFromRequest(
829 array( 'wgRightsUrl', 'wgRightsText', 'wgRightsIcon' ) );
830 if ( count( $newValues ) != 3 ) {
831 $this->parent->showError( 'config-cc-error' );
832 return;
833 }
834 $this->setVar( '_CCDone', true );
835 $this->addHTML( $this->getCCDoneBox() );
836 }
837
838 public function submit() {
839 $this->parent->setVarsFromRequest( array( '_RightsProfile', '_LicenseCode',
840 'wgEnableEmail', 'wgPasswordSender', 'wgEnableUploads', 'wgLogo',
841 'wgEnableUserEmail', 'wgEnotifUserTalk', 'wgEnotifWatchlist',
842 'wgEmailAuthentication', 'wgMainCacheType', '_MemCachedServers',
843 'wgUseInstantCommons' ) );
844
845 if ( !in_array( $this->getVar( '_RightsProfile' ),
846 array_keys( $this->parent->rightsProfiles ) ) )
847 {
848 reset( $this->parent->rightsProfiles );
849 $this->setVar( '_RightsProfile', key( $this->parent->rightsProfiles ) );
850 }
851
852 $code = $this->getVar( '_LicenseCode' );
853 if ( $code == 'cc-choose' ) {
854 if ( !$this->getVar( '_CCDone' ) ) {
855 $this->parent->showError( 'config-cc-not-chosen' );
856 return false;
857 }
858 } elseif ( in_array( $code, array_keys( $this->parent->licenses ) ) ) {
859 $entry = $this->parent->licenses[$code];
860 if ( isset( $entry['text'] ) ) {
861 $this->setVar( 'wgRightsText', $entry['text'] );
862 } else {
863 $this->setVar( 'wgRightsText', wfMsg( 'config-license-' . $code ) );
864 }
865 $this->setVar( 'wgRightsUrl', $entry['url'] );
866 $this->setVar( 'wgRightsIcon', $entry['icon'] );
867 } else {
868 $this->setVar( 'wgRightsText', '' );
869 $this->setVar( 'wgRightsUrl', '' );
870 $this->setVar( 'wgRightsIcon', '' );
871 }
872
873 $extsAvailable = $this->parent->findExtensions();
874 $extsToInstall = array();
875 foreach( $extsAvailable as $ext ) {
876 if( $this->parent->request->getCheck( 'config_ext-' . $ext ) ) {
877 $extsToInstall[] = $ext;
878 }
879 }
880 $this->parent->setVar( '_Extensions', $extsToInstall );
881 return true;
882 }
883
884 }
885
886 class WebInstaller_Install extends WebInstallerPage {
887
888 public function execute() {
889 if( $this->parent->request->wasPosted() ) {
890 return 'continue';
891 } elseif( $this->getVar( '_InstallDone' ) ) {
892 $this->startForm();
893 $status = new Status();
894 $status->warning( 'config-install-alreadydone' );
895 $this->parent->showStatusBox( $status );
896 } elseif( $this->getVar( '_UpgradeDone' ) ) {
897 return 'skip';
898 } else {
899 $this->startForm();
900 $this->addHTML("<ul>");
901 $this->parent->performInstallation(
902 array( $this, 'startStage'),
903 array( $this, 'endStage' )
904 );
905 $this->addHTML("</ul>");
906 }
907 $this->endForm();
908 return true;
909 }
910
911 public function startStage( $step ) {
912 $this->addHTML( "<li>" . wfMsgHtml( "config-install-$step" ) . wfMsg( 'ellipsis') );
913 }
914
915 public function endStage( $step, $status ) {
916 $msg = $status->isOk() ? 'config-install-step-done' : 'config-install-step-failed';
917 $html = wfMsgHtml( 'word-separator' ) . wfMsgHtml( $msg );
918 if ( !$status->isOk() ) {
919 $html = "<span class=\"error\">$html</span>";
920 }
921 $this->addHTML( $html . "</li>\n" );
922 if( !$status->isGood() ) {
923 $this->parent->showStatusBox( $status );
924 }
925 }
926
927 }
928
929 class WebInstaller_Complete extends WebInstallerPage {
930
931 public function execute() {
932 // Pop up a dialog box, to make it difficult for the user to forget
933 // to download the file
934 $lsUrl = $GLOBALS['wgServer'] . $this->parent->getURL( array( 'localsettings' => 1 ) );
935 $this->parent->request->response()->header( "Refresh: 0;$lsUrl" );
936
937 $this->startForm();
938 $this->addHTML(
939 $this->parent->getInfoBox(
940 wfMsgNoTrans( 'config-install-done',
941 $lsUrl,
942 $GLOBALS['wgServer'] .
943 $this->getVar( 'wgScriptPath' ) . '/index' .
944 $this->getVar( 'wgScriptExtension' )
945 ), 'tick-32.png'
946 )
947 );
948 $this->endForm( false );
949 }
950 }
951
952 class WebInstaller_Restart extends WebInstallerPage {
953
954 public function execute() {
955 $r = $this->parent->request;
956 if ( $r->wasPosted() ) {
957 $really = $r->getVal( 'submit-restart' );
958 if ( $really ) {
959 $this->parent->session = array();
960 $this->parent->happyPages = array();
961 $this->parent->settings = array();
962 }
963 return 'continue';
964 }
965
966 $this->startForm();
967 $s = $this->parent->getWarningBox( wfMsgNoTrans( 'config-help-restart' ) );
968 $this->addHTML( $s );
969 $this->endForm( 'restart' );
970 }
971
972 }
973
974 abstract class WebInstaller_Document extends WebInstallerPage {
975
976 protected abstract function getFileName();
977
978 public function execute() {
979 $text = $this->getFileContents();
980 $text = $this->formatTextFile( $text );
981 $this->parent->output->addWikiText( $text );
982 $this->startForm();
983 $this->endForm( false );
984 }
985
986 public function getFileContents() {
987 return file_get_contents( dirname( __FILE__ ) . '/../../' . $this->getFileName() );
988 }
989
990 protected function formatTextFile( $text ) {
991 // Use Unix line endings, escape some wikitext stuff
992 $text = str_replace( array( '<', '{{', '[[', "\r" ),
993 array( '&lt;', '&#123;&#123;', '&#91;&#91;', '' ), $text );
994 // join word-wrapped lines into one
995 do {
996 $prev = $text;
997 $text = preg_replace( "/\n([\\*#\t])([^\n]*?)\n([^\n#\\*:]+)/", "\n\\1\\2 \\3", $text );
998 } while ( $text != $prev );
999 // Replace tab indents with colons
1000 $text = preg_replace( '/^\t\t/m', '::', $text );
1001 $text = preg_replace( '/^\t/m', ':', $text );
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 return $text;
1007 }
1008
1009 private function replaceBugLinks( $matches ) {
1010 return '<span class="config-plainlink">[https://bugzilla.wikimedia.org/' .
1011 $matches[1] . ' bug ' . $matches[1] . ']</span>';
1012 }
1013
1014 private function replaceConfigLinks( $matches ) {
1015 return '<span class="config-plainlink">[http://www.mediawiki.org/wiki/Manual:' .
1016 $matches[1] . ' ' . $matches[1] . ']</span>';
1017 }
1018
1019 }
1020
1021 class WebInstaller_Readme extends WebInstaller_Document {
1022 protected function getFileName() { return 'README'; }
1023 }
1024
1025 class WebInstaller_ReleaseNotes extends WebInstaller_Document {
1026 protected function getFileName() { return 'RELEASE-NOTES'; }
1027 }
1028
1029 class WebInstaller_UpgradeDoc extends WebInstaller_Document {
1030 protected function getFileName() { return 'UPGRADE'; }
1031 }
1032
1033 class WebInstaller_Copying extends WebInstaller_Document {
1034 protected function getFileName() { return 'COPYING'; }
1035 }
1036