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