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