r81182 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r81181‎ | r81182 | r81183 >
Date:01:59, 29 January 2011
Author:demon
Status:ok
Tags:
Comment:
Modified paths:
  • /branches/REL1_17/phase3 (modified) (history)
  • /branches/REL1_17/phase3/config/index.php (modified) (history)
  • /branches/REL1_17/phase3/includes/AutoLoader.php (modified) (history)
  • /branches/REL1_17/phase3/includes/db/Database.php (modified) (history)
  • /branches/REL1_17/phase3/includes/db/DatabaseOracle.php (modified) (history)
  • /branches/REL1_17/phase3/includes/db/LoadBalancer.php (modified) (history)
  • /branches/REL1_17/phase3/includes/extauth/MediaWiki.php (modified) (history)
  • /branches/REL1_17/phase3/includes/filerepo/ForeignDBRepo.php (modified) (history)
  • /branches/REL1_17/phase3/includes/installer/CoreInstaller.php (modified) (history)
  • /branches/REL1_17/phase3/includes/installer/DatabaseInstaller.php (modified) (history)
  • /branches/REL1_17/phase3/includes/installer/Installer.i18n.php (modified) (history)
  • /branches/REL1_17/phase3/includes/installer/MysqlInstaller.php (modified) (history)
  • /branches/REL1_17/phase3/includes/installer/OracleInstaller.php (modified) (history)
  • /branches/REL1_17/phase3/includes/installer/PostgresInstaller.php (modified) (history)
  • /branches/REL1_17/phase3/includes/installer/WebInstallerPage.php (modified) (history)
  • /branches/REL1_17/phase3/maintenance/oracle/archives/patch_16_17_schema_changes.sql (modified) (history)
  • /branches/REL1_17/phase3/maintenance/oracle/tables.sql (modified) (history)

Diff [purge]

Index: branches/REL1_17/phase3/maintenance/oracle/archives/patch_16_17_schema_changes.sql
@@ -31,7 +31,8 @@
3232 ALTER TABLE &mw_prefix.image MODIFY img_bits DEFAULT 0 NOT NULL;
3333 ALTER TABLE &mw_prefix.image MODIFY img_user DEFAULT 0 NOT NULL;
3434
35 -ALTER TABLE &mw_prefix.interwiki ADD iw_api BLOB NOT NULL;
 35+ALTER TABLE &mw_prefix.interwiki ADD iw_api BLOB DEFAULT EMPTY_BLOB();
 36+ALTER TABLE &mw_prefix.interwiki MODIFY iw_api DEFAULT NULL NOT NULL;
3637 ALTER TABLE &mw_prefix.interwiki ADD iw_wikiid VARCHAR2(64);
3738
3839 ALTER TABLE &mw_prefix.ipblocks MODIFY ipb_user DEFAULT 0 NOT NULL;
Index: branches/REL1_17/phase3/maintenance/oracle/tables.sql
@@ -803,7 +803,6 @@
804804 FROM user_triggers
805805 WHERE table_name = p_oldprefix || p_tabname) LOOP
806806 l_temp_ei_sql := SUBSTR(rc.ddlvc2, 1, INSTR(rc.ddlvc2, 'ALTER ') - 1);
807 - dbms_output.put_line(l_temp_ei_sql);
808807 EXECUTE IMMEDIATE l_temp_ei_sql;
809808 END LOOP;
810809 END;
Index: branches/REL1_17/phase3/includes/db/DatabaseOracle.php
@@ -7,21 +7,6 @@
88 */
99
1010 /**
11 - * @ingroup Database
12 - */
13 -class ORABlob {
14 - var $mData;
15 -
16 - function __construct( $data ) {
17 - $this->mData = $data;
18 - }
19 -
20 - function getData() {
21 - return $this->mData;
22 - }
23 -}
24 -
25 -/**
2611 * The oci8 extension is fairly weak and doesn't support oci_num_rows, among
2712 * other things. We use a wrapper class to handle that and other
2813 * Oracle-specific bits, like converting column names back to lowercase.
@@ -496,7 +481,7 @@
497482 }
498483
499484 if ( $val === null ) {
500 - if ( $col_info != false && $col_info->nullable() == 0 && $col_info->defaultValue() != null ) {
 485+ if ( $col_info != false && $col_info->isNullable() == 0 && $col_info->defaultValue() != null ) {
501486 $bind .= 'DEFAULT';
502487 } else {
503488 $bind .= 'NULL';
@@ -862,6 +847,37 @@
863848 return $this->doQuery( 'BEGIN DUPLICATE_TABLE(\'' . $tabName . '\', \'' . $oldPrefix . '\', \'' . strtoupper( $wgDBprefix ) . '\', ' . $temporary . '); END;' );
864849 }
865850
 851+ function listTables( $prefix = null, $fname = 'DatabaseOracle::listTables' ) {
 852+ $listWhere = '';
 853+ if (!empty($prefix)) {
 854+ $listWhere = ' AND table_name LIKE \''.strtoupper($prefix).'%\'';
 855+ }
 856+
 857+ $result = $this->doQuery( "SELECT table_name FROM user_tables WHERE table_name NOT LIKE '%!_IDX$_' ESCAPE '!' $listWhere" );
 858+
 859+ // dirty code ... i know
 860+ $endArray = array();
 861+ $endArray[] = $prefix.'MWUSER';
 862+ $endArray[] = $prefix.'PAGE';
 863+ $endArray[] = $prefix.'IMAGE';
 864+ $fixedOrderTabs = $endArray;
 865+ while (($row = $result->fetchRow()) !== false) {
 866+ if (!in_array($row['table_name'], $fixedOrderTabs))
 867+ $endArray[] = $row['table_name'];
 868+ }
 869+
 870+ return $endArray;
 871+ }
 872+
 873+ public function dropTable( $tableName, $fName = 'DatabaseOracle::dropTable' ) {
 874+ $tableName = $this->tableName($tableName);
 875+ if( !$this->tableExists( $tableName ) ) {
 876+ return false;
 877+ }
 878+
 879+ return $this->doQuery( "DROP TABLE $tableName CASCADE CONSTRAINTS PURGE" );
 880+ }
 881+
866882 function timestamp( $ts = 0 ) {
867883 return wfTimestamp( TS_ORACLE, $ts );
868884 }
@@ -910,6 +926,7 @@
911927 * Query whether a given table exists (in the given schema, or the default mw one if not given)
912928 */
913929 function tableExists( $table ) {
 930+ $table = trim($this->tableName($table), '"');
914931 $SQL = "SELECT 1 FROM user_tables WHERE table_name='$table'";
915932 $res = $this->doQuery( $SQL );
916933 if ( $res ) {
@@ -1048,7 +1065,7 @@
10491066 }
10501067 } else {
10511068 foreach ( $replacements as $mwVar => $scVar ) {
1052 - $cmd = str_replace( '&' . $scVar . '.', '{$' . $mwVar . '}', $cmd );
 1069+ $cmd = str_replace( '&' . $scVar . '.', '`{$' . $mwVar . '}`', $cmd );
10531070 }
10541071
10551072 $cmd = $this->replaceVars( $cmd );
@@ -1126,24 +1143,35 @@
11271144 return "'" . $this->strencode( $s ) . "'";
11281145 }
11291146
 1147+ public function addIdentifierQuotes( $s ) {
 1148+ if ( !$this->mFlags & DBO_DDLMODE ) {
 1149+ $s = '"' . str_replace( '"', '""', $s ) . '"';
 1150+ }
 1151+ return $s;
 1152+ }
 1153+
11301154 function selectRow( $table, $vars, $conds, $fname = 'DatabaseOracle::selectRow', $options = array(), $join_conds = array() ) {
11311155 global $wgContLang;
11321156
1133 - $conds2 = array();
1134 - $conds = ( $conds != null && !is_array( $conds ) ) ? array( $conds ) : $conds;
1135 - foreach ( $conds as $col => $val ) {
1136 - $col_info = $this->fieldInfoMulti( $table, $col );
1137 - $col_type = $col_info != false ? $col_info->type() : 'CONSTANT';
1138 - if ( $col_type == 'CLOB' ) {
1139 - $conds2['TO_CHAR(' . $col . ')'] = $wgContLang->checkTitleEncoding( $val );
1140 - } elseif ( $col_type == 'VARCHAR2' && !mb_check_encoding( $val ) ) {
1141 - $conds2[$col] = $wgContLang->checkTitleEncoding( $val );
1142 - } else {
1143 - $conds2[$col] = $val;
 1157+ if ($conds != null) {
 1158+ $conds2 = array();
 1159+ $conds = ( !is_array( $conds ) ) ? array( $conds ) : $conds;
 1160+ foreach ( $conds as $col => $val ) {
 1161+ $col_info = $this->fieldInfoMulti( $table, $col );
 1162+ $col_type = $col_info != false ? $col_info->type() : 'CONSTANT';
 1163+ if ( $col_type == 'CLOB' ) {
 1164+ $conds2['TO_CHAR(' . $col . ')'] = $wgContLang->checkTitleEncoding( $val );
 1165+ } elseif ( $col_type == 'VARCHAR2' && !mb_check_encoding( $val ) ) {
 1166+ $conds2[$col] = $wgContLang->checkTitleEncoding( $val );
 1167+ } else {
 1168+ $conds2[$col] = $val;
 1169+ }
11441170 }
 1171+
 1172+ return parent::selectRow( $table, $vars, $conds2, $fname, $options, $join_conds );
 1173+ } else {
 1174+ return parent::selectRow( $table, $vars, $conds, $fname, $options, $join_conds );
11451175 }
1146 -
1147 - return parent::selectRow( $table, $vars, $conds2, $fname, $options, $join_conds );
11481176 }
11491177
11501178 /**
@@ -1192,9 +1220,9 @@
11931221 public function delete( $table, $conds, $fname = 'DatabaseOracle::delete' ) {
11941222 global $wgContLang;
11951223
1196 - if ( $wgContLang != null && $conds != '*' ) {
 1224+ if ( $wgContLang != null && $conds != null && $conds != '*' ) {
11971225 $conds2 = array();
1198 - $conds = ( $conds != null && !is_array( $conds ) ) ? array( $conds ) : $conds;
 1226+ $conds = ( !is_array( $conds ) ) ? array( $conds ) : $conds;
11991227 foreach ( $conds as $col => $val ) {
12001228 $col_info = $this->fieldInfoMulti( $table, $col );
12011229 $col_type = $col_info != false ? $col_info->type() : 'CONSTANT';
Index: branches/REL1_17/phase3/includes/db/Database.php
@@ -540,6 +540,27 @@
541541 return new DatabaseMysql( $server, $user, $password, $dbName, $flags );
542542 }
543543
 544+ /**
 545+ * Given a DB type, construct the name of the appropriate child class of
 546+ * DatabaseBase. This is designed to replace all of the manual stuff like:
 547+ * $class = 'Database' . ucfirst( strtolower( $type ) );
 548+ * as well as validate against the canonical list of DB types we have
 549+ *
 550+ * @param $dbType String A possible DB type
 551+ * @return DatabaseBase subclass or null
 552+ */
 553+ public final static function classFromType( $dbType ) {
 554+ $canonicalDBTypes = array(
 555+ 'mysql', 'postgres', 'sqlite', 'oracle', 'mssql', 'ibm_db2'
 556+ );
 557+ $dbType = strtolower( $dbType );
 558+ if( in_array( $dbType, $canonicalDBTypes ) ) {
 559+ return 'Database' . ucfirst( $dbType );
 560+ } else {
 561+ return null;
 562+ }
 563+ }
 564+
544565 protected function installErrorHandler() {
545566 $this->mPHPError = false;
546567 $this->htmlErrors = ini_set( 'html_errors', '0' );
Property changes on: branches/REL1_17/phase3/includes/db/Database.php
___________________________________________________________________
Modified: svn:mergeinfo
547568 Merged /trunk/phase3/includes/db/Database.php:r79828,79830,79848,79853,79950-79951,79954,79989,80006-80007,80013,80016,80080,80083,80124,80128,80238
Index: branches/REL1_17/phase3/includes/db/LoadBalancer.php
@@ -625,7 +625,7 @@
626626 }
627627
628628 # Get class for this database type
629 - $class = 'Database' . ucfirst( $type );
 629+ $class = DatabaseBase::classFromType( $type );
630630
631631 # Create object
632632 wfDebug( "Connecting to $host $dbname...\n" );
Index: branches/REL1_17/phase3/includes/filerepo/ForeignDBRepo.php
@@ -35,7 +35,7 @@
3636
3737 function getMasterDB() {
3838 if ( !isset( $this->dbConn ) ) {
39 - $class = 'Database' . ucfirst( $this->dbType );
 39+ $class = DatabaseBase::classFromType( $this->dbType );
4040 $this->dbConn = new $class( $this->dbServer, $this->dbUser,
4141 $this->dbPassword, $this->dbName, $this->dbFlags,
4242 $this->tablePrefix );
Property changes on: branches/REL1_17/phase3/includes/filerepo/ForeignDBRepo.php
___________________________________________________________________
Modified: svn:mergeinfo
4343 Merged /trunk/phase3/includes/filerepo/ForeignDBRepo.php:r79828,79830,79848,79853,79950-79951,79954,79989,80006-80007,80013,80016,80080,80083,80124,80128,80238
Index: branches/REL1_17/phase3/includes/installer/CoreInstaller.php
@@ -263,7 +263,7 @@
264264 */
265265 public function setParserLanguage( $lang ) {
266266 $this->parserOptions->setTargetLanguage( $lang );
267 - $this->parserOptions->setUserLang( $lang );
 267+ $this->parserOptions->setUserLang( $lang->getCode() );
268268 }
269269
270270 /**
@@ -345,45 +345,37 @@
346346 array( 'name' => 'sysop', 'callback' => array( $this, 'createSysop' ) ),
347347 array( 'name' => 'mainpage', 'callback' => array( $this, 'createMainpage' ) ),
348348 );
 349+
 350+ // Build the array of install steps starting from the core install list,
 351+ // then adding any callbacks that wanted to attach after a given step
 352+ foreach( $coreInstallSteps as $step ) {
 353+ $this->installSteps[] = $step;
 354+ if( isset( $this->extraInstallSteps[ $step['name'] ] ) ) {
 355+ $this->installSteps = array_merge(
 356+ $this->installSteps,
 357+ $this->extraInstallSteps[ $step['name'] ]
 358+ );
 359+ }
 360+ }
 361+
 362+ // Prepend any steps that want to be at the beginning
 363+ if( isset( $this->extraInstallSteps['BEGINNING'] ) ) {
 364+ $this->installSteps = array_merge(
 365+ $this->extraInstallSteps['BEGINNING'],
 366+ $this->installSteps
 367+ );
 368+ }
 369+
 370+ // Extensions should always go first, chance to tie into hooks and such
349371 if( count( $this->getVar( '_Extensions' ) ) ) {
350 - array_unshift( $coreInstallSteps,
 372+ array_unshift( $this->installSteps,
351373 array( 'name' => 'extensions', 'callback' => array( $this, 'includeExtensions' ) )
352374 );
353375 }
354 - $this->installSteps = $coreInstallSteps;
355 - foreach( $this->extraInstallSteps as $step ) {
356 - // Put the step at the beginning
357 - if( !strval( $step['position' ] ) ) {
358 - array_unshift( $installSteps, $step['callback'] );
359 - continue;
360 - } else {
361 - // Walk the $coreInstallSteps array to see if we can modify
362 - // $this->installSteps with a callback that wants to attach after
363 - // a given step
364 - array_walk(
365 - $coreInstallSteps,
366 - array( $this, 'installStepCallback' ),
367 - $step
368 - );
369 - }
370 - }
371376 return $this->installSteps;
372377 }
373378
374379 /**
375 - * Callback for getInstallSteps() - used for finding if a given $insertableStep
376 - * should be inserted after the current $coreStep in question
377 - */
378 - private function installStepCallback( $coreStep, $key, $insertableStep ) {
379 - if( $coreStep['name'] == $insertableStep['position'] ) {
380 - $front = array_slice( $this->installSteps, 0, $key + 1 );
381 - $front[] = $insertableStep['callback'];
382 - $back = array_slice( $this->installSteps, $key + 1 );
383 - $this->installSteps = array_merge( $front, $back );
384 - }
385 - }
386 -
387 - /**
388380 * Actually perform the installation.
389381 *
390382 * @param $startCB A callback array for the beginning of each step
@@ -592,9 +584,7 @@
593585 * @param $callback Array A valid callback array, with name and callback given
594586 * @param $findStep String the step to find. Omit to put the step at the beginning
595587 */
596 - public function addInstallStep( $callback, $findStep = '' ) {
597 - $this->extraInstallSteps[] = array(
598 - 'position' => $findStep, 'callback' => $callback
599 - );
 588+ public function addInstallStep( $callback, $findStep = 'BEGINNING' ) {
 589+ $this->extraInstallSteps[$findStep][] = $callback;
600590 }
601591 }
Property changes on: branches/REL1_17/phase3/includes/installer/CoreInstaller.php
___________________________________________________________________
Modified: svn:mergeinfo
602592 Merged /trunk/phase3/includes/installer/CoreInstaller.php:r79828,79830,79848,79853,79950-79951,79954,79989,80006-80007,80013,80016,80080,80083,80124,80128,80238
Index: branches/REL1_17/phase3/includes/installer/Installer.i18n.php
@@ -229,6 +229,7 @@
230230 'config-header-oracle' => 'Oracle settings',
231231 'config-invalid-db-type' => 'Invalid database type',
232232 'config-missing-db-name' => 'You must enter a value for "Database name"',
 233+ 'config-missing-db-host' => 'You must enter a value for "Database host"',
233234 'config-missing-db-server-oracle' => 'You must enter a value for "Database TNS"',
234235 'config-invalid-db-server-oracle' => 'Invalid database TNS "$1".
235236 Use only ASCII letters (a-z, A-Z), numbers (0-9), underscores (_) and dots (.).',
@@ -450,7 +451,11 @@
451452 'config-install-pg-schema-failed' => 'Tables creation failed.
452453 Make sure that the user "$1" can write to the schema "$2".',
453454 'config-install-pg-commit' => 'Committing changes',
 455+ 'config-pg-plpgsql' => 'Checking for language PL/pgSQL',
454456 'config-pg-no-plpgsql' => 'You need to install the language PL/pgSQL in the database $1',
 457+ 'config-install-pg-ts2' => 'Checking for tsearch2',
 458+ 'config-install-pg-ts2-failed' => "'''FAILED''' tsearch2 must be installed in the database $1
 459+Please read [$2 these instructions] or ask on #postgresql on irc.freenode.net</li>\n",
455460 'config-install-user' => 'Creating database user',
456461 'config-install-user-failed' => 'Granting permission to user "$1" failed: $2',
457462 'config-install-tables' => 'Creating tables',
Index: branches/REL1_17/phase3/includes/installer/DatabaseInstaller.php
@@ -129,8 +129,8 @@
130130 return $status;
131131 }
132132
 133+ $this->db->setFlag( DBO_DDLMODE ); // For Oracle's handling of schema files
133134 $this->db->begin( __METHOD__ );
134 -
135135 $error = $this->db->sourceFile( $this->db->getSchema() );
136136 if( $error !== true ) {
137137 $this->db->reportQueryError( $error, 0, '', __METHOD__ );
Property changes on: branches/REL1_17/phase3/includes/installer/DatabaseInstaller.php
___________________________________________________________________
Modified: svn:mergeinfo
138138 Merged /trunk/phase3/includes/installer/DatabaseInstaller.php:r79828,79830,79848,79853,79950-79951,79954,79989,80006-80007,80013,80016,80080,80083,80124,80128,80238
Index: branches/REL1_17/phase3/includes/installer/MysqlInstaller.php
@@ -74,6 +74,9 @@
7575
7676 // Validate them.
7777 $status = Status::newGood();
 78+ if ( !strlen( $newValues['wgDBserver'] ) ) {
 79+ $status->fatal( 'config-missing-db-host' );
 80+ }
7881 if ( !strlen( $newValues['wgDBname'] ) ) {
7982 $status->fatal( 'config-missing-db-name' );
8083 } elseif ( !preg_match( '/^[a-z0-9_-]+$/i', $newValues['wgDBname'] ) ) {
@@ -410,7 +413,7 @@
411414 $conn = $status->value;
412415 $dbName = $this->getVar( 'wgDBname' );
413416 if( !$conn->selectDB( $dbName ) ) {
414 - $conn->query( "CREATE DATABASE `$dbName`", __METHOD__ );
 417+ $conn->query( "CREATE DATABASE " . $conn->addIdentifierQuotes( $dbName ), __METHOD__ );
415418 $conn->selectDB( $dbName );
416419 }
417420 return $status;
Index: branches/REL1_17/phase3/includes/installer/OracleInstaller.php
@@ -15,7 +15,7 @@
1616 class OracleInstaller extends DatabaseInstaller {
1717
1818 protected $globalNames = array(
19 - 'wgDBport',
 19+ 'wgDBserver',
2020 'wgDBname',
2121 'wgDBuser',
2222 'wgDBpassword',
@@ -24,9 +24,10 @@
2525
2626 protected $internalDefaults = array(
2727 '_OracleDefTS' => 'USERS',
28 - '_OracleTempTS' => 'TEMP',
29 - '_OracleUseSysdba' => true
 28+ '_OracleTempTS' => 'TEMP'
3029 );
 30+
 31+ protected $useSysDBA = false;
3132
3233 public $minimumVersion = '9.0.1'; // 9iR1
3334
@@ -92,6 +93,7 @@
9394 }
9495
9596 // Try to connect
 97+ $this->useSysDBA = true;
9698 $status = $this->getConnection();
9799 if ( !$status->isOK() ) {
98100 return $status;
@@ -110,13 +112,13 @@
111113 public function getConnection() {
112114 $status = Status::newGood();
113115 try {
114 - if ( $this->getVar( '_OracleUseSysdba' ) ) {
 116+ if ( $this->useSysDBA ) {
115117 $this->db = new DatabaseOracle(
116118 $this->getVar( 'wgDBserver' ),
117119 $this->getVar( '_InstallUser' ),
118120 $this->getVar( '_InstallPassword' ),
119121 $this->getVar( 'wgDBname' ),
120 - DBO_SYSDBA,
 122+ DBO_SYSDBA | DBO_DDLMODE,
121123 $this->getVar( 'wgDBprefix' )
122124 );
123125 } else {
@@ -147,17 +149,15 @@
148150 public function preInstall() {
149151 # Add our user callback to installSteps, right before the tables are created.
150152 $callback = array(
151 - array(
152 - 'name' => 'user',
153 - 'callback' => array( $this, 'setupUser' ),
154 - )
 153+ 'name' => 'user',
 154+ 'callback' => array( $this, 'setupUser' )
155155 );
156156 $this->parent->addInstallStepFollowing( "database", $callback );
157157 }
158158
159159
160160 public function setupDatabase() {
161 - $this->parent->setVar( '_OracleUseSysdba', false );
 161+ $this->useSysDBA = false;
162162 $status = Status::newGood();
163163 return $status;
164164 }
@@ -168,6 +168,8 @@
169169 if ( !$this->getVar( '_CreateDBAccount' ) ) {
170170 return Status::newGood();
171171 }
 172+
 173+ $this->useSysDBA = true;
172174 $status = $this->getConnection();
173175 if ( !$status->isOK() ) {
174176 return $status;
@@ -180,6 +182,7 @@
181183 */
182184 $GLOBALS['_OracleDefTS'] = $this->getVar( '_OracleDefTS' );
183185 $GLOBALS['_OracleTempTS'] = $this->getVar( '_OracleTempTS' );
 186+ $this->db->setFlag( DBO_DDLMODE );
184187 $error = $this->db->sourceFile( "$IP/maintenance/oracle/user.sql" );
185188 if ( $error !== true || !$this->db->selectDB( $this->getVar( 'wgDBuser' ) ) ) {
186189 $status->fatal( 'config-install-user-failed', $this->getVar( 'wgDBuser' ), $error );
Index: branches/REL1_17/phase3/includes/installer/PostgresInstaller.php
@@ -25,6 +25,7 @@
2626 );
2727
2828 var $minimumVersion = '8.1';
 29+ private $ts2MaxVersion = '8.3'; // Doing ts2 is not necessary in PG > 8.3
2930
3031 function getName() {
3132 return 'postgres';
@@ -80,6 +81,12 @@
8182 return $status;
8283 }
8384
 85+/* //Make sure install user can create
 86+ $status->merge( $this->canCreateAccounts() );
 87+ if ( !$status->isOK() ) {
 88+ return $status;
 89+ } */
 90+
8491 // Check version
8592 $version = $this->db->getServerVersion();
8693 if ( version_compare( $version, $this->minimumVersion ) < 0 ) {
@@ -91,7 +98,7 @@
9299 return $status;
93100 }
94101
95 - function getConnection() {
 102+ function getConnection($database = 'template1') {
96103 $status = Status::newGood();
97104
98105 try {
@@ -99,7 +106,7 @@
100107 $this->getVar( 'wgDBserver' ),
101108 $this->getVar( '_InstallUser' ),
102109 $this->getVar( '_InstallPassword' ),
103 - $this->getVar( 'wgDBname' ) );
 110+ $database );
104111 $status->value = $this->db;
105112 } catch ( DBConnectionError $e ) {
106113 $status->fatal( 'config-connection-error', $e->getMessage() );
@@ -107,13 +114,101 @@
108115 return $status;
109116 }
110117
 118+ protected function canCreateAccounts() {
 119+ $status = $this->getConnection();
 120+ if ( !$status->isOK() ) {
 121+ return false;
 122+ }
 123+ $conn = $status->value;
 124+
 125+ $superuser = $this->getVar( '_InstallUser' );
 126+
 127+ $rights = $conn->selectField( 'pg_catalog.pg_user',
 128+ 'CASE WHEN usesuper IS TRUE THEN
 129+ CASE WHEN usecreatedb IS TRUE THEN 3 ELSE 1 END
 130+ ELSE CASE WHEN usecreatedb IS TRUE THEN 2 ELSE 0 END
 131+ END AS rights',
 132+ array( 'usename' => $superuser ), __METHOD__
 133+ );
 134+
 135+ if( !$rights ) {
 136+ return false;
 137+ }
 138+
 139+ if( $rights != 1 && $rights != 3 ) {
 140+ return false;
 141+ }
 142+
 143+ return true;
 144+ }
 145+
 146+ public function getSettingsForm() {
 147+ if ( $this->canCreateAccounts() ) {
 148+ $noCreateMsg = false;
 149+ } else {
 150+ $noCreateMsg = 'config-db-web-no-create-privs';
 151+ }
 152+ $s = $this->getWebUserBox( $noCreateMsg );
 153+
 154+ return $s;
 155+ }
 156+
 157+ public function submitSettingsForm() {
 158+ $status = $this->submitWebUserBox();
 159+ if ( !$status->isOK() ) {
 160+ return $status;
 161+ }
 162+
 163+ // Validate the create checkbox
 164+ $canCreate = $this->canCreateAccounts();
 165+ if ( !$canCreate ) {
 166+ $this->setVar( '_CreateDBAccount', false );
 167+ $create = false;
 168+ } else {
 169+ $create = $this->getVar( '_CreateDBAccount' );
 170+ }
 171+
 172+ if ( !$create ) {
 173+ // Test the web account
 174+ try {
 175+ new DatabasePostgres(
 176+ $this->getVar( 'wgDBserver' ),
 177+ $this->getVar( 'wgDBuser' ),
 178+ $this->getVar( 'wgDBpassword' ),
 179+ false,
 180+ false,
 181+ 0,
 182+ $this->getVar( 'wgDBprefix' )
 183+ );
 184+ } catch ( DBConnectionError $e ) {
 185+ return Status::newFatal( 'config-connection-error', $e->getMessage() );
 186+ }
 187+ }
 188+
 189+ return Status::newGood();
 190+ }
 191+
111192 public function preInstall() {
112 - # Add our user callback to installSteps, right before the tables are created.
113 - $callback = array(
 193+ $commitCB = array(
114194 'name' => 'pg-commit',
115195 'callback' => array( $this, 'commitChanges' ),
116196 );
117 - $this->parent->addInstallStepFollowing( 'interwiki', $callback );
 197+ $userCB = array(
 198+ 'name' => 'user',
 199+ 'callback' => array( $this, 'setupUser' ),
 200+ );
 201+ $ts2CB = array(
 202+ 'name' => 'pg-ts2',
 203+ 'callback' => array( $this, 'setupTs2' ),
 204+ );
 205+ $plpgCB = array(
 206+ 'name' => 'pg-plpgsql',
 207+ 'callback' => array( $this, 'setupPLpgSQL' ),
 208+ );
 209+ $this->parent->addInstallStep( $commitCB, 'interwiki' );
 210+ $this->parent->addInstallStep( $userCB );
 211+ $this->parent->addInstallStep( $ts2CB, 'database' );
 212+ $this->parent->addInstallStep( $plpgCB, 'database' );
118213 }
119214
120215 function setupDatabase() {
@@ -123,30 +218,113 @@
124219 }
125220 $conn = $status->value;
126221
127 - // Make sure that we can write to the correct schema
128 - // If not, Postgres will happily and silently go to the next search_path item
129 - $schema = $this->getVar( 'wgDBmwschema' );
130 - $ctest = 'mediawiki_test_table';
131 - $safeschema = $conn->addIdentifierQuotes( $schema );
132 - if ( $conn->tableExists( $ctest, $schema ) ) {
133 - $conn->query( "DROP TABLE $safeschema.$ctest" );
 222+ $dbName = $this->getVar( 'wgDBname' );
 223+ $SQL = "SELECT 1 FROM pg_catalog.pg_database WHERE datname = " . $conn->addQuotes( $dbName );
 224+ $rows = $conn->numRows( $conn->query( $SQL ) );
 225+ if( !$rows ) {
 226+ $schema = $this->getVar( 'wgDBmwschema' );
 227+ $user = $this->getVar( 'wgDBuser' );
 228+
 229+ $safeschema = $conn->addIdentifierQuotes( $schema );
 230+ $safeuser = $conn->addIdentifierQuotes( $user );
 231+
 232+ $safedb = $conn->addIdentifierQuotes( $dbName );
 233+
 234+ $conn->query( "CREATE DATABASE $safedb OWNER $safeuser", __METHOD__ );
 235+
 236+ $conn = new DatabasePostgres(
 237+ $this->getVar( 'wgDBserver' ),
 238+ $this->getVar( 'wgDBuser' ),
 239+ $this->getVar( 'wgDBpassword' ),
 240+ $dbName,
 241+ false,
 242+ 0,
 243+ $this->getVar( 'wgDBprefix' )
 244+ );
 245+
 246+ $result = $conn->schemaExists( $schema );
 247+ if( !$result ) {
 248+ $result = $conn->query( "CREATE SCHEMA $safeschema AUTHORIZATION $safeuser" );
 249+ if( !$result ) {
 250+ $status->fatal( 'config-install-pg-schema-failed', $user, $schema );
 251+ }
 252+ } else {
 253+ $safeschema2 = $conn->addQuotes( $schema );
 254+ $SQL = "SELECT 'GRANT ALL ON '||pg_catalog.quote_ident(relname)||' TO $safeuser;'\n".
 255+ "FROM pg_catalog.pg_class p, pg_catalog.pg_namespace n\n" .
 256+ "WHERE relnamespace = n.oid AND n.nspname = $safeschema2\n" .
 257+ "AND p.relkind IN ('r','S','v')\n";
 258+ $SQL .= "UNION\n";
 259+ $SQL .= "SELECT 'GRANT ALL ON FUNCTION '||pg_catalog.quote_ident(proname)||'('||\n".
 260+ "pg_catalog.oidvectortypes(p.proargtypes)||') TO $safeuser;'\n" .
 261+ "FROM pg_catalog.pg_proc p, pg_catalog.pg_namespace n\n" .
 262+ "WHERE p.pronamespace = n.oid AND n.nspname = $safeschema2";
 263+ $res = $conn->query( $SQL );
 264+ $conn->query( "SET search_path = $safeschema" );
 265+ }
134266 }
135 - $res = $conn->query( "CREATE TABLE $safeschema.$ctest(a int)" );
136 - if ( !$res ) {
137 - $status->fatal( 'config-install-pg-schema-failed',
138 - $this->getVar( 'wgDBuser'), $schema );
 267+ return $status;
 268+ }
 269+
 270+ /**
 271+ * Ts2 isn't needed in newer versions of Postgres, so wrap it in a nice big
 272+ * version check and skip it if we're new. Maybe we can bump $minimumVersion
 273+ * one day and render this obsolete :)
 274+ *
 275+ * @return Status
 276+ */
 277+ function setupTs2() {
 278+ $status = $this->getConnection();
 279+ if ( !$status->isOK() ) {
 280+ return $status;
139281 }
140 - $conn->query( "DROP TABLE $safeschema.$ctest" );
141282
142 - return $status;
 283+ if( version_compare( $this->db->getServerVersion(), $this->ts2MaxVersion, '<' ) ) {
 284+ if ( !$this->db->tableExists( 'pg_ts_cfg', $this->getVar( 'wgDBts2schema' ) ) ) {
 285+ return Status::newFatal(
 286+ 'config-install-pg-ts2-failed',
 287+ $this->getVar( 'wgDBname' ),
 288+ 'http://www.devx.com/opensource/Article/21674/0/page/2'
 289+ );
 290+ }
 291+ $safeuser = $this->db->addQuotes( $this->getVar( 'wgDBuser' ) );
 292+ foreach ( array( 'cfg', 'cfgmap', 'dict', 'parser' ) as $table ) {
 293+ $sql = "GRANT SELECT ON pg_ts_$table TO $safeuser";
 294+ $this->db->query( $sql, __METHOD__ );
 295+ }
 296+ }
 297+ return Status::newGood();
143298 }
144299
145300 function commitChanges() {
146301 $this->db->query( 'COMMIT' );
147 -
148302 return Status::newGood();
149303 }
150304
 305+ function setupUser() {
 306+ if ( !$this->getVar( '_CreateDBAccount' ) ) {
 307+ return Status::newGood();
 308+ }
 309+
 310+ $status = $this->getConnection();
 311+ if ( !$status->isOK() ) {
 312+ return $status;
 313+ }
 314+
 315+ $db = $this->getVar( 'wgDBname' );
 316+ $this->db->selectDB( $db );
 317+ $safeuser = $this->db->addIdentifierQuotes( $this->getVar( 'wgDBuser' ) );
 318+ $safepass = $this->db->addQuotes( $this->getVar( 'wgDBpassword' ) );
 319+ $res = $this->db->query( "CREATE USER $safeuser NOCREATEDB PASSWORD $safepass", __METHOD__ );
 320+ return $status;
 321+
 322+ if ( $res !== true ) {
 323+ $status->fatal( 'config-install-user-failed', $this->getVar( 'wgDBuser' ) );
 324+ }
 325+
 326+ return $status;
 327+ }
 328+
151329 function getLocalSettings() {
152330 $port = $this->getVar( 'wgDBport' );
153331 $schema = $this->getVar( 'wgDBmwschema' );
@@ -167,23 +345,28 @@
168346 $wgDBpassword = $this->getVar( '_InstallPassword' );
169347 }
170348
171 - private function setupPLpgSQL() {
172 - $rows = $this->numRows(
 349+ public function setupPLpgSQL() {
 350+ $status = $this->getConnection();
 351+ if ( !$status->isOK() ) {
 352+ return $status;
 353+ }
 354+
 355+ $rows = $this->db->numRows(
173356 $this->db->query( "SELECT 1 FROM pg_catalog.pg_language WHERE lanname = 'plpgsql'" )
174357 );
175358 if ( $rows < 1 ) {
176359 // plpgsql is not installed, but if we have a pg_pltemplate table, we should be able to create it
177360 $SQL = "SELECT 1 FROM pg_catalog.pg_class c JOIN pg_catalog.pg_namespace n ON (n.oid = c.relnamespace) ".
178361 "WHERE relname = 'pg_pltemplate' AND nspname='pg_catalog'";
179 - $rows = $this->numRows( $this->db->query( $SQL ) );
180 - global $wgDBname;
 362+ $rows = $this->db->numRows( $this->db->query( $SQL ) );
 363+ $dbName = $this->getVar( 'wgDBname' );
181364 if ( $rows >= 1 ) {
182365 $result = $this->db->query( 'CREATE LANGUAGE plpgsql' );
183366 if ( !$result ) {
184 - return Status::newFatal( 'config-pg-no-plpgsql', $wgDBname );
 367+ return Status::newFatal( 'config-pg-no-plpgsql', $dbName );
185368 }
186369 } else {
187 - return Status::newFatal( 'config-pg-no-plpgsql', $wgDBname );
 370+ return Status::newFatal( 'config-pg-no-plpgsql', $dbName );
188371 }
189372 }
190373 return Status::newGood();
Index: branches/REL1_17/phase3/includes/installer/WebInstallerPage.php
@@ -300,7 +300,7 @@
301301 }
302302
303303 // Set the relevant variables from LocalSettings.php
304 - $requiredVars = array( 'wgDBtype', 'wgDBuser', 'wgDBpassword' );
 304+ $requiredVars = array( 'wgDBtype' );
305305 $status = $this->importVariables( $requiredVars , $vars );
306306 $installer = $this->parent->getDBInstaller();
307307 $status->merge( $this->importVariables( $installer->getGlobalNames(), $vars ) );
@@ -384,7 +384,7 @@
385385
386386 $dbSupport = '';
387387 foreach( $this->parent->getDBTypes() as $type ) {
388 - $db = 'Database' . ucfirst( $type );
 388+ $db = DatabaseBase::classFromType( $type );
389389 $dbSupport .= wfMsgNoTrans( "config-support-$type",
390390 call_user_func( array( $db, 'getSoftwareLink' ) ) ) . "\n";
391391 }
Property changes on: branches/REL1_17/phase3/includes/installer/WebInstallerPage.php
___________________________________________________________________
Modified: svn:mergeinfo
392392 Merged /trunk/phase3/includes/installer/WebInstallerPage.php:r79828,79830,79848,79853,79950-79951,79954,79989,80006-80007,80013,80016,80080,80083,80124,80128,80238
Index: branches/REL1_17/phase3/includes/AutoLoader.php
@@ -393,7 +393,6 @@
394394 'LoadMonitor_MySQL' => 'includes/db/LoadMonitor.php',
395395 'MySQLField' => 'includes/db/DatabaseMysql.php',
396396 'MySQLMasterPos' => 'includes/db/DatabaseMysql.php',
397 - 'ORABlob' => 'includes/db/DatabaseOracle.php',
398397 'ORAField' => 'includes/db/DatabaseOracle.php',
399398 'ORAResult' => 'includes/db/DatabaseOracle.php',
400399 'PostgresField' => 'includes/db/DatabasePostgres.php',
Property changes on: branches/REL1_17/phase3/includes/AutoLoader.php
___________________________________________________________________
Modified: svn:mergeinfo
401400 Merged /trunk/phase3/includes/AutoLoader.php:r79828,79830,79848,79853,79950-79951,79954,79989,80006-80007,80013,80016,80080,80083,80124,80128,80238
Index: branches/REL1_17/phase3/includes/extauth/MediaWiki.php
@@ -72,7 +72,7 @@
7373 private function initFromCond( $cond ) {
7474 global $wgExternalAuthConf;
7575
76 - $class = 'Database' . $wgExternalAuthConf['DBtype'];
 76+ $class = DatabaseBase::classFromType( $wgExternalAuthConf['DBtype'] );
7777 $this->mDb = new $class(
7878 $wgExternalAuthConf['DBserver'],
7979 $wgExternalAuthConf['DBuser'],
Property changes on: branches/REL1_17/phase3/includes/extauth/MediaWiki.php
___________________________________________________________________
Modified: svn:mergeinfo
8080 Merged /trunk/phase3/includes/extauth/MediaWiki.php:r79828,79830,79848,79853,79950-79951,79954,79989,80006-80007,80013,80016,80080,80083,80124,80128,80238
Index: branches/REL1_17/phase3/config/index.php
@@ -39,7 +39,7 @@
4040 }
4141 $wgLang = Language::factory( $langCode );
4242
43 - $installer->setParserLanguage( $wgLang->getCode() );
 43+ $installer->setParserLanguage( $wgLang );
4444
4545 $wgMetaNamespace = $wgCanonicalNamespaceNames[NS_PROJECT];
4646
Property changes on: branches/REL1_17/phase3
___________________________________________________________________
Modified: svn:mergeinfo
4747 Merged /trunk/phase3:r79828,79830,79848,79853,79950-79951,79954,79989,80006-80007,80013,80016,80080,80083,80124,80128,80238

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r79828Move over some initial_setup() for Postgres (THIS IS BROKEN, NEEDS REVIEW/WOR...demon18:24, 7 January 2011
r79830Forgot param 1, make URL param 2 per Nikerabbitdemon18:41, 7 January 2011
r79848Add DatabaseBase::classFromType() to reduce the 'Database' . $type duplicationdemon22:32, 7 January 2011
r79853Follow up r79848. Fix the syntax error.platonides00:46, 8 January 2011
r79950More postgres...demon19:18, 10 January 2011
r79951* fixed Oracle code for installer and phpunit tests...freakolowsky19:22, 10 January 2011
r79954* fixed oracle code for updater (corrected not null BLOB field adding) ...freakolowsky20:11, 10 January 2011
r79989I have no clue how the callbacks work, this at least sets up a database, ever...overlordq03:07, 11 January 2011
r80006Fix callback issue noted in r79989 (broken in r78774)....demon13:54, 11 January 2011
r80007Fix copy+paste mistake from r79989demon14:00, 11 January 2011
r80013Fix callbacks for the final time so it actually works per documentation....demon15:02, 11 January 2011
r80016Fix a few doQuery() -> query()demon16:02, 11 January 2011
r80080Fix for r79741, setTargetLanguage and setUserLang want an object and string, ...demon08:53, 12 January 2011
r80083(bug 26688) Proper warning message is not displayed for the blank 'Database h...demon09:59, 12 January 2011
r80124Fix undefined variable from r79828demon21:28, 12 January 2011
r80128Spaces to tabsreedy23:01, 12 January 2011
r80238* changed variable list as per comment on r79954 left only wgDBtype...freakolowsky07:05, 14 January 2011

Status & tagging log