Add support for Number grouping(commafy) based on CLDR number grouping patterns like...
[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 /**
36 * Is this a slow-running page in the installer? If so, WebInstaller will
37 * set_time_limit(0) before calling execute(). Right now this only applies
38 * to Install and Upgrade pages
39 */
40 public function isSlow() {
41 return false;
42 }
43
44 public function addHTML( $html ) {
45 $this->parent->output->addHTML( $html );
46 }
47
48 public function startForm() {
49 $this->addHTML(
50 "<div class=\"config-section\">\n" .
51 Html::openElement(
52 'form',
53 array(
54 'method' => 'post',
55 'action' => $this->parent->getUrl( array( 'page' => $this->getName() ) )
56 )
57 ) . "\n"
58 );
59 }
60
61 public function endForm( $continue = 'continue', $back = 'back' ) {
62 $s = "<div class=\"config-submit\">\n";
63 $id = $this->getId();
64
65 if ( $id === false ) {
66 $s .= Html::hidden( 'lastPage', $this->parent->request->getVal( 'lastPage' ) );
67 }
68
69 if ( $continue ) {
70 // Fake submit button for enter keypress (bug 26267)
71 $s .= Xml::submitButton( wfMsg( "config-$continue" ),
72 array( 'name' => "enter-$continue", 'style' => 'visibility:hidden;overflow:hidden;width:1px;margin:0' ) ) . "\n";
73 }
74
75 if ( $back ) {
76 $s .= Xml::submitButton( wfMsg( "config-$back" ),
77 array(
78 'name' => "submit-$back",
79 'tabindex' => $this->parent->nextTabIndex()
80 ) ) . "\n";
81 }
82
83 if ( $continue ) {
84 $s .= Xml::submitButton( wfMsg( "config-$continue" ),
85 array(
86 'name' => "submit-$continue",
87 'tabindex' => $this->parent->nextTabIndex(),
88 ) ) . "\n";
89 }
90
91 $s .= "</div></form></div>\n";
92 $this->addHTML( $s );
93 }
94
95 public function getName() {
96 return str_replace( 'WebInstaller_', '', get_class( $this ) );
97 }
98
99 protected function getId() {
100 return array_search( $this->getName(), $this->parent->pageSequence );
101 }
102
103 public function getVar( $var ) {
104 return $this->parent->getVar( $var );
105 }
106
107 public function setVar( $name, $value ) {
108 $this->parent->setVar( $name, $value );
109 }
110
111 /**
112 * Get the starting tags of a fieldset.
113 *
114 * @param $legend String: message name
115 *
116 * @return string
117 */
118 protected function getFieldsetStart( $legend ) {
119 return "\n<fieldset><legend>" . wfMsgHtml( $legend ) . "</legend>\n";
120 }
121
122 /**
123 * Get the end tag of a fieldset.
124 *
125 * @returns string
126 */
127 protected function getFieldsetEnd() {
128 return "</fieldset>\n";
129 }
130
131 /**
132 * Opens a textarea used to display the progress of a long operation
133 */
134 protected function startLiveBox() {
135 $this->addHTML(
136 '<div id="config-spinner" style="display:none;"><img src="../skins/common/images/ajax-loader.gif" /></div>' .
137 '<script>jQuery( "#config-spinner" ).show();</script>' .
138 '<div id="config-live-log"><textarea name="LiveLog" rows="10" cols="30" readonly="readonly">'
139 );
140 $this->parent->output->flush();
141 }
142
143 /**
144 * Opposite to startLiveBox()
145 */
146 protected function endLiveBox() {
147 $this->addHTML( '</textarea></div>
148 <script>jQuery( "#config-spinner" ).hide()</script>' );
149 $this->parent->output->flush();
150 }
151 }
152
153 class WebInstaller_Language extends WebInstallerPage {
154
155 public function execute() {
156 global $wgLang;
157 $r = $this->parent->request;
158 $userLang = $r->getVal( 'UserLang' );
159 $contLang = $r->getVal( 'ContLang' );
160
161 $lifetime = intval( ini_get( 'session.gc_maxlifetime' ) );
162 if ( !$lifetime ) {
163 $lifetime = 1440; // PHP default
164 }
165
166 if ( $r->wasPosted() ) {
167 # Do session test
168 if ( $this->parent->getSession( 'test' ) === null ) {
169 $requestTime = $r->getVal( 'LanguageRequestTime' );
170 if ( !$requestTime ) {
171 // The most likely explanation is that the user was knocked back
172 // from another page on POST due to session expiry
173 $msg = 'config-session-expired';
174 } elseif ( time() - $requestTime > $lifetime ) {
175 $msg = 'config-session-expired';
176 } else {
177 $msg = 'config-no-session';
178 }
179 $this->parent->showError( $msg, $wgLang->formatTimePeriod( $lifetime ) );
180 } else {
181 $languages = Language::getLanguageNames();
182 if ( isset( $languages[$userLang] ) ) {
183 $this->setVar( '_UserLang', $userLang );
184 }
185 if ( isset( $languages[$contLang] ) ) {
186 $this->setVar( 'wgLanguageCode', $contLang );
187 }
188 return 'continue';
189 }
190 } elseif ( $this->parent->showSessionWarning ) {
191 # The user was knocked back from another page to the start
192 # This probably indicates a session expiry
193 $this->parent->showError( 'config-session-expired', $wgLang->formatTimePeriod( $lifetime ) );
194 }
195
196 $this->parent->setSession( 'test', true );
197
198 if ( !isset( $languages[$userLang] ) ) {
199 $userLang = $this->getVar( '_UserLang', 'en' );
200 }
201 if ( !isset( $languages[$contLang] ) ) {
202 $contLang = $this->getVar( 'wgLanguageCode', 'en' );
203 }
204 $this->startForm();
205 $s = Html::hidden( 'LanguageRequestTime', time() ) .
206 $this->getLanguageSelector( 'UserLang', 'config-your-language', $userLang, $this->parent->getHelpBox( 'config-your-language-help' ) ) .
207 $this->getLanguageSelector( 'ContLang', 'config-wiki-language', $contLang, $this->parent->getHelpBox( 'config-wiki-language-help' ) );
208 $this->addHTML( $s );
209 $this->endForm( 'continue', false );
210 }
211
212 /**
213 * Get a <select> for selecting languages.
214 *
215 * @return string
216 */
217 public function getLanguageSelector( $name, $label, $selectedCode, $helpHtml = '' ) {
218 global $wgDummyLanguageCodes;
219
220 $s = $helpHtml;
221
222 $s .= Html::openElement( 'select', array( 'id' => $name, 'name' => $name ) ) . "\n";
223
224 $languages = Language::getLanguageNames();
225 ksort( $languages );
226 $dummies = array_flip( $wgDummyLanguageCodes );
227 foreach ( $languages as $code => $lang ) {
228 if ( isset( $dummies[$code] ) ) continue;
229 $s .= "\n" . Xml::option( "$code - $lang", $code, $code == $selectedCode );
230 }
231 $s .= "\n</select>\n";
232 return $this->parent->label( $label, $name, $s );
233 }
234
235 }
236
237 class WebInstaller_ExistingWiki extends WebInstallerPage {
238 public function execute() {
239 // If there is no LocalSettings.php, continue to the installer welcome page
240 $vars = Installer::getExistingLocalSettings();
241 if ( !$vars ) {
242 return 'skip';
243 }
244
245 // Check if the upgrade key supplied to the user has appeared in LocalSettings.php
246 if ( $vars['wgUpgradeKey'] !== false
247 && $this->getVar( '_UpgradeKeySupplied' )
248 && $this->getVar( 'wgUpgradeKey' ) === $vars['wgUpgradeKey'] )
249 {
250 // It's there, so the user is authorized
251 $status = $this->handleExistingUpgrade( $vars );
252 if ( $status->isOK() ) {
253 return 'skip';
254 } else {
255 $this->startForm();
256 $this->parent->showStatusBox( $status );
257 $this->endForm( 'continue' );
258 return 'output';
259 }
260 }
261
262 // If there is no $wgUpgradeKey, tell the user to add one to LocalSettings.php
263 if ( $vars['wgUpgradeKey'] === false ) {
264 if ( $this->getVar( 'wgUpgradeKey', false ) === false ) {
265 $secretKey = $this->getVar( 'wgSecretKey' ); // preserve $wgSecretKey
266 $this->parent->generateKeys();
267 $this->setVar( 'wgSecretKey', $secretKey );
268 $this->setVar( '_UpgradeKeySupplied', true );
269 }
270 $this->startForm();
271 $this->addHTML( $this->parent->getInfoBox(
272 wfMsgNoTrans( 'config-upgrade-key-missing',
273 "<pre>\$wgUpgradeKey = '" . $this->getVar( 'wgUpgradeKey' ) . "';</pre>" )
274 ) );
275 $this->endForm( 'continue' );
276 return 'output';
277 }
278
279 // If there is an upgrade key, but it wasn't supplied, prompt the user to enter it
280
281 $r = $this->parent->request;
282 if ( $r->wasPosted() ) {
283 $key = $r->getText( 'config_wgUpgradeKey' );
284 if( !$key || $key !== $vars['wgUpgradeKey'] ) {
285 $this->parent->showError( 'config-localsettings-badkey' );
286 $this->showKeyForm();
287 return 'output';
288 }
289 // Key was OK
290 $status = $this->handleExistingUpgrade( $vars );
291 if ( $status->isOK() ) {
292 return 'continue';
293 } else {
294 $this->parent->showStatusBox( $status );
295 $this->showKeyForm();
296 return 'output';
297 }
298 } else {
299 $this->showKeyForm();
300 return 'output';
301 }
302 }
303
304 /**
305 * Show the "enter key" form
306 */
307 protected function showKeyForm() {
308 $this->startForm();
309 $this->addHTML(
310 $this->parent->getInfoBox( wfMsgNoTrans( 'config-localsettings-upgrade' ) ).
311 '<br />' .
312 $this->parent->getTextBox( array(
313 'var' => 'wgUpgradeKey',
314 'label' => 'config-localsettings-key',
315 'attribs' => array( 'autocomplete' => 'off' ),
316 ) )
317 );
318 $this->endForm( 'continue' );
319 }
320
321 protected function importVariables( $names, $vars ) {
322 $status = Status::newGood();
323 foreach ( $names as $name ) {
324 if ( !isset( $vars[$name] ) ) {
325 $status->fatal( 'config-localsettings-incomplete', $name );
326 }
327 $this->setVar( $name, $vars[$name] );
328 }
329 return $status;
330 }
331
332 /**
333 * Initiate an upgrade of the existing database
334 * @param $vars Variables from LocalSettings.php and AdminSettings.php
335 * @return Status
336 */
337 protected function handleExistingUpgrade( $vars ) {
338 // Check $wgDBtype
339 if ( !isset( $vars['wgDBtype'] ) || !in_array( $vars['wgDBtype'], Installer::getDBTypes() ) ) {
340 return Status::newFatal( 'config-localsettings-connection-error', '' );
341 }
342
343 // Set the relevant variables from LocalSettings.php
344 $requiredVars = array( 'wgDBtype' );
345 $status = $this->importVariables( $requiredVars , $vars );
346 $installer = $this->parent->getDBInstaller();
347 $status->merge( $this->importVariables( $installer->getGlobalNames(), $vars ) );
348 if ( !$status->isOK() ) {
349 return $status;
350 }
351
352 if ( isset( $vars['wgDBadminuser'] ) ) {
353 $this->setVar( '_InstallUser', $vars['wgDBadminuser'] );
354 } else {
355 $this->setVar( '_InstallUser', $vars['wgDBuser'] );
356 }
357 if ( isset( $vars['wgDBadminpassword'] ) ) {
358 $this->setVar( '_InstallPassword', $vars['wgDBadminpassword'] );
359 } else {
360 $this->setVar( '_InstallPassword', $vars['wgDBpassword'] );
361 }
362
363 // Test the database connection
364 $status = $installer->getConnection();
365 if ( !$status->isOK() ) {
366 // Adjust the error message to explain things correctly
367 $status->replaceMessage( 'config-connection-error',
368 'config-localsettings-connection-error' );
369 return $status;
370 }
371
372 // All good
373 $this->setVar( '_ExistingDBSettings', true );
374 return $status;
375 }
376 }
377
378 class WebInstaller_Welcome extends WebInstallerPage {
379
380 public function execute() {
381 if ( $this->parent->request->wasPosted() ) {
382 if ( $this->getVar( '_Environment' ) ) {
383 return 'continue';
384 }
385 }
386 $this->parent->output->addWikiText( wfMsgNoTrans( 'config-welcome' ) );
387 $status = $this->parent->doEnvironmentChecks();
388 if ( $status->isGood() ) {
389 $this->parent->output->addHTML( '<span class="success-message">' .
390 wfMsgHtml( 'config-env-good' ) . '</span>' );
391 $this->parent->output->addWikiText( wfMsgNoTrans( 'config-copyright',
392 SpecialVersion::getCopyrightAndAuthorList() ) );
393 $this->startForm();
394 $this->endForm();
395 } else {
396 $this->parent->showStatusMessage( $status );
397 }
398 }
399
400 }
401
402 class WebInstaller_DBConnect extends WebInstallerPage {
403
404 public function execute() {
405 if ( $this->getVar( '_ExistingDBSettings' ) ) {
406 return 'skip';
407 }
408
409 $r = $this->parent->request;
410 if ( $r->wasPosted() ) {
411 $status = $this->submit();
412
413 if ( $status->isGood() ) {
414 $this->setVar( '_UpgradeDone', false );
415 return 'continue';
416 } else {
417 $this->parent->showStatusBox( $status );
418 }
419 }
420
421 $this->startForm();
422
423 $types = "<ul class=\"config-settings-block\">\n";
424 $settings = '';
425 $defaultType = $this->getVar( 'wgDBtype' );
426
427 $dbSupport = '';
428 foreach( $this->parent->getDBTypes() as $type ) {
429 $link = DatabaseBase::factory( $type )->getSoftwareLink();
430 $dbSupport .= wfMsgNoTrans( "config-support-$type", $link ) . "\n";
431 }
432 $this->addHTML( $this->parent->getInfoBox(
433 wfMsg( 'config-support-info', $dbSupport ) ) );
434
435 foreach ( $this->parent->getVar( '_CompiledDBs' ) as $type ) {
436 $installer = $this->parent->getDBInstaller( $type );
437 $types .=
438 '<li>' .
439 Xml::radioLabel(
440 $installer->getReadableName(),
441 'DBType',
442 $type,
443 "DBType_$type",
444 $type == $defaultType,
445 array( 'class' => 'dbRadio', 'rel' => "DB_wrapper_$type" )
446 ) .
447 "</li>\n";
448
449 $settings .=
450 Html::openElement( 'div', array( 'id' => 'DB_wrapper_' . $type, 'class' => 'dbWrapper' ) ) .
451 Html::element( 'h3', array(), wfMsg( 'config-header-' . $type ) ) .
452 $installer->getConnectForm() .
453 "</div>\n";
454 }
455 $types .= "</ul><br clear=\"left\"/>\n";
456
457 $this->addHTML(
458 $this->parent->label( 'config-db-type', false, $types ) .
459 $settings
460 );
461
462 $this->endForm();
463 }
464
465 public function submit() {
466 $r = $this->parent->request;
467 $type = $r->getVal( 'DBType' );
468 $this->setVar( 'wgDBtype', $type );
469 $installer = $this->parent->getDBInstaller( $type );
470 if ( !$installer ) {
471 return Status::newFatal( 'config-invalid-db-type' );
472 }
473 return $installer->submitConnectForm();
474 }
475
476 }
477
478 class WebInstaller_Upgrade extends WebInstallerPage {
479 public function isSlow() {
480 return true;
481 }
482
483 public function execute() {
484 if ( $this->getVar( '_UpgradeDone' ) ) {
485 // Allow regeneration of LocalSettings.php, unless we are working
486 // from a pre-existing LocalSettings.php file and we want to avoid
487 // leaking its contents
488 if ( $this->parent->request->wasPosted() && !$this->getVar( '_ExistingDBSettings' ) ) {
489 // Done message acknowledged
490 return 'continue';
491 } else {
492 // Back button click
493 // Show the done message again
494 // Make them click back again if they want to do the upgrade again
495 $this->showDoneMessage();
496 return 'output';
497 }
498 }
499
500 // wgDBtype is generally valid here because otherwise the previous page
501 // (connect) wouldn't have declared its happiness
502 $type = $this->getVar( 'wgDBtype' );
503 $installer = $this->parent->getDBInstaller( $type );
504
505 if ( !$installer->needsUpgrade() ) {
506 return 'skip';
507 }
508
509 if ( $this->parent->request->wasPosted() ) {
510 $installer->preUpgrade();
511
512 $this->startLiveBox();
513 $result = $installer->doUpgrade();
514 $this->endLiveBox();
515
516 if ( $result ) {
517 // If they're going to possibly regenerate LocalSettings, we
518 // need to create the upgrade/secret keys. Bug 26481
519 if( !$this->getVar( '_ExistingDBSettings' ) ) {
520 $this->parent->generateKeys();
521 }
522 $this->setVar( '_UpgradeDone', true );
523 $this->showDoneMessage();
524 return 'output';
525 }
526 }
527
528 $this->startForm();
529 $this->addHTML( $this->parent->getInfoBox(
530 wfMsgNoTrans( 'config-can-upgrade', $GLOBALS['wgVersion'] ) ) );
531 $this->endForm();
532 }
533
534 public function showDoneMessage() {
535 $this->startForm();
536 $regenerate = !$this->getVar( '_ExistingDBSettings' );
537 if ( $regenerate ) {
538 $msg = 'config-upgrade-done';
539 } else {
540 $msg = 'config-upgrade-done-no-regenerate';
541 }
542 $this->parent->disableLinkPopups();
543 $this->addHTML(
544 $this->parent->getInfoBox(
545 wfMsgNoTrans( $msg,
546 $this->getVar( 'wgServer' ) .
547 $this->getVar( 'wgScriptPath' ) . '/index' .
548 $this->getVar( 'wgScriptExtension' )
549 ), 'tick-32.png'
550 )
551 );
552 $this->parent->restoreLinkPopups();
553 $this->endForm( $regenerate ? 'regenerate' : false, false );
554 }
555
556 }
557
558 class WebInstaller_DBSettings extends WebInstallerPage {
559
560 public function execute() {
561 $installer = $this->parent->getDBInstaller( $this->getVar( 'wgDBtype' ) );
562
563 $r = $this->parent->request;
564 if ( $r->wasPosted() ) {
565 $status = $installer->submitSettingsForm();
566 if ( $status === false ) {
567 return 'skip';
568 } elseif ( $status->isGood() ) {
569 return 'continue';
570 } else {
571 $this->parent->showStatusBox( $status );
572 }
573 }
574
575 $form = $installer->getSettingsForm();
576 if ( $form === false ) {
577 return 'skip';
578 }
579
580 $this->startForm();
581 $this->addHTML( $form );
582 $this->endForm();
583 }
584
585 }
586
587 class WebInstaller_Name extends WebInstallerPage {
588
589 public function execute() {
590 $r = $this->parent->request;
591 if ( $r->wasPosted() ) {
592 if ( $this->submit() ) {
593 return 'continue';
594 }
595 }
596
597 $this->startForm();
598
599 // Encourage people to not name their site 'MediaWiki' by blanking the
600 // field. I think that was the intent with the original $GLOBALS['wgSitename']
601 // but these two always were the same so had the effect of making the
602 // installer forget $wgSitename when navigating back to this page.
603 if ( $this->getVar( 'wgSitename' ) == 'MediaWiki' ) {
604 $this->setVar( 'wgSitename', '' );
605 }
606
607 // Set wgMetaNamespace to something valid before we show the form.
608 // $wgMetaNamespace defaults to $wgSiteName which is 'MediaWiki'
609 $metaNS = $this->getVar( 'wgMetaNamespace' );
610 $this->setVar( 'wgMetaNamespace', wfMsgForContent( 'config-ns-other-default' ) );
611
612 $this->addHTML(
613 $this->parent->getTextBox( array(
614 'var' => 'wgSitename',
615 'label' => 'config-site-name',
616 'help' => $this->parent->getHelpBox( 'config-site-name-help' )
617 ) ) .
618 $this->parent->getRadioSet( array(
619 'var' => '_NamespaceType',
620 'label' => 'config-project-namespace',
621 'itemLabelPrefix' => 'config-ns-',
622 'values' => array( 'site-name', 'generic', 'other' ),
623 'commonAttribs' => array( 'class' => 'enableForOther', 'rel' => 'config_wgMetaNamespace' ),
624 'help' => $this->parent->getHelpBox( 'config-project-namespace-help' )
625 ) ) .
626 $this->parent->getTextBox( array(
627 'var' => 'wgMetaNamespace',
628 'label' => '', //TODO: Needs a label?
629 'attribs' => array( 'readonly' => 'readonly', 'class' => 'enabledByOther' ),
630
631 ) ) .
632 $this->getFieldSetStart( 'config-admin-box' ) .
633 $this->parent->getTextBox( array(
634 'var' => '_AdminName',
635 'label' => 'config-admin-name',
636 'help' => $this->parent->getHelpBox( 'config-admin-help' )
637 ) ) .
638 $this->parent->getPasswordBox( array(
639 'var' => '_AdminPassword',
640 'label' => 'config-admin-password',
641 ) ) .
642 $this->parent->getPasswordBox( array(
643 'var' => '_AdminPassword2',
644 'label' => 'config-admin-password-confirm'
645 ) ) .
646 $this->parent->getTextBox( array(
647 'var' => '_AdminEmail',
648 'label' => 'config-admin-email',
649 'help' => $this->parent->getHelpBox( 'config-admin-email-help' )
650 ) ) .
651 $this->parent->getCheckBox( array(
652 'var' => '_Subscribe',
653 'label' => 'config-subscribe',
654 'help' => $this->parent->getHelpBox( 'config-subscribe-help' )
655 ) ) .
656 $this->getFieldSetEnd() .
657 $this->parent->getInfoBox( wfMsg( 'config-almost-done' ) ) .
658 $this->parent->getRadioSet( array(
659 'var' => '_SkipOptional',
660 'itemLabelPrefix' => 'config-optional-',
661 'values' => array( 'continue', 'skip' )
662 ) )
663 );
664
665 // Restore the default value
666 $this->setVar( 'wgMetaNamespace', $metaNS );
667
668 $this->endForm();
669 return 'output';
670 }
671
672 public function submit() {
673 $retVal = true;
674 $this->parent->setVarsFromRequest( array( 'wgSitename', '_NamespaceType',
675 '_AdminName', '_AdminPassword', '_AdminPassword2', '_AdminEmail',
676 '_Subscribe', '_SkipOptional', 'wgMetaNamespace' ) );
677
678 // Validate site name
679 if ( strval( $this->getVar( 'wgSitename' ) ) === '' ) {
680 $this->parent->showError( 'config-site-name-blank' );
681 $retVal = false;
682 }
683
684 // Fetch namespace
685 $nsType = $this->getVar( '_NamespaceType' );
686 if ( $nsType == 'site-name' ) {
687 $name = $this->getVar( 'wgSitename' );
688 // Sanitize for namespace
689 // This algorithm should match the JS one in WebInstallerOutput.php
690 $name = preg_replace( '/[\[\]\{\}|#<>%+? ]/', '_', $name );
691 $name = str_replace( '&', '&amp;', $name );
692 $name = preg_replace( '/__+/', '_', $name );
693 $name = ucfirst( trim( $name, '_' ) );
694 } elseif ( $nsType == 'generic' ) {
695 $name = wfMsg( 'config-ns-generic' );
696 } else { // other
697 $name = $this->getVar( 'wgMetaNamespace' );
698 }
699
700 // Validate namespace
701 if ( strpos( $name, ':' ) !== false ) {
702 $good = false;
703 } else {
704 // Title-style validation
705 $title = Title::newFromText( $name );
706 if ( !$title ) {
707 $good = $nsType == 'site-name';
708 } else {
709 $name = $title->getDBkey();
710 $good = true;
711 }
712 }
713 if ( !$good ) {
714 $this->parent->showError( 'config-ns-invalid', $name );
715 $retVal = false;
716 }
717
718 // Make sure it won't conflict with any existing namespaces
719 global $wgContLang;
720 $nsIndex = $wgContLang->getNsIndex( $name );
721 if( $nsIndex !== false && $nsIndex !== NS_PROJECT ) {
722 $this->parent->showError( 'config-ns-conflict', $name );
723 $retVal = false;
724 }
725
726 $this->setVar( 'wgMetaNamespace', $name );
727
728 // Validate username for creation
729 $name = $this->getVar( '_AdminName' );
730 if ( strval( $name ) === '' ) {
731 $this->parent->showError( 'config-admin-name-blank' );
732 $cname = $name;
733 $retVal = false;
734 } else {
735 $cname = User::getCanonicalName( $name, 'creatable' );
736 if ( $cname === false ) {
737 $this->parent->showError( 'config-admin-name-invalid', $name );
738 $retVal = false;
739 } else {
740 $this->setVar( '_AdminName', $cname );
741 }
742 }
743
744 // Validate password
745 $msg = false;
746 $pwd = $this->getVar( '_AdminPassword' );
747 $user = User::newFromName( $cname );
748 $valid = $user && $user->getPasswordValidity( $pwd );
749 if ( strval( $pwd ) === '' ) {
750 # $user->getPasswordValidity just checks for $wgMinimalPasswordLength.
751 # This message is more specific and helpful.
752 $msg = 'config-admin-password-blank';
753 } elseif ( $pwd !== $this->getVar( '_AdminPassword2' ) ) {
754 $msg = 'config-admin-password-mismatch';
755 } elseif ( $valid !== true ) {
756 # As of writing this will only catch the username being e.g. 'FOO' and
757 # the password 'foo'
758 $msg = $valid;
759 }
760 if ( $msg !== false ) {
761 call_user_func_array( array( $this->parent, 'showError' ), (array)$msg );
762 $this->setVar( '_AdminPassword', '' );
763 $this->setVar( '_AdminPassword2', '' );
764 $retVal = false;
765 }
766
767 // Validate e-mail if provided
768 $email = $this->getVar( '_AdminEmail' );
769 if( $email && !Sanitizer::validateEmail( $email ) ) {
770 $this->parent->showError( 'config-admin-error-bademail' );
771 $retVal = false;
772 }
773 // If they asked to subscribe to mediawiki-announce but didn't give
774 // an e-mail, show an error. Bug 29332
775 if( !$email && $this->getVar( '_Subscribe' ) ) {
776 $this->parent->showError( 'config-subscribe-noemail' );
777 $retVal = false;
778 }
779
780 return $retVal;
781 }
782
783 }
784
785 class WebInstaller_Options extends WebInstallerPage {
786
787 public function execute() {
788 if ( $this->getVar( '_SkipOptional' ) == 'skip' ) {
789 return 'skip';
790 }
791 if ( $this->parent->request->wasPosted() ) {
792 if ( $this->submit() ) {
793 return 'continue';
794 }
795 }
796
797 $emailwrapperStyle = $this->getVar( 'wgEnableEmail' ) ? '' : 'display: none';
798 $this->startForm();
799 $this->addHTML(
800 # User Rights
801 $this->parent->getRadioSet( array(
802 'var' => '_RightsProfile',
803 'label' => 'config-profile',
804 'itemLabelPrefix' => 'config-profile-',
805 'values' => array_keys( $this->parent->rightsProfiles ),
806 ) ) .
807 $this->parent->getInfoBox( wfMsgNoTrans( 'config-profile-help' ) ) .
808
809 # Licensing
810 $this->parent->getRadioSet( array(
811 'var' => '_LicenseCode',
812 'label' => 'config-license',
813 'itemLabelPrefix' => 'config-license-',
814 'values' => array_keys( $this->parent->licenses ),
815 'commonAttribs' => array( 'class' => 'licenseRadio' ),
816 ) ) .
817 $this->getCCChooser() .
818 $this->parent->getHelpBox( 'config-license-help' ) .
819
820 # E-mail
821 $this->getFieldSetStart( 'config-email-settings' ) .
822 $this->parent->getCheckBox( array(
823 'var' => 'wgEnableEmail',
824 'label' => 'config-enable-email',
825 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'emailwrapper' ),
826 ) ) .
827 $this->parent->getHelpBox( 'config-enable-email-help' ) .
828 "<div id=\"emailwrapper\" style=\"$emailwrapperStyle\">" .
829 $this->parent->getTextBox( array(
830 'var' => 'wgPasswordSender',
831 'label' => 'config-email-sender'
832 ) ) .
833 $this->parent->getHelpBox( 'config-email-sender-help' ) .
834 $this->parent->getCheckBox( array(
835 'var' => 'wgEnableUserEmail',
836 'label' => 'config-email-user',
837 ) ) .
838 $this->parent->getHelpBox( 'config-email-user-help' ) .
839 $this->parent->getCheckBox( array(
840 'var' => 'wgEnotifUserTalk',
841 'label' => 'config-email-usertalk',
842 ) ) .
843 $this->parent->getHelpBox( 'config-email-usertalk-help' ) .
844 $this->parent->getCheckBox( array(
845 'var' => 'wgEnotifWatchlist',
846 'label' => 'config-email-watchlist',
847 ) ) .
848 $this->parent->getHelpBox( 'config-email-watchlist-help' ) .
849 $this->parent->getCheckBox( array(
850 'var' => 'wgEmailAuthentication',
851 'label' => 'config-email-auth',
852 ) ) .
853 $this->parent->getHelpBox( 'config-email-auth-help' ) .
854 "</div>" .
855 $this->getFieldSetEnd()
856 );
857
858 $extensions = $this->parent->findExtensions();
859
860 if( $extensions ) {
861 $extHtml = $this->getFieldSetStart( 'config-extensions' );
862
863 foreach( $extensions as $ext ) {
864 $extHtml .= $this->parent->getCheckBox( array(
865 'var' => "ext-$ext",
866 'rawtext' => $ext,
867 ) );
868 }
869
870 $extHtml .= $this->parent->getHelpBox( 'config-extensions-help' ) .
871 $this->getFieldSetEnd();
872 $this->addHTML( $extHtml );
873 }
874
875 // Having / in paths in Windows looks funny :)
876 $this->setVar( 'wgDeletedDirectory',
877 str_replace(
878 '/', DIRECTORY_SEPARATOR,
879 $this->getVar( 'wgDeletedDirectory' )
880 )
881 );
882
883 $uploadwrapperStyle = $this->getVar( 'wgEnableUploads' ) ? '' : 'display: none';
884 $this->addHTML(
885 # Uploading
886 $this->getFieldSetStart( 'config-upload-settings' ) .
887 $this->parent->getCheckBox( array(
888 'var' => 'wgEnableUploads',
889 'label' => 'config-upload-enable',
890 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'uploadwrapper' ),
891 'help' => $this->parent->getHelpBox( 'config-upload-help' )
892 ) ) .
893 '<div id="uploadwrapper" style="' . $uploadwrapperStyle . '">' .
894 $this->parent->getTextBox( array(
895 'var' => 'wgDeletedDirectory',
896 'label' => 'config-upload-deleted',
897 'attribs' => array( 'dir' => 'ltr' ),
898 'help' => $this->parent->getHelpBox( 'config-upload-deleted-help' )
899 ) ) .
900 '</div>' .
901 $this->parent->getTextBox( array(
902 'var' => 'wgLogo',
903 'label' => 'config-logo',
904 'attribs' => array( 'dir' => 'ltr' ),
905 'help' => $this->parent->getHelpBox( 'config-logo-help' )
906 ) )
907 );
908 $this->addHTML(
909 $this->parent->getCheckBox( array(
910 'var' => 'wgUseInstantCommons',
911 'label' => 'config-instantcommons',
912 'help' => $this->parent->getHelpBox( 'config-instantcommons-help' )
913 ) ) .
914 $this->getFieldSetEnd()
915 );
916
917 $caches = array( 'none' );
918 if( count( $this->getVar( '_Caches' ) ) ) {
919 $caches[] = 'accel';
920 }
921 $caches[] = 'memcached';
922
923 // We'll hide/show this on demand when the value changes, see config.js.
924 $cacheval = $this->getVar( 'wgMainCacheType' );
925 if (!$cacheval) {
926 // We need to set a default here; but don't hardcode it
927 // or we lose it every time we reload the page for validation
928 // or going back!
929 $cacheval = 'none';
930 }
931 $hidden = ($cacheval == 'memcached') ? '' : 'display: none';
932 $this->addHTML(
933 # Advanced settings
934 $this->getFieldSetStart( 'config-advanced-settings' ) .
935 # Object cache settings
936 $this->parent->getRadioSet( array(
937 'var' => 'wgMainCacheType',
938 'label' => 'config-cache-options',
939 'itemLabelPrefix' => 'config-cache-',
940 'values' => $caches,
941 'value' => $cacheval,
942 ) ) .
943 $this->parent->getHelpBox( 'config-cache-help' ) .
944 "<div id=\"config-memcachewrapper\" style=\"$hidden\">" .
945 $this->parent->getTextArea( array(
946 'var' => '_MemCachedServers',
947 'label' => 'config-memcached-servers',
948 'help' => $this->parent->getHelpBox( 'config-memcached-help' )
949 ) ) .
950 '</div>' .
951 $this->getFieldSetEnd()
952 );
953 $this->endForm();
954 }
955
956 /**
957 * @return string
958 */
959 public function getCCPartnerUrl() {
960 $server = $this->getVar( 'wgServer' );
961 $exitUrl = $server . $this->parent->getUrl( array(
962 'page' => 'Options',
963 'SubmitCC' => 'indeed',
964 'config__LicenseCode' => 'cc',
965 'config_wgRightsUrl' => '[license_url]',
966 'config_wgRightsText' => '[license_name]',
967 'config_wgRightsIcon' => '[license_button]',
968 ) );
969 $styleUrl = $server . dirname( dirname( $this->parent->getUrl() ) ) .
970 '/skins/common/config-cc.css';
971 $iframeUrl = 'http://creativecommons.org/license/?' .
972 wfArrayToCGI( array(
973 'partner' => 'MediaWiki',
974 'exit_url' => $exitUrl,
975 'lang' => $this->getVar( '_UserLang' ),
976 'stylesheet' => $styleUrl,
977 ) );
978 return $iframeUrl;
979 }
980
981 public function getCCChooser() {
982 $iframeAttribs = array(
983 'class' => 'config-cc-iframe',
984 'name' => 'config-cc-iframe',
985 'id' => 'config-cc-iframe',
986 'frameborder' => 0,
987 'width' => '100%',
988 'height' => '100%',
989 );
990 if ( $this->getVar( '_CCDone' ) ) {
991 $iframeAttribs['src'] = $this->parent->getUrl( array( 'ShowCC' => 'yes' ) );
992 } else {
993 $iframeAttribs['src'] = $this->getCCPartnerUrl();
994 }
995 $wrapperStyle = ($this->getVar('_LicenseCode') == 'cc-choose') ? '' : 'display: none';
996
997 return
998 "<div class=\"config-cc-wrapper\" id=\"config-cc-wrapper\" style=\"$wrapperStyle\">\n" .
999 Html::element( 'iframe', $iframeAttribs, '', false /* not short */ ) .
1000 "</div>\n";
1001 }
1002
1003 public function getCCDoneBox() {
1004 $js = "parent.document.getElementById('config-cc-wrapper').style.height = '$1';";
1005 // If you change this height, also change it in config.css
1006 $expandJs = str_replace( '$1', '54em', $js );
1007 $reduceJs = str_replace( '$1', '70px', $js );
1008 return
1009 '<p>'.
1010 Html::element( 'img', array( 'src' => $this->getVar( 'wgRightsIcon' ) ) ) .
1011 '&#160;&#160;' .
1012 htmlspecialchars( $this->getVar( 'wgRightsText' ) ) .
1013 "</p>\n" .
1014 "<p style=\"text-align: center\">" .
1015 Html::element( 'a',
1016 array(
1017 'href' => $this->getCCPartnerUrl(),
1018 'onclick' => $expandJs,
1019 ),
1020 wfMsg( 'config-cc-again' )
1021 ) .
1022 "</p>\n" .
1023 "<script type=\"text/javascript\">\n" .
1024 # Reduce the wrapper div height
1025 htmlspecialchars( $reduceJs ) .
1026 "\n" .
1027 "</script>\n";
1028 }
1029
1030 public function submitCC() {
1031 $newValues = $this->parent->setVarsFromRequest(
1032 array( 'wgRightsUrl', 'wgRightsText', 'wgRightsIcon' ) );
1033 if ( count( $newValues ) != 3 ) {
1034 $this->parent->showError( 'config-cc-error' );
1035 return;
1036 }
1037 $this->setVar( '_CCDone', true );
1038 $this->addHTML( $this->getCCDoneBox() );
1039 }
1040
1041 public function submit() {
1042 $this->parent->setVarsFromRequest( array( '_RightsProfile', '_LicenseCode',
1043 'wgEnableEmail', 'wgPasswordSender', 'wgEnableUploads', 'wgLogo',
1044 'wgEnableUserEmail', 'wgEnotifUserTalk', 'wgEnotifWatchlist',
1045 'wgEmailAuthentication', 'wgMainCacheType', '_MemCachedServers',
1046 'wgUseInstantCommons' ) );
1047
1048 if ( !in_array( $this->getVar( '_RightsProfile' ),
1049 array_keys( $this->parent->rightsProfiles ) ) )
1050 {
1051 reset( $this->parent->rightsProfiles );
1052 $this->setVar( '_RightsProfile', key( $this->parent->rightsProfiles ) );
1053 }
1054
1055 $code = $this->getVar( '_LicenseCode' );
1056 if ( $code == 'cc-choose' ) {
1057 if ( !$this->getVar( '_CCDone' ) ) {
1058 $this->parent->showError( 'config-cc-not-chosen' );
1059 return false;
1060 }
1061 } elseif ( in_array( $code, array_keys( $this->parent->licenses ) ) ) {
1062 $entry = $this->parent->licenses[$code];
1063 if ( isset( $entry['text'] ) ) {
1064 $this->setVar( 'wgRightsText', $entry['text'] );
1065 } else {
1066 $this->setVar( 'wgRightsText', wfMsg( 'config-license-' . $code ) );
1067 }
1068 $this->setVar( 'wgRightsUrl', $entry['url'] );
1069 $this->setVar( 'wgRightsIcon', $entry['icon'] );
1070 } else {
1071 $this->setVar( 'wgRightsText', '' );
1072 $this->setVar( 'wgRightsUrl', '' );
1073 $this->setVar( 'wgRightsIcon', '' );
1074 }
1075
1076 $extsAvailable = $this->parent->findExtensions();
1077 $extsToInstall = array();
1078 foreach( $extsAvailable as $ext ) {
1079 if( $this->parent->request->getCheck( 'config_ext-' . $ext ) ) {
1080 $extsToInstall[] = $ext;
1081 }
1082 }
1083 $this->parent->setVar( '_Extensions', $extsToInstall );
1084
1085 if( $this->getVar( 'wgMainCacheType' ) == 'memcached' ) {
1086 $memcServers = explode( "\n", $this->getVar( '_MemCachedServers' ) );
1087 if( !$memcServers ) {
1088 $this->parent->showError( 'config-memcache-needservers' );
1089 return false;
1090 }
1091
1092 foreach( $memcServers as $server ) {
1093 $memcParts = explode( ":", $server, 2 );
1094 if ( !isset( $memcParts[0] )
1095 || ( !IP::isValid( $memcParts[0] )
1096 && ( gethostbyname( $memcParts[0] ) == $memcParts[0] ) ) ) {
1097 $this->parent->showError( 'config-memcache-badip', $memcParts[0] );
1098 return false;
1099 } elseif( !isset( $memcParts[1] ) ) {
1100 $this->parent->showError( 'config-memcache-noport', $memcParts[0] );
1101 return false;
1102 } elseif( $memcParts[1] < 1 || $memcParts[1] > 65535 ) {
1103 $this->parent->showError( 'config-memcache-badport', 1, 65535 );
1104 return false;
1105 }
1106 }
1107 }
1108 return true;
1109 }
1110
1111 }
1112
1113 class WebInstaller_Install extends WebInstallerPage {
1114 public function isSlow() {
1115 return true;
1116 }
1117
1118 public function execute() {
1119 if( $this->getVar( '_UpgradeDone' ) ) {
1120 return 'skip';
1121 } elseif( $this->getVar( '_InstallDone' ) ) {
1122 return 'continue';
1123 } elseif( $this->parent->request->wasPosted() ) {
1124 $this->startForm();
1125 $this->addHTML("<ul>");
1126 $results = $this->parent->performInstallation(
1127 array( $this, 'startStage'),
1128 array( $this, 'endStage' )
1129 );
1130 $this->addHTML("</ul>");
1131 // PerformInstallation bails on a fatal, so make sure the last item
1132 // completed before giving 'next.' Likewise, only provide back on failure
1133 $lastStep = end( $results );
1134 $continue = $lastStep->isOK() ? 'continue' : false;
1135 $back = $lastStep->isOK() ? false : 'back';
1136 $this->endForm( $continue, $back );
1137 } else {
1138 $this->startForm();
1139 $this->addHTML( $this->parent->getInfoBox( wfMsgNoTrans( 'config-install-begin' ) ) );
1140 $this->endForm();
1141 }
1142 return true;
1143 }
1144
1145 public function startStage( $step ) {
1146 $this->addHTML( "<li>" . wfMsgHtml( "config-install-$step" ) . wfMsg( 'ellipsis') );
1147 if ( $step == 'extension-tables' ) {
1148 $this->startLiveBox();
1149 }
1150 }
1151
1152 /**
1153 * @param $step
1154 * @param $status Status
1155 */
1156 public function endStage( $step, $status ) {
1157 if ( $step == 'extension-tables' ) {
1158 $this->endLiveBox();
1159 }
1160 $msg = $status->isOk() ? 'config-install-step-done' : 'config-install-step-failed';
1161 $html = wfMsgHtml( 'word-separator' ) . wfMsgHtml( $msg );
1162 if ( !$status->isOk() ) {
1163 $html = "<span class=\"error\">$html</span>";
1164 }
1165 $this->addHTML( $html . "</li>\n" );
1166 if( !$status->isGood() ) {
1167 $this->parent->showStatusBox( $status );
1168 }
1169 }
1170
1171 }
1172
1173 class WebInstaller_Complete extends WebInstallerPage {
1174
1175 public function execute() {
1176 // Pop up a dialog box, to make it difficult for the user to forget
1177 // to download the file
1178 $lsUrl = $this->getVar( 'wgServer' ) . $this->parent->getURL( array( 'localsettings' => 1 ) );
1179 if ( isset( $_SERVER['HTTP_USER_AGENT'] ) && strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE' ) !== false ) {
1180 // JS appears the only method that works consistently with IE7+
1181 $this->addHtml( "\n<script type=\"" . $GLOBALS['wgJsMimeType'] . '">jQuery( document ).ready( function() { document.location='
1182 . Xml::encodeJsVar( $lsUrl) . "; } );</script>\n" );
1183 } else {
1184 $this->parent->request->response()->header( "Refresh: 0;url=$lsUrl" );
1185 }
1186
1187 $this->startForm();
1188 $this->parent->disableLinkPopups();
1189 $this->addHTML(
1190 $this->parent->getInfoBox(
1191 wfMsgNoTrans( 'config-install-done',
1192 $lsUrl,
1193 $this->getVar( 'wgServer' ) .
1194 $this->getVar( 'wgScriptPath' ) . '/index' .
1195 $this->getVar( 'wgScriptExtension' ),
1196 '<downloadlink/>'
1197 ), 'tick-32.png'
1198 )
1199 );
1200 $this->parent->restoreLinkPopups();
1201 $this->endForm( false, false );
1202 }
1203 }
1204
1205 class WebInstaller_Restart extends WebInstallerPage {
1206
1207 public function execute() {
1208 $r = $this->parent->request;
1209 if ( $r->wasPosted() ) {
1210 $really = $r->getVal( 'submit-restart' );
1211 if ( $really ) {
1212 $this->parent->reset();
1213 }
1214 return 'continue';
1215 }
1216
1217 $this->startForm();
1218 $s = $this->parent->getWarningBox( wfMsgNoTrans( 'config-help-restart' ) );
1219 $this->addHTML( $s );
1220 $this->endForm( 'restart' );
1221 }
1222
1223 }
1224
1225 abstract class WebInstaller_Document extends WebInstallerPage {
1226
1227 protected abstract function getFileName();
1228
1229 public function execute() {
1230 $text = $this->getFileContents();
1231 $text = InstallDocFormatter::format( $text );
1232 $this->parent->output->addWikiText( $text );
1233 $this->startForm();
1234 $this->endForm( false );
1235 }
1236
1237 public function getFileContents() {
1238 return file_get_contents( dirname( __FILE__ ) . '/../../' . $this->getFileName() );
1239 }
1240
1241 }
1242
1243 class WebInstaller_Readme extends WebInstaller_Document {
1244 protected function getFileName() { return 'README'; }
1245 }
1246
1247 class WebInstaller_ReleaseNotes extends WebInstaller_Document {
1248 protected function getFileName() { return 'RELEASE-NOTES'; }
1249 }
1250
1251 class WebInstaller_UpgradeDoc extends WebInstaller_Document {
1252 protected function getFileName() { return 'UPGRADE'; }
1253 }
1254
1255 class WebInstaller_Copying extends WebInstaller_Document {
1256 protected function getFileName() { return 'COPYING'; }
1257 }
1258