Merge "Don't check namespace in SpecialWantedtemplates"
[lhc/web/wiklou.git] / includes / installer / WebInstallerPage.php
1 <?php
2 /**
3 * Base code for web installer pages.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 * @ingroup Deployment
22 */
23
24 /**
25 * Abstract class to define pages for the web installer.
26 *
27 * @ingroup Deployment
28 * @since 1.17
29 */
30 abstract class WebInstallerPage {
31
32 /**
33 * The WebInstaller object this WebInstallerPage belongs to.
34 *
35 * @var WebInstaller
36 */
37 public $parent;
38
39 /**
40 * @return string
41 */
42 abstract public function execute();
43
44 /**
45 * @param WebInstaller $parent
46 */
47 public function __construct( WebInstaller $parent ) {
48 $this->parent = $parent;
49 }
50
51 /**
52 * Is this a slow-running page in the installer? If so, WebInstaller will
53 * set_time_limit(0) before calling execute(). Right now this only applies
54 * to Install and Upgrade pages
55 *
56 * @return bool Always false in this default implementation.
57 */
58 public function isSlow() {
59 return false;
60 }
61
62 /**
63 * @param string $html
64 */
65 public function addHTML( $html ) {
66 $this->parent->output->addHTML( $html );
67 }
68
69 public function startForm() {
70 $this->addHTML(
71 "<div class=\"config-section\">\n" .
72 Html::openElement(
73 'form',
74 array(
75 'method' => 'post',
76 'action' => $this->parent->getUrl( array( 'page' => $this->getName() ) )
77 )
78 ) . "\n"
79 );
80 }
81
82 /**
83 * @param string|bool $continue
84 * @param string|bool $back
85 */
86 public function endForm( $continue = 'continue', $back = 'back' ) {
87 $s = "<div class=\"config-submit\">\n";
88 $id = $this->getId();
89
90 if ( $id === false ) {
91 $s .= Html::hidden( 'lastPage', $this->parent->request->getVal( 'lastPage' ) );
92 }
93
94 if ( $continue ) {
95 // Fake submit button for enter keypress (bug 26267)
96 // Messages: config-continue, config-restart, config-regenerate
97 $s .= Xml::submitButton(
98 wfMessage( "config-$continue" )->text(),
99 array(
100 'name' => "enter-$continue",
101 'style' => 'visibility:hidden;overflow:hidden;width:1px;margin:0'
102 )
103 ) . "\n";
104 }
105
106 if ( $back ) {
107 // Message: config-back
108 $s .= Xml::submitButton(
109 wfMessage( "config-$back" )->text(),
110 array(
111 'name' => "submit-$back",
112 'tabindex' => $this->parent->nextTabIndex()
113 )
114 ) . "\n";
115 }
116
117 if ( $continue ) {
118 // Messages: config-continue, config-restart, config-regenerate
119 $s .= Xml::submitButton(
120 wfMessage( "config-$continue" )->text(),
121 array(
122 'name' => "submit-$continue",
123 'tabindex' => $this->parent->nextTabIndex(),
124 )
125 ) . "\n";
126 }
127
128 $s .= "</div></form></div>\n";
129 $this->addHTML( $s );
130 }
131
132 /**
133 * @return string
134 */
135 public function getName() {
136 return str_replace( 'WebInstaller', '', get_class( $this ) );
137 }
138
139 /**
140 * @return string
141 */
142 protected function getId() {
143 return array_search( $this->getName(), $this->parent->pageSequence );
144 }
145
146 /**
147 * @param string $var
148 * @param mixed $default
149 *
150 * @return mixed
151 */
152 public function getVar( $var, $default = null ) {
153 return $this->parent->getVar( $var, $default );
154 }
155
156 /**
157 * @param string $name
158 * @param mixed $value
159 */
160 public function setVar( $name, $value ) {
161 $this->parent->setVar( $name, $value );
162 }
163
164 /**
165 * Get the starting tags of a fieldset.
166 *
167 * @param string $legend Message name
168 *
169 * @return string
170 */
171 protected function getFieldsetStart( $legend ) {
172 return "\n<fieldset><legend>" . wfMessage( $legend )->escaped() . "</legend>\n";
173 }
174
175 /**
176 * Get the end tag of a fieldset.
177 *
178 * @return string
179 */
180 protected function getFieldsetEnd() {
181 return "</fieldset>\n";
182 }
183
184 /**
185 * Opens a textarea used to display the progress of a long operation
186 */
187 protected function startLiveBox() {
188 $this->addHTML(
189 '<div id="config-spinner" style="display:none;">' .
190 '<img src="images/ajax-loader.gif" /></div>' .
191 '<script>jQuery( "#config-spinner" ).show();</script>' .
192 '<div id="config-live-log">' .
193 '<textarea name="LiveLog" rows="10" cols="30" readonly="readonly">'
194 );
195 $this->parent->output->flush();
196 }
197
198 /**
199 * Opposite to WebInstallerPage::startLiveBox
200 */
201 protected function endLiveBox() {
202 $this->addHTML( '</textarea></div>
203 <script>jQuery( "#config-spinner" ).hide()</script>' );
204 $this->parent->output->flush();
205 }
206
207 }
208
209 class WebInstallerLanguage extends WebInstallerPage {
210
211 /**
212 * @return string|null
213 */
214 public function execute() {
215 global $wgLang;
216 $r = $this->parent->request;
217 $userLang = $r->getVal( 'uselang' );
218 $contLang = $r->getVal( 'ContLang' );
219
220 $languages = Language::fetchLanguageNames();
221 $lifetime = intval( ini_get( 'session.gc_maxlifetime' ) );
222 if ( !$lifetime ) {
223 $lifetime = 1440; // PHP default
224 }
225
226 if ( $r->wasPosted() ) {
227 # Do session test
228 if ( $this->parent->getSession( 'test' ) === null ) {
229 $requestTime = $r->getVal( 'LanguageRequestTime' );
230 if ( !$requestTime ) {
231 // The most likely explanation is that the user was knocked back
232 // from another page on POST due to session expiry
233 $msg = 'config-session-expired';
234 } elseif ( time() - $requestTime > $lifetime ) {
235 $msg = 'config-session-expired';
236 } else {
237 $msg = 'config-no-session';
238 }
239 $this->parent->showError( $msg, $wgLang->formatTimePeriod( $lifetime ) );
240 } else {
241 if ( isset( $languages[$userLang] ) ) {
242 $this->setVar( '_UserLang', $userLang );
243 }
244 if ( isset( $languages[$contLang] ) ) {
245 $this->setVar( 'wgLanguageCode', $contLang );
246 }
247
248 return 'continue';
249 }
250 } elseif ( $this->parent->showSessionWarning ) {
251 # The user was knocked back from another page to the start
252 # This probably indicates a session expiry
253 $this->parent->showError( 'config-session-expired',
254 $wgLang->formatTimePeriod( $lifetime ) );
255 }
256
257 $this->parent->setSession( 'test', true );
258
259 if ( !isset( $languages[$userLang] ) ) {
260 $userLang = $this->getVar( '_UserLang', 'en' );
261 }
262 if ( !isset( $languages[$contLang] ) ) {
263 $contLang = $this->getVar( 'wgLanguageCode', 'en' );
264 }
265 $this->startForm();
266 $s = Html::hidden( 'LanguageRequestTime', time() ) .
267 $this->getLanguageSelector( 'uselang', 'config-your-language', $userLang,
268 $this->parent->getHelpBox( 'config-your-language-help' ) ) .
269 $this->getLanguageSelector( 'ContLang', 'config-wiki-language', $contLang,
270 $this->parent->getHelpBox( 'config-wiki-language-help' ) );
271 $this->addHTML( $s );
272 $this->endForm( 'continue', false );
273
274 return null;
275 }
276
277 /**
278 * Get a "<select>" for selecting languages.
279 *
280 * @param string $name
281 * @param string $label
282 * @param string $selectedCode
283 * @param string $helpHtml
284 *
285 * @return string
286 */
287 public function getLanguageSelector( $name, $label, $selectedCode, $helpHtml = '' ) {
288 global $wgDummyLanguageCodes;
289
290 $output = $helpHtml;
291
292 $select = new XmlSelect( $name, $name, $selectedCode );
293 $select->setAttribute( 'tabindex', $this->parent->nextTabIndex() );
294
295 $languages = Language::fetchLanguageNames();
296 ksort( $languages );
297 foreach ( $languages as $code => $lang ) {
298 if ( isset( $wgDummyLanguageCodes[$code] ) ) {
299 continue;
300 }
301 $select->addOption( "$code - $lang", $code );
302 }
303
304 $output .= $select->getHTML();
305 return $this->parent->label( $label, $name, $output );
306 }
307
308 }
309
310 class WebInstallerExistingWiki extends WebInstallerPage {
311
312 /**
313 * @return string
314 */
315 public function execute() {
316 // If there is no LocalSettings.php, continue to the installer welcome page
317 $vars = Installer::getExistingLocalSettings();
318 if ( !$vars ) {
319 return 'skip';
320 }
321
322 // Check if the upgrade key supplied to the user has appeared in LocalSettings.php
323 if ( $vars['wgUpgradeKey'] !== false
324 && $this->getVar( '_UpgradeKeySupplied' )
325 && $this->getVar( 'wgUpgradeKey' ) === $vars['wgUpgradeKey']
326 ) {
327 // It's there, so the user is authorized
328 $status = $this->handleExistingUpgrade( $vars );
329 if ( $status->isOK() ) {
330 return 'skip';
331 } else {
332 $this->startForm();
333 $this->parent->showStatusBox( $status );
334 $this->endForm( 'continue' );
335
336 return 'output';
337 }
338 }
339
340 // If there is no $wgUpgradeKey, tell the user to add one to LocalSettings.php
341 if ( $vars['wgUpgradeKey'] === false ) {
342 if ( $this->getVar( 'wgUpgradeKey', false ) === false ) {
343 $secretKey = $this->getVar( 'wgSecretKey' ); // preserve $wgSecretKey
344 $this->parent->generateKeys();
345 $this->setVar( 'wgSecretKey', $secretKey );
346 $this->setVar( '_UpgradeKeySupplied', true );
347 }
348 $this->startForm();
349 $this->addHTML( $this->parent->getInfoBox(
350 wfMessage( 'config-upgrade-key-missing', "<pre dir=\"ltr\">\$wgUpgradeKey = '" .
351 $this->getVar( 'wgUpgradeKey' ) . "';</pre>" )->plain()
352 ) );
353 $this->endForm( 'continue' );
354
355 return 'output';
356 }
357
358 // If there is an upgrade key, but it wasn't supplied, prompt the user to enter it
359
360 $r = $this->parent->request;
361 if ( $r->wasPosted() ) {
362 $key = $r->getText( 'config_wgUpgradeKey' );
363 if ( !$key || $key !== $vars['wgUpgradeKey'] ) {
364 $this->parent->showError( 'config-localsettings-badkey' );
365 $this->showKeyForm();
366
367 return 'output';
368 }
369 // Key was OK
370 $status = $this->handleExistingUpgrade( $vars );
371 if ( $status->isOK() ) {
372 return 'continue';
373 } else {
374 $this->parent->showStatusBox( $status );
375 $this->showKeyForm();
376
377 return 'output';
378 }
379 } else {
380 $this->showKeyForm();
381
382 return 'output';
383 }
384 }
385
386 /**
387 * Show the "enter key" form
388 */
389 protected function showKeyForm() {
390 $this->startForm();
391 $this->addHTML(
392 $this->parent->getInfoBox( wfMessage( 'config-localsettings-upgrade' )->plain() ) .
393 '<br />' .
394 $this->parent->getTextBox( array(
395 'var' => 'wgUpgradeKey',
396 'label' => 'config-localsettings-key',
397 'attribs' => array( 'autocomplete' => 'off' ),
398 ) )
399 );
400 $this->endForm( 'continue' );
401 }
402
403 /**
404 * @param string[] $names
405 * @param mixed[] $vars
406 *
407 * @return Status
408 */
409 protected function importVariables( $names, $vars ) {
410 $status = Status::newGood();
411 foreach ( $names as $name ) {
412 if ( !isset( $vars[$name] ) ) {
413 $status->fatal( 'config-localsettings-incomplete', $name );
414 }
415 $this->setVar( $name, $vars[$name] );
416 }
417
418 return $status;
419 }
420
421 /**
422 * Initiate an upgrade of the existing database
423 *
424 * @param mixed[] $vars Variables from LocalSettings.php
425 *
426 * @return Status
427 */
428 protected function handleExistingUpgrade( $vars ) {
429 // Check $wgDBtype
430 if ( !isset( $vars['wgDBtype'] ) ||
431 !in_array( $vars['wgDBtype'], Installer::getDBTypes() )
432 ) {
433 return Status::newFatal( 'config-localsettings-connection-error', '' );
434 }
435
436 // Set the relevant variables from LocalSettings.php
437 $requiredVars = array( 'wgDBtype' );
438 $status = $this->importVariables( $requiredVars, $vars );
439 $installer = $this->parent->getDBInstaller();
440 $status->merge( $this->importVariables( $installer->getGlobalNames(), $vars ) );
441 if ( !$status->isOK() ) {
442 return $status;
443 }
444
445 if ( isset( $vars['wgDBadminuser'] ) ) {
446 $this->setVar( '_InstallUser', $vars['wgDBadminuser'] );
447 } else {
448 $this->setVar( '_InstallUser', $vars['wgDBuser'] );
449 }
450 if ( isset( $vars['wgDBadminpassword'] ) ) {
451 $this->setVar( '_InstallPassword', $vars['wgDBadminpassword'] );
452 } else {
453 $this->setVar( '_InstallPassword', $vars['wgDBpassword'] );
454 }
455
456 // Test the database connection
457 $status = $installer->getConnection();
458 if ( !$status->isOK() ) {
459 // Adjust the error message to explain things correctly
460 $status->replaceMessage( 'config-connection-error',
461 'config-localsettings-connection-error' );
462
463 return $status;
464 }
465
466 // All good
467 $this->setVar( '_ExistingDBSettings', true );
468
469 return $status;
470 }
471
472 }
473
474 class WebInstallerWelcome extends WebInstallerPage {
475
476 /**
477 * @return string
478 */
479 public function execute() {
480 if ( $this->parent->request->wasPosted() ) {
481 if ( $this->getVar( '_Environment' ) ) {
482 return 'continue';
483 }
484 }
485 $this->parent->output->addWikiText( wfMessage( 'config-welcome' )->plain() );
486 $status = $this->parent->doEnvironmentChecks();
487 if ( $status->isGood() ) {
488 $this->parent->output->addHTML( '<span class="success-message">' .
489 wfMessage( 'config-env-good' )->escaped() . '</span>' );
490 $this->parent->output->addWikiText( wfMessage( 'config-copyright',
491 SpecialVersion::getCopyrightAndAuthorList() )->plain() );
492 $this->startForm();
493 $this->endForm();
494 } else {
495 $this->parent->showStatusMessage( $status );
496 }
497
498 return '';
499 }
500
501 }
502
503 class WebInstallerDBConnect extends WebInstallerPage {
504
505 /**
506 * @return string|null When string, "skip" or "continue"
507 */
508 public function execute() {
509 if ( $this->getVar( '_ExistingDBSettings' ) ) {
510 return 'skip';
511 }
512
513 $r = $this->parent->request;
514 if ( $r->wasPosted() ) {
515 $status = $this->submit();
516
517 if ( $status->isGood() ) {
518 $this->setVar( '_UpgradeDone', false );
519
520 return 'continue';
521 } else {
522 $this->parent->showStatusBox( $status );
523 }
524 }
525
526 $this->startForm();
527
528 $types = "<ul class=\"config-settings-block\">\n";
529 $settings = '';
530 $defaultType = $this->getVar( 'wgDBtype' );
531
532 // Messages: config-dbsupport-mysql, config-dbsupport-postgres, config-dbsupport-oracle,
533 // config-dbsupport-sqlite, config-dbsupport-mssql
534 $dbSupport = '';
535 foreach ( Installer::getDBTypes() as $type ) {
536 $dbSupport .= wfMessage( "config-dbsupport-$type" )->plain() . "\n";
537 }
538 $this->addHTML( $this->parent->getInfoBox(
539 wfMessage( 'config-support-info', trim( $dbSupport ) )->text() ) );
540
541 // It's possible that the library for the default DB type is not compiled in.
542 // In that case, instead select the first supported DB type in the list.
543 $compiledDBs = $this->parent->getCompiledDBs();
544 if ( !in_array( $defaultType, $compiledDBs ) ) {
545 $defaultType = $compiledDBs[0];
546 }
547
548 foreach ( $compiledDBs as $type ) {
549 $installer = $this->parent->getDBInstaller( $type );
550 $types .=
551 '<li>' .
552 Xml::radioLabel(
553 $installer->getReadableName(),
554 'DBType',
555 $type,
556 "DBType_$type",
557 $type == $defaultType,
558 array( 'class' => 'dbRadio', 'rel' => "DB_wrapper_$type" )
559 ) .
560 "</li>\n";
561
562 // Messages: config-header-mysql, config-header-postgres, config-header-oracle,
563 // config-header-sqlite
564 $settings .= Html::openElement(
565 'div',
566 array(
567 'id' => 'DB_wrapper_' . $type,
568 'class' => 'dbWrapper'
569 )
570 ) .
571 Html::element( 'h3', array(), wfMessage( 'config-header-' . $type )->text() ) .
572 $installer->getConnectForm() .
573 "</div>\n";
574 }
575
576 $types .= "</ul><br style=\"clear: left\"/>\n";
577
578 $this->addHTML( $this->parent->label( 'config-db-type', false, $types ) . $settings );
579 $this->endForm();
580
581 return null;
582 }
583
584 /**
585 * @return Status
586 */
587 public function submit() {
588 $r = $this->parent->request;
589 $type = $r->getVal( 'DBType' );
590 if ( !$type ) {
591 return Status::newFatal( 'config-invalid-db-type' );
592 }
593 $this->setVar( 'wgDBtype', $type );
594 $installer = $this->parent->getDBInstaller( $type );
595 if ( !$installer ) {
596 return Status::newFatal( 'config-invalid-db-type' );
597 }
598
599 return $installer->submitConnectForm();
600 }
601
602 }
603
604 class WebInstallerUpgrade extends WebInstallerPage {
605
606 /**
607 * @return bool Always true.
608 */
609 public function isSlow() {
610 return true;
611 }
612
613 /**
614 * @return string|null
615 */
616 public function execute() {
617 if ( $this->getVar( '_UpgradeDone' ) ) {
618 // Allow regeneration of LocalSettings.php, unless we are working
619 // from a pre-existing LocalSettings.php file and we want to avoid
620 // leaking its contents
621 if ( $this->parent->request->wasPosted() && !$this->getVar( '_ExistingDBSettings' ) ) {
622 // Done message acknowledged
623 return 'continue';
624 } else {
625 // Back button click
626 // Show the done message again
627 // Make them click back again if they want to do the upgrade again
628 $this->showDoneMessage();
629
630 return 'output';
631 }
632 }
633
634 // wgDBtype is generally valid here because otherwise the previous page
635 // (connect) wouldn't have declared its happiness
636 $type = $this->getVar( 'wgDBtype' );
637 $installer = $this->parent->getDBInstaller( $type );
638
639 if ( !$installer->needsUpgrade() ) {
640 return 'skip';
641 }
642
643 if ( $this->parent->request->wasPosted() ) {
644 $installer->preUpgrade();
645
646 $this->startLiveBox();
647 $result = $installer->doUpgrade();
648 $this->endLiveBox();
649
650 if ( $result ) {
651 // If they're going to possibly regenerate LocalSettings, we
652 // need to create the upgrade/secret keys. Bug 26481
653 if ( !$this->getVar( '_ExistingDBSettings' ) ) {
654 $this->parent->generateKeys();
655 }
656 $this->setVar( '_UpgradeDone', true );
657 $this->showDoneMessage();
658
659 return 'output';
660 }
661 }
662
663 $this->startForm();
664 $this->addHTML( $this->parent->getInfoBox(
665 wfMessage( 'config-can-upgrade', $GLOBALS['wgVersion'] )->plain() ) );
666 $this->endForm();
667
668 return null;
669 }
670
671 public function showDoneMessage() {
672 global $wgScriptExtension;
673
674 $this->startForm();
675 $regenerate = !$this->getVar( '_ExistingDBSettings' );
676 if ( $regenerate ) {
677 $msg = 'config-upgrade-done';
678 } else {
679 $msg = 'config-upgrade-done-no-regenerate';
680 }
681 $this->parent->disableLinkPopups();
682 $this->addHTML(
683 $this->parent->getInfoBox(
684 wfMessage( $msg,
685 $this->getVar( 'wgServer' ) .
686 $this->getVar( 'wgScriptPath' ) . '/index' .
687 $wgScriptExtension
688 )->plain(), 'tick-32.png'
689 )
690 );
691 $this->parent->restoreLinkPopups();
692 $this->endForm( $regenerate ? 'regenerate' : false, false );
693 }
694
695 }
696
697 class WebInstallerDBSettings extends WebInstallerPage {
698
699 /**
700 * @return string|null
701 */
702 public function execute() {
703 $installer = $this->parent->getDBInstaller( $this->getVar( 'wgDBtype' ) );
704
705 $r = $this->parent->request;
706 if ( $r->wasPosted() ) {
707 $status = $installer->submitSettingsForm();
708 if ( $status === false ) {
709 return 'skip';
710 } elseif ( $status->isGood() ) {
711 return 'continue';
712 } else {
713 $this->parent->showStatusBox( $status );
714 }
715 }
716
717 $form = $installer->getSettingsForm();
718 if ( $form === false ) {
719 return 'skip';
720 }
721
722 $this->startForm();
723 $this->addHTML( $form );
724 $this->endForm();
725
726 return null;
727 }
728
729 }
730
731 class WebInstallerName extends WebInstallerPage {
732
733 /**
734 * @return string
735 */
736 public function execute() {
737 $r = $this->parent->request;
738 if ( $r->wasPosted() ) {
739 if ( $this->submit() ) {
740 return 'continue';
741 }
742 }
743
744 $this->startForm();
745
746 // Encourage people to not name their site 'MediaWiki' by blanking the
747 // field. I think that was the intent with the original $GLOBALS['wgSitename']
748 // but these two always were the same so had the effect of making the
749 // installer forget $wgSitename when navigating back to this page.
750 if ( $this->getVar( 'wgSitename' ) == 'MediaWiki' ) {
751 $this->setVar( 'wgSitename', '' );
752 }
753
754 // Set wgMetaNamespace to something valid before we show the form.
755 // $wgMetaNamespace defaults to $wgSiteName which is 'MediaWiki'
756 $metaNS = $this->getVar( 'wgMetaNamespace' );
757 $this->setVar(
758 'wgMetaNamespace',
759 wfMessage( 'config-ns-other-default' )->inContentLanguage()->text()
760 );
761
762 $this->addHTML(
763 $this->parent->getTextBox( array(
764 'var' => 'wgSitename',
765 'label' => 'config-site-name',
766 'help' => $this->parent->getHelpBox( 'config-site-name-help' )
767 ) ) .
768 // getRadioSet() builds a set of labeled radio buttons.
769 // For grep: The following messages are used as the item labels:
770 // config-ns-site-name, config-ns-generic, config-ns-other
771 $this->parent->getRadioSet( array(
772 'var' => '_NamespaceType',
773 'label' => 'config-project-namespace',
774 'itemLabelPrefix' => 'config-ns-',
775 'values' => array( 'site-name', 'generic', 'other' ),
776 'commonAttribs' => array( 'class' => 'enableForOther',
777 'rel' => 'config_wgMetaNamespace' ),
778 'help' => $this->parent->getHelpBox( 'config-project-namespace-help' )
779 ) ) .
780 $this->parent->getTextBox( array(
781 'var' => 'wgMetaNamespace',
782 'label' => '', // @todo Needs a label?
783 'attribs' => array( 'readonly' => 'readonly', 'class' => 'enabledByOther' )
784 ) ) .
785 $this->getFieldSetStart( 'config-admin-box' ) .
786 $this->parent->getTextBox( array(
787 'var' => '_AdminName',
788 'label' => 'config-admin-name',
789 'help' => $this->parent->getHelpBox( 'config-admin-help' )
790 ) ) .
791 $this->parent->getPasswordBox( array(
792 'var' => '_AdminPassword',
793 'label' => 'config-admin-password',
794 ) ) .
795 $this->parent->getPasswordBox( array(
796 'var' => '_AdminPasswordConfirm',
797 'label' => 'config-admin-password-confirm'
798 ) ) .
799 $this->parent->getTextBox( array(
800 'var' => '_AdminEmail',
801 'attribs' => array(
802 'dir' => 'ltr',
803 ),
804 'label' => 'config-admin-email',
805 'help' => $this->parent->getHelpBox( 'config-admin-email-help' )
806 ) ) .
807 $this->parent->getCheckBox( array(
808 'var' => '_Subscribe',
809 'label' => 'config-subscribe',
810 'help' => $this->parent->getHelpBox( 'config-subscribe-help' )
811 ) ) .
812 $this->getFieldSetEnd() .
813 $this->parent->getInfoBox( wfMessage( 'config-almost-done' )->text() ) .
814 // getRadioSet() builds a set of labeled radio buttons.
815 // For grep: The following messages are used as the item labels:
816 // config-optional-continue, config-optional-skip
817 $this->parent->getRadioSet( array(
818 'var' => '_SkipOptional',
819 'itemLabelPrefix' => 'config-optional-',
820 'values' => array( 'continue', 'skip' )
821 ) )
822 );
823
824 // Restore the default value
825 $this->setVar( 'wgMetaNamespace', $metaNS );
826
827 $this->endForm();
828
829 return 'output';
830 }
831
832 /**
833 * @return bool
834 */
835 public function submit() {
836 $retVal = true;
837 $this->parent->setVarsFromRequest( array( 'wgSitename', '_NamespaceType',
838 '_AdminName', '_AdminPassword', '_AdminPasswordConfirm', '_AdminEmail',
839 '_Subscribe', '_SkipOptional', 'wgMetaNamespace' ) );
840
841 // Validate site name
842 if ( strval( $this->getVar( 'wgSitename' ) ) === '' ) {
843 $this->parent->showError( 'config-site-name-blank' );
844 $retVal = false;
845 }
846
847 // Fetch namespace
848 $nsType = $this->getVar( '_NamespaceType' );
849 if ( $nsType == 'site-name' ) {
850 $name = $this->getVar( 'wgSitename' );
851 // Sanitize for namespace
852 // This algorithm should match the JS one in WebInstallerOutput.php
853 $name = preg_replace( '/[\[\]\{\}|#<>%+? ]/', '_', $name );
854 $name = str_replace( '&', '&amp;', $name );
855 $name = preg_replace( '/__+/', '_', $name );
856 $name = ucfirst( trim( $name, '_' ) );
857 } elseif ( $nsType == 'generic' ) {
858 $name = wfMessage( 'config-ns-generic' )->text();
859 } else { // other
860 $name = $this->getVar( 'wgMetaNamespace' );
861 }
862
863 // Validate namespace
864 if ( strpos( $name, ':' ) !== false ) {
865 $good = false;
866 } else {
867 // Title-style validation
868 $title = Title::newFromText( $name );
869 if ( !$title ) {
870 $good = $nsType == 'site-name';
871 } else {
872 $name = $title->getDBkey();
873 $good = true;
874 }
875 }
876 if ( !$good ) {
877 $this->parent->showError( 'config-ns-invalid', $name );
878 $retVal = false;
879 }
880
881 // Make sure it won't conflict with any existing namespaces
882 global $wgContLang;
883 $nsIndex = $wgContLang->getNsIndex( $name );
884 if ( $nsIndex !== false && $nsIndex !== NS_PROJECT ) {
885 $this->parent->showError( 'config-ns-conflict', $name );
886 $retVal = false;
887 }
888
889 $this->setVar( 'wgMetaNamespace', $name );
890
891 // Validate username for creation
892 $name = $this->getVar( '_AdminName' );
893 if ( strval( $name ) === '' ) {
894 $this->parent->showError( 'config-admin-name-blank' );
895 $cname = $name;
896 $retVal = false;
897 } else {
898 $cname = User::getCanonicalName( $name, 'creatable' );
899 if ( $cname === false ) {
900 $this->parent->showError( 'config-admin-name-invalid', $name );
901 $retVal = false;
902 } else {
903 $this->setVar( '_AdminName', $cname );
904 }
905 }
906
907 // Validate password
908 $msg = false;
909 $pwd = $this->getVar( '_AdminPassword' );
910 $user = User::newFromName( $cname );
911 if ( $user ) {
912 $status = $user->checkPasswordValidity( $pwd, 'create' );
913 $valid = $status->isGood() ? true : $status->getMessage()->escaped();
914 } else {
915 $valid = 'config-admin-name-invalid';
916 }
917 if ( strval( $pwd ) === '' ) {
918 # $user->getPasswordValidity just checks for $wgMinimalPasswordLength.
919 # This message is more specific and helpful.
920 $msg = 'config-admin-password-blank';
921 } elseif ( $pwd !== $this->getVar( '_AdminPasswordConfirm' ) ) {
922 $msg = 'config-admin-password-mismatch';
923 } elseif ( $valid !== true ) {
924 $msg = $valid;
925 }
926 if ( $msg !== false ) {
927 call_user_func_array( array( $this->parent, 'showError' ), (array)$msg );
928 $this->setVar( '_AdminPassword', '' );
929 $this->setVar( '_AdminPasswordConfirm', '' );
930 $retVal = false;
931 }
932
933 // Validate e-mail if provided
934 $email = $this->getVar( '_AdminEmail' );
935 if ( $email && !Sanitizer::validateEmail( $email ) ) {
936 $this->parent->showError( 'config-admin-error-bademail' );
937 $retVal = false;
938 }
939 // If they asked to subscribe to mediawiki-announce but didn't give
940 // an e-mail, show an error. Bug 29332
941 if ( !$email && $this->getVar( '_Subscribe' ) ) {
942 $this->parent->showError( 'config-subscribe-noemail' );
943 $retVal = false;
944 }
945
946 return $retVal;
947 }
948
949 }
950
951 class WebInstallerOptions extends WebInstallerPage {
952
953 /**
954 * @return string|null
955 */
956 public function execute() {
957 if ( $this->getVar( '_SkipOptional' ) == 'skip' ) {
958 $this->submitSkins();
959 return 'skip';
960 }
961 if ( $this->parent->request->wasPosted() ) {
962 if ( $this->submit() ) {
963 return 'continue';
964 }
965 }
966
967 $emailwrapperStyle = $this->getVar( 'wgEnableEmail' ) ? '' : 'display: none';
968 $this->startForm();
969 $this->addHTML(
970 # User Rights
971 // getRadioSet() builds a set of labeled radio buttons.
972 // For grep: The following messages are used as the item labels:
973 // config-profile-wiki, config-profile-no-anon, config-profile-fishbowl, config-profile-private
974 $this->parent->getRadioSet( array(
975 'var' => '_RightsProfile',
976 'label' => 'config-profile',
977 'itemLabelPrefix' => 'config-profile-',
978 'values' => array_keys( $this->parent->rightsProfiles ),
979 ) ) .
980 $this->parent->getInfoBox( wfMessage( 'config-profile-help' )->plain() ) .
981
982 # Licensing
983 // getRadioSet() builds a set of labeled radio buttons.
984 // For grep: The following messages are used as the item labels:
985 // config-license-cc-by, config-license-cc-by-sa, config-license-cc-by-nc-sa,
986 // config-license-cc-0, config-license-pd, config-license-gfdl,
987 // config-license-none, config-license-cc-choose
988 $this->parent->getRadioSet( array(
989 'var' => '_LicenseCode',
990 'label' => 'config-license',
991 'itemLabelPrefix' => 'config-license-',
992 'values' => array_keys( $this->parent->licenses ),
993 'commonAttribs' => array( 'class' => 'licenseRadio' ),
994 ) ) .
995 $this->getCCChooser() .
996 $this->parent->getHelpBox( 'config-license-help' ) .
997
998 # E-mail
999 $this->getFieldSetStart( 'config-email-settings' ) .
1000 $this->parent->getCheckBox( array(
1001 'var' => 'wgEnableEmail',
1002 'label' => 'config-enable-email',
1003 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'emailwrapper' ),
1004 ) ) .
1005 $this->parent->getHelpBox( 'config-enable-email-help' ) .
1006 "<div id=\"emailwrapper\" style=\"$emailwrapperStyle\">" .
1007 $this->parent->getTextBox( array(
1008 'var' => 'wgPasswordSender',
1009 'label' => 'config-email-sender'
1010 ) ) .
1011 $this->parent->getHelpBox( 'config-email-sender-help' ) .
1012 $this->parent->getCheckBox( array(
1013 'var' => 'wgEnableUserEmail',
1014 'label' => 'config-email-user',
1015 ) ) .
1016 $this->parent->getHelpBox( 'config-email-user-help' ) .
1017 $this->parent->getCheckBox( array(
1018 'var' => 'wgEnotifUserTalk',
1019 'label' => 'config-email-usertalk',
1020 ) ) .
1021 $this->parent->getHelpBox( 'config-email-usertalk-help' ) .
1022 $this->parent->getCheckBox( array(
1023 'var' => 'wgEnotifWatchlist',
1024 'label' => 'config-email-watchlist',
1025 ) ) .
1026 $this->parent->getHelpBox( 'config-email-watchlist-help' ) .
1027 $this->parent->getCheckBox( array(
1028 'var' => 'wgEmailAuthentication',
1029 'label' => 'config-email-auth',
1030 ) ) .
1031 $this->parent->getHelpBox( 'config-email-auth-help' ) .
1032 "</div>" .
1033 $this->getFieldSetEnd()
1034 );
1035
1036 $skins = $this->parent->findExtensions( 'skins' );
1037 $skinHtml = $this->getFieldSetStart( 'config-skins' );
1038
1039 $skinNames = array_map( 'strtolower', $skins );
1040 $chosenSkinName = $this->getVar( 'wgDefaultSkin', $this->parent->getDefaultSkin( $skinNames ) );
1041
1042 if ( $skins ) {
1043 $radioButtons = $this->parent->getRadioElements( array(
1044 'var' => 'wgDefaultSkin',
1045 'itemLabels' => array_fill_keys( $skinNames, 'config-skins-use-as-default' ),
1046 'values' => $skinNames,
1047 'value' => $chosenSkinName,
1048 ) );
1049
1050 foreach ( $skins as $skin ) {
1051 $skinHtml .=
1052 '<div class="config-skins-item">' .
1053 $this->parent->getCheckBox( array(
1054 'var' => "skin-$skin",
1055 'rawtext' => $skin,
1056 'value' => $this->getVar( "skin-$skin", true ), // all found skins enabled by default
1057 ) ) .
1058 '<div class="config-skins-use-as-default">' . $radioButtons[strtolower( $skin )] . '</div>' .
1059 '</div>';
1060 }
1061 } else {
1062 $skinHtml .=
1063 $this->parent->getWarningBox( wfMessage( 'config-skins-missing' )->plain() ) .
1064 Html::hidden( 'config_wgDefaultSkin', $chosenSkinName );
1065 }
1066
1067 $skinHtml .= $this->parent->getHelpBox( 'config-skins-help' ) .
1068 $this->getFieldSetEnd();
1069 $this->addHTML( $skinHtml );
1070
1071 $extensions = $this->parent->findExtensions();
1072
1073 if ( $extensions ) {
1074 $extHtml = $this->getFieldSetStart( 'config-extensions' );
1075
1076 foreach ( $extensions as $ext ) {
1077 $extHtml .= $this->parent->getCheckBox( array(
1078 'var' => "ext-$ext",
1079 'rawtext' => $ext,
1080 ) );
1081 }
1082
1083 $extHtml .= $this->parent->getHelpBox( 'config-extensions-help' ) .
1084 $this->getFieldSetEnd();
1085 $this->addHTML( $extHtml );
1086 }
1087
1088 // Having / in paths in Windows looks funny :)
1089 $this->setVar( 'wgDeletedDirectory',
1090 str_replace(
1091 '/', DIRECTORY_SEPARATOR,
1092 $this->getVar( 'wgDeletedDirectory' )
1093 )
1094 );
1095
1096 $uploadwrapperStyle = $this->getVar( 'wgEnableUploads' ) ? '' : 'display: none';
1097 $this->addHTML(
1098 # Uploading
1099 $this->getFieldSetStart( 'config-upload-settings' ) .
1100 $this->parent->getCheckBox( array(
1101 'var' => 'wgEnableUploads',
1102 'label' => 'config-upload-enable',
1103 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'uploadwrapper' ),
1104 'help' => $this->parent->getHelpBox( 'config-upload-help' )
1105 ) ) .
1106 '<div id="uploadwrapper" style="' . $uploadwrapperStyle . '">' .
1107 $this->parent->getTextBox( array(
1108 'var' => 'wgDeletedDirectory',
1109 'label' => 'config-upload-deleted',
1110 'attribs' => array( 'dir' => 'ltr' ),
1111 'help' => $this->parent->getHelpBox( 'config-upload-deleted-help' )
1112 ) ) .
1113 '</div>' .
1114 $this->parent->getTextBox( array(
1115 'var' => 'wgLogo',
1116 'label' => 'config-logo',
1117 'attribs' => array( 'dir' => 'ltr' ),
1118 'help' => $this->parent->getHelpBox( 'config-logo-help' )
1119 ) )
1120 );
1121 $this->addHTML(
1122 $this->parent->getCheckBox( array(
1123 'var' => 'wgUseInstantCommons',
1124 'label' => 'config-instantcommons',
1125 'help' => $this->parent->getHelpBox( 'config-instantcommons-help' )
1126 ) ) .
1127 $this->getFieldSetEnd()
1128 );
1129
1130 $caches = array( 'none' );
1131 if ( count( $this->getVar( '_Caches' ) ) ) {
1132 $caches[] = 'accel';
1133 }
1134 $caches[] = 'memcached';
1135
1136 // We'll hide/show this on demand when the value changes, see config.js.
1137 $cacheval = $this->getVar( 'wgMainCacheType' );
1138 if ( !$cacheval ) {
1139 // We need to set a default here; but don't hardcode it
1140 // or we lose it every time we reload the page for validation
1141 // or going back!
1142 $cacheval = 'none';
1143 }
1144 $hidden = ( $cacheval == 'memcached' ) ? '' : 'display: none';
1145 $this->addHTML(
1146 # Advanced settings
1147 $this->getFieldSetStart( 'config-advanced-settings' ) .
1148 # Object cache settings
1149 // getRadioSet() builds a set of labeled radio buttons.
1150 // For grep: The following messages are used as the item labels:
1151 // config-cache-none, config-cache-accel, config-cache-memcached
1152 $this->parent->getRadioSet( array(
1153 'var' => 'wgMainCacheType',
1154 'label' => 'config-cache-options',
1155 'itemLabelPrefix' => 'config-cache-',
1156 'values' => $caches,
1157 'value' => $cacheval,
1158 ) ) .
1159 $this->parent->getHelpBox( 'config-cache-help' ) .
1160 "<div id=\"config-memcachewrapper\" style=\"$hidden\">" .
1161 $this->parent->getTextArea( array(
1162 'var' => '_MemCachedServers',
1163 'label' => 'config-memcached-servers',
1164 'help' => $this->parent->getHelpBox( 'config-memcached-help' )
1165 ) ) .
1166 '</div>' .
1167 $this->getFieldSetEnd()
1168 );
1169 $this->endForm();
1170
1171 return null;
1172 }
1173
1174 /**
1175 * @return string
1176 */
1177 public function getCCPartnerUrl() {
1178 $server = $this->getVar( 'wgServer' );
1179 $exitUrl = $server . $this->parent->getUrl( array(
1180 'page' => 'Options',
1181 'SubmitCC' => 'indeed',
1182 'config__LicenseCode' => 'cc',
1183 'config_wgRightsUrl' => '[license_url]',
1184 'config_wgRightsText' => '[license_name]',
1185 'config_wgRightsIcon' => '[license_button]',
1186 ) );
1187 $styleUrl = $server . dirname( dirname( $this->parent->getUrl() ) ) .
1188 '/mw-config/config-cc.css';
1189 $iframeUrl = '//creativecommons.org/license/?' .
1190 wfArrayToCgi( array(
1191 'partner' => 'MediaWiki',
1192 'exit_url' => $exitUrl,
1193 'lang' => $this->getVar( '_UserLang' ),
1194 'stylesheet' => $styleUrl,
1195 ) );
1196
1197 return $iframeUrl;
1198 }
1199
1200 /**
1201 * @return string
1202 */
1203 public function getCCChooser() {
1204 $iframeAttribs = array(
1205 'class' => 'config-cc-iframe',
1206 'name' => 'config-cc-iframe',
1207 'id' => 'config-cc-iframe',
1208 'frameborder' => 0,
1209 'width' => '100%',
1210 'height' => '100%',
1211 );
1212 if ( $this->getVar( '_CCDone' ) ) {
1213 $iframeAttribs['src'] = $this->parent->getUrl( array( 'ShowCC' => 'yes' ) );
1214 } else {
1215 $iframeAttribs['src'] = $this->getCCPartnerUrl();
1216 }
1217 $wrapperStyle = ( $this->getVar( '_LicenseCode' ) == 'cc-choose' ) ? '' : 'display: none';
1218
1219 return "<div class=\"config-cc-wrapper\" id=\"config-cc-wrapper\" style=\"$wrapperStyle\">\n" .
1220 Html::element( 'iframe', $iframeAttribs, '', false /* not short */ ) .
1221 "</div>\n";
1222 }
1223
1224 /**
1225 * @return string
1226 */
1227 public function getCCDoneBox() {
1228 $js = "parent.document.getElementById('config-cc-wrapper').style.height = '$1';";
1229 // If you change this height, also change it in config.css
1230 $expandJs = str_replace( '$1', '54em', $js );
1231 $reduceJs = str_replace( '$1', '70px', $js );
1232
1233 return '<p>' .
1234 Html::element( 'img', array( 'src' => $this->getVar( 'wgRightsIcon' ) ) ) .
1235 '&#160;&#160;' .
1236 htmlspecialchars( $this->getVar( 'wgRightsText' ) ) .
1237 "</p>\n" .
1238 "<p style=\"text-align: center;\">" .
1239 Html::element( 'a',
1240 array(
1241 'href' => $this->getCCPartnerUrl(),
1242 'onclick' => $expandJs,
1243 ),
1244 wfMessage( 'config-cc-again' )->text()
1245 ) .
1246 "</p>\n" .
1247 "<script>\n" .
1248 # Reduce the wrapper div height
1249 htmlspecialchars( $reduceJs ) .
1250 "\n" .
1251 "</script>\n";
1252 }
1253
1254 public function submitCC() {
1255 $newValues = $this->parent->setVarsFromRequest(
1256 array( 'wgRightsUrl', 'wgRightsText', 'wgRightsIcon' ) );
1257 if ( count( $newValues ) != 3 ) {
1258 $this->parent->showError( 'config-cc-error' );
1259
1260 return;
1261 }
1262 $this->setVar( '_CCDone', true );
1263 $this->addHTML( $this->getCCDoneBox() );
1264 }
1265
1266 /**
1267 * If the user skips this installer page, we still need to set up the default skins, but ignore
1268 * everything else.
1269 *
1270 * @return bool
1271 */
1272 public function submitSkins() {
1273 $skins = $this->parent->findExtensions( 'skins' );
1274 $this->parent->setVar( '_Skins', $skins );
1275
1276 if ( $skins ) {
1277 $skinNames = array_map( 'strtolower', $skins );
1278 $this->parent->setVar( 'wgDefaultSkin', $this->parent->getDefaultSkin( $skinNames ) );
1279 }
1280
1281 return true;
1282 }
1283
1284 /**
1285 * @return bool
1286 */
1287 public function submit() {
1288 $this->parent->setVarsFromRequest( array( '_RightsProfile', '_LicenseCode',
1289 'wgEnableEmail', 'wgPasswordSender', 'wgEnableUploads', 'wgLogo',
1290 'wgEnableUserEmail', 'wgEnotifUserTalk', 'wgEnotifWatchlist',
1291 'wgEmailAuthentication', 'wgMainCacheType', '_MemCachedServers',
1292 'wgUseInstantCommons', 'wgDefaultSkin' ) );
1293
1294 $retVal = true;
1295
1296 if ( !array_key_exists( $this->getVar( '_RightsProfile' ), $this->parent->rightsProfiles ) ) {
1297 reset( $this->parent->rightsProfiles );
1298 $this->setVar( '_RightsProfile', key( $this->parent->rightsProfiles ) );
1299 }
1300
1301 $code = $this->getVar( '_LicenseCode' );
1302 if ( $code == 'cc-choose' ) {
1303 if ( !$this->getVar( '_CCDone' ) ) {
1304 $this->parent->showError( 'config-cc-not-chosen' );
1305 $retVal = false;
1306 }
1307 } elseif ( array_key_exists( $code, $this->parent->licenses ) ) {
1308 // Messages:
1309 // config-license-cc-by, config-license-cc-by-sa, config-license-cc-by-nc-sa,
1310 // config-license-cc-0, config-license-pd, config-license-gfdl, config-license-none,
1311 // config-license-cc-choose
1312 $entry = $this->parent->licenses[$code];
1313 if ( isset( $entry['text'] ) ) {
1314 $this->setVar( 'wgRightsText', $entry['text'] );
1315 } else {
1316 $this->setVar( 'wgRightsText', wfMessage( 'config-license-' . $code )->text() );
1317 }
1318 $this->setVar( 'wgRightsUrl', $entry['url'] );
1319 $this->setVar( 'wgRightsIcon', $entry['icon'] );
1320 } else {
1321 $this->setVar( 'wgRightsText', '' );
1322 $this->setVar( 'wgRightsUrl', '' );
1323 $this->setVar( 'wgRightsIcon', '' );
1324 }
1325
1326 $skinsAvailable = $this->parent->findExtensions( 'skins' );
1327 $skinsToInstall = array();
1328 foreach ( $skinsAvailable as $skin ) {
1329 $this->parent->setVarsFromRequest( array( "skin-$skin" ) );
1330 if ( $this->getVar( "skin-$skin" ) ) {
1331 $skinsToInstall[] = $skin;
1332 }
1333 }
1334 $this->parent->setVar( '_Skins', $skinsToInstall );
1335
1336 if ( !$skinsToInstall && $skinsAvailable ) {
1337 $this->parent->showError( 'config-skins-must-enable-some' );
1338 $retVal = false;
1339 }
1340 $defaultSkin = $this->getVar( 'wgDefaultSkin' );
1341 $skinsToInstallLowercase = array_map( 'strtolower', $skinsToInstall );
1342 if ( $skinsToInstall && array_search( $defaultSkin, $skinsToInstallLowercase ) === false ) {
1343 $this->parent->showError( 'config-skins-must-enable-default' );
1344 $retVal = false;
1345 }
1346
1347 $extsAvailable = $this->parent->findExtensions();
1348 $extsToInstall = array();
1349 foreach ( $extsAvailable as $ext ) {
1350 $this->parent->setVarsFromRequest( array( "ext-$ext" ) );
1351 if ( $this->getVar( "ext-$ext" ) ) {
1352 $extsToInstall[] = $ext;
1353 }
1354 }
1355 $this->parent->setVar( '_Extensions', $extsToInstall );
1356
1357 if ( $this->getVar( 'wgMainCacheType' ) == 'memcached' ) {
1358 $memcServers = explode( "\n", $this->getVar( '_MemCachedServers' ) );
1359 if ( !$memcServers ) {
1360 $this->parent->showError( 'config-memcache-needservers' );
1361 $retVal = false;
1362 }
1363
1364 foreach ( $memcServers as $server ) {
1365 $memcParts = explode( ":", $server, 2 );
1366 if ( !isset( $memcParts[0] )
1367 || ( !IP::isValid( $memcParts[0] )
1368 && ( gethostbyname( $memcParts[0] ) == $memcParts[0] ) )
1369 ) {
1370 $this->parent->showError( 'config-memcache-badip', $memcParts[0] );
1371 $retVal = false;
1372 } elseif ( !isset( $memcParts[1] ) ) {
1373 $this->parent->showError( 'config-memcache-noport', $memcParts[0] );
1374 $retVal = false;
1375 } elseif ( $memcParts[1] < 1 || $memcParts[1] > 65535 ) {
1376 $this->parent->showError( 'config-memcache-badport', 1, 65535 );
1377 $retVal = false;
1378 }
1379 }
1380 }
1381
1382 return $retVal;
1383 }
1384
1385 }
1386
1387 class WebInstallerInstall extends WebInstallerPage {
1388
1389 /**
1390 * @return bool Always true.
1391 */
1392 public function isSlow() {
1393 return true;
1394 }
1395
1396 /**
1397 * @return string|bool
1398 */
1399 public function execute() {
1400 if ( $this->getVar( '_UpgradeDone' ) ) {
1401 return 'skip';
1402 } elseif ( $this->getVar( '_InstallDone' ) ) {
1403 return 'continue';
1404 } elseif ( $this->parent->request->wasPosted() ) {
1405 $this->startForm();
1406 $this->addHTML( "<ul>" );
1407 $results = $this->parent->performInstallation(
1408 array( $this, 'startStage' ),
1409 array( $this, 'endStage' )
1410 );
1411 $this->addHTML( "</ul>" );
1412 // PerformInstallation bails on a fatal, so make sure the last item
1413 // completed before giving 'next.' Likewise, only provide back on failure
1414 $lastStep = end( $results );
1415 $continue = $lastStep->isOK() ? 'continue' : false;
1416 $back = $lastStep->isOK() ? false : 'back';
1417 $this->endForm( $continue, $back );
1418 } else {
1419 $this->startForm();
1420 $this->addHTML( $this->parent->getInfoBox( wfMessage( 'config-install-begin' )->plain() ) );
1421 $this->endForm();
1422 }
1423
1424 return true;
1425 }
1426
1427 /**
1428 * @param string $step
1429 */
1430 public function startStage( $step ) {
1431 // Messages: config-install-database, config-install-tables, config-install-interwiki,
1432 // config-install-stats, config-install-keys, config-install-sysop, config-install-mainpage
1433 $this->addHTML( "<li>" . wfMessage( "config-install-$step" )->escaped() .
1434 wfMessage( 'ellipsis' )->escaped() );
1435
1436 if ( $step == 'extension-tables' ) {
1437 $this->startLiveBox();
1438 }
1439 }
1440
1441 /**
1442 * @param string $step
1443 * @param Status $status
1444 */
1445 public function endStage( $step, $status ) {
1446 if ( $step == 'extension-tables' ) {
1447 $this->endLiveBox();
1448 }
1449 $msg = $status->isOk() ? 'config-install-step-done' : 'config-install-step-failed';
1450 $html = wfMessage( 'word-separator' )->escaped() . wfMessage( $msg )->escaped();
1451 if ( !$status->isOk() ) {
1452 $html = "<span class=\"error\">$html</span>";
1453 }
1454 $this->addHTML( $html . "</li>\n" );
1455 if ( !$status->isGood() ) {
1456 $this->parent->showStatusBox( $status );
1457 }
1458 }
1459
1460 }
1461
1462 class WebInstallerComplete extends WebInstallerPage {
1463
1464 public function execute() {
1465 // Pop up a dialog box, to make it difficult for the user to forget
1466 // to download the file
1467 $lsUrl = $this->getVar( 'wgServer' ) . $this->parent->getURL( array( 'localsettings' => 1 ) );
1468 if ( isset( $_SERVER['HTTP_USER_AGENT'] ) &&
1469 strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE' ) !== false
1470 ) {
1471 // JS appears to be the only method that works consistently with IE7+
1472 $this->addHtml( "\n<script>jQuery( function () { location.href = " .
1473 Xml::encodeJsVar( $lsUrl ) . "; } );</script>\n" );
1474 } else {
1475 $this->parent->request->response()->header( "Refresh: 0;url=$lsUrl" );
1476 }
1477
1478 $this->startForm();
1479 $this->parent->disableLinkPopups();
1480 $this->addHTML(
1481 $this->parent->getInfoBox(
1482 wfMessage( 'config-install-done',
1483 $lsUrl,
1484 $this->getVar( 'wgServer' ) .
1485 $this->getVar( 'wgScriptPath' ) . '/index.php',
1486 '<downloadlink/>'
1487 )->plain(), 'tick-32.png'
1488 )
1489 );
1490 $this->addHTML( $this->parent->getInfoBox(
1491 wfMessage( 'config-extension-link' )->text() ) );
1492
1493 $this->parent->restoreLinkPopups();
1494 $this->endForm( false, false );
1495 }
1496
1497 }
1498
1499 class WebInstallerRestart extends WebInstallerPage {
1500
1501 /**
1502 * @return string|null
1503 */
1504 public function execute() {
1505 $r = $this->parent->request;
1506 if ( $r->wasPosted() ) {
1507 $really = $r->getVal( 'submit-restart' );
1508 if ( $really ) {
1509 $this->parent->reset();
1510 }
1511
1512 return 'continue';
1513 }
1514
1515 $this->startForm();
1516 $s = $this->parent->getWarningBox( wfMessage( 'config-help-restart' )->plain() );
1517 $this->addHTML( $s );
1518 $this->endForm( 'restart' );
1519
1520 return null;
1521 }
1522
1523 }
1524
1525 abstract class WebInstallerDocument extends WebInstallerPage {
1526
1527 /**
1528 * @return string
1529 */
1530 abstract protected function getFileName();
1531
1532 public function execute() {
1533 $text = $this->getFileContents();
1534 $text = InstallDocFormatter::format( $text );
1535 $this->parent->output->addWikiText( $text );
1536 $this->startForm();
1537 $this->endForm( false );
1538 }
1539
1540 /**
1541 * @return string
1542 */
1543 public function getFileContents() {
1544 $file = __DIR__ . '/../../' . $this->getFileName();
1545 if ( !file_exists( $file ) ) {
1546 return wfMessage( 'config-nofile', $file )->plain();
1547 }
1548
1549 return file_get_contents( $file );
1550 }
1551
1552 }
1553
1554 class WebInstallerReadme extends WebInstallerDocument {
1555
1556 /**
1557 * @return string
1558 */
1559 protected function getFileName() {
1560 return 'README';
1561 }
1562
1563 }
1564
1565 class WebInstallerReleaseNotes extends WebInstallerDocument {
1566
1567 /**
1568 * @throws MWException
1569 * @return string
1570 */
1571 protected function getFileName() {
1572 global $wgVersion;
1573
1574 if ( !preg_match( '/^(\d+)\.(\d+).*/i', $wgVersion, $result ) ) {
1575 throw new MWException( 'Variable $wgVersion has an invalid value.' );
1576 }
1577
1578 return 'RELEASE-NOTES-' . $result[1] . '.' . $result[2];
1579 }
1580
1581 }
1582
1583 class WebInstallerUpgradeDoc extends WebInstallerDocument {
1584
1585 /**
1586 * @return string
1587 */
1588 protected function getFileName() {
1589 return 'UPGRADE';
1590 }
1591
1592 }
1593
1594 class WebInstallerCopying extends WebInstallerDocument {
1595
1596 /**
1597 * @return string
1598 */
1599 protected function getFileName() {
1600 return 'COPYING';
1601 }
1602
1603 }