* Made the web upgrade process more friendly. Instead of saying "access denied, go...
[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' ) {
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 ( $id !== 0 ) {
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();
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 if ( $this->parent->request->wasPosted() ) {
439 // Done message acknowledged
440 return 'continue';
441 } else {
442 // Back button click
443 // Show the done message again
444 // Make them click back again if they want to do the upgrade again
445 $this->showDoneMessage();
446 return 'output';
447 }
448 }
449
450 // wgDBtype is generally valid here because otherwise the previous page
451 // (connect) wouldn't have declared its happiness
452 $type = $this->getVar( 'wgDBtype' );
453 $installer = $this->parent->getDBInstaller( $type );
454
455 if ( !$installer->needsUpgrade() ) {
456 return 'skip';
457 }
458
459 if ( $this->parent->request->wasPosted() ) {
460 $installer->preUpgrade();
461 $this->addHTML(
462 '<div id="config-spinner" style="display:none;"><img src="../skins/common/images/ajax-loader.gif" /></div>' .
463 '<script>jQuery( "#config-spinner" )[0].style.display = "block";</script>' .
464 '<textarea id="config-update-log" name="UpdateLog" rows="10" readonly="readonly">'
465 );
466 $this->parent->output->flush();
467 $result = $installer->doUpgrade();
468 $this->addHTML( '</textarea>
469 <script>jQuery( "#config-spinner" )[0].style.display = "none";</script>' );
470 $this->parent->output->flush();
471 if ( $result ) {
472 $this->setVar( '_UpgradeDone', true );
473 $this->showDoneMessage();
474 return 'output';
475 }
476 }
477
478 $this->startForm();
479 $this->addHTML( $this->parent->getInfoBox(
480 wfMsgNoTrans( 'config-can-upgrade', $GLOBALS['wgVersion'] ) ) );
481 $this->endForm();
482 }
483
484 public function showDoneMessage() {
485 $this->startForm();
486 $this->addHTML(
487 $this->parent->getInfoBox(
488 wfMsgNoTrans( 'config-upgrade-done',
489 $GLOBALS['wgServer'] .
490 $this->getVar( 'wgScriptPath' ) . '/index' .
491 $this->getVar( 'wgScriptExtension' )
492 ), 'tick-32.png'
493 )
494 );
495 $this->endForm( 'regenerate' );
496 }
497
498 }
499
500 class WebInstaller_DBSettings extends WebInstallerPage {
501
502 public function execute() {
503 $installer = $this->parent->getDBInstaller( $this->getVar( 'wgDBtype' ) );
504
505 $r = $this->parent->request;
506 if ( $r->wasPosted() ) {
507 $status = $installer->submitSettingsForm();
508 if ( $status === false ) {
509 return 'skip';
510 } elseif ( $status->isGood() ) {
511 return 'continue';
512 } else {
513 $this->parent->showStatusBox( $status );
514 }
515 }
516
517 $form = $installer->getSettingsForm();
518 if ( $form === false ) {
519 return 'skip';
520 }
521
522 $this->startForm();
523 $this->addHTML( $form );
524 $this->endForm();
525 }
526
527 }
528
529 class WebInstaller_Name extends WebInstallerPage {
530
531 public function execute() {
532 $r = $this->parent->request;
533 if ( $r->wasPosted() ) {
534 if ( $this->submit() ) {
535 return 'continue';
536 }
537 }
538
539 $this->startForm();
540
541 if ( $this->getVar( 'wgSitename' ) == $GLOBALS['wgSitename'] ) {
542 $this->setVar( 'wgSitename', '' );
543 }
544
545 // Set wgMetaNamespace to something valid before we show the form.
546 // $wgMetaNamespace defaults to $wgSiteName which is 'MediaWiki'
547 $metaNS = $this->getVar( 'wgMetaNamespace' );
548 $this->setVar( 'wgMetaNamespace', wfMsgForContent( 'config-ns-other-default' ) );
549
550 $this->addHTML(
551 $this->parent->getTextBox( array(
552 'var' => 'wgSitename',
553 'label' => 'config-site-name',
554 'help' => $this->parent->getHelpBox( 'config-site-name-help' )
555 ) ) .
556 $this->parent->getRadioSet( array(
557 'var' => '_NamespaceType',
558 'label' => 'config-project-namespace',
559 'itemLabelPrefix' => 'config-ns-',
560 'values' => array( 'site-name', 'generic', 'other' ),
561 'commonAttribs' => array( 'class' => 'enableForOther', 'rel' => 'config_wgMetaNamespace' ),
562 'help' => $this->parent->getHelpBox( 'config-project-namespace-help' )
563 ) ) .
564 $this->parent->getTextBox( array(
565 'var' => 'wgMetaNamespace',
566 'label' => '', //TODO: Needs a label?
567 'attribs' => array( 'readonly' => 'readonly', 'class' => 'enabledByOther' ),
568
569 ) ) .
570 $this->getFieldSetStart( 'config-admin-box' ) .
571 $this->parent->getTextBox( array(
572 'var' => '_AdminName',
573 'label' => 'config-admin-name',
574 'help' => $this->parent->getHelpBox( 'config-admin-help' )
575 ) ) .
576 $this->parent->getPasswordBox( array(
577 'var' => '_AdminPassword',
578 'label' => 'config-admin-password',
579 ) ) .
580 $this->parent->getPasswordBox( array(
581 'var' => '_AdminPassword2',
582 'label' => 'config-admin-password-confirm'
583 ) ) .
584 $this->parent->getTextBox( array(
585 'var' => '_AdminEmail',
586 'label' => 'config-admin-email',
587 'help' => $this->parent->getHelpBox( 'config-admin-email-help' )
588 ) ) .
589 $this->parent->getCheckBox( array(
590 'var' => '_Subscribe',
591 'label' => 'config-subscribe',
592 'help' => $this->parent->getHelpBox( 'config-subscribe-help' )
593 ) ) .
594 $this->getFieldSetEnd() .
595 $this->parent->getInfoBox( wfMsg( 'config-almost-done' ) ) .
596 $this->parent->getRadioSet( array(
597 'var' => '_SkipOptional',
598 'itemLabelPrefix' => 'config-optional-',
599 'values' => array( 'continue', 'skip' )
600 ) )
601 );
602
603 // Restore the default value
604 $this->setVar( 'wgMetaNamespace', $metaNS );
605
606 $this->endForm();
607 return 'output';
608 }
609
610 public function submit() {
611 $retVal = true;
612 $this->parent->setVarsFromRequest( array( 'wgSitename', '_NamespaceType',
613 '_AdminName', '_AdminPassword', '_AdminPassword2', '_AdminEmail',
614 '_Subscribe', '_SkipOptional' ) );
615
616 // Validate site name
617 if ( strval( $this->getVar( 'wgSitename' ) ) === '' ) {
618 $this->parent->showError( 'config-site-name-blank' );
619 $retVal = false;
620 }
621
622 // Fetch namespace
623 $nsType = $this->getVar( '_NamespaceType' );
624 if ( $nsType == 'site-name' ) {
625 $name = $this->getVar( 'wgSitename' );
626 // Sanitize for namespace
627 // This algorithm should match the JS one in WebInstallerOutput.php
628 $name = preg_replace( '/[\[\]\{\}|#<>%+? ]/', '_', $name );
629 $name = str_replace( '&', '&amp;', $name );
630 $name = preg_replace( '/__+/', '_', $name );
631 $name = ucfirst( trim( $name, '_' ) );
632 } elseif ( $nsType == 'generic' ) {
633 $name = wfMsg( 'config-ns-generic' );
634 } else { // other
635 $name = $this->getVar( 'wgMetaNamespace' );
636 }
637
638 // Validate namespace
639 if ( strpos( $name, ':' ) !== false ) {
640 $good = false;
641 } else {
642 // Title-style validation
643 $title = Title::newFromText( $name );
644 if ( !$title ) {
645 $good = $nsType == 'site-name';
646 } else {
647 $name = $title->getDBkey();
648 $good = true;
649 }
650 }
651 if ( !$good ) {
652 $this->parent->showError( 'config-ns-invalid', $name );
653 $retVal = false;
654 }
655 $this->setVar( 'wgMetaNamespace', $name );
656
657 // Validate username for creation
658 $name = $this->getVar( '_AdminName' );
659 if ( strval( $name ) === '' ) {
660 $this->parent->showError( 'config-admin-name-blank' );
661 $cname = $name;
662 $retVal = false;
663 } else {
664 $cname = User::getCanonicalName( $name, 'creatable' );
665 if ( $cname === false ) {
666 $this->parent->showError( 'config-admin-name-invalid', $name );
667 $retVal = false;
668 } else {
669 $this->setVar( '_AdminName', $cname );
670 }
671 }
672
673 // Validate password
674 $msg = false;
675 $valid = false;
676 $pwd = $this->getVar( '_AdminPassword' );
677 $user = User::newFromName( $cname );
678 $valid = $user && $user->getPasswordValidity( $pwd );
679 if ( strval( $pwd ) === '' ) {
680 # $user->getPasswordValidity just checks for $wgMinimalPasswordLength.
681 # This message is more specific and helpful.
682 $msg = 'config-admin-password-blank';
683 } elseif ( $pwd !== $this->getVar( '_AdminPassword2' ) ) {
684 $msg = 'config-admin-password-mismatch';
685 } elseif ( $valid !== true ) {
686 # As of writing this will only catch the username being e.g. 'FOO' and
687 # the password 'foo'
688 $msg = $valid;
689 }
690 if ( $msg !== false ) {
691 $this->parent->showError( $msg );
692 $this->setVar( '_AdminPassword', '' );
693 $this->setVar( '_AdminPassword2', '' );
694 $retVal = false;
695 }
696 return $retVal;
697 }
698
699 }
700
701 class WebInstaller_Options extends WebInstallerPage {
702
703 public function execute() {
704 if ( $this->getVar( '_SkipOptional' ) == 'skip' ) {
705 return 'skip';
706 }
707 if ( $this->parent->request->wasPosted() ) {
708 if ( $this->submit() ) {
709 return 'continue';
710 }
711 }
712
713 $this->startForm();
714 $this->addHTML(
715 # User Rights
716 $this->parent->getRadioSet( array(
717 'var' => '_RightsProfile',
718 'label' => 'config-profile',
719 'itemLabelPrefix' => 'config-profile-',
720 'values' => array_keys( $this->parent->rightsProfiles ),
721 ) ) .
722 $this->parent->getHelpBox( 'config-profile-help' ) .
723
724 # Licensing
725 $this->parent->getRadioSet( array(
726 'var' => '_LicenseCode',
727 'label' => 'config-license',
728 'itemLabelPrefix' => 'config-license-',
729 'values' => array_keys( $this->parent->licenses ),
730 'commonAttribs' => array( 'class' => 'licenseRadio' ),
731 ) ) .
732 $this->getCCChooser() .
733 $this->parent->getHelpBox( 'config-license-help' ) .
734
735 # E-mail
736 $this->getFieldSetStart( 'config-email-settings' ) .
737 $this->parent->getCheckBox( array(
738 'var' => 'wgEnableEmail',
739 'label' => 'config-enable-email',
740 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'emailwrapper' ),
741 ) ) .
742 $this->parent->getHelpBox( 'config-enable-email-help' ) .
743 "<div id=\"emailwrapper\">" .
744 $this->parent->getTextBox( array(
745 'var' => 'wgPasswordSender',
746 'label' => 'config-email-sender'
747 ) ) .
748 $this->parent->getHelpBox( 'config-email-sender-help' ) .
749 $this->parent->getCheckBox( array(
750 'var' => 'wgEnableUserEmail',
751 'label' => 'config-email-user',
752 ) ) .
753 $this->parent->getHelpBox( 'config-email-user-help' ) .
754 $this->parent->getCheckBox( array(
755 'var' => 'wgEnotifUserTalk',
756 'label' => 'config-email-usertalk',
757 ) ) .
758 $this->parent->getHelpBox( 'config-email-usertalk-help' ) .
759 $this->parent->getCheckBox( array(
760 'var' => 'wgEnotifWatchlist',
761 'label' => 'config-email-watchlist',
762 ) ) .
763 $this->parent->getHelpBox( 'config-email-watchlist-help' ) .
764 $this->parent->getCheckBox( array(
765 'var' => 'wgEmailAuthentication',
766 'label' => 'config-email-auth',
767 ) ) .
768 $this->parent->getHelpBox( 'config-email-auth-help' ) .
769 "</div>" .
770 $this->getFieldSetEnd()
771 );
772
773 $extensions = $this->parent->findExtensions();
774
775 if( $extensions ) {
776 $extHtml = $this->getFieldSetStart( 'config-extensions' );
777
778 foreach( $extensions as $ext ) {
779 $extHtml .= $this->parent->getCheckBox( array(
780 'var' => "ext-$ext",
781 'rawtext' => $ext,
782 ) );
783 }
784
785 $extHtml .= $this->parent->getHelpBox( 'config-extensions-help' ) .
786 $this->getFieldSetEnd();
787 $this->addHTML( $extHtml );
788 }
789
790 $this->addHTML(
791 # Uploading
792 $this->getFieldSetStart( 'config-upload-settings' ) .
793 $this->parent->getCheckBox( array(
794 'var' => 'wgEnableUploads',
795 'label' => 'config-upload-enable',
796 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'uploadwrapper' ),
797 'help' => $this->parent->getHelpBox( 'config-upload-help' )
798 ) ) .
799 '<div id="uploadwrapper" style="display: none;">' .
800 $this->parent->getTextBox( array(
801 'var' => 'wgDeletedDirectory',
802 'label' => 'config-upload-deleted',
803 'help' => $this->parent->getHelpBox( 'config-upload-deleted-help' )
804 ) ) .
805 '</div>' .
806 $this->parent->getTextBox( array(
807 'var' => 'wgLogo',
808 'label' => 'config-logo',
809 'help' => $this->parent->getHelpBox( 'config-logo-help' )
810 ) )
811 );
812 $this->addHTML(
813 $this->parent->getCheckBox( array(
814 'var' => 'wgUseInstantCommons',
815 'label' => 'config-instantcommons',
816 'help' => $this->parent->getHelpBox( 'config-instantcommons-help' )
817 ) ) .
818 $this->getFieldSetEnd()
819 );
820
821 $caches = array( 'none' );
822 if( count( $this->getVar( '_Caches' ) ) ) {
823 $caches[] = 'accel';
824 }
825 $caches[] = 'memcached';
826
827 $this->addHTML(
828 # Advanced settings
829 $this->getFieldSetStart( 'config-advanced-settings' ) .
830 # Object cache settings
831 $this->parent->getRadioSet( array(
832 'var' => 'wgMainCacheType',
833 'label' => 'config-cache-options',
834 'itemLabelPrefix' => 'config-cache-',
835 'values' => $caches,
836 'value' => 'none',
837 ) ) .
838 $this->parent->getHelpBox( 'config-cache-help' ) .
839 '<div id="config-memcachewrapper">' .
840 $this->parent->getTextBox( array(
841 'var' => '_MemCachedServers',
842 'label' => 'config-memcached-servers',
843 'help' => $this->parent->getHelpBox( 'config-memcached-help' )
844 ) ) .
845 '</div>' .
846 $this->getFieldSetEnd()
847 );
848 $this->endForm();
849 }
850
851 public function getCCPartnerUrl() {
852 global $wgServer;
853 $exitUrl = $wgServer . $this->parent->getUrl( array(
854 'page' => 'Options',
855 'SubmitCC' => 'indeed',
856 'config__LicenseCode' => 'cc',
857 'config_wgRightsUrl' => '[license_url]',
858 'config_wgRightsText' => '[license_name]',
859 'config_wgRightsIcon' => '[license_button]',
860 ) );
861 $styleUrl = $wgServer . dirname( dirname( $this->parent->getUrl() ) ) .
862 '/skins/common/config-cc.css';
863 $iframeUrl = 'http://creativecommons.org/license/?' .
864 wfArrayToCGI( array(
865 'partner' => 'MediaWiki',
866 'exit_url' => $exitUrl,
867 'lang' => $this->getVar( '_UserLang' ),
868 'stylesheet' => $styleUrl,
869 ) );
870 return $iframeUrl;
871 }
872
873 public function getCCChooser() {
874 $iframeAttribs = array(
875 'class' => 'config-cc-iframe',
876 'name' => 'config-cc-iframe',
877 'id' => 'config-cc-iframe',
878 'frameborder' => 0,
879 'width' => '100%',
880 'height' => '100%',
881 );
882 if ( $this->getVar( '_CCDone' ) ) {
883 $iframeAttribs['src'] = $this->parent->getUrl( array( 'ShowCC' => 'yes' ) );
884 } else {
885 $iframeAttribs['src'] = $this->getCCPartnerUrl();
886 }
887
888 return
889 "<div class=\"config-cc-wrapper\" id=\"config-cc-wrapper\" style=\"display: none;\">\n" .
890 Html::element( 'iframe', $iframeAttribs, '', false /* not short */ ) .
891 "</div>\n";
892 }
893
894 public function getCCDoneBox() {
895 $js = "parent.document.getElementById('config-cc-wrapper').style.height = '$1';";
896 // If you change this height, also change it in config.css
897 $expandJs = str_replace( '$1', '54em', $js );
898 $reduceJs = str_replace( '$1', '70px', $js );
899 return
900 '<p>'.
901 Html::element( 'img', array( 'src' => $this->getVar( 'wgRightsIcon' ) ) ) .
902 '&#160;&#160;' .
903 htmlspecialchars( $this->getVar( 'wgRightsText' ) ) .
904 "</p>\n" .
905 "<p style=\"text-align: center\">" .
906 Html::element( 'a',
907 array(
908 'href' => $this->getCCPartnerUrl(),
909 'onclick' => $expandJs,
910 ),
911 wfMsg( 'config-cc-again' )
912 ) .
913 "</p>\n" .
914 "<script type=\"text/javascript\">\n" .
915 # Reduce the wrapper div height
916 htmlspecialchars( $reduceJs ) .
917 "\n" .
918 "</script>\n";
919 }
920
921 public function submitCC() {
922 $newValues = $this->parent->setVarsFromRequest(
923 array( 'wgRightsUrl', 'wgRightsText', 'wgRightsIcon' ) );
924 if ( count( $newValues ) != 3 ) {
925 $this->parent->showError( 'config-cc-error' );
926 return;
927 }
928 $this->setVar( '_CCDone', true );
929 $this->addHTML( $this->getCCDoneBox() );
930 }
931
932 public function submit() {
933 $this->parent->setVarsFromRequest( array( '_RightsProfile', '_LicenseCode',
934 'wgEnableEmail', 'wgPasswordSender', 'wgEnableUploads', 'wgLogo',
935 'wgEnableUserEmail', 'wgEnotifUserTalk', 'wgEnotifWatchlist',
936 'wgEmailAuthentication', 'wgMainCacheType', '_MemCachedServers',
937 'wgUseInstantCommons' ) );
938
939 if ( !in_array( $this->getVar( '_RightsProfile' ),
940 array_keys( $this->parent->rightsProfiles ) ) )
941 {
942 reset( $this->parent->rightsProfiles );
943 $this->setVar( '_RightsProfile', key( $this->parent->rightsProfiles ) );
944 }
945
946 $code = $this->getVar( '_LicenseCode' );
947 if ( $code == 'cc-choose' ) {
948 if ( !$this->getVar( '_CCDone' ) ) {
949 $this->parent->showError( 'config-cc-not-chosen' );
950 return false;
951 }
952 } elseif ( in_array( $code, array_keys( $this->parent->licenses ) ) ) {
953 $entry = $this->parent->licenses[$code];
954 if ( isset( $entry['text'] ) ) {
955 $this->setVar( 'wgRightsText', $entry['text'] );
956 } else {
957 $this->setVar( 'wgRightsText', wfMsg( 'config-license-' . $code ) );
958 }
959 $this->setVar( 'wgRightsUrl', $entry['url'] );
960 $this->setVar( 'wgRightsIcon', $entry['icon'] );
961 } else {
962 $this->setVar( 'wgRightsText', '' );
963 $this->setVar( 'wgRightsUrl', '' );
964 $this->setVar( 'wgRightsIcon', '' );
965 }
966
967 $extsAvailable = $this->parent->findExtensions();
968 $extsToInstall = array();
969 foreach( $extsAvailable as $ext ) {
970 if( $this->parent->request->getCheck( 'config_ext-' . $ext ) ) {
971 $extsToInstall[] = $ext;
972 }
973 }
974 $this->parent->setVar( '_Extensions', $extsToInstall );
975 return true;
976 }
977
978 }
979
980 class WebInstaller_Install extends WebInstallerPage {
981
982 public function execute() {
983 if( $this->parent->request->wasPosted() ) {
984 return 'continue';
985 } elseif( $this->getVar( '_InstallDone' ) ) {
986 $this->startForm();
987 $status = new Status();
988 $status->warning( 'config-install-alreadydone' );
989 $this->parent->showStatusBox( $status );
990 } elseif( $this->getVar( '_UpgradeDone' ) ) {
991 return 'skip';
992 } else {
993 $this->startForm();
994 $this->addHTML("<ul>");
995 $this->parent->performInstallation(
996 array( $this, 'startStage'),
997 array( $this, 'endStage' )
998 );
999 $this->addHTML("</ul>");
1000 }
1001 $this->endForm();
1002 return true;
1003 }
1004
1005 public function startStage( $step ) {
1006 $this->addHTML( "<li>" . wfMsgHtml( "config-install-$step" ) . wfMsg( 'ellipsis') );
1007 }
1008
1009 public function endStage( $step, $status ) {
1010 $msg = $status->isOk() ? 'config-install-step-done' : 'config-install-step-failed';
1011 $html = wfMsgHtml( 'word-separator' ) . wfMsgHtml( $msg );
1012 if ( !$status->isOk() ) {
1013 $html = "<span class=\"error\">$html</span>";
1014 }
1015 $this->addHTML( $html . "</li>\n" );
1016 if( !$status->isGood() ) {
1017 $this->parent->showStatusBox( $status );
1018 }
1019 }
1020
1021 }
1022
1023 class WebInstaller_Complete extends WebInstallerPage {
1024
1025 public function execute() {
1026 // Pop up a dialog box, to make it difficult for the user to forget
1027 // to download the file
1028 $lsUrl = $GLOBALS['wgServer'] . $this->parent->getURL( array( 'localsettings' => 1 ) );
1029 $this->parent->request->response()->header( "Refresh: 0;$lsUrl" );
1030
1031 $this->startForm();
1032 $this->addHTML(
1033 $this->parent->getInfoBox(
1034 wfMsgNoTrans( 'config-install-done',
1035 $lsUrl,
1036 $GLOBALS['wgServer'] .
1037 $this->getVar( 'wgScriptPath' ) . '/index' .
1038 $this->getVar( 'wgScriptExtension' ),
1039 '<downloadlink/>'
1040 ), 'tick-32.png'
1041 )
1042 );
1043 $this->endForm( false );
1044 }
1045 }
1046
1047 class WebInstaller_Restart extends WebInstallerPage {
1048
1049 public function execute() {
1050 $r = $this->parent->request;
1051 if ( $r->wasPosted() ) {
1052 $really = $r->getVal( 'submit-restart' );
1053 if ( $really ) {
1054 $this->parent->session = array();
1055 $this->parent->happyPages = array();
1056 $this->parent->settings = array();
1057 }
1058 return 'continue';
1059 }
1060
1061 $this->startForm();
1062 $s = $this->parent->getWarningBox( wfMsgNoTrans( 'config-help-restart' ) );
1063 $this->addHTML( $s );
1064 $this->endForm( 'restart' );
1065 }
1066
1067 }
1068
1069 abstract class WebInstaller_Document extends WebInstallerPage {
1070
1071 protected abstract function getFileName();
1072
1073 public function execute() {
1074 $text = $this->getFileContents();
1075 $text = $this->formatTextFile( $text );
1076 $this->parent->output->addWikiText( $text );
1077 $this->startForm();
1078 $this->endForm( false );
1079 }
1080
1081 public function getFileContents() {
1082 return file_get_contents( dirname( __FILE__ ) . '/../../' . $this->getFileName() );
1083 }
1084
1085 protected function formatTextFile( $text ) {
1086 // Use Unix line endings, escape some wikitext stuff
1087 $text = str_replace( array( '<', '{{', '[[', "\r" ),
1088 array( '&lt;', '&#123;&#123;', '&#91;&#91;', '' ), $text );
1089 // join word-wrapped lines into one
1090 do {
1091 $prev = $text;
1092 $text = preg_replace( "/\n([\\*#\t])([^\n]*?)\n([^\n#\\*:]+)/", "\n\\1\\2 \\3", $text );
1093 } while ( $text != $prev );
1094 // Replace tab indents with colons
1095 $text = preg_replace( '/^\t\t/m', '::', $text );
1096 $text = preg_replace( '/^\t/m', ':', $text );
1097 // turn (bug nnnn) into links
1098 $text = preg_replace_callback('/bug (\d+)/', array( $this, 'replaceBugLinks' ), $text );
1099 // add links to manual to every global variable mentioned
1100 $text = preg_replace_callback('/(\$wg[a-z0-9_]+)/i', array( $this, 'replaceConfigLinks' ), $text );
1101 return $text;
1102 }
1103
1104 private function replaceBugLinks( $matches ) {
1105 return '<span class="config-plainlink">[https://bugzilla.wikimedia.org/' .
1106 $matches[1] . ' bug ' . $matches[1] . ']</span>';
1107 }
1108
1109 private function replaceConfigLinks( $matches ) {
1110 return '<span class="config-plainlink">[http://www.mediawiki.org/wiki/Manual:' .
1111 $matches[1] . ' ' . $matches[1] . ']</span>';
1112 }
1113
1114 }
1115
1116 class WebInstaller_Readme extends WebInstaller_Document {
1117 protected function getFileName() { return 'README'; }
1118 }
1119
1120 class WebInstaller_ReleaseNotes extends WebInstaller_Document {
1121 protected function getFileName() { return 'RELEASE-NOTES'; }
1122 }
1123
1124 class WebInstaller_UpgradeDoc extends WebInstaller_Document {
1125 protected function getFileName() { return 'UPGRADE'; }
1126 }
1127
1128 class WebInstaller_Copying extends WebInstaller_Document {
1129 protected function getFileName() { return 'COPYING'; }
1130 }
1131