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