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