* (bug 6023) Fixed mismatch of 0/NULL for wl_notificationtimestamp; now notification
[lhc/web/wiklou.git] / includes / Database.php
index 4ab1b98..eaecc1a 100644 (file)
@@ -5,11 +5,6 @@
  * @package MediaWiki
  */
 
-/**
- * Depends on the CacheManager
- */
-require_once( 'CacheManager.php' );
-
 /** See Database::makeList() */
 define( 'LIST_COMMA', 0 );
 define( 'LIST_AND', 1 );
@@ -91,6 +86,11 @@ class DBConnectionError extends DBError {
                return $this->getMessage() . "\n";
        }
 
+       function getLogMessage() {
+               # Don't send to the exception log
+               return false;
+       }
+
        function getPageTitle() {
                global $wgSitename;
                return "$wgSitename has a problem";
@@ -210,6 +210,11 @@ class DBQueryError extends DBError {
                }
        }
        
+       function getLogMessage() {
+               # Don't send to the exception log
+               return false;
+       }
+
        function getPageTitle() {
                return $this->msg( 'databaseerror', 'Database error' );
        }
@@ -249,6 +254,9 @@ class Database {
        protected $mTrxLevel = 0;
        protected $mErrorCount = 0;
        protected $mLBInfo = array();
+       protected $mCascadingDeletes = false;
+       protected $mCleanupTriggers = false;
+       protected $mStrictIPs = false;
 
 #------------------------------------------------------------------------------
 # Accessors
@@ -339,6 +347,28 @@ class Database {
                }
        }
 
+       /**
+        * Returns true if this database supports (and uses) cascading deletes
+        */
+       function cascadingDeletes() {
+               return $this->mCascadingDeletes;
+       }
+
+       /**
+        * Returns true if this database supports (and uses) triggers (e.g. on the page table)
+        */
+       function cleanupTriggers() {
+               return $this->mCleanupTriggers;
+       }
+
+       /**
+        * Returns true if this database is strict about what can be put into an IP field.
+        * Specifically, it uses a NULL value instead of an empty string.
+        */
+       function strictIPs() {
+               return $this->mStrictIPs;
+       }
+
        /**#@+
         * Get function
         */
@@ -438,6 +468,7 @@ class Database {
         */
        function open( $server, $user, $password, $dbName ) {
                global $wguname;
+               wfProfileIn( __METHOD__ );
 
                # Test for missing mysql.so
                # First try to load it
@@ -485,18 +516,19 @@ class Database {
                        $success = (bool)$this->mConn;
                }
 
-               if ( !$success ) {
+               if ( $success ) {
+                       global $wgDBmysql5;
+                       if( $wgDBmysql5 ) {
+                               // Tell the server we're communicating with it in UTF-8.
+                               // This may engage various charset conversions.
+                               $this->query( 'SET NAMES utf8' );
+                       }
+               } else {
                        $this->reportConnectionError();
                }
 
-               global $wgDBmysql5;
-               if( $wgDBmysql5 ) {
-                       // Tell the server we're communicating with it in UTF-8.
-                       // This may engage various charset conversions.
-                       $this->query( 'SET NAMES utf8' );
-               }
-
                $this->mOpened = $success;
+               wfProfileOut( __METHOD__ );
                return $success;
        }
        /**@}}*/
@@ -765,8 +797,8 @@ class Database {
         */
        function fetchObject( $res ) {
                @/**/$row = mysql_fetch_object( $res );
-               if( mysql_errno() ) {
-                       throw new DBUnexpectedError( $this, 'Error in fetchObject(): ' . htmlspecialchars( mysql_error() ) );
+               if( $this->lastErrno() ) {
+                       throw new DBUnexpectedError( $this, 'Error in fetchObject(): ' . htmlspecialchars( $this->lastError() ) );
                }
                return $row;
        }
@@ -777,8 +809,8 @@ class Database {
         */
        function fetchRow( $res ) {
                @/**/$row = mysql_fetch_array( $res );
-               if (mysql_errno() ) {
-                       throw new DBUnexpectedError( $this, 'Error in fetchRow(): ' . htmlspecialchars( mysql_error() ) );
+               if ( $this->lastErrno() ) {
+                       throw new DBUnexpectedError( $this, 'Error in fetchRow(): ' . htmlspecialchars( $this->lastError() ) );
                }
                return $row;
        }
@@ -788,8 +820,8 @@ class Database {
         */
        function numRows( $res ) {
                @/**/$n = mysql_num_rows( $res );
-               if( mysql_errno() ) {
-                       throw new DBUnexpectedError( $this, 'Error in numRows(): ' . htmlspecialchars( mysql_error() ) );
+               if( $this->lastErrno() ) {
+                       throw new DBUnexpectedError( $this, 'Error in numRows(): ' . htmlspecialchars( $this->lastError() ) );
                }
                return $n;
        }
@@ -1367,7 +1399,7 @@ class Database {
         * @return string slashed string.
         */
        function strencode( $s ) {
-               return addslashes( $s );
+               return mysql_real_escape_string( $s, $this->mConn );
        }
 
        /**
@@ -1859,6 +1891,10 @@ class Database {
                return $b;
        }
 
+       function decodeBlob($b) {
+               return $b;
+       }
+
        /**
         * Read and execute SQL commands from a file.
         * Returns true on success, error string on failure
@@ -1866,7 +1902,7 @@ class Database {
        function sourceFile( $filename ) {
                $fp = fopen( $filename, 'r' );
                if ( false === $fp ) {
-                       return "Could not open \"{$fname}\".\n";
+                       return "Could not open \"{$filename}\".\n";
                }
 
                $cmd = "";
@@ -1931,7 +1967,7 @@ class Database {
                // Ordinary variables
                foreach ( $varnames as $var ) {
                        if( isset( $GLOBALS[$var] ) ) {
-                               $val = addslashes( $GLOBALS[$var] );
+                               $val = addslashes( $GLOBALS[$var] ); // FIXME: safety check?
                                $ins = str_replace( '{$' . $var . '}', $val, $ins );
                                $ins = str_replace( '/*$' . $var . '*/`', '`' . $val, $ins );
                                $ins = str_replace( '/*$' . $var . '*/', $val, $ins );