Merge "Add oldRev parameter to DiffRevisionTools hook"
[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 * @return string|void When string, "skip" or "continue"
459 */
460 public function execute() {
461 if ( $this->getVar( '_ExistingDBSettings' ) ) {
462 return 'skip';
463 }
464
465 $r = $this->parent->request;
466 if ( $r->wasPosted() ) {
467 $status = $this->submit();
468
469 if ( $status->isGood() ) {
470 $this->setVar( '_UpgradeDone', false );
471
472 return 'continue';
473 } else {
474 $this->parent->showStatusBox( $status );
475 }
476 }
477
478 $this->startForm();
479
480 $types = "<ul class=\"config-settings-block\">\n";
481 $settings = '';
482 $defaultType = $this->getVar( 'wgDBtype' );
483
484 // Messages: config-dbsupport-mysql, config-dbsupport-postgres, config-dbsupport-oracle,
485 // config-dbsupport-sqlite
486 $dbSupport = '';
487 foreach ( Installer::getDBTypes() as $type ) {
488 $dbSupport .= wfMessage( "config-dbsupport-$type" )->plain() . "\n";
489 }
490 $this->addHTML( $this->parent->getInfoBox(
491 wfMessage( 'config-support-info', trim( $dbSupport ) )->text() ) );
492
493 // It's possible that the library for the default DB type is not compiled in.
494 // In that case, instead select the first supported DB type in the list.
495 $compiledDBs = $this->parent->getCompiledDBs();
496 if ( !in_array( $defaultType, $compiledDBs ) ) {
497 $defaultType = $compiledDBs[0];
498 }
499
500 foreach ( $compiledDBs as $type ) {
501 $installer = $this->parent->getDBInstaller( $type );
502 $types .=
503 '<li>' .
504 Xml::radioLabel(
505 $installer->getReadableName(),
506 'DBType',
507 $type,
508 "DBType_$type",
509 $type == $defaultType,
510 array( 'class' => 'dbRadio', 'rel' => "DB_wrapper_$type" )
511 ) .
512 "</li>\n";
513
514 // Messages: config-header-mysql, config-header-postgres, config-header-oracle,
515 // config-header-sqlite
516 $settings .= Html::openElement(
517 'div',
518 array(
519 'id' => 'DB_wrapper_' . $type,
520 'class' => 'dbWrapper'
521 )
522 ) .
523 Html::element( 'h3', array(), wfMessage( 'config-header-' . $type )->text() ) .
524 $installer->getConnectForm() .
525 "</div>\n";
526 }
527
528 $types .= "</ul><br style=\"clear: left\"/>\n";
529
530 $this->addHTML( $this->parent->label( 'config-db-type', false, $types ) . $settings );
531 $this->endForm();
532 }
533
534 public function submit() {
535 $r = $this->parent->request;
536 $type = $r->getVal( 'DBType' );
537 if ( !$type ) {
538 return Status::newFatal( 'config-invalid-db-type' );
539 }
540 $this->setVar( 'wgDBtype', $type );
541 $installer = $this->parent->getDBInstaller( $type );
542 if ( !$installer ) {
543 return Status::newFatal( 'config-invalid-db-type' );
544 }
545
546 return $installer->submitConnectForm();
547 }
548 }
549
550 class WebInstaller_Upgrade extends WebInstallerPage {
551 public function isSlow() {
552 return true;
553 }
554
555 public function execute() {
556 if ( $this->getVar( '_UpgradeDone' ) ) {
557 // Allow regeneration of LocalSettings.php, unless we are working
558 // from a pre-existing LocalSettings.php file and we want to avoid
559 // leaking its contents
560 if ( $this->parent->request->wasPosted() && !$this->getVar( '_ExistingDBSettings' ) ) {
561 // Done message acknowledged
562 return 'continue';
563 } else {
564 // Back button click
565 // Show the done message again
566 // Make them click back again if they want to do the upgrade again
567 $this->showDoneMessage();
568
569 return 'output';
570 }
571 }
572
573 // wgDBtype is generally valid here because otherwise the previous page
574 // (connect) wouldn't have declared its happiness
575 $type = $this->getVar( 'wgDBtype' );
576 $installer = $this->parent->getDBInstaller( $type );
577
578 if ( !$installer->needsUpgrade() ) {
579 return 'skip';
580 }
581
582 if ( $this->parent->request->wasPosted() ) {
583 $installer->preUpgrade();
584
585 $this->startLiveBox();
586 $result = $installer->doUpgrade();
587 $this->endLiveBox();
588
589 if ( $result ) {
590 // If they're going to possibly regenerate LocalSettings, we
591 // need to create the upgrade/secret keys. Bug 26481
592 if ( !$this->getVar( '_ExistingDBSettings' ) ) {
593 $this->parent->generateKeys();
594 }
595 $this->setVar( '_UpgradeDone', true );
596 $this->showDoneMessage();
597
598 return 'output';
599 }
600 }
601
602 $this->startForm();
603 $this->addHTML( $this->parent->getInfoBox(
604 wfMessage( 'config-can-upgrade', $GLOBALS['wgVersion'] )->plain() ) );
605 $this->endForm();
606 }
607
608 public function showDoneMessage() {
609 $this->startForm();
610 $regenerate = !$this->getVar( '_ExistingDBSettings' );
611 if ( $regenerate ) {
612 $msg = 'config-upgrade-done';
613 } else {
614 $msg = 'config-upgrade-done-no-regenerate';
615 }
616 $this->parent->disableLinkPopups();
617 $this->addHTML(
618 $this->parent->getInfoBox(
619 wfMessage( $msg,
620 $this->getVar( 'wgServer' ) .
621 $this->getVar( 'wgScriptPath' ) . '/index' .
622 $this->getVar( 'wgScriptExtension' )
623 )->plain(), 'tick-32.png'
624 )
625 );
626 $this->parent->restoreLinkPopups();
627 $this->endForm( $regenerate ? 'regenerate' : false, false );
628 }
629 }
630
631 class WebInstaller_DBSettings extends WebInstallerPage {
632
633 public function execute() {
634 $installer = $this->parent->getDBInstaller( $this->getVar( 'wgDBtype' ) );
635
636 $r = $this->parent->request;
637 if ( $r->wasPosted() ) {
638 $status = $installer->submitSettingsForm();
639 if ( $status === false ) {
640 return 'skip';
641 } elseif ( $status->isGood() ) {
642 return 'continue';
643 } else {
644 $this->parent->showStatusBox( $status );
645 }
646 }
647
648 $form = $installer->getSettingsForm();
649 if ( $form === false ) {
650 return 'skip';
651 }
652
653 $this->startForm();
654 $this->addHTML( $form );
655 $this->endForm();
656 }
657 }
658
659 class WebInstaller_Name extends WebInstallerPage {
660
661 public function execute() {
662 $r = $this->parent->request;
663 if ( $r->wasPosted() ) {
664 if ( $this->submit() ) {
665 return 'continue';
666 }
667 }
668
669 $this->startForm();
670
671 // Encourage people to not name their site 'MediaWiki' by blanking the
672 // field. I think that was the intent with the original $GLOBALS['wgSitename']
673 // but these two always were the same so had the effect of making the
674 // installer forget $wgSitename when navigating back to this page.
675 if ( $this->getVar( 'wgSitename' ) == 'MediaWiki' ) {
676 $this->setVar( 'wgSitename', '' );
677 }
678
679 // Set wgMetaNamespace to something valid before we show the form.
680 // $wgMetaNamespace defaults to $wgSiteName which is 'MediaWiki'
681 $metaNS = $this->getVar( 'wgMetaNamespace' );
682 $this->setVar(
683 'wgMetaNamespace',
684 wfMessage( 'config-ns-other-default' )->inContentLanguage()->text()
685 );
686
687 $this->addHTML(
688 $this->parent->getTextBox( array(
689 'var' => 'wgSitename',
690 'label' => 'config-site-name',
691 'help' => $this->parent->getHelpBox( 'config-site-name-help' )
692 ) ) .
693 // getRadioSet() builds a set of labeled radio buttons.
694 // For grep: The following messages are used as the item labels:
695 // config-ns-site-name, config-ns-generic, config-ns-other
696 $this->parent->getRadioSet( array(
697 'var' => '_NamespaceType',
698 'label' => 'config-project-namespace',
699 'itemLabelPrefix' => 'config-ns-',
700 'values' => array( 'site-name', 'generic', 'other' ),
701 'commonAttribs' => array( 'class' => 'enableForOther',
702 'rel' => 'config_wgMetaNamespace' ),
703 'help' => $this->parent->getHelpBox( 'config-project-namespace-help' )
704 ) ) .
705 $this->parent->getTextBox( array(
706 'var' => 'wgMetaNamespace',
707 'label' => '', // @todo Needs a label?
708 'attribs' => array( 'readonly' => 'readonly', 'class' => 'enabledByOther' )
709 ) ) .
710 $this->getFieldSetStart( 'config-admin-box' ) .
711 $this->parent->getTextBox( array(
712 'var' => '_AdminName',
713 'label' => 'config-admin-name',
714 'help' => $this->parent->getHelpBox( 'config-admin-help' )
715 ) ) .
716 $this->parent->getPasswordBox( array(
717 'var' => '_AdminPassword',
718 'label' => 'config-admin-password',
719 ) ) .
720 $this->parent->getPasswordBox( array(
721 'var' => '_AdminPassword2',
722 'label' => 'config-admin-password-confirm'
723 ) ) .
724 $this->parent->getTextBox( array(
725 'var' => '_AdminEmail',
726 'label' => 'config-admin-email',
727 'help' => $this->parent->getHelpBox( 'config-admin-email-help' )
728 ) ) .
729 $this->parent->getCheckBox( array(
730 'var' => '_Subscribe',
731 'label' => 'config-subscribe',
732 'help' => $this->parent->getHelpBox( 'config-subscribe-help' )
733 ) ) .
734 $this->getFieldSetEnd() .
735 $this->parent->getInfoBox( wfMessage( 'config-almost-done' )->text() ) .
736 // getRadioSet() builds a set of labeled radio buttons.
737 // For grep: The following messages are used as the item labels:
738 // config-optional-continue, config-optional-skip
739 $this->parent->getRadioSet( array(
740 'var' => '_SkipOptional',
741 'itemLabelPrefix' => 'config-optional-',
742 'values' => array( 'continue', 'skip' )
743 ) )
744 );
745
746 // Restore the default value
747 $this->setVar( 'wgMetaNamespace', $metaNS );
748
749 $this->endForm();
750
751 return 'output';
752 }
753
754 public function submit() {
755 $retVal = true;
756 $this->parent->setVarsFromRequest( array( 'wgSitename', '_NamespaceType',
757 '_AdminName', '_AdminPassword', '_AdminPassword2', '_AdminEmail',
758 '_Subscribe', '_SkipOptional', 'wgMetaNamespace' ) );
759
760 // Validate site name
761 if ( strval( $this->getVar( 'wgSitename' ) ) === '' ) {
762 $this->parent->showError( 'config-site-name-blank' );
763 $retVal = false;
764 }
765
766 // Fetch namespace
767 $nsType = $this->getVar( '_NamespaceType' );
768 if ( $nsType == 'site-name' ) {
769 $name = $this->getVar( 'wgSitename' );
770 // Sanitize for namespace
771 // This algorithm should match the JS one in WebInstallerOutput.php
772 $name = preg_replace( '/[\[\]\{\}|#<>%+? ]/', '_', $name );
773 $name = str_replace( '&', '&amp;', $name );
774 $name = preg_replace( '/__+/', '_', $name );
775 $name = ucfirst( trim( $name, '_' ) );
776 } elseif ( $nsType == 'generic' ) {
777 $name = wfMessage( 'config-ns-generic' )->text();
778 } else { // other
779 $name = $this->getVar( 'wgMetaNamespace' );
780 }
781
782 // Validate namespace
783 if ( strpos( $name, ':' ) !== false ) {
784 $good = false;
785 } else {
786 // Title-style validation
787 $title = Title::newFromText( $name );
788 if ( !$title ) {
789 $good = $nsType == 'site-name';
790 } else {
791 $name = $title->getDBkey();
792 $good = true;
793 }
794 }
795 if ( !$good ) {
796 $this->parent->showError( 'config-ns-invalid', $name );
797 $retVal = false;
798 }
799
800 // Make sure it won't conflict with any existing namespaces
801 global $wgContLang;
802 $nsIndex = $wgContLang->getNsIndex( $name );
803 if ( $nsIndex !== false && $nsIndex !== NS_PROJECT ) {
804 $this->parent->showError( 'config-ns-conflict', $name );
805 $retVal = false;
806 }
807
808 $this->setVar( 'wgMetaNamespace', $name );
809
810 // Validate username for creation
811 $name = $this->getVar( '_AdminName' );
812 if ( strval( $name ) === '' ) {
813 $this->parent->showError( 'config-admin-name-blank' );
814 $cname = $name;
815 $retVal = false;
816 } else {
817 $cname = User::getCanonicalName( $name, 'creatable' );
818 if ( $cname === false ) {
819 $this->parent->showError( 'config-admin-name-invalid', $name );
820 $retVal = false;
821 } else {
822 $this->setVar( '_AdminName', $cname );
823 }
824 }
825
826 // Validate password
827 $msg = false;
828 $pwd = $this->getVar( '_AdminPassword' );
829 $user = User::newFromName( $cname );
830 $valid = $user && $user->getPasswordValidity( $pwd );
831 if ( strval( $pwd ) === '' ) {
832 # $user->getPasswordValidity just checks for $wgMinimalPasswordLength.
833 # This message is more specific and helpful.
834 $msg = 'config-admin-password-blank';
835 } elseif ( $pwd !== $this->getVar( '_AdminPassword2' ) ) {
836 $msg = 'config-admin-password-mismatch';
837 } elseif ( $valid !== true ) {
838 # As of writing this will only catch the username being e.g. 'FOO' and
839 # the password 'foo'
840 $msg = $valid;
841 }
842 if ( $msg !== false ) {
843 call_user_func_array( array( $this->parent, 'showError' ), (array)$msg );
844 $this->setVar( '_AdminPassword', '' );
845 $this->setVar( '_AdminPassword2', '' );
846 $retVal = false;
847 }
848
849 // Validate e-mail if provided
850 $email = $this->getVar( '_AdminEmail' );
851 if ( $email && !Sanitizer::validateEmail( $email ) ) {
852 $this->parent->showError( 'config-admin-error-bademail' );
853 $retVal = false;
854 }
855 // If they asked to subscribe to mediawiki-announce but didn't give
856 // an e-mail, show an error. Bug 29332
857 if ( !$email && $this->getVar( '_Subscribe' ) ) {
858 $this->parent->showError( 'config-subscribe-noemail' );
859 $retVal = false;
860 }
861
862 return $retVal;
863 }
864 }
865
866 class WebInstaller_Options extends WebInstallerPage {
867 public function execute() {
868 if ( $this->getVar( '_SkipOptional' ) == 'skip' ) {
869 return 'skip';
870 }
871 if ( $this->parent->request->wasPosted() ) {
872 if ( $this->submit() ) {
873 return 'continue';
874 }
875 }
876
877 $emailwrapperStyle = $this->getVar( 'wgEnableEmail' ) ? '' : 'display: none';
878 $this->startForm();
879 $this->addHTML(
880 # User Rights
881 // getRadioSet() builds a set of labeled radio buttons.
882 // For grep: The following messages are used as the item labels:
883 // config-profile-wiki, config-profile-no-anon, config-profile-fishbowl, config-profile-private
884 $this->parent->getRadioSet( array(
885 'var' => '_RightsProfile',
886 'label' => 'config-profile',
887 'itemLabelPrefix' => 'config-profile-',
888 'values' => array_keys( $this->parent->rightsProfiles ),
889 ) ) .
890 $this->parent->getInfoBox( wfMessage( 'config-profile-help' )->plain() ) .
891
892 # Licensing
893 // getRadioSet() builds a set of labeled radio buttons.
894 // For grep: The following messages are used as the item labels:
895 // config-license-cc-by, config-license-cc-by-sa, config-license-cc-by-nc-sa,
896 // config-license-cc-0, config-license-pd, config-license-gfdl,
897 // config-license-none, config-license-cc-choose
898 $this->parent->getRadioSet( array(
899 'var' => '_LicenseCode',
900 'label' => 'config-license',
901 'itemLabelPrefix' => 'config-license-',
902 'values' => array_keys( $this->parent->licenses ),
903 'commonAttribs' => array( 'class' => 'licenseRadio' ),
904 ) ) .
905 $this->getCCChooser() .
906 $this->parent->getHelpBox( 'config-license-help' ) .
907
908 # E-mail
909 $this->getFieldSetStart( 'config-email-settings' ) .
910 $this->parent->getCheckBox( array(
911 'var' => 'wgEnableEmail',
912 'label' => 'config-enable-email',
913 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'emailwrapper' ),
914 ) ) .
915 $this->parent->getHelpBox( 'config-enable-email-help' ) .
916 "<div id=\"emailwrapper\" style=\"$emailwrapperStyle\">" .
917 $this->parent->getTextBox( array(
918 'var' => 'wgPasswordSender',
919 'label' => 'config-email-sender'
920 ) ) .
921 $this->parent->getHelpBox( 'config-email-sender-help' ) .
922 $this->parent->getCheckBox( array(
923 'var' => 'wgEnableUserEmail',
924 'label' => 'config-email-user',
925 ) ) .
926 $this->parent->getHelpBox( 'config-email-user-help' ) .
927 $this->parent->getCheckBox( array(
928 'var' => 'wgEnotifUserTalk',
929 'label' => 'config-email-usertalk',
930 ) ) .
931 $this->parent->getHelpBox( 'config-email-usertalk-help' ) .
932 $this->parent->getCheckBox( array(
933 'var' => 'wgEnotifWatchlist',
934 'label' => 'config-email-watchlist',
935 ) ) .
936 $this->parent->getHelpBox( 'config-email-watchlist-help' ) .
937 $this->parent->getCheckBox( array(
938 'var' => 'wgEmailAuthentication',
939 'label' => 'config-email-auth',
940 ) ) .
941 $this->parent->getHelpBox( 'config-email-auth-help' ) .
942 "</div>" .
943 $this->getFieldSetEnd()
944 );
945
946 $extensions = $this->parent->findExtensions();
947
948 if ( $extensions ) {
949 $extHtml = $this->getFieldSetStart( 'config-extensions' );
950
951 foreach ( $extensions as $ext ) {
952 $extHtml .= $this->parent->getCheckBox( array(
953 'var' => "ext-$ext",
954 'rawtext' => $ext,
955 ) );
956 }
957
958 $extHtml .= $this->parent->getHelpBox( 'config-extensions-help' ) .
959 $this->getFieldSetEnd();
960 $this->addHTML( $extHtml );
961 }
962
963 // Having / in paths in Windows looks funny :)
964 $this->setVar( 'wgDeletedDirectory',
965 str_replace(
966 '/', DIRECTORY_SEPARATOR,
967 $this->getVar( 'wgDeletedDirectory' )
968 )
969 );
970 // If we're using the default, let the user set it relative to $wgScriptPath
971 $curLogo = $this->getVar( 'wgLogo' );
972 $logoString = ( $curLogo == "/wiki/skins/common/images/wiki.png" ) ?
973 '$wgStylePath/common/images/wiki.png' : $curLogo;
974
975 $uploadwrapperStyle = $this->getVar( 'wgEnableUploads' ) ? '' : 'display: none';
976 $this->addHTML(
977 # Uploading
978 $this->getFieldSetStart( 'config-upload-settings' ) .
979 $this->parent->getCheckBox( array(
980 'var' => 'wgEnableUploads',
981 'label' => 'config-upload-enable',
982 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'uploadwrapper' ),
983 'help' => $this->parent->getHelpBox( 'config-upload-help' )
984 ) ) .
985 '<div id="uploadwrapper" style="' . $uploadwrapperStyle . '">' .
986 $this->parent->getTextBox( array(
987 'var' => 'wgDeletedDirectory',
988 'label' => 'config-upload-deleted',
989 'attribs' => array( 'dir' => 'ltr' ),
990 'help' => $this->parent->getHelpBox( 'config-upload-deleted-help' )
991 ) ) .
992 '</div>' .
993 $this->parent->getTextBox( array(
994 'var' => 'wgLogo',
995 'value' => $logoString,
996 'label' => 'config-logo',
997 'attribs' => array( 'dir' => 'ltr' ),
998 'help' => $this->parent->getHelpBox( 'config-logo-help' )
999 ) )
1000 );
1001 $this->addHTML(
1002 $this->parent->getCheckBox( array(
1003 'var' => 'wgUseInstantCommons',
1004 'label' => 'config-instantcommons',
1005 'help' => $this->parent->getHelpBox( 'config-instantcommons-help' )
1006 ) ) .
1007 $this->getFieldSetEnd()
1008 );
1009
1010 $caches = array( 'none' );
1011 if ( count( $this->getVar( '_Caches' ) ) ) {
1012 $caches[] = 'accel';
1013 }
1014 $caches[] = 'memcached';
1015
1016 // We'll hide/show this on demand when the value changes, see config.js.
1017 $cacheval = $this->getVar( 'wgMainCacheType' );
1018 if ( !$cacheval ) {
1019 // We need to set a default here; but don't hardcode it
1020 // or we lose it every time we reload the page for validation
1021 // or going back!
1022 $cacheval = 'none';
1023 }
1024 $hidden = ( $cacheval == 'memcached' ) ? '' : 'display: none';
1025 $this->addHTML(
1026 # Advanced settings
1027 $this->getFieldSetStart( 'config-advanced-settings' ) .
1028 # Object cache settings
1029 // getRadioSet() builds a set of labeled radio buttons.
1030 // For grep: The following messages are used as the item labels:
1031 // config-cache-none, config-cache-accel, config-cache-memcached
1032 $this->parent->getRadioSet( array(
1033 'var' => 'wgMainCacheType',
1034 'label' => 'config-cache-options',
1035 'itemLabelPrefix' => 'config-cache-',
1036 'values' => $caches,
1037 'value' => $cacheval,
1038 ) ) .
1039 $this->parent->getHelpBox( 'config-cache-help' ) .
1040 "<div id=\"config-memcachewrapper\" style=\"$hidden\">" .
1041 $this->parent->getTextArea( array(
1042 'var' => '_MemCachedServers',
1043 'label' => 'config-memcached-servers',
1044 'help' => $this->parent->getHelpBox( 'config-memcached-help' )
1045 ) ) .
1046 '</div>' .
1047 $this->getFieldSetEnd()
1048 );
1049 $this->endForm();
1050 }
1051
1052 /**
1053 * @return string
1054 */
1055 public function getCCPartnerUrl() {
1056 $server = $this->getVar( 'wgServer' );
1057 $exitUrl = $server . $this->parent->getUrl( array(
1058 'page' => 'Options',
1059 'SubmitCC' => 'indeed',
1060 'config__LicenseCode' => 'cc',
1061 'config_wgRightsUrl' => '[license_url]',
1062 'config_wgRightsText' => '[license_name]',
1063 'config_wgRightsIcon' => '[license_button]',
1064 ) );
1065 $styleUrl = $server . dirname( dirname( $this->parent->getUrl() ) ) .
1066 '/skins/common/config-cc.css';
1067 $iframeUrl = 'http://creativecommons.org/license/?' .
1068 wfArrayToCgi( array(
1069 'partner' => 'MediaWiki',
1070 'exit_url' => $exitUrl,
1071 'lang' => $this->getVar( '_UserLang' ),
1072 'stylesheet' => $styleUrl,
1073 ) );
1074
1075 return $iframeUrl;
1076 }
1077
1078 public function getCCChooser() {
1079 $iframeAttribs = array(
1080 'class' => 'config-cc-iframe',
1081 'name' => 'config-cc-iframe',
1082 'id' => 'config-cc-iframe',
1083 'frameborder' => 0,
1084 'width' => '100%',
1085 'height' => '100%',
1086 );
1087 if ( $this->getVar( '_CCDone' ) ) {
1088 $iframeAttribs['src'] = $this->parent->getUrl( array( 'ShowCC' => 'yes' ) );
1089 } else {
1090 $iframeAttribs['src'] = $this->getCCPartnerUrl();
1091 }
1092 $wrapperStyle = ( $this->getVar( '_LicenseCode' ) == 'cc-choose' ) ? '' : 'display: none';
1093
1094 return "<div class=\"config-cc-wrapper\" id=\"config-cc-wrapper\" style=\"$wrapperStyle\">\n" .
1095 Html::element( 'iframe', $iframeAttribs, '', false /* not short */ ) .
1096 "</div>\n";
1097 }
1098
1099 public function getCCDoneBox() {
1100 $js = "parent.document.getElementById('config-cc-wrapper').style.height = '$1';";
1101 // If you change this height, also change it in config.css
1102 $expandJs = str_replace( '$1', '54em', $js );
1103 $reduceJs = str_replace( '$1', '70px', $js );
1104
1105 return '<p>' .
1106 Html::element( 'img', array( 'src' => $this->getVar( 'wgRightsIcon' ) ) ) .
1107 '&#160;&#160;' .
1108 htmlspecialchars( $this->getVar( 'wgRightsText' ) ) .
1109 "</p>\n" .
1110 "<p style=\"text-align: center;\">" .
1111 Html::element( 'a',
1112 array(
1113 'href' => $this->getCCPartnerUrl(),
1114 'onclick' => $expandJs,
1115 ),
1116 wfMessage( 'config-cc-again' )->text()
1117 ) .
1118 "</p>\n" .
1119 "<script>\n" .
1120 # Reduce the wrapper div height
1121 htmlspecialchars( $reduceJs ) .
1122 "\n" .
1123 "</script>\n";
1124 }
1125
1126 public function submitCC() {
1127 $newValues = $this->parent->setVarsFromRequest(
1128 array( 'wgRightsUrl', 'wgRightsText', 'wgRightsIcon' ) );
1129 if ( count( $newValues ) != 3 ) {
1130 $this->parent->showError( 'config-cc-error' );
1131
1132 return;
1133 }
1134 $this->setVar( '_CCDone', true );
1135 $this->addHTML( $this->getCCDoneBox() );
1136 }
1137
1138 public function submit() {
1139 $this->parent->setVarsFromRequest( array( '_RightsProfile', '_LicenseCode',
1140 'wgEnableEmail', 'wgPasswordSender', 'wgEnableUploads', 'wgLogo',
1141 'wgEnableUserEmail', 'wgEnotifUserTalk', 'wgEnotifWatchlist',
1142 'wgEmailAuthentication', 'wgMainCacheType', '_MemCachedServers',
1143 'wgUseInstantCommons' ) );
1144
1145 if ( !in_array( $this->getVar( '_RightsProfile' ),
1146 array_keys( $this->parent->rightsProfiles ) )
1147 ) {
1148 reset( $this->parent->rightsProfiles );
1149 $this->setVar( '_RightsProfile', key( $this->parent->rightsProfiles ) );
1150 }
1151
1152 $code = $this->getVar( '_LicenseCode' );
1153 if ( $code == 'cc-choose' ) {
1154 if ( !$this->getVar( '_CCDone' ) ) {
1155 $this->parent->showError( 'config-cc-not-chosen' );
1156
1157 return false;
1158 }
1159 } elseif ( in_array( $code, array_keys( $this->parent->licenses ) ) ) {
1160 // Messages:
1161 // config-license-cc-by, config-license-cc-by-sa, config-license-cc-by-nc-sa,
1162 // config-license-cc-0, config-license-pd, config-license-gfdl, config-license-none,
1163 // config-license-cc-choose
1164 $entry = $this->parent->licenses[$code];
1165 if ( isset( $entry['text'] ) ) {
1166 $this->setVar( 'wgRightsText', $entry['text'] );
1167 } else {
1168 $this->setVar( 'wgRightsText', wfMessage( 'config-license-' . $code )->text() );
1169 }
1170 $this->setVar( 'wgRightsUrl', $entry['url'] );
1171 $this->setVar( 'wgRightsIcon', $entry['icon'] );
1172 } else {
1173 $this->setVar( 'wgRightsText', '' );
1174 $this->setVar( 'wgRightsUrl', '' );
1175 $this->setVar( 'wgRightsIcon', '' );
1176 }
1177
1178 $extsAvailable = $this->parent->findExtensions();
1179 $extsToInstall = array();
1180 foreach ( $extsAvailable as $ext ) {
1181 if ( $this->parent->request->getCheck( 'config_ext-' . $ext ) ) {
1182 $extsToInstall[] = $ext;
1183 }
1184 }
1185 $this->parent->setVar( '_Extensions', $extsToInstall );
1186
1187 if ( $this->getVar( 'wgMainCacheType' ) == 'memcached' ) {
1188 $memcServers = explode( "\n", $this->getVar( '_MemCachedServers' ) );
1189 if ( !$memcServers ) {
1190 $this->parent->showError( 'config-memcache-needservers' );
1191
1192 return false;
1193 }
1194
1195 foreach ( $memcServers as $server ) {
1196 $memcParts = explode( ":", $server, 2 );
1197 if ( !isset( $memcParts[0] )
1198 || ( !IP::isValid( $memcParts[0] )
1199 && ( gethostbyname( $memcParts[0] ) == $memcParts[0] ) )
1200 ) {
1201 $this->parent->showError( 'config-memcache-badip', $memcParts[0] );
1202
1203 return false;
1204 } elseif ( !isset( $memcParts[1] ) ) {
1205 $this->parent->showError( 'config-memcache-noport', $memcParts[0] );
1206
1207 return false;
1208 } elseif ( $memcParts[1] < 1 || $memcParts[1] > 65535 ) {
1209 $this->parent->showError( 'config-memcache-badport', 1, 65535 );
1210
1211 return false;
1212 }
1213 }
1214 }
1215
1216 return true;
1217 }
1218 }
1219
1220 class WebInstaller_Install extends WebInstallerPage {
1221 public function isSlow() {
1222 return true;
1223 }
1224
1225 public function execute() {
1226 if ( $this->getVar( '_UpgradeDone' ) ) {
1227 return 'skip';
1228 } elseif ( $this->getVar( '_InstallDone' ) ) {
1229 return 'continue';
1230 } elseif ( $this->parent->request->wasPosted() ) {
1231 $this->startForm();
1232 $this->addHTML( "<ul>" );
1233 $results = $this->parent->performInstallation(
1234 array( $this, 'startStage' ),
1235 array( $this, 'endStage' )
1236 );
1237 $this->addHTML( "</ul>" );
1238 // PerformInstallation bails on a fatal, so make sure the last item
1239 // completed before giving 'next.' Likewise, only provide back on failure
1240 $lastStep = end( $results );
1241 $continue = $lastStep->isOK() ? 'continue' : false;
1242 $back = $lastStep->isOK() ? false : 'back';
1243 $this->endForm( $continue, $back );
1244 } else {
1245 $this->startForm();
1246 $this->addHTML( $this->parent->getInfoBox( wfMessage( 'config-install-begin' )->plain() ) );
1247 $this->endForm();
1248 }
1249
1250 return true;
1251 }
1252
1253 public function startStage( $step ) {
1254 // Messages: config-install-database, config-install-tables, config-install-interwiki,
1255 // config-install-stats, config-install-keys, config-install-sysop, config-install-mainpage
1256 $this->addHTML( "<li>" . wfMessage( "config-install-$step" )->escaped() .
1257 wfMessage( 'ellipsis' )->escaped() );
1258
1259 if ( $step == 'extension-tables' ) {
1260 $this->startLiveBox();
1261 }
1262 }
1263
1264 /**
1265 * @param $step
1266 * @param $status Status
1267 */
1268 public function endStage( $step, $status ) {
1269 if ( $step == 'extension-tables' ) {
1270 $this->endLiveBox();
1271 }
1272 $msg = $status->isOk() ? 'config-install-step-done' : 'config-install-step-failed';
1273 $html = wfMessage( 'word-separator' )->escaped() . wfMessage( $msg )->escaped();
1274 if ( !$status->isOk() ) {
1275 $html = "<span class=\"error\">$html</span>";
1276 }
1277 $this->addHTML( $html . "</li>\n" );
1278 if ( !$status->isGood() ) {
1279 $this->parent->showStatusBox( $status );
1280 }
1281 }
1282 }
1283
1284 class WebInstaller_Complete extends WebInstallerPage {
1285 public function execute() {
1286 // Pop up a dialog box, to make it difficult for the user to forget
1287 // to download the file
1288 $lsUrl = $this->getVar( 'wgServer' ) . $this->parent->getURL( array( 'localsettings' => 1 ) );
1289 if ( isset( $_SERVER['HTTP_USER_AGENT'] ) &&
1290 strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE' ) !== false
1291 ) {
1292 // JS appears to be the only method that works consistently with IE7+
1293 $this->addHtml( "\n<script>jQuery( function () { document.location = " .
1294 Xml::encodeJsVar( $lsUrl ) . "; } );</script>\n" );
1295 } else {
1296 $this->parent->request->response()->header( "Refresh: 0;url=$lsUrl" );
1297 }
1298
1299 $this->startForm();
1300 $this->parent->disableLinkPopups();
1301 $this->addHTML(
1302 $this->parent->getInfoBox(
1303 wfMessage( 'config-install-done',
1304 $lsUrl,
1305 $this->getVar( 'wgServer' ) .
1306 $this->getVar( 'wgScriptPath' ) . '/index' .
1307 $this->getVar( 'wgScriptExtension' ),
1308 '<downloadlink/>'
1309 )->plain(), 'tick-32.png'
1310 )
1311 );
1312 $this->addHTML( $this->parent->getInfoBox(
1313 wfMessage( 'config-extension-link' )->text() ) );
1314
1315 $this->parent->restoreLinkPopups();
1316 $this->endForm( false, false );
1317 }
1318 }
1319
1320 class WebInstaller_Restart extends WebInstallerPage {
1321
1322 public function execute() {
1323 $r = $this->parent->request;
1324 if ( $r->wasPosted() ) {
1325 $really = $r->getVal( 'submit-restart' );
1326 if ( $really ) {
1327 $this->parent->reset();
1328 }
1329
1330 return 'continue';
1331 }
1332
1333 $this->startForm();
1334 $s = $this->parent->getWarningBox( wfMessage( 'config-help-restart' )->plain() );
1335 $this->addHTML( $s );
1336 $this->endForm( 'restart' );
1337 }
1338 }
1339
1340 abstract class WebInstaller_Document extends WebInstallerPage {
1341
1342 abstract protected function getFileName();
1343
1344 public function execute() {
1345 $text = $this->getFileContents();
1346 $text = InstallDocFormatter::format( $text );
1347 $this->parent->output->addWikiText( $text );
1348 $this->startForm();
1349 $this->endForm( false );
1350 }
1351
1352 public function getFileContents() {
1353 $file = __DIR__ . '/../../' . $this->getFileName();
1354 if ( !file_exists( $file ) ) {
1355 return wfMessage( 'config-nofile', $file )->plain();
1356 }
1357
1358 return file_get_contents( $file );
1359 }
1360 }
1361
1362 class WebInstaller_Readme extends WebInstaller_Document {
1363 protected function getFileName() {
1364 return 'README';
1365 }
1366 }
1367
1368 class WebInstaller_ReleaseNotes extends WebInstaller_Document {
1369 protected function getFileName() {
1370 global $wgVersion;
1371
1372 if ( !preg_match( '/^(\d+)\.(\d+).*/i', $wgVersion, $result ) ) {
1373 throw new MWException( 'Variable $wgVersion has an invalid value.' );
1374 }
1375
1376 return 'RELEASE-NOTES-' . $result[1] . '.' . $result[2];
1377 }
1378 }
1379
1380 class WebInstaller_UpgradeDoc extends WebInstaller_Document {
1381 protected function getFileName() {
1382 return 'UPGRADE';
1383 }
1384 }
1385
1386 class WebInstaller_Copying extends WebInstaller_Document {
1387 protected function getFileName() {
1388 return 'COPYING';
1389 }
1390 }