From 19c5d5e595f3a7d73c57402c831ac7aefc51c4d7 Mon Sep 17 00:00:00 2001 From: Alexandre Emsenhuber Date: Mon, 4 Jul 2011 15:00:30 +0000 Subject: [PATCH] * Removed usage of error suppression operator in includes/db * Changed an usage of $_REQUEST to $wgRequest --- includes/db/Database.php | 4 ++-- includes/db/DatabaseError.php | 6 +++--- includes/db/DatabaseIbm_db2.php | 23 +++++++++++++++++------ includes/db/DatabaseMysql.php | 21 ++++++++++++++++----- includes/db/DatabasePostgres.php | 17 +++++++++++++---- 5 files changed, 51 insertions(+), 20 deletions(-) diff --git a/includes/db/Database.php b/includes/db/Database.php index 74fe86bfe3..038332e266 100644 --- a/includes/db/Database.php +++ b/includes/db/Database.php @@ -1877,9 +1877,9 @@ abstract class DatabaseBase implements DatabaseType { # the correct table. $dbDetails = array_reverse( explode( '.', $name, 2 ) ); if ( isset( $dbDetails[1] ) ) { - @list( $table, $database ) = $dbDetails; + list( $table, $database ) = $dbDetails; } else { - @list( $table ) = $dbDetails; + list( $table ) = $dbDetails; } $prefix = $this->mTablePrefix; # Default prefix diff --git a/includes/db/DatabaseError.php b/includes/db/DatabaseError.php index 732b387921..b7fb1b2273 100644 --- a/includes/db/DatabaseError.php +++ b/includes/db/DatabaseError.php @@ -17,7 +17,7 @@ class DBError extends MWException { * @param $error String A simple error message to be used for debugging */ function __construct( DatabaseBase &$db, $error ) { - $this->db =& $db; + $this->db = $db; parent::__construct( $error ); } @@ -178,13 +178,13 @@ class DBConnectionError extends DBError { * @return string */ function searchForm() { - global $wgSitename, $wgServer; + global $wgSitename, $wgServer, $wgRequest; $usegoogle = htmlspecialchars( $this->msg( 'dberr-usegoogle', 'You can try searching via Google in the meantime.' ) ); $outofdate = htmlspecialchars( $this->msg( 'dberr-outofdate', 'Note that their indexes of our content may be out of date.' ) ); $googlesearch = htmlspecialchars( $this->msg( 'searchbutton', 'Search' ) ); - $search = htmlspecialchars( @$_REQUEST['search'] ); + $search = htmlspecialchars( $wgRequest->getVal( 'search' ) ); $server = htmlspecialchars( $wgServer ); $sitename = htmlspecialchars( $wgSitename ); diff --git a/includes/db/DatabaseIbm_db2.php b/includes/db/DatabaseIbm_db2.php index 661b8929d1..147b9d592c 100644 --- a/includes/db/DatabaseIbm_db2.php +++ b/includes/db/DatabaseIbm_db2.php @@ -379,7 +379,9 @@ class DatabaseIbm_db2 extends DatabaseBase { * Opens a cataloged database connection, sets mConn */ protected function openCataloged( $dbName, $user, $password ) { - @$this->mConn = db2_pconnect( $dbName, $user, $password ); + wfSuppressWarnings(); + $this->mConn = db2_pconnect( $dbName, $user, $password ); + wfRestoreWarnings(); } /** @@ -388,7 +390,9 @@ class DatabaseIbm_db2 extends DatabaseBase { protected function openUncataloged( $dbName, $user, $password, $server, $port ) { $dsn = "DRIVER={IBM DB2 ODBC DRIVER};DATABASE=$dbName;CHARSET=UTF-8;HOSTNAME=$server;PORT=$port;PROTOCOL=TCPIP;UID=$user;PWD=$password;"; - @$this->mConn = db2_pconnect($dsn, "", "", array()); + wfSuppressWarnings(); + $this->mConn = db2_pconnect($dsn, "", "", array()); + wfRestoreWarnings(); } /** @@ -501,7 +505,7 @@ class DatabaseIbm_db2 extends DatabaseBase { } // If the table exists, there should be one of it - @$row = $this->fetchRow( $res ); + $row = $this->fetchRow( $res ); $count = $row[0]; if ( $count == '1' || $count == 1 ) { return true; @@ -523,7 +527,9 @@ class DatabaseIbm_db2 extends DatabaseBase { if ( $res instanceof ResultWrapper ) { $res = $res->result; } - @$row = db2_fetch_object( $res ); + wfSuppressWarnings(); + $row = db2_fetch_object( $res ); + wfRestoreWarnings(); if( $this->lastErrno() ) { throw new DBUnexpectedError( $this, 'Error in fetchObject(): ' . htmlspecialchars( $this->lastError() ) ); @@ -544,7 +550,9 @@ class DatabaseIbm_db2 extends DatabaseBase { $res = $res->result; } if ( db2_num_rows( $res ) > 0) { - @$row = db2_fetch_array( $res ); + wfSuppressWarnings(); + $row = db2_fetch_array( $res ); + wfRestoreWarnings(); if ( $this->lastErrno() ) { throw new DBUnexpectedError( $this, 'Error in fetchRow(): ' . htmlspecialchars( $this->lastError() ) ); @@ -1072,7 +1080,10 @@ class DatabaseIbm_db2 extends DatabaseBase { if ( $res instanceof ResultWrapper ) { $res = $res->result; } - if ( !@db2_free_result( $res ) ) { + wfSuppressWarnings(); + $ok = db2_free_result( $res ); + wfRestoreWarnings(); + if ( !$ok ) { throw new DBUnexpectedError( $this, "Unable to free DB2 result\n" ); } } diff --git a/includes/db/DatabaseMysql.php b/includes/db/DatabaseMysql.php index d5e8d19f6b..b2aac5da14 100644 --- a/includes/db/DatabaseMysql.php +++ b/includes/db/DatabaseMysql.php @@ -95,7 +95,9 @@ class DatabaseMysql extends DatabaseBase { wfProfileOut("dbconnect-$server"); if ( $dbName != '' && $this->mConn !== false ) { - $success = @/**/mysql_select_db( $dbName, $this->mConn ); + wfSuppressWarnings(); + $success = mysql_select_db( $dbName, $this->mConn ); + wfRestoreWarnings(); if ( !$success ) { $error = "Error selecting database $dbName on server {$this->mServer} " . "from client host " . wfHostname() . "\n"; @@ -152,7 +154,10 @@ class DatabaseMysql extends DatabaseBase { if ( $res instanceof ResultWrapper ) { $res = $res->result; } - if ( !@/**/mysql_free_result( $res ) ) { + wfSuppressWarnings(); + $ok = mysql_free_result( $res ); + wfRestoreWarnings(); + if ( !$ok ) { throw new DBUnexpectedError( $this, "Unable to free MySQL result" ); } } @@ -161,7 +166,9 @@ class DatabaseMysql extends DatabaseBase { if ( $res instanceof ResultWrapper ) { $res = $res->result; } - @/**/$row = mysql_fetch_object( $res ); + wfSuppressWarnings(); + $row = mysql_fetch_object( $res ); + wfRestoreWarnings(); if( $this->lastErrno() ) { throw new DBUnexpectedError( $this, 'Error in fetchObject(): ' . htmlspecialchars( $this->lastError() ) ); } @@ -172,7 +179,9 @@ class DatabaseMysql extends DatabaseBase { if ( $res instanceof ResultWrapper ) { $res = $res->result; } - @/**/$row = mysql_fetch_array( $res ); + wfSuppressWarnings(); + $row = mysql_fetch_array( $res ); + wfRestoreWarnings(); if ( $this->lastErrno() ) { throw new DBUnexpectedError( $this, 'Error in fetchRow(): ' . htmlspecialchars( $this->lastError() ) ); } @@ -183,7 +192,9 @@ class DatabaseMysql extends DatabaseBase { if ( $res instanceof ResultWrapper ) { $res = $res->result; } - @/**/$n = mysql_num_rows( $res ); + wfSuppressWarnings(); + $n = mysql_num_rows( $res ); + wfRestoreWarnings(); if( $this->lastErrno() ) { throw new DBUnexpectedError( $this, 'Error in numRows(): ' . htmlspecialchars( $this->lastError() ) ); } diff --git a/includes/db/DatabasePostgres.php b/includes/db/DatabasePostgres.php index 74316cf567..742a8b518b 100644 --- a/includes/db/DatabasePostgres.php +++ b/includes/db/DatabasePostgres.php @@ -263,7 +263,10 @@ class DatabasePostgres extends DatabaseBase { if ( $res instanceof ResultWrapper ) { $res = $res->result; } - if ( !@pg_free_result( $res ) ) { + wfSuppressWarnings(); + $ok = pg_free_result( $res ); + wfRestoreWarnings(); + if ( !$ok ) { throw new DBUnexpectedError( $this, "Unable to free Postgres result\n" ); } } @@ -272,7 +275,9 @@ class DatabasePostgres extends DatabaseBase { if ( $res instanceof ResultWrapper ) { $res = $res->result; } - @$row = pg_fetch_object( $res ); + wfSuppressWarnings(); + $row = pg_fetch_object( $res ); + wfRestoreWarnings(); # @todo FIXME: HACK HACK HACK HACK debug # @todo hashar: not sure if the following test really trigger if the object @@ -287,7 +292,9 @@ class DatabasePostgres extends DatabaseBase { if ( $res instanceof ResultWrapper ) { $res = $res->result; } - @$row = pg_fetch_array( $res ); + wfSuppressWarnings(); + $row = pg_fetch_array( $res ); + wfRestoreWarnings(); if( pg_last_error( $this->mConn ) ) { throw new DBUnexpectedError( $this, 'SQL error: ' . htmlspecialchars( pg_last_error( $this->mConn ) ) ); } @@ -298,7 +305,9 @@ class DatabasePostgres extends DatabaseBase { if ( $res instanceof ResultWrapper ) { $res = $res->result; } - @$n = pg_num_rows( $res ); + wfSuppressWarnings(); + $n = pg_num_rows( $res ); + wfRestoreWarnings(); if( pg_last_error( $this->mConn ) ) { throw new DBUnexpectedError( $this, 'SQL error: ' . htmlspecialchars( pg_last_error( $this->mConn ) ) ); } -- 2.20.1