r64258 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r64257‎ | r64258 | r64259 >
Date:15:31, 27 March 2010
Author:demon
Status:ok
Tags:
Comment:
Refactor install steps into parent class
Modified paths:
  • /branches/new-installer/phase3/includes/installer/Installer.php (modified) (history)
  • /branches/new-installer/phase3/includes/installer/WebInstaller.php (modified) (history)
  • /branches/new-installer/phase3/languages/messages/MessagesEn.php (modified) (history)
  • /branches/new-installer/phase3/maintenance/language/messages.inc (modified) (history)

Diff [purge]

Index: branches/new-installer/phase3/maintenance/language/messages.inc
@@ -3351,14 +3351,14 @@
33523352 'config-memcached-help',
33533353 'config-extensions',
33543354 'config-extensions-help',
3355 - 'config-stage-done',
 3355+ 'config-install-step-done',
 3356+ 'config-install-step-failed',
33563357 'config-install-extensions',
33573358 'config-install-database',
33583359 'config-install-tables',
33593360 'config-install-interwiki-sql',
33603361 'config-install-secretkey',
3361 - 'config-insecure-secretkey',
3362 - 'config-install-user',
 3362+ 'config-install-sysop',
33633363 'config-install-localsettings',
33643364 'config-install-done',
33653365 ),
Index: branches/new-installer/phase3/includes/installer/WebInstaller.php
@@ -1502,85 +1502,24 @@
15031503 }
15041504 $this->startForm();
15051505 $this->parent->output->addHTML("<ul>");
1506 -
1507 - // Extensions
1508 - $exts = $this->parent->getVar( '_Extensions' );
1509 - if( count( $exts ) ) {
1510 - global $wgHooks, $wgAutoloadClasses;
1511 - $this->startStage( 'config-install-extensions' );
1512 - $path = $this->getVar( 'IP' ) . '/extensions';
1513 - foreach( $exts as $e ) {
1514 - require( "$path/$e/$e.php" );
1515 - }
1516 - $this->endStage();
 1506+ foreach( $this->parent->getInstallSteps() as $step ) {
 1507+ $this->startStage( "config-install-$step" );
 1508+ $func = 'install' . ucfirst( $step );
 1509+ $success = $this->parent->{$func}();
 1510+ $this->endStage( $success );
15171511 }
1518 -
1519 - // Get database
1520 - $this->startStage( 'config-install-database' );
1521 - $dbType = $this->parent->getVar( 'wgDBtype' );
1522 - $installer = $this->parent->getDBInstaller( $dbType );
1523 - $db = $installer->setupDatabase();
1524 - if( !$db ) {
1525 - // @todo Need some sort of failure
1526 - return;
1527 - }
1528 - $this->endStage();
1529 -
1530 - // Create tables
1531 - $this->startStage( 'config-install-tables' );
1532 - $this->parent->createTables();
1533 - $this->endStage();
1534 -
1535 - $this->startStage( 'config-install-secretkey' );
1536 - $file = @fopen( "/dev/urandom", "r" );
1537 - if ( $file ) {
1538 - $secretKey = bin2hex( fread( $file, 32 ) );
1539 - fclose( $file );
1540 - $this->endStage();
1541 - } else {
1542 - $secretKey = "";
1543 - for ( $i=0; $i<8; $i++ ) {
1544 - $secretKey .= dechex(mt_rand(0, 0x7fffffff));
1545 - }
1546 - $this->parent->output->addHTML( wfMsgHtml( 'config-insecure-secretkey' ) . "</li>\n" );
1547 - }
1548 - $this->setVar( 'wgSecretKey', $secretKey );
1549 -
1550 - // @TODO initialize DB first
1551 - //$this->createWikiSysop();
1552 -
1553 - $this->startStage( 'config-install-localsettings' );
1554 - $localSettings = new LocalSettings( $this->parent );
1555 - $localSettings->writeLocalSettings();
1556 - $this->endStage();
1557 -
15581512 $this->endForm();
1559 - }
 1513+ return true;
15601514
1561 - private function createWikiSysop() {
1562 - $user = User::newFromName( $this->getVar( '_AdminName' ) );
1563 - if ( !$user ) {
1564 - //@todo
1565 - }
1566 - if ( $user->idForName() == 0 ) {
1567 - $user->addToDatabase();
1568 - try {
1569 - $user->setPassword( $this->getVar( '_AdminPassword' ) );
1570 - } catch( PasswordError $pwe ) {
1571 - // need better failure here!
1572 - }
1573 - $user->saveSettings();
1574 - $user->addGroup( 'sysop' );
1575 - $user->addGroup( 'bureaucrat' );
1576 - }
15771515 }
15781516
15791517 private function startStage( $msg ) {
15801518 $this->parent->output->addHTML( "<li>" . wfMsgHtml( $msg ) . wfMsg( 'ellipsis') );
15811519 }
15821520
1583 - private function endStage() {
1584 - $this->parent->output->addHTML( wfMsgHtml( 'config-stage-done' ) . "</li>\n" );
 1521+ private function endStage( $success = true ) {
 1522+ $msg = $success ? 'config-install-step-done' : 'config-install-step-failed';
 1523+ $this->parent->output->addHTML( wfMsgHtml( $msg ) . "</li>\n" );
15851524 }
15861525 }
15871526 class WebInstaller_Complete extends WebInstallerPage {
Index: branches/new-installer/phase3/includes/installer/Installer.php
@@ -124,6 +124,15 @@
125125 'envCheckShellLocale',
126126 );
127127
 128+ var $installSteps = array(
 129+ 'extensions',
 130+ 'database',
 131+ 'tables',
 132+ 'secretkey',
 133+ // 'sysop',
 134+ 'localsettings',
 135+ );
 136+
128137 /**
129138 * Known object cache types and the functions used to test for their existence
130139 * @protected
@@ -732,10 +741,81 @@
733742 return $exts;
734743 }
735744
736 - public function createTables() {
 745+
 746+
 747+ public function getInstallSteps() {
 748+ if( !count( $this->getVar( '_Extensions' ) ) ) {
 749+ unset( $this->installSteps['extensions'] );
 750+ }
 751+ return $this->installSteps;
 752+ }
 753+
 754+ public function installExtensions() {
 755+ global $wgHooks, $wgAutoloadClasses;
 756+ $exts = $this->getVar( '_Extensions' );
 757+ $path = $this->getVar( 'IP' ) . '/extensions';
 758+ foreach( $exts as $e ) {
 759+ require( "$path/$e/$e.php" );
 760+ }
 761+ return true;
 762+ }
 763+
 764+ public function installDatabase() {
 765+ $installer = $this->getDBInstaller( $this->getVar( 'wgDBtype' ) );
 766+ $db = $installer->setupDatabase();
 767+ if( !$db ) {
 768+ return false;
 769+ }
 770+ return true;
 771+ }
 772+
 773+ public function installTables() {
737774 $installer = $this->getDBInstaller();
738 - $installer->createTables();
 775+ $status = $installer->createTables();
 776+ return $status->isGood();
739777 }
 778+
 779+ public function installSecretKey() {
 780+ $file = wfIsWindows() ? null : @fopen( "/dev/urandom", "r" );
 781+ if ( $file ) {
 782+ $secretKey = bin2hex( fread( $file, 32 ) );
 783+ fclose( $file );
 784+ $ret = true;
 785+ } else {
 786+ $secretKey = "";
 787+ for ( $i=0; $i<8; $i++ ) {
 788+ $secretKey .= dechex(mt_rand(0, 0x7fffffff));
 789+ }
 790+ $ret = false;
 791+ }
 792+ $this->setVar( 'wgSecretKey', $secretKey );
 793+ return $ret;
 794+ }
 795+
 796+ private function installSysop() {
 797+ $user = User::newFromName( $this->getVar( '_AdminName' ) );
 798+ if ( !$user ) {
 799+ return false; // we should've validated this earlier anyway!
 800+ }
 801+ if ( $user->idForName() == 0 ) {
 802+ $user->addToDatabase();
 803+ try {
 804+ $user->setPassword( $this->getVar( '_AdminPassword' ) );
 805+ } catch( PasswordError $pwe ) {
 806+ return false;
 807+ }
 808+ $user->saveSettings();
 809+ $user->addGroup( 'sysop' );
 810+ $user->addGroup( 'bureaucrat' );
 811+ }
 812+ return true;
 813+ }
 814+
 815+ public function installLocalsettings() {
 816+ $localSettings = new LocalSettings( $this );
 817+ $localSettings->writeLocalSettings();
 818+ return true;
 819+ }
740820 }
741821
742822 /**
Index: branches/new-installer/phase3/languages/messages/MessagesEn.php
@@ -4450,14 +4450,14 @@
44514451 'config-extensions-help' => "The following extensions were automatically detected in your extensions directory.\n
44524452 They may require additional configuration, but you can enable them now",
44534453
4454 -'config-stage-done' => 'done',
 4454+'config-install-step-done' => 'done',
 4455+'config-install-step-failed' => "'''FAILED'''",
44554456 'config-install-extensions' => 'Including extensions',
44564457 'config-install-database' => 'Setting up database',
44574458 'config-install-tables' => 'Creating tables',
44584459 'config-install-interwiki-sql' => 'Could not find file interwiki.sql',
44594460 'config-install-secretkey' => 'Generating secret key',
4460 -'config-insecure-secretkey' => 'Warning: Unable to create secure $wgSecretKey. Consider changing it manually.',
4461 -'config-install-user' => 'Creating administrator user account',
 4461+'config-install-sysop' => 'Creating administrator user account',
44624462 'config-install-localsettings' => 'Writing LocalSettings.php',
44634463 'config-install-done' => "'''Congratulations''', you have successfully installed MediaWiki.
44644464

Status & tagging log