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