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