From: Alexandre Emsenhuber Date: Mon, 5 Nov 2012 19:15:40 +0000 (+0100) Subject: Simplify DatabaseBase::tableName() X-Git-Tag: 1.31.0-rc.0~20950^2 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/pie.php?a=commitdiff_plain;h=f2e0870c2ffe8aa6270b2bcc1e85b2d2bf9f4f7b;p=lhc%2Fweb%2Fwiklou.git Simplify DatabaseBase::tableName() - Removed isset() check for configuration setting since they are always defined - Removed triple check whether a database is already defined by putting everything in the same place - Simplify the construction of the result string Change-Id: Iaaf68149f16b1d38a038db1b41909464f29e2289 --- diff --git a/includes/db/Database.php b/includes/db/Database.php index db050f2df5..264533ceb8 100644 --- a/includes/db/Database.php +++ b/includes/db/Database.php @@ -1983,47 +1983,39 @@ abstract class DatabaseBase implements DatabaseType { # Split database and table into proper variables. # We reverse the explode so that database.table and table both output # the correct table. - $dbDetails = array_reverse( explode( '.', $name, 2 ) ); - if ( isset( $dbDetails[1] ) ) { - list( $table, $database ) = $dbDetails; + $dbDetails = explode( '.', $name, 2 ); + if ( count( $dbDetails ) == 2 ) { + list( $database, $table ) = $dbDetails; + # We don't want any prefix added in this case + $prefix = ''; } else { list( $table ) = $dbDetails; - } - $prefix = $this->mTablePrefix; # Default prefix - - # A database name has been specified in input. We don't want any - # prefixes added. - if ( isset( $database ) ) { - $prefix = ''; + if ( $wgSharedDB !== null # We have a shared database + && !$this->isQuotedIdentifier( $table ) # Paranoia check to prevent shared tables listing '`table`' + && in_array( $table, $wgSharedTables ) # A shared table is selected + ) { + $database = $wgSharedDB; + $prefix = $wgSharedPrefix === null ? $this->mTablePrefix : $wgSharedPrefix; + } else { + $database = null; + $prefix = $this->mTablePrefix; # Default prefix + } } - # Note that we use the long format because php will complain in in_array if - # the input is not an array, and will complain in is_array if it is not set. - if ( !isset( $database ) # Don't use shared database if pre selected. - && isset( $wgSharedDB ) # We have a shared database - && !$this->isQuotedIdentifier( $table ) # Paranoia check to prevent shared tables listing '`table`' - && isset( $wgSharedTables ) - && is_array( $wgSharedTables ) - && in_array( $table, $wgSharedTables ) ) { # A shared table is selected - $database = $wgSharedDB; - $prefix = isset( $wgSharedPrefix ) ? $wgSharedPrefix : $prefix; + # Quote $table and apply the prefix if not quoted. + $tableName = "{$prefix}{$table}"; + if ( $format == 'quoted' && !$this->isQuotedIdentifier( $tableName ) ) { + $tableName = $this->addIdentifierQuotes( $tableName ); } - # Quote the $database and $table and apply the prefix if not quoted. - if ( isset( $database ) ) { + # Quote $database and merge it with the table name if needed + if ( $database !== null ) { if ( $format == 'quoted' && !$this->isQuotedIdentifier( $database ) ) { $database = $this->addIdentifierQuotes( $database ); } + $tableName = $database . '.' . $tableName; } - $table = "{$prefix}{$table}"; - if ( $format == 'quoted' && !$this->isQuotedIdentifier( $table ) ) { - $table = $this->addIdentifierQuotes( "{$table}" ); - } - - # Merge our database and table into our final table name. - $tableName = ( isset( $database ) ? "{$database}.{$table}" : "{$table}" ); - return $tableName; }