Checking permissions for $wgUser while doing an edit with another user is not a good...
[lhc/web/wiklou.git] / includes / installer / WebInstallerPage.php
1 <?php
2 /**
3 * Base code for web installer pages.
4 *
5 * @file
6 * @ingroup Deployment
7 */
8
9 /**
10 * Abstract class to define pages for the web installer.
11 *
12 * @ingroup Deployment
13 * @since 1.17
14 */
15 abstract class WebInstallerPage {
16
17 /**
18 * The WebInstaller object this WebInstallerPage belongs to.
19 *
20 * @var WebInstaller
21 */
22 public $parent;
23
24 public abstract function execute();
25
26 /**
27 * Constructor.
28 *
29 * @param $parent WebInstaller
30 */
31 public function __construct( WebInstaller $parent ) {
32 $this->parent = $parent;
33 }
34
35 public function addHTML( $html ) {
36 $this->parent->output->addHTML( $html );
37 }
38
39 public function startForm() {
40 $this->addHTML(
41 "<div class=\"config-section\">\n" .
42 Html::openElement(
43 'form',
44 array(
45 'method' => 'post',
46 'action' => $this->parent->getUrl( array( 'page' => $this->getName() ) )
47 )
48 ) . "\n"
49 );
50 }
51
52 public function endForm( $continue = 'continue', $back = 'back' ) {
53 $s = "<div class=\"config-submit\">\n";
54 $id = $this->getId();
55
56 if ( $id === false ) {
57 $s .= Html::hidden( 'lastPage', $this->parent->request->getVal( 'lastPage' ) );
58 }
59
60 if ( $continue ) {
61 // Fake submit button for enter keypress (bug 26267)
62 $s .= Xml::submitButton( wfMsg( "config-$continue" ),
63 array( 'name' => "enter-$continue", 'style' => 'visibility:hidden;overflow:hidden;width:1px;margin:0' ) ) . "\n";
64 }
65
66 if ( $back ) {
67 $s .= Xml::submitButton( wfMsg( "config-$back" ),
68 array(
69 'name' => "submit-$back",
70 'tabindex' => $this->parent->nextTabIndex()
71 ) ) . "\n";
72 }
73
74 if ( $continue ) {
75 $s .= Xml::submitButton( wfMsg( "config-$continue" ),
76 array(
77 'name' => "submit-$continue",
78 'tabindex' => $this->parent->nextTabIndex(),
79 ) ) . "\n";
80 }
81
82 $s .= "</div></form></div>\n";
83 $this->addHTML( $s );
84 }
85
86 public function getName() {
87 return str_replace( 'WebInstaller_', '', get_class( $this ) );
88 }
89
90 protected function getId() {
91 return array_search( $this->getName(), $this->parent->pageSequence );
92 }
93
94 public function getVar( $var ) {
95 return $this->parent->getVar( $var );
96 }
97
98 public function setVar( $name, $value ) {
99 $this->parent->setVar( $name, $value );
100 }
101
102 /**
103 * Get the starting tags of a fieldset.
104 *
105 * @param $legend String: message name
106 */
107 protected function getFieldsetStart( $legend ) {
108 return "\n<fieldset><legend>" . wfMsgHtml( $legend ) . "</legend>\n";
109 }
110
111 /**
112 * Get the end tag of a fieldset.
113 */
114 protected function getFieldsetEnd() {
115 return "</fieldset>\n";
116 }
117 }
118
119 class WebInstaller_Language extends WebInstallerPage {
120
121 public function execute() {
122 global $wgLang;
123 $r = $this->parent->request;
124 $userLang = $r->getVal( 'UserLang' );
125 $contLang = $r->getVal( 'ContLang' );
126
127 $lifetime = intval( ini_get( 'session.gc_maxlifetime' ) );
128 if ( !$lifetime ) {
129 $lifetime = 1440; // PHP default
130 }
131
132 if ( $r->wasPosted() ) {
133 # Do session test
134 if ( $this->parent->getSession( 'test' ) === null ) {
135 $requestTime = $r->getVal( 'LanguageRequestTime' );
136 if ( !$requestTime ) {
137 // The most likely explanation is that the user was knocked back
138 // from another page on POST due to session expiry
139 $msg = 'config-session-expired';
140 } elseif ( time() - $requestTime > $lifetime ) {
141 $msg = 'config-session-expired';
142 } else {
143 $msg = 'config-no-session';
144 }
145 $this->parent->showError( $msg, $wgLang->formatTimePeriod( $lifetime ) );
146 } else {
147 $languages = Language::getLanguageNames();
148 if ( isset( $languages[$userLang] ) ) {
149 $this->setVar( '_UserLang', $userLang );
150 }
151 if ( isset( $languages[$contLang] ) ) {
152 $this->setVar( 'wgLanguageCode', $contLang );
153 }
154 return 'continue';
155 }
156 } elseif ( $this->parent->showSessionWarning ) {
157 # The user was knocked back from another page to the start
158 # This probably indicates a session expiry
159 $this->parent->showError( 'config-session-expired', $wgLang->formatTimePeriod( $lifetime ) );
160 }
161
162 $this->parent->setSession( 'test', true );
163
164 if ( !isset( $languages[$userLang] ) ) {
165 $userLang = $this->getVar( '_UserLang', 'en' );
166 }
167 if ( !isset( $languages[$contLang] ) ) {
168 $contLang = $this->getVar( 'wgLanguageCode', 'en' );
169 }
170 $this->startForm();
171 $s = Html::hidden( 'LanguageRequestTime', time() ) .
172 $this->getLanguageSelector( 'UserLang', 'config-your-language', $userLang, $this->parent->getHelpBox( 'config-your-language-help' ) ) .
173 $this->getLanguageSelector( 'ContLang', 'config-wiki-language', $contLang, $this->parent->getHelpBox( 'config-wiki-language-help' ) );
174 $this->addHTML( $s );
175 $this->endForm( 'continue', false );
176 }
177
178 /**
179 * Get a <select> for selecting languages.
180 */
181 public function getLanguageSelector( $name, $label, $selectedCode ) {
182 global $wgDummyLanguageCodes;
183 $s = Html::openElement( 'select', array( 'id' => $name, 'name' => $name ) ) . "\n";
184
185 $languages = Language::getLanguageNames();
186 ksort( $languages );
187 $dummies = array_flip( $wgDummyLanguageCodes );
188 foreach ( $languages as $code => $lang ) {
189 if ( isset( $dummies[$code] ) ) continue;
190 $s .= "\n" . Xml::option( "$code - $lang", $code, $code == $selectedCode );
191 }
192 $s .= "\n</select>\n";
193 return $this->parent->label( $label, $name, $s );
194 }
195
196 }
197
198 class WebInstaller_ExistingWiki extends WebInstallerPage {
199 public function execute() {
200 // If there is no LocalSettings.php, continue to the installer welcome page
201 $vars = $this->parent->getExistingLocalSettings();
202 if ( !$vars ) {
203 return 'skip';
204 }
205
206 // Check if the upgrade key supplied to the user has appeared in LocalSettings.php
207 if ( $vars['wgUpgradeKey'] !== false
208 && $this->getVar( '_UpgradeKeySupplied' )
209 && $this->getVar( 'wgUpgradeKey' ) === $vars['wgUpgradeKey'] )
210 {
211 // It's there, so the user is authorized
212 $status = $this->handleExistingUpgrade( $vars );
213 if ( $status->isOK() ) {
214 return 'skip';
215 } else {
216 $this->startForm();
217 $this->parent->showStatusBox( $status );
218 $this->endForm( 'continue' );
219 return 'output';
220 }
221 return $this->handleExistingUpgrade( $vars );
222 }
223
224 // If there is no $wgUpgradeKey, tell the user to add one to LocalSettings.php
225 if ( $vars['wgUpgradeKey'] === false ) {
226 if ( $this->getVar( 'wgUpgradeKey', false ) === false ) {
227 $this->parent->generateUpgradeKey();
228 $this->setVar( '_UpgradeKeySupplied', true );
229 }
230 $this->startForm();
231 $this->addHTML( $this->parent->getInfoBox(
232 wfMsgNoTrans( 'config-upgrade-key-missing',
233 "<pre>\$wgUpgradeKey = '" . $this->getVar( 'wgUpgradeKey' ) . "';</pre>" )
234 ) );
235 $this->endForm( 'continue' );
236 return 'output';
237 }
238
239 // If there is an upgrade key, but it wasn't supplied, prompt the user to enter it
240
241 $r = $this->parent->request;
242 if ( $r->wasPosted() ) {
243 $key = $r->getText( 'config_wgUpgradeKey' );
244 if( !$key || $key !== $vars['wgUpgradeKey'] ) {
245 $this->parent->showError( 'config-localsettings-badkey' );
246 $this->showKeyForm();
247 return 'output';
248 }
249 // Key was OK
250 $status = $this->handleExistingUpgrade( $vars );
251 if ( $status->isOK() ) {
252 return 'continue';
253 } else {
254 $this->parent->showStatusBox( $status );
255 $this->showKeyForm();
256 return 'output';
257 }
258 } else {
259 $this->showKeyForm();
260 return 'output';
261 }
262 }
263
264 /**
265 * Show the "enter key" form
266 */
267 protected function showKeyForm() {
268 $this->startForm();
269 $this->addHTML(
270 $this->parent->getInfoBox( wfMsgNoTrans( 'config-localsettings-upgrade' ) ).
271 '<br />' .
272 $this->parent->getTextBox( array(
273 'var' => 'wgUpgradeKey',
274 'label' => 'config-localsettings-key',
275 'attribs' => array( 'autocomplete' => 'off' ),
276 ) )
277 );
278 $this->endForm( 'continue' );
279 }
280
281 protected function importVariables( $names, $vars ) {
282 $status = Status::newGood();
283 foreach ( $names as $name ) {
284 if ( !isset( $vars[$name] ) ) {
285 $status->fatal( 'config-localsettings-incomplete', $name );
286 }
287 $this->setVar( $name, $vars[$name] );
288 }
289 return $status;
290 }
291
292 /**
293 * Initiate an upgrade of the existing database
294 * @param $vars Variables from LocalSettings.php and AdminSettings.php
295 * @return Status
296 */
297 protected function handleExistingUpgrade( $vars ) {
298 // Check $wgDBtype
299 if ( !isset( $vars['wgDBtype'] ) || !in_array( $vars['wgDBtype'], Installer::getDBTypes() ) ) {
300 return Status::newFatal( 'config-localsettings-connection-error', '' );
301 }
302
303 // Set the relevant variables from LocalSettings.php
304 $requiredVars = array( 'wgDBtype', 'wgDBuser', 'wgDBpassword' );
305 $status = $this->importVariables( $requiredVars , $vars );
306 $installer = $this->parent->getDBInstaller();
307 $status->merge( $this->importVariables( $installer->getGlobalNames(), $vars ) );
308 if ( !$status->isOK() ) {
309 return $status;
310 }
311
312 if ( isset( $vars['wgDBadminuser'] ) ) {
313 $this->setVar( '_InstallUser', $vars['wgDBadminuser'] );
314 } else {
315 $this->setVar( '_InstallUser', $vars['wgDBuser'] );
316 }
317 if ( isset( $vars['wgDBadminpassword'] ) ) {
318 $this->setVar( '_InstallPassword', $vars['wgDBadminpassword'] );
319 } else {
320 $this->setVar( '_InstallPassword', $vars['wgDBpassword'] );
321 }
322
323 // Test the database connection
324 $status = $installer->getConnection();
325 if ( !$status->isOK() ) {
326 // Adjust the error message to explain things correctly
327 $status->replaceMessage( 'config-connection-error',
328 'config-localsettings-connection-error' );
329 return $status;
330 }
331
332 // All good
333 $this->setVar( '_ExistingDBSettings', true );
334 return $status;
335 }
336 }
337
338 class WebInstaller_Welcome extends WebInstallerPage {
339
340 public function execute() {
341 if ( $this->parent->request->wasPosted() ) {
342 if ( $this->getVar( '_Environment' ) ) {
343 return 'continue';
344 }
345 }
346 $this->parent->output->addWikiText( wfMsgNoTrans( 'config-welcome' ) );
347 $status = $this->parent->doEnvironmentChecks();
348 if ( $status ) {
349 $this->parent->output->addWikiText( wfMsgNoTrans( 'config-copyright',
350 SpecialVersion::getCopyrightAndAuthorList() ) );
351 $this->startForm();
352 $this->endForm();
353 }
354 }
355
356 }
357
358 class WebInstaller_DBConnect extends WebInstallerPage {
359
360 public function execute() {
361 if ( $this->getVar( '_ExistingDBSettings' ) ) {
362 return 'skip';
363 }
364
365 $r = $this->parent->request;
366 if ( $r->wasPosted() ) {
367 $status = $this->submit();
368 if ( $status->isGood() ) {
369 $this->setVar( '_UpgradeDone', false );
370 return 'continue';
371 } else {
372 $this->parent->showStatusBox( $status );
373 }
374 }
375
376 $this->startForm();
377
378 $types = "<ul class=\"config-settings-block\">\n";
379 $settings = '';
380 $defaultType = $this->getVar( 'wgDBtype' );
381
382 $dbSupport = '';
383 foreach( $this->parent->getDBTypes() as $type ) {
384 $db = 'Database' . ucfirst( $type );
385 $dbSupport .= wfMsgNoTrans( "config-support-$type",
386 call_user_func( array( $db, 'getSoftwareLink' ) ) ) . "\n";
387 }
388 $this->addHTML( $this->parent->getInfoBox(
389 wfMsg( 'config-support-info', $dbSupport ) ) );
390
391 foreach ( $this->parent->getVar( '_CompiledDBs' ) as $type ) {
392 $installer = $this->parent->getDBInstaller( $type );
393 $types .=
394 '<li>' .
395 Xml::radioLabel(
396 $installer->getReadableName(),
397 'DBType',
398 $type,
399 "DBType_$type",
400 $type == $defaultType,
401 array( 'class' => 'dbRadio', 'rel' => "DB_wrapper_$type" )
402 ) .
403 "</li>\n";
404
405 $settings .=
406 Html::openElement( 'div', array( 'id' => 'DB_wrapper_' . $type, 'class' => 'dbWrapper' ) ) .
407 Html::element( 'h3', array(), wfMsg( 'config-header-' . $type ) ) .
408 $installer->getConnectForm() .
409 "</div>\n";
410 }
411 $types .= "</ul><br clear=\"left\"/>\n";
412
413 $this->addHTML(
414 $this->parent->label( 'config-db-type', false, $types ) .
415 $settings
416 );
417
418 $this->endForm();
419 }
420
421 public function submit() {
422 $r = $this->parent->request;
423 $type = $r->getVal( 'DBType' );
424 $this->setVar( 'wgDBtype', $type );
425 $installer = $this->parent->getDBInstaller( $type );
426 if ( !$installer ) {
427 return Status::newFatal( 'config-invalid-db-type' );
428 }
429 return $installer->submitConnectForm();
430 }
431
432 }
433
434 class WebInstaller_Upgrade extends WebInstallerPage {
435
436 public function execute() {
437 if ( $this->getVar( '_UpgradeDone' ) ) {
438 // Allow regeneration of LocalSettings.php, unless we are working
439 // from a pre-existing LocalSettings.php file and we want to avoid
440 // leaking its contents
441 if ( $this->parent->request->wasPosted() && !$this->getVar( '_ExistingDBSettings' ) ) {
442 // Done message acknowledged
443 return 'continue';
444 } else {
445 // Back button click
446 // Show the done message again
447 // Make them click back again if they want to do the upgrade again
448 $this->showDoneMessage();
449 return 'output';
450 }
451 }
452
453 // wgDBtype is generally valid here because otherwise the previous page
454 // (connect) wouldn't have declared its happiness
455 $type = $this->getVar( 'wgDBtype' );
456 $installer = $this->parent->getDBInstaller( $type );
457
458 if ( !$installer->needsUpgrade() ) {
459 return 'skip';
460 }
461
462 if ( $this->parent->request->wasPosted() ) {
463 $installer->preUpgrade();
464 $this->addHTML(
465 '<div id="config-spinner" style="display:none;"><img src="../skins/common/images/ajax-loader.gif" /></div>' .
466 '<script>jQuery( "#config-spinner" )[0].style.display = "block";</script>' .
467 '<textarea id="config-update-log" name="UpdateLog" rows="10" readonly="readonly">'
468 );
469 $this->parent->output->flush();
470 $result = $installer->doUpgrade();
471 $this->addHTML( '</textarea>
472 <script>jQuery( "#config-spinner" )[0].style.display = "none";</script>' );
473 $this->parent->output->flush();
474 if ( $result ) {
475 $this->setVar( '_UpgradeDone', true );
476 $this->showDoneMessage();
477 return 'output';
478 }
479 }
480
481 $this->startForm();
482 $this->addHTML( $this->parent->getInfoBox(
483 wfMsgNoTrans( 'config-can-upgrade', $GLOBALS['wgVersion'] ) ) );
484 $this->endForm();
485 }
486
487 public function showDoneMessage() {
488 $this->startForm();
489 $regenerate = !$this->getVar( '_ExistingDBSettings' );
490 if ( $regenerate ) {
491 $msg = 'config-upgrade-done';
492 } else {
493 $msg = 'config-upgrade-done-no-regenerate';
494 }
495 $this->parent->disableLinkPopups();
496 $this->addHTML(
497 $this->parent->getInfoBox(
498 wfMsgNoTrans( $msg,
499 $GLOBALS['wgServer'] .
500 $this->getVar( 'wgScriptPath' ) . '/index' .
501 $this->getVar( 'wgScriptExtension' )
502 ), 'tick-32.png'
503 )
504 );
505 $this->parent->restoreLinkPopups();
506 $this->endForm( $regenerate ? 'regenerate' : false, false );
507 }
508
509 }
510
511 class WebInstaller_DBSettings extends WebInstallerPage {
512
513 public function execute() {
514 $installer = $this->parent->getDBInstaller( $this->getVar( 'wgDBtype' ) );
515
516 $r = $this->parent->request;
517 if ( $r->wasPosted() ) {
518 $status = $installer->submitSettingsForm();
519 if ( $status === false ) {
520 return 'skip';
521 } elseif ( $status->isGood() ) {
522 return 'continue';
523 } else {
524 $this->parent->showStatusBox( $status );
525 }
526 }
527
528 $form = $installer->getSettingsForm();
529 if ( $form === false ) {
530 return 'skip';
531 }
532
533 $this->startForm();
534 $this->addHTML( $form );
535 $this->endForm();
536 }
537
538 }
539
540 class WebInstaller_Name extends WebInstallerPage {
541
542 public function execute() {
543 $r = $this->parent->request;
544 if ( $r->wasPosted() ) {
545 if ( $this->submit() ) {
546 return 'continue';
547 }
548 }
549
550 $this->startForm();
551
552 if ( $this->getVar( 'wgSitename' ) == $GLOBALS['wgSitename'] ) {
553 $this->setVar( 'wgSitename', '' );
554 }
555
556 // Set wgMetaNamespace to something valid before we show the form.
557 // $wgMetaNamespace defaults to $wgSiteName which is 'MediaWiki'
558 $metaNS = $this->getVar( 'wgMetaNamespace' );
559 $this->setVar( 'wgMetaNamespace', wfMsgForContent( 'config-ns-other-default' ) );
560
561 $this->addHTML(
562 $this->parent->getTextBox( array(
563 'var' => 'wgSitename',
564 'label' => 'config-site-name',
565 'help' => $this->parent->getHelpBox( 'config-site-name-help' )
566 ) ) .
567 $this->parent->getRadioSet( array(
568 'var' => '_NamespaceType',
569 'label' => 'config-project-namespace',
570 'itemLabelPrefix' => 'config-ns-',
571 'values' => array( 'site-name', 'generic', 'other' ),
572 'commonAttribs' => array( 'class' => 'enableForOther', 'rel' => 'config_wgMetaNamespace' ),
573 'help' => $this->parent->getHelpBox( 'config-project-namespace-help' )
574 ) ) .
575 $this->parent->getTextBox( array(
576 'var' => 'wgMetaNamespace',
577 'label' => '', //TODO: Needs a label?
578 'attribs' => array( 'readonly' => 'readonly', 'class' => 'enabledByOther' ),
579
580 ) ) .
581 $this->getFieldSetStart( 'config-admin-box' ) .
582 $this->parent->getTextBox( array(
583 'var' => '_AdminName',
584 'label' => 'config-admin-name',
585 'help' => $this->parent->getHelpBox( 'config-admin-help' )
586 ) ) .
587 $this->parent->getPasswordBox( array(
588 'var' => '_AdminPassword',
589 'label' => 'config-admin-password',
590 ) ) .
591 $this->parent->getPasswordBox( array(
592 'var' => '_AdminPassword2',
593 'label' => 'config-admin-password-confirm'
594 ) ) .
595 $this->parent->getTextBox( array(
596 'var' => '_AdminEmail',
597 'label' => 'config-admin-email',
598 'help' => $this->parent->getHelpBox( 'config-admin-email-help' )
599 ) ) .
600 $this->parent->getCheckBox( array(
601 'var' => '_Subscribe',
602 'label' => 'config-subscribe',
603 'help' => $this->parent->getHelpBox( 'config-subscribe-help' )
604 ) ) .
605 $this->getFieldSetEnd() .
606 $this->parent->getInfoBox( wfMsg( 'config-almost-done' ) ) .
607 $this->parent->getRadioSet( array(
608 'var' => '_SkipOptional',
609 'itemLabelPrefix' => 'config-optional-',
610 'values' => array( 'continue', 'skip' )
611 ) )
612 );
613
614 // Restore the default value
615 $this->setVar( 'wgMetaNamespace', $metaNS );
616
617 $this->endForm();
618 return 'output';
619 }
620
621 public function submit() {
622 $retVal = true;
623 $this->parent->setVarsFromRequest( array( 'wgSitename', '_NamespaceType',
624 '_AdminName', '_AdminPassword', '_AdminPassword2', '_AdminEmail',
625 '_Subscribe', '_SkipOptional' ) );
626
627 // Validate site name
628 if ( strval( $this->getVar( 'wgSitename' ) ) === '' ) {
629 $this->parent->showError( 'config-site-name-blank' );
630 $retVal = false;
631 }
632
633 // Fetch namespace
634 $nsType = $this->getVar( '_NamespaceType' );
635 if ( $nsType == 'site-name' ) {
636 $name = $this->getVar( 'wgSitename' );
637 // Sanitize for namespace
638 // This algorithm should match the JS one in WebInstallerOutput.php
639 $name = preg_replace( '/[\[\]\{\}|#<>%+? ]/', '_', $name );
640 $name = str_replace( '&', '&amp;', $name );
641 $name = preg_replace( '/__+/', '_', $name );
642 $name = ucfirst( trim( $name, '_' ) );
643 } elseif ( $nsType == 'generic' ) {
644 $name = wfMsg( 'config-ns-generic' );
645 } else { // other
646 $name = $this->getVar( 'wgMetaNamespace' );
647 }
648
649 // Validate namespace
650 if ( strpos( $name, ':' ) !== false ) {
651 $good = false;
652 } else {
653 // Title-style validation
654 $title = Title::newFromText( $name );
655 if ( !$title ) {
656 $good = $nsType == 'site-name';
657 } else {
658 $name = $title->getDBkey();
659 $good = true;
660 }
661 }
662 if ( !$good ) {
663 $this->parent->showError( 'config-ns-invalid', $name );
664 $retVal = false;
665 }
666 $this->setVar( 'wgMetaNamespace', $name );
667
668 // Validate username for creation
669 $name = $this->getVar( '_AdminName' );
670 if ( strval( $name ) === '' ) {
671 $this->parent->showError( 'config-admin-name-blank' );
672 $cname = $name;
673 $retVal = false;
674 } else {
675 $cname = User::getCanonicalName( $name, 'creatable' );
676 if ( $cname === false ) {
677 $this->parent->showError( 'config-admin-name-invalid', $name );
678 $retVal = false;
679 } else {
680 $this->setVar( '_AdminName', $cname );
681 }
682 }
683
684 // Validate password
685 $msg = false;
686 $valid = false;
687 $pwd = $this->getVar( '_AdminPassword' );
688 $user = User::newFromName( $cname );
689 $valid = $user && $user->getPasswordValidity( $pwd );
690 if ( strval( $pwd ) === '' ) {
691 # $user->getPasswordValidity just checks for $wgMinimalPasswordLength.
692 # This message is more specific and helpful.
693 $msg = 'config-admin-password-blank';
694 } elseif ( $pwd !== $this->getVar( '_AdminPassword2' ) ) {
695 $msg = 'config-admin-password-mismatch';
696 } elseif ( $valid !== true ) {
697 # As of writing this will only catch the username being e.g. 'FOO' and
698 # the password 'foo'
699 $msg = $valid;
700 }
701 if ( $msg !== false ) {
702 $this->parent->showError( $msg );
703 $this->setVar( '_AdminPassword', '' );
704 $this->setVar( '_AdminPassword2', '' );
705 $retVal = false;
706 }
707 return $retVal;
708 }
709
710 }
711
712 class WebInstaller_Options extends WebInstallerPage {
713
714 public function execute() {
715 if ( $this->getVar( '_SkipOptional' ) == 'skip' ) {
716 return 'skip';
717 }
718 if ( $this->parent->request->wasPosted() ) {
719 if ( $this->submit() ) {
720 return 'continue';
721 }
722 }
723
724 $this->startForm();
725 $this->addHTML(
726 # User Rights
727 $this->parent->getRadioSet( array(
728 'var' => '_RightsProfile',
729 'label' => 'config-profile',
730 'itemLabelPrefix' => 'config-profile-',
731 'values' => array_keys( $this->parent->rightsProfiles ),
732 ) ) .
733 $this->parent->getHelpBox( 'config-profile-help' ) .
734
735 # Licensing
736 $this->parent->getRadioSet( array(
737 'var' => '_LicenseCode',
738 'label' => 'config-license',
739 'itemLabelPrefix' => 'config-license-',
740 'values' => array_keys( $this->parent->licenses ),
741 'commonAttribs' => array( 'class' => 'licenseRadio' ),
742 ) ) .
743 $this->getCCChooser() .
744 $this->parent->getHelpBox( 'config-license-help' ) .
745
746 # E-mail
747 $this->getFieldSetStart( 'config-email-settings' ) .
748 $this->parent->getCheckBox( array(
749 'var' => 'wgEnableEmail',
750 'label' => 'config-enable-email',
751 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'emailwrapper' ),
752 ) ) .
753 $this->parent->getHelpBox( 'config-enable-email-help' ) .
754 "<div id=\"emailwrapper\">" .
755 $this->parent->getTextBox( array(
756 'var' => 'wgPasswordSender',
757 'label' => 'config-email-sender'
758 ) ) .
759 $this->parent->getHelpBox( 'config-email-sender-help' ) .
760 $this->parent->getCheckBox( array(
761 'var' => 'wgEnableUserEmail',
762 'label' => 'config-email-user',
763 ) ) .
764 $this->parent->getHelpBox( 'config-email-user-help' ) .
765 $this->parent->getCheckBox( array(
766 'var' => 'wgEnotifUserTalk',
767 'label' => 'config-email-usertalk',
768 ) ) .
769 $this->parent->getHelpBox( 'config-email-usertalk-help' ) .
770 $this->parent->getCheckBox( array(
771 'var' => 'wgEnotifWatchlist',
772 'label' => 'config-email-watchlist',
773 ) ) .
774 $this->parent->getHelpBox( 'config-email-watchlist-help' ) .
775 $this->parent->getCheckBox( array(
776 'var' => 'wgEmailAuthentication',
777 'label' => 'config-email-auth',
778 ) ) .
779 $this->parent->getHelpBox( 'config-email-auth-help' ) .
780 "</div>" .
781 $this->getFieldSetEnd()
782 );
783
784 $extensions = $this->parent->findExtensions();
785
786 if( $extensions ) {
787 $extHtml = $this->getFieldSetStart( 'config-extensions' );
788
789 foreach( $extensions as $ext ) {
790 $extHtml .= $this->parent->getCheckBox( array(
791 'var' => "ext-$ext",
792 'rawtext' => $ext,
793 ) );
794 }
795
796 $extHtml .= $this->parent->getHelpBox( 'config-extensions-help' ) .
797 $this->getFieldSetEnd();
798 $this->addHTML( $extHtml );
799 }
800
801 $this->addHTML(
802 # Uploading
803 $this->getFieldSetStart( 'config-upload-settings' ) .
804 $this->parent->getCheckBox( array(
805 'var' => 'wgEnableUploads',
806 'label' => 'config-upload-enable',
807 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'uploadwrapper' ),
808 'help' => $this->parent->getHelpBox( 'config-upload-help' )
809 ) ) .
810 '<div id="uploadwrapper" style="display: none;">' .
811 $this->parent->getTextBox( array(
812 'var' => 'wgDeletedDirectory',
813 'label' => 'config-upload-deleted',
814 'help' => $this->parent->getHelpBox( 'config-upload-deleted-help' )
815 ) ) .
816 '</div>' .
817 $this->parent->getTextBox( array(
818 'var' => 'wgLogo',
819 'label' => 'config-logo',
820 'help' => $this->parent->getHelpBox( 'config-logo-help' )
821 ) )
822 );
823 $this->addHTML(
824 $this->parent->getCheckBox( array(
825 'var' => 'wgUseInstantCommons',
826 'label' => 'config-instantcommons',
827 'help' => $this->parent->getHelpBox( 'config-instantcommons-help' )
828 ) ) .
829 $this->getFieldSetEnd()
830 );
831
832 $caches = array( 'none' );
833 if( count( $this->getVar( '_Caches' ) ) ) {
834 $caches[] = 'accel';
835 }
836 $caches[] = 'memcached';
837
838 $this->addHTML(
839 # Advanced settings
840 $this->getFieldSetStart( 'config-advanced-settings' ) .
841 # Object cache settings
842 $this->parent->getRadioSet( array(
843 'var' => 'wgMainCacheType',
844 'label' => 'config-cache-options',
845 'itemLabelPrefix' => 'config-cache-',
846 'values' => $caches,
847 'value' => 'none',
848 ) ) .
849 $this->parent->getHelpBox( 'config-cache-help' ) .
850 '<div id="config-memcachewrapper">' .
851 $this->parent->getTextBox( array(
852 'var' => '_MemCachedServers',
853 'label' => 'config-memcached-servers',
854 'help' => $this->parent->getHelpBox( 'config-memcached-help' )
855 ) ) .
856 '</div>' .
857 $this->getFieldSetEnd()
858 );
859 $this->endForm();
860 }
861
862 public function getCCPartnerUrl() {
863 global $wgServer;
864 $exitUrl = $wgServer . $this->parent->getUrl( array(
865 'page' => 'Options',
866 'SubmitCC' => 'indeed',
867 'config__LicenseCode' => 'cc',
868 'config_wgRightsUrl' => '[license_url]',
869 'config_wgRightsText' => '[license_name]',
870 'config_wgRightsIcon' => '[license_button]',
871 ) );
872 $styleUrl = $wgServer . dirname( dirname( $this->parent->getUrl() ) ) .
873 '/skins/common/config-cc.css';
874 $iframeUrl = 'http://creativecommons.org/license/?' .
875 wfArrayToCGI( array(
876 'partner' => 'MediaWiki',
877 'exit_url' => $exitUrl,
878 'lang' => $this->getVar( '_UserLang' ),
879 'stylesheet' => $styleUrl,
880 ) );
881 return $iframeUrl;
882 }
883
884 public function getCCChooser() {
885 $iframeAttribs = array(
886 'class' => 'config-cc-iframe',
887 'name' => 'config-cc-iframe',
888 'id' => 'config-cc-iframe',
889 'frameborder' => 0,
890 'width' => '100%',
891 'height' => '100%',
892 );
893 if ( $this->getVar( '_CCDone' ) ) {
894 $iframeAttribs['src'] = $this->parent->getUrl( array( 'ShowCC' => 'yes' ) );
895 } else {
896 $iframeAttribs['src'] = $this->getCCPartnerUrl();
897 }
898
899 return
900 "<div class=\"config-cc-wrapper\" id=\"config-cc-wrapper\" style=\"display: none;\">\n" .
901 Html::element( 'iframe', $iframeAttribs, '', false /* not short */ ) .
902 "</div>\n";
903 }
904
905 public function getCCDoneBox() {
906 $js = "parent.document.getElementById('config-cc-wrapper').style.height = '$1';";
907 // If you change this height, also change it in config.css
908 $expandJs = str_replace( '$1', '54em', $js );
909 $reduceJs = str_replace( '$1', '70px', $js );
910 return
911 '<p>'.
912 Html::element( 'img', array( 'src' => $this->getVar( 'wgRightsIcon' ) ) ) .
913 '&#160;&#160;' .
914 htmlspecialchars( $this->getVar( 'wgRightsText' ) ) .
915 "</p>\n" .
916 "<p style=\"text-align: center\">" .
917 Html::element( 'a',
918 array(
919 'href' => $this->getCCPartnerUrl(),
920 'onclick' => $expandJs,
921 ),
922 wfMsg( 'config-cc-again' )
923 ) .
924 "</p>\n" .
925 "<script type=\"text/javascript\">\n" .
926 # Reduce the wrapper div height
927 htmlspecialchars( $reduceJs ) .
928 "\n" .
929 "</script>\n";
930 }
931
932 public function submitCC() {
933 $newValues = $this->parent->setVarsFromRequest(
934 array( 'wgRightsUrl', 'wgRightsText', 'wgRightsIcon' ) );
935 if ( count( $newValues ) != 3 ) {
936 $this->parent->showError( 'config-cc-error' );
937 return;
938 }
939 $this->setVar( '_CCDone', true );
940 $this->addHTML( $this->getCCDoneBox() );
941 }
942
943 public function submit() {
944 $this->parent->setVarsFromRequest( array( '_RightsProfile', '_LicenseCode',
945 'wgEnableEmail', 'wgPasswordSender', 'wgEnableUploads', 'wgLogo',
946 'wgEnableUserEmail', 'wgEnotifUserTalk', 'wgEnotifWatchlist',
947 'wgEmailAuthentication', 'wgMainCacheType', '_MemCachedServers',
948 'wgUseInstantCommons' ) );
949
950 if ( !in_array( $this->getVar( '_RightsProfile' ),
951 array_keys( $this->parent->rightsProfiles ) ) )
952 {
953 reset( $this->parent->rightsProfiles );
954 $this->setVar( '_RightsProfile', key( $this->parent->rightsProfiles ) );
955 }
956
957 $code = $this->getVar( '_LicenseCode' );
958 if ( $code == 'cc-choose' ) {
959 if ( !$this->getVar( '_CCDone' ) ) {
960 $this->parent->showError( 'config-cc-not-chosen' );
961 return false;
962 }
963 } elseif ( in_array( $code, array_keys( $this->parent->licenses ) ) ) {
964 $entry = $this->parent->licenses[$code];
965 if ( isset( $entry['text'] ) ) {
966 $this->setVar( 'wgRightsText', $entry['text'] );
967 } else {
968 $this->setVar( 'wgRightsText', wfMsg( 'config-license-' . $code ) );
969 }
970 $this->setVar( 'wgRightsUrl', $entry['url'] );
971 $this->setVar( 'wgRightsIcon', $entry['icon'] );
972 } else {
973 $this->setVar( 'wgRightsText', '' );
974 $this->setVar( 'wgRightsUrl', '' );
975 $this->setVar( 'wgRightsIcon', '' );
976 }
977
978 $extsAvailable = $this->parent->findExtensions();
979 $extsToInstall = array();
980 foreach( $extsAvailable as $ext ) {
981 if( $this->parent->request->getCheck( 'config_ext-' . $ext ) ) {
982 $extsToInstall[] = $ext;
983 }
984 }
985 $this->parent->setVar( '_Extensions', $extsToInstall );
986 return true;
987 }
988
989 }
990
991 class WebInstaller_Install extends WebInstallerPage {
992
993 public function execute() {
994 if( $this->parent->request->wasPosted() ) {
995 return 'continue';
996 } elseif( $this->getVar( '_InstallDone' ) ) {
997 $this->startForm();
998 $status = new Status();
999 $status->warning( 'config-install-alreadydone' );
1000 $this->parent->showStatusBox( $status );
1001 } elseif( $this->getVar( '_UpgradeDone' ) ) {
1002 return 'skip';
1003 } else {
1004 $this->startForm();
1005 $this->addHTML("<ul>");
1006 $this->parent->performInstallation(
1007 array( $this, 'startStage'),
1008 array( $this, 'endStage' )
1009 );
1010 $this->addHTML("</ul>");
1011 }
1012 $this->endForm();
1013 return true;
1014 }
1015
1016 public function startStage( $step ) {
1017 $this->addHTML( "<li>" . wfMsgHtml( "config-install-$step" ) . wfMsg( 'ellipsis') );
1018 }
1019
1020 public function endStage( $step, $status ) {
1021 $msg = $status->isOk() ? 'config-install-step-done' : 'config-install-step-failed';
1022 $html = wfMsgHtml( 'word-separator' ) . wfMsgHtml( $msg );
1023 if ( !$status->isOk() ) {
1024 $html = "<span class=\"error\">$html</span>";
1025 }
1026 $this->addHTML( $html . "</li>\n" );
1027 if( !$status->isGood() ) {
1028 $this->parent->showStatusBox( $status );
1029 }
1030 }
1031
1032 }
1033
1034 class WebInstaller_Complete extends WebInstallerPage {
1035
1036 public function execute() {
1037 // Pop up a dialog box, to make it difficult for the user to forget
1038 // to download the file
1039 $lsUrl = $GLOBALS['wgServer'] . $this->parent->getURL( array( 'localsettings' => 1 ) );
1040 $this->parent->request->response()->header( "Refresh: 0;$lsUrl" );
1041
1042 $this->startForm();
1043 $this->parent->disableLinkPopups();
1044 $this->addHTML(
1045 $this->parent->getInfoBox(
1046 wfMsgNoTrans( 'config-install-done',
1047 $lsUrl,
1048 $GLOBALS['wgServer'] .
1049 $this->getVar( 'wgScriptPath' ) . '/index' .
1050 $this->getVar( 'wgScriptExtension' ),
1051 '<downloadlink/>'
1052 ), 'tick-32.png'
1053 )
1054 );
1055 $this->parent->restoreLinkPopups();
1056 $this->endForm( false, false );
1057 }
1058 }
1059
1060 class WebInstaller_Restart extends WebInstallerPage {
1061
1062 public function execute() {
1063 $r = $this->parent->request;
1064 if ( $r->wasPosted() ) {
1065 $really = $r->getVal( 'submit-restart' );
1066 if ( $really ) {
1067 $this->parent->session = array();
1068 $this->parent->happyPages = array();
1069 $this->parent->settings = array();
1070 }
1071 return 'continue';
1072 }
1073
1074 $this->startForm();
1075 $s = $this->parent->getWarningBox( wfMsgNoTrans( 'config-help-restart' ) );
1076 $this->addHTML( $s );
1077 $this->endForm( 'restart' );
1078 }
1079
1080 }
1081
1082 abstract class WebInstaller_Document extends WebInstallerPage {
1083
1084 protected abstract function getFileName();
1085
1086 public function execute() {
1087 $text = $this->getFileContents();
1088 $text = $this->formatTextFile( $text );
1089 $this->parent->output->addWikiText( $text );
1090 $this->startForm();
1091 $this->endForm( false );
1092 }
1093
1094 public function getFileContents() {
1095 return file_get_contents( dirname( __FILE__ ) . '/../../' . $this->getFileName() );
1096 }
1097
1098 protected function formatTextFile( $text ) {
1099 // Use Unix line endings, escape some wikitext stuff
1100 $text = str_replace( array( '<', '{{', '[[', "\r" ),
1101 array( '&lt;', '&#123;&#123;', '&#91;&#91;', '' ), $text );
1102 // join word-wrapped lines into one
1103 do {
1104 $prev = $text;
1105 $text = preg_replace( "/\n([\\*#\t])([^\n]*?)\n([^\n#\\*:]+)/", "\n\\1\\2 \\3", $text );
1106 } while ( $text != $prev );
1107 // Replace tab indents with colons
1108 $text = preg_replace( '/^\t\t/m', '::', $text );
1109 $text = preg_replace( '/^\t/m', ':', $text );
1110 // turn (bug nnnn) into links
1111 $text = preg_replace_callback('/bug (\d+)/', array( $this, 'replaceBugLinks' ), $text );
1112 // add links to manual to every global variable mentioned
1113 $text = preg_replace_callback('/(\$wg[a-z0-9_]+)/i', array( $this, 'replaceConfigLinks' ), $text );
1114 return $text;
1115 }
1116
1117 private function replaceBugLinks( $matches ) {
1118 return '<span class="config-plainlink">[https://bugzilla.wikimedia.org/' .
1119 $matches[1] . ' bug ' . $matches[1] . ']</span>';
1120 }
1121
1122 private function replaceConfigLinks( $matches ) {
1123 return '<span class="config-plainlink">[http://www.mediawiki.org/wiki/Manual:' .
1124 $matches[1] . ' ' . $matches[1] . ']</span>';
1125 }
1126
1127 }
1128
1129 class WebInstaller_Readme extends WebInstaller_Document {
1130 protected function getFileName() { return 'README'; }
1131 }
1132
1133 class WebInstaller_ReleaseNotes extends WebInstaller_Document {
1134 protected function getFileName() { return 'RELEASE-NOTES'; }
1135 }
1136
1137 class WebInstaller_UpgradeDoc extends WebInstaller_Document {
1138 protected function getFileName() { return 'UPGRADE'; }
1139 }
1140
1141 class WebInstaller_Copying extends WebInstaller_Document {
1142 protected function getFileName() { return 'COPYING'; }
1143 }
1144