API: Use message-per-value for apihelp-query+allcategories-param-prop
[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 global $wgPasswordPolicy;
837
838 $retVal = true;
839 $this->parent->setVarsFromRequest( array( 'wgSitename', '_NamespaceType',
840 '_AdminName', '_AdminPassword', '_AdminPasswordConfirm', '_AdminEmail',
841 '_Subscribe', '_SkipOptional', 'wgMetaNamespace' ) );
842
843 // Validate site name
844 if ( strval( $this->getVar( 'wgSitename' ) ) === '' ) {
845 $this->parent->showError( 'config-site-name-blank' );
846 $retVal = false;
847 }
848
849 // Fetch namespace
850 $nsType = $this->getVar( '_NamespaceType' );
851 if ( $nsType == 'site-name' ) {
852 $name = $this->getVar( 'wgSitename' );
853 // Sanitize for namespace
854 // This algorithm should match the JS one in WebInstallerOutput.php
855 $name = preg_replace( '/[\[\]\{\}|#<>%+? ]/', '_', $name );
856 $name = str_replace( '&', '&amp;', $name );
857 $name = preg_replace( '/__+/', '_', $name );
858 $name = ucfirst( trim( $name, '_' ) );
859 } elseif ( $nsType == 'generic' ) {
860 $name = wfMessage( 'config-ns-generic' )->text();
861 } else { // other
862 $name = $this->getVar( 'wgMetaNamespace' );
863 }
864
865 // Validate namespace
866 if ( strpos( $name, ':' ) !== false ) {
867 $good = false;
868 } else {
869 // Title-style validation
870 $title = Title::newFromText( $name );
871 if ( !$title ) {
872 $good = $nsType == 'site-name';
873 } else {
874 $name = $title->getDBkey();
875 $good = true;
876 }
877 }
878 if ( !$good ) {
879 $this->parent->showError( 'config-ns-invalid', $name );
880 $retVal = false;
881 }
882
883 // Make sure it won't conflict with any existing namespaces
884 global $wgContLang;
885 $nsIndex = $wgContLang->getNsIndex( $name );
886 if ( $nsIndex !== false && $nsIndex !== NS_PROJECT ) {
887 $this->parent->showError( 'config-ns-conflict', $name );
888 $retVal = false;
889 }
890
891 $this->setVar( 'wgMetaNamespace', $name );
892
893 // Validate username for creation
894 $name = $this->getVar( '_AdminName' );
895 if ( strval( $name ) === '' ) {
896 $this->parent->showError( 'config-admin-name-blank' );
897 $cname = $name;
898 $retVal = false;
899 } else {
900 $cname = User::getCanonicalName( $name, 'creatable' );
901 if ( $cname === false ) {
902 $this->parent->showError( 'config-admin-name-invalid', $name );
903 $retVal = false;
904 } else {
905 $this->setVar( '_AdminName', $cname );
906 }
907 }
908
909 // Validate password
910 $msg = false;
911 $pwd = $this->getVar( '_AdminPassword' );
912 $user = User::newFromName( $cname );
913 if ( $user ) {
914 $status = $user->checkPasswordValidity( $pwd, 'create' );
915 $valid = $status->isGood() ? true : $status->getMessage()->escaped();
916 } else {
917 $valid = 'config-admin-name-invalid';
918 }
919 if ( strval( $pwd ) === '' ) {
920 # $user->getPasswordValidity just checks for $wgMinimalPasswordLength.
921 # This message is more specific and helpful.
922 $msg = 'config-admin-password-blank';
923 } elseif ( $pwd !== $this->getVar( '_AdminPasswordConfirm' ) ) {
924 $msg = 'config-admin-password-mismatch';
925 } elseif ( $valid !== true ) {
926 $msg = $valid;
927 }
928 if ( $msg !== false ) {
929 call_user_func_array( array( $this->parent, 'showError' ), (array)$msg );
930 $this->setVar( '_AdminPassword', '' );
931 $this->setVar( '_AdminPasswordConfirm', '' );
932 $retVal = false;
933 }
934
935 // Validate e-mail if provided
936 $email = $this->getVar( '_AdminEmail' );
937 if ( $email && !Sanitizer::validateEmail( $email ) ) {
938 $this->parent->showError( 'config-admin-error-bademail' );
939 $retVal = false;
940 }
941 // If they asked to subscribe to mediawiki-announce but didn't give
942 // an e-mail, show an error. Bug 29332
943 if ( !$email && $this->getVar( '_Subscribe' ) ) {
944 $this->parent->showError( 'config-subscribe-noemail' );
945 $retVal = false;
946 }
947
948 return $retVal;
949 }
950
951 }
952
953 class WebInstallerOptions extends WebInstallerPage {
954
955 /**
956 * @return string|null
957 */
958 public function execute() {
959 if ( $this->getVar( '_SkipOptional' ) == 'skip' ) {
960 $this->submitSkins();
961 return 'skip';
962 }
963 if ( $this->parent->request->wasPosted() ) {
964 if ( $this->submit() ) {
965 return 'continue';
966 }
967 }
968
969 $emailwrapperStyle = $this->getVar( 'wgEnableEmail' ) ? '' : 'display: none';
970 $this->startForm();
971 $this->addHTML(
972 # User Rights
973 // getRadioSet() builds a set of labeled radio buttons.
974 // For grep: The following messages are used as the item labels:
975 // config-profile-wiki, config-profile-no-anon, config-profile-fishbowl, config-profile-private
976 $this->parent->getRadioSet( array(
977 'var' => '_RightsProfile',
978 'label' => 'config-profile',
979 'itemLabelPrefix' => 'config-profile-',
980 'values' => array_keys( $this->parent->rightsProfiles ),
981 ) ) .
982 $this->parent->getInfoBox( wfMessage( 'config-profile-help' )->plain() ) .
983
984 # Licensing
985 // getRadioSet() builds a set of labeled radio buttons.
986 // For grep: The following messages are used as the item labels:
987 // config-license-cc-by, config-license-cc-by-sa, config-license-cc-by-nc-sa,
988 // config-license-cc-0, config-license-pd, config-license-gfdl,
989 // config-license-none, config-license-cc-choose
990 $this->parent->getRadioSet( array(
991 'var' => '_LicenseCode',
992 'label' => 'config-license',
993 'itemLabelPrefix' => 'config-license-',
994 'values' => array_keys( $this->parent->licenses ),
995 'commonAttribs' => array( 'class' => 'licenseRadio' ),
996 ) ) .
997 $this->getCCChooser() .
998 $this->parent->getHelpBox( 'config-license-help' ) .
999
1000 # E-mail
1001 $this->getFieldSetStart( 'config-email-settings' ) .
1002 $this->parent->getCheckBox( array(
1003 'var' => 'wgEnableEmail',
1004 'label' => 'config-enable-email',
1005 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'emailwrapper' ),
1006 ) ) .
1007 $this->parent->getHelpBox( 'config-enable-email-help' ) .
1008 "<div id=\"emailwrapper\" style=\"$emailwrapperStyle\">" .
1009 $this->parent->getTextBox( array(
1010 'var' => 'wgPasswordSender',
1011 'label' => 'config-email-sender'
1012 ) ) .
1013 $this->parent->getHelpBox( 'config-email-sender-help' ) .
1014 $this->parent->getCheckBox( array(
1015 'var' => 'wgEnableUserEmail',
1016 'label' => 'config-email-user',
1017 ) ) .
1018 $this->parent->getHelpBox( 'config-email-user-help' ) .
1019 $this->parent->getCheckBox( array(
1020 'var' => 'wgEnotifUserTalk',
1021 'label' => 'config-email-usertalk',
1022 ) ) .
1023 $this->parent->getHelpBox( 'config-email-usertalk-help' ) .
1024 $this->parent->getCheckBox( array(
1025 'var' => 'wgEnotifWatchlist',
1026 'label' => 'config-email-watchlist',
1027 ) ) .
1028 $this->parent->getHelpBox( 'config-email-watchlist-help' ) .
1029 $this->parent->getCheckBox( array(
1030 'var' => 'wgEmailAuthentication',
1031 'label' => 'config-email-auth',
1032 ) ) .
1033 $this->parent->getHelpBox( 'config-email-auth-help' ) .
1034 "</div>" .
1035 $this->getFieldSetEnd()
1036 );
1037
1038 $skins = $this->parent->findExtensions( 'skins' );
1039 $skinHtml = $this->getFieldSetStart( 'config-skins' );
1040
1041 $skinNames = array_map( 'strtolower', $skins );
1042 $chosenSkinName = $this->getVar( 'wgDefaultSkin', $this->parent->getDefaultSkin( $skinNames ) );
1043
1044 if ( $skins ) {
1045 $radioButtons = $this->parent->getRadioElements( array(
1046 'var' => 'wgDefaultSkin',
1047 'itemLabels' => array_fill_keys( $skinNames, 'config-skins-use-as-default' ),
1048 'values' => $skinNames,
1049 'value' => $chosenSkinName,
1050 ) );
1051
1052 foreach ( $skins as $skin ) {
1053 $skinHtml .=
1054 '<div class="config-skins-item">' .
1055 $this->parent->getCheckBox( array(
1056 'var' => "skin-$skin",
1057 'rawtext' => $skin,
1058 'value' => $this->getVar( "skin-$skin", true ), // all found skins enabled by default
1059 ) ) .
1060 '<div class="config-skins-use-as-default">' . $radioButtons[strtolower( $skin )] . '</div>' .
1061 '</div>';
1062 }
1063 } else {
1064 $skinHtml .=
1065 $this->parent->getWarningBox( wfMessage( 'config-skins-missing' )->plain() ) .
1066 Html::hidden( 'config_wgDefaultSkin', $chosenSkinName );
1067 }
1068
1069 $skinHtml .= $this->parent->getHelpBox( 'config-skins-help' ) .
1070 $this->getFieldSetEnd();
1071 $this->addHTML( $skinHtml );
1072
1073 $extensions = $this->parent->findExtensions();
1074
1075 if ( $extensions ) {
1076 $extHtml = $this->getFieldSetStart( 'config-extensions' );
1077
1078 foreach ( $extensions as $ext ) {
1079 $extHtml .= $this->parent->getCheckBox( array(
1080 'var' => "ext-$ext",
1081 'rawtext' => $ext,
1082 ) );
1083 }
1084
1085 $extHtml .= $this->parent->getHelpBox( 'config-extensions-help' ) .
1086 $this->getFieldSetEnd();
1087 $this->addHTML( $extHtml );
1088 }
1089
1090 // Having / in paths in Windows looks funny :)
1091 $this->setVar( 'wgDeletedDirectory',
1092 str_replace(
1093 '/', DIRECTORY_SEPARATOR,
1094 $this->getVar( 'wgDeletedDirectory' )
1095 )
1096 );
1097
1098 $uploadwrapperStyle = $this->getVar( 'wgEnableUploads' ) ? '' : 'display: none';
1099 $this->addHTML(
1100 # Uploading
1101 $this->getFieldSetStart( 'config-upload-settings' ) .
1102 $this->parent->getCheckBox( array(
1103 'var' => 'wgEnableUploads',
1104 'label' => 'config-upload-enable',
1105 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'uploadwrapper' ),
1106 'help' => $this->parent->getHelpBox( 'config-upload-help' )
1107 ) ) .
1108 '<div id="uploadwrapper" style="' . $uploadwrapperStyle . '">' .
1109 $this->parent->getTextBox( array(
1110 'var' => 'wgDeletedDirectory',
1111 'label' => 'config-upload-deleted',
1112 'attribs' => array( 'dir' => 'ltr' ),
1113 'help' => $this->parent->getHelpBox( 'config-upload-deleted-help' )
1114 ) ) .
1115 '</div>' .
1116 $this->parent->getTextBox( array(
1117 'var' => 'wgLogo',
1118 'label' => 'config-logo',
1119 'attribs' => array( 'dir' => 'ltr' ),
1120 'help' => $this->parent->getHelpBox( 'config-logo-help' )
1121 ) )
1122 );
1123 $this->addHTML(
1124 $this->parent->getCheckBox( array(
1125 'var' => 'wgUseInstantCommons',
1126 'label' => 'config-instantcommons',
1127 'help' => $this->parent->getHelpBox( 'config-instantcommons-help' )
1128 ) ) .
1129 $this->getFieldSetEnd()
1130 );
1131
1132 $caches = array( 'none' );
1133 if ( count( $this->getVar( '_Caches' ) ) ) {
1134 $caches[] = 'accel';
1135 }
1136 $caches[] = 'memcached';
1137
1138 // We'll hide/show this on demand when the value changes, see config.js.
1139 $cacheval = $this->getVar( 'wgMainCacheType' );
1140 if ( !$cacheval ) {
1141 // We need to set a default here; but don't hardcode it
1142 // or we lose it every time we reload the page for validation
1143 // or going back!
1144 $cacheval = 'none';
1145 }
1146 $hidden = ( $cacheval == 'memcached' ) ? '' : 'display: none';
1147 $this->addHTML(
1148 # Advanced settings
1149 $this->getFieldSetStart( 'config-advanced-settings' ) .
1150 # Object cache settings
1151 // getRadioSet() builds a set of labeled radio buttons.
1152 // For grep: The following messages are used as the item labels:
1153 // config-cache-none, config-cache-accel, config-cache-memcached
1154 $this->parent->getRadioSet( array(
1155 'var' => 'wgMainCacheType',
1156 'label' => 'config-cache-options',
1157 'itemLabelPrefix' => 'config-cache-',
1158 'values' => $caches,
1159 'value' => $cacheval,
1160 ) ) .
1161 $this->parent->getHelpBox( 'config-cache-help' ) .
1162 "<div id=\"config-memcachewrapper\" style=\"$hidden\">" .
1163 $this->parent->getTextArea( array(
1164 'var' => '_MemCachedServers',
1165 'label' => 'config-memcached-servers',
1166 'help' => $this->parent->getHelpBox( 'config-memcached-help' )
1167 ) ) .
1168 '</div>' .
1169 $this->getFieldSetEnd()
1170 );
1171 $this->endForm();
1172
1173 return null;
1174 }
1175
1176 /**
1177 * @return string
1178 */
1179 public function getCCPartnerUrl() {
1180 $server = $this->getVar( 'wgServer' );
1181 $exitUrl = $server . $this->parent->getUrl( array(
1182 'page' => 'Options',
1183 'SubmitCC' => 'indeed',
1184 'config__LicenseCode' => 'cc',
1185 'config_wgRightsUrl' => '[license_url]',
1186 'config_wgRightsText' => '[license_name]',
1187 'config_wgRightsIcon' => '[license_button]',
1188 ) );
1189 $styleUrl = $server . dirname( dirname( $this->parent->getUrl() ) ) .
1190 '/mw-config/config-cc.css';
1191 $iframeUrl = '//creativecommons.org/license/?' .
1192 wfArrayToCgi( array(
1193 'partner' => 'MediaWiki',
1194 'exit_url' => $exitUrl,
1195 'lang' => $this->getVar( '_UserLang' ),
1196 'stylesheet' => $styleUrl,
1197 ) );
1198
1199 return $iframeUrl;
1200 }
1201
1202 /**
1203 * @return string
1204 */
1205 public function getCCChooser() {
1206 $iframeAttribs = array(
1207 'class' => 'config-cc-iframe',
1208 'name' => 'config-cc-iframe',
1209 'id' => 'config-cc-iframe',
1210 'frameborder' => 0,
1211 'width' => '100%',
1212 'height' => '100%',
1213 );
1214 if ( $this->getVar( '_CCDone' ) ) {
1215 $iframeAttribs['src'] = $this->parent->getUrl( array( 'ShowCC' => 'yes' ) );
1216 } else {
1217 $iframeAttribs['src'] = $this->getCCPartnerUrl();
1218 }
1219 $wrapperStyle = ( $this->getVar( '_LicenseCode' ) == 'cc-choose' ) ? '' : 'display: none';
1220
1221 return "<div class=\"config-cc-wrapper\" id=\"config-cc-wrapper\" style=\"$wrapperStyle\">\n" .
1222 Html::element( 'iframe', $iframeAttribs, '', false /* not short */ ) .
1223 "</div>\n";
1224 }
1225
1226 /**
1227 * @return string
1228 */
1229 public function getCCDoneBox() {
1230 $js = "parent.document.getElementById('config-cc-wrapper').style.height = '$1';";
1231 // If you change this height, also change it in config.css
1232 $expandJs = str_replace( '$1', '54em', $js );
1233 $reduceJs = str_replace( '$1', '70px', $js );
1234
1235 return '<p>' .
1236 Html::element( 'img', array( 'src' => $this->getVar( 'wgRightsIcon' ) ) ) .
1237 '&#160;&#160;' .
1238 htmlspecialchars( $this->getVar( 'wgRightsText' ) ) .
1239 "</p>\n" .
1240 "<p style=\"text-align: center;\">" .
1241 Html::element( 'a',
1242 array(
1243 'href' => $this->getCCPartnerUrl(),
1244 'onclick' => $expandJs,
1245 ),
1246 wfMessage( 'config-cc-again' )->text()
1247 ) .
1248 "</p>\n" .
1249 "<script>\n" .
1250 # Reduce the wrapper div height
1251 htmlspecialchars( $reduceJs ) .
1252 "\n" .
1253 "</script>\n";
1254 }
1255
1256 public function submitCC() {
1257 $newValues = $this->parent->setVarsFromRequest(
1258 array( 'wgRightsUrl', 'wgRightsText', 'wgRightsIcon' ) );
1259 if ( count( $newValues ) != 3 ) {
1260 $this->parent->showError( 'config-cc-error' );
1261
1262 return;
1263 }
1264 $this->setVar( '_CCDone', true );
1265 $this->addHTML( $this->getCCDoneBox() );
1266 }
1267
1268 /**
1269 * If the user skips this installer page, we still need to set up the default skins, but ignore
1270 * everything else.
1271 *
1272 * @return bool
1273 */
1274 public function submitSkins() {
1275 $skins = $this->parent->findExtensions( 'skins' );
1276 $this->parent->setVar( '_Skins', $skins );
1277
1278 if ( $skins ) {
1279 $skinNames = array_map( 'strtolower', $skins );
1280 $this->parent->setVar( 'wgDefaultSkin', $this->parent->getDefaultSkin( $skinNames ) );
1281 }
1282
1283 return true;
1284 }
1285
1286 /**
1287 * @return bool
1288 */
1289 public function submit() {
1290 $this->parent->setVarsFromRequest( array( '_RightsProfile', '_LicenseCode',
1291 'wgEnableEmail', 'wgPasswordSender', 'wgEnableUploads', 'wgLogo',
1292 'wgEnableUserEmail', 'wgEnotifUserTalk', 'wgEnotifWatchlist',
1293 'wgEmailAuthentication', 'wgMainCacheType', '_MemCachedServers',
1294 'wgUseInstantCommons', 'wgDefaultSkin' ) );
1295
1296 $retVal = true;
1297
1298 if ( !array_key_exists( $this->getVar( '_RightsProfile' ), $this->parent->rightsProfiles ) ) {
1299 reset( $this->parent->rightsProfiles );
1300 $this->setVar( '_RightsProfile', key( $this->parent->rightsProfiles ) );
1301 }
1302
1303 $code = $this->getVar( '_LicenseCode' );
1304 if ( $code == 'cc-choose' ) {
1305 if ( !$this->getVar( '_CCDone' ) ) {
1306 $this->parent->showError( 'config-cc-not-chosen' );
1307 $retVal = false;
1308 }
1309 } elseif ( array_key_exists( $code, $this->parent->licenses ) ) {
1310 // Messages:
1311 // config-license-cc-by, config-license-cc-by-sa, config-license-cc-by-nc-sa,
1312 // config-license-cc-0, config-license-pd, config-license-gfdl, config-license-none,
1313 // config-license-cc-choose
1314 $entry = $this->parent->licenses[$code];
1315 if ( isset( $entry['text'] ) ) {
1316 $this->setVar( 'wgRightsText', $entry['text'] );
1317 } else {
1318 $this->setVar( 'wgRightsText', wfMessage( 'config-license-' . $code )->text() );
1319 }
1320 $this->setVar( 'wgRightsUrl', $entry['url'] );
1321 $this->setVar( 'wgRightsIcon', $entry['icon'] );
1322 } else {
1323 $this->setVar( 'wgRightsText', '' );
1324 $this->setVar( 'wgRightsUrl', '' );
1325 $this->setVar( 'wgRightsIcon', '' );
1326 }
1327
1328 $skinsAvailable = $this->parent->findExtensions( 'skins' );
1329 $skinsToInstall = array();
1330 foreach ( $skinsAvailable as $skin ) {
1331 $this->parent->setVarsFromRequest( array( "skin-$skin" ) );
1332 if ( $this->getVar( "skin-$skin" ) ) {
1333 $skinsToInstall[] = $skin;
1334 }
1335 }
1336 $this->parent->setVar( '_Skins', $skinsToInstall );
1337
1338 if ( !$skinsToInstall && $skinsAvailable ) {
1339 $this->parent->showError( 'config-skins-must-enable-some' );
1340 $retVal = false;
1341 }
1342 $defaultSkin = $this->getVar( 'wgDefaultSkin' );
1343 $skinsToInstallLowercase = array_map( 'strtolower', $skinsToInstall );
1344 if ( $skinsToInstall && array_search( $defaultSkin, $skinsToInstallLowercase ) === false ) {
1345 $this->parent->showError( 'config-skins-must-enable-default' );
1346 $retVal = false;
1347 }
1348
1349 $extsAvailable = $this->parent->findExtensions();
1350 $extsToInstall = array();
1351 foreach ( $extsAvailable as $ext ) {
1352 $this->parent->setVarsFromRequest( array( "ext-$ext" ) );
1353 if ( $this->getVar( "ext-$ext" ) ) {
1354 $extsToInstall[] = $ext;
1355 }
1356 }
1357 $this->parent->setVar( '_Extensions', $extsToInstall );
1358
1359 if ( $this->getVar( 'wgMainCacheType' ) == 'memcached' ) {
1360 $memcServers = explode( "\n", $this->getVar( '_MemCachedServers' ) );
1361 if ( !$memcServers ) {
1362 $this->parent->showError( 'config-memcache-needservers' );
1363 $retVal = false;
1364 }
1365
1366 foreach ( $memcServers as $server ) {
1367 $memcParts = explode( ":", $server, 2 );
1368 if ( !isset( $memcParts[0] )
1369 || ( !IP::isValid( $memcParts[0] )
1370 && ( gethostbyname( $memcParts[0] ) == $memcParts[0] ) )
1371 ) {
1372 $this->parent->showError( 'config-memcache-badip', $memcParts[0] );
1373 $retVal = false;
1374 } elseif ( !isset( $memcParts[1] ) ) {
1375 $this->parent->showError( 'config-memcache-noport', $memcParts[0] );
1376 $retVal = false;
1377 } elseif ( $memcParts[1] < 1 || $memcParts[1] > 65535 ) {
1378 $this->parent->showError( 'config-memcache-badport', 1, 65535 );
1379 $retVal = false;
1380 }
1381 }
1382 }
1383
1384 return $retVal;
1385 }
1386
1387 }
1388
1389 class WebInstallerInstall extends WebInstallerPage {
1390
1391 /**
1392 * @return bool Always true.
1393 */
1394 public function isSlow() {
1395 return true;
1396 }
1397
1398 /**
1399 * @return string|bool
1400 */
1401 public function execute() {
1402 if ( $this->getVar( '_UpgradeDone' ) ) {
1403 return 'skip';
1404 } elseif ( $this->getVar( '_InstallDone' ) ) {
1405 return 'continue';
1406 } elseif ( $this->parent->request->wasPosted() ) {
1407 $this->startForm();
1408 $this->addHTML( "<ul>" );
1409 $results = $this->parent->performInstallation(
1410 array( $this, 'startStage' ),
1411 array( $this, 'endStage' )
1412 );
1413 $this->addHTML( "</ul>" );
1414 // PerformInstallation bails on a fatal, so make sure the last item
1415 // completed before giving 'next.' Likewise, only provide back on failure
1416 $lastStep = end( $results );
1417 $continue = $lastStep->isOK() ? 'continue' : false;
1418 $back = $lastStep->isOK() ? false : 'back';
1419 $this->endForm( $continue, $back );
1420 } else {
1421 $this->startForm();
1422 $this->addHTML( $this->parent->getInfoBox( wfMessage( 'config-install-begin' )->plain() ) );
1423 $this->endForm();
1424 }
1425
1426 return true;
1427 }
1428
1429 /**
1430 * @param string $step
1431 */
1432 public function startStage( $step ) {
1433 // Messages: config-install-database, config-install-tables, config-install-interwiki,
1434 // config-install-stats, config-install-keys, config-install-sysop, config-install-mainpage
1435 $this->addHTML( "<li>" . wfMessage( "config-install-$step" )->escaped() .
1436 wfMessage( 'ellipsis' )->escaped() );
1437
1438 if ( $step == 'extension-tables' ) {
1439 $this->startLiveBox();
1440 }
1441 }
1442
1443 /**
1444 * @param string $step
1445 * @param Status $status
1446 */
1447 public function endStage( $step, $status ) {
1448 if ( $step == 'extension-tables' ) {
1449 $this->endLiveBox();
1450 }
1451 $msg = $status->isOk() ? 'config-install-step-done' : 'config-install-step-failed';
1452 $html = wfMessage( 'word-separator' )->escaped() . wfMessage( $msg )->escaped();
1453 if ( !$status->isOk() ) {
1454 $html = "<span class=\"error\">$html</span>";
1455 }
1456 $this->addHTML( $html . "</li>\n" );
1457 if ( !$status->isGood() ) {
1458 $this->parent->showStatusBox( $status );
1459 }
1460 }
1461
1462 }
1463
1464 class WebInstallerComplete extends WebInstallerPage {
1465
1466 public function execute() {
1467 // Pop up a dialog box, to make it difficult for the user to forget
1468 // to download the file
1469 $lsUrl = $this->getVar( 'wgServer' ) . $this->parent->getURL( array( 'localsettings' => 1 ) );
1470 if ( isset( $_SERVER['HTTP_USER_AGENT'] ) &&
1471 strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE' ) !== false
1472 ) {
1473 // JS appears to be the only method that works consistently with IE7+
1474 $this->addHtml( "\n<script>jQuery( function () { location.href = " .
1475 Xml::encodeJsVar( $lsUrl ) . "; } );</script>\n" );
1476 } else {
1477 $this->parent->request->response()->header( "Refresh: 0;url=$lsUrl" );
1478 }
1479
1480 $this->startForm();
1481 $this->parent->disableLinkPopups();
1482 $this->addHTML(
1483 $this->parent->getInfoBox(
1484 wfMessage( 'config-install-done',
1485 $lsUrl,
1486 $this->getVar( 'wgServer' ) .
1487 $this->getVar( 'wgScriptPath' ) . '/index.php',
1488 '<downloadlink/>'
1489 )->plain(), 'tick-32.png'
1490 )
1491 );
1492 $this->addHTML( $this->parent->getInfoBox(
1493 wfMessage( 'config-extension-link' )->text() ) );
1494
1495 $this->parent->restoreLinkPopups();
1496 $this->endForm( false, false );
1497 }
1498
1499 }
1500
1501 class WebInstallerRestart extends WebInstallerPage {
1502
1503 /**
1504 * @return string|null
1505 */
1506 public function execute() {
1507 $r = $this->parent->request;
1508 if ( $r->wasPosted() ) {
1509 $really = $r->getVal( 'submit-restart' );
1510 if ( $really ) {
1511 $this->parent->reset();
1512 }
1513
1514 return 'continue';
1515 }
1516
1517 $this->startForm();
1518 $s = $this->parent->getWarningBox( wfMessage( 'config-help-restart' )->plain() );
1519 $this->addHTML( $s );
1520 $this->endForm( 'restart' );
1521
1522 return null;
1523 }
1524
1525 }
1526
1527 abstract class WebInstallerDocument extends WebInstallerPage {
1528
1529 /**
1530 * @return string
1531 */
1532 abstract protected function getFileName();
1533
1534 public function execute() {
1535 $text = $this->getFileContents();
1536 $text = InstallDocFormatter::format( $text );
1537 $this->parent->output->addWikiText( $text );
1538 $this->startForm();
1539 $this->endForm( false );
1540 }
1541
1542 /**
1543 * @return string
1544 */
1545 public function getFileContents() {
1546 $file = __DIR__ . '/../../' . $this->getFileName();
1547 if ( !file_exists( $file ) ) {
1548 return wfMessage( 'config-nofile', $file )->plain();
1549 }
1550
1551 return file_get_contents( $file );
1552 }
1553
1554 }
1555
1556 class WebInstallerReadme extends WebInstallerDocument {
1557
1558 /**
1559 * @return string
1560 */
1561 protected function getFileName() {
1562 return 'README';
1563 }
1564
1565 }
1566
1567 class WebInstallerReleaseNotes extends WebInstallerDocument {
1568
1569 /**
1570 * @throws MWException
1571 * @return string
1572 */
1573 protected function getFileName() {
1574 global $wgVersion;
1575
1576 if ( !preg_match( '/^(\d+)\.(\d+).*/i', $wgVersion, $result ) ) {
1577 throw new MWException( 'Variable $wgVersion has an invalid value.' );
1578 }
1579
1580 return 'RELEASE-NOTES-' . $result[1] . '.' . $result[2];
1581 }
1582
1583 }
1584
1585 class WebInstallerUpgradeDoc extends WebInstallerDocument {
1586
1587 /**
1588 * @return string
1589 */
1590 protected function getFileName() {
1591 return 'UPGRADE';
1592 }
1593
1594 }
1595
1596 class WebInstallerCopying extends WebInstallerDocument {
1597
1598 /**
1599 * @return string
1600 */
1601 protected function getFileName() {
1602 return 'COPYING';
1603 }
1604
1605 }