Handle multiple warnings correctly in ApiBase::setWarning(). Calling this function...
[lhc/web/wiklou.git] / includes / Database.php
index 001b044..84b6b26 100644 (file)
@@ -1,5 +1,9 @@
 <?php
 /**
+ * @defgroup Database Database
+ *
+ * @file
+ * @ingroup Database
  * This file deals with MySQL interface functions
  * and query specifics/optimisations
  */
@@ -13,7 +17,7 @@ define( 'DEADLOCK_DELAY_MAX', 1500000 );
 
 /**
  * Database abstraction object
- * @addtogroup Database
+ * @ingroup Database
  */
 class Database {
 
@@ -226,6 +230,14 @@ class Database {
                return $this->$name;
        }
 
+       function getWikiID() {
+               if( $this->mTablePrefix ) {
+                       return "{$this->mDBname}-{$this->mTablePrefix}";
+               } else {
+                       return $this->mDBname;
+               }
+       }
+
 #------------------------------------------------------------------------------
 # Other functions
 #------------------------------------------------------------------------------
@@ -937,6 +949,24 @@ class Database {
         */
        function select( $table, $vars, $conds='', $fname = 'Database::select', $options = array(), $join_conds = array() )
        {
+               $sql = $this->selectSQLText( $table, $vars, $conds, $fname, $options, $join_conds );
+               return $this->query( $sql, $fname );
+       }
+       
+       /**
+        * SELECT wrapper
+        *
+        * @param mixed  $table   Array or string, table name(s) (prefix auto-added)
+        * @param mixed  $vars    Array or string, field name(s) to be retrieved
+        * @param mixed  $conds   Array or string, condition(s) for WHERE
+        * @param string $fname   Calling function name (use __METHOD__) for logs/profiling
+        * @param array  $options Associative array of options (e.g. array('GROUP BY' => 'page_title')),
+        *                        see Database::makeSelectOptions code for list of supported stuff
+        * @param array $join_conds Associative array of table join conditions (optional)
+        *                        (e.g. array( 'page' => array('LEFT JOIN','page_latest=rev_id') )
+        * @return string, the SQL text
+        */
+       function selectSQLText( $table, $vars, $conds='', $fname = 'Database::select', $options = array(), $join_conds = array() ) {
                if( is_array( $vars ) ) {
                        $vars = implode( ',', $vars );
                }
@@ -977,7 +1007,7 @@ class Database {
                if (isset($options['EXPLAIN'])) {
                        $sql = 'EXPLAIN ' . $sql;
                }
-               return $this->query( $sql, $fname );
+               return $sql;
        }
 
        /**
@@ -994,9 +1024,9 @@ class Database {
         *
         * @todo migrate documentation to phpdocumentor format
         */
-       function selectRow( $table, $vars, $conds, $fname = 'Database::selectRow', $options = array() ) {
+       function selectRow( $table, $vars, $conds, $fname = 'Database::selectRow', $options = array(), $join_conds = array() ) {
                $options['LIMIT'] = 1;
-               $res = $this->select( $table, $vars, $conds, $fname, $options );
+               $res = $this->select( $table, $vars, $conds, $fname, $options, $join_conds );
                if ( $res === false )
                        return false;
                if ( !$this->numRows($res) ) {
@@ -2192,7 +2222,7 @@ class Database {
  * Database abstraction object for mySQL
  * Inherit all methods and properties of Database::Database()
  *
- * @addtogroup Database
+ * @ingroup Database
  * @see Database
  */
 class DatabaseMysql extends Database {
@@ -2205,7 +2235,7 @@ class DatabaseMysql extends Database {
 
 /**
  * Utility class.
- * @addtogroup Database
+ * @ingroup Database
  */
 class DBObject {
        public $mData;
@@ -2225,7 +2255,7 @@ class DBObject {
 
 /**
  * Utility class
- * @addtogroup Database
+ * @ingroup Database
  *
  * This allows us to distinguish a blob from a normal string and an array of strings
  */
@@ -2241,7 +2271,7 @@ class Blob {
 
 /**
  * Utility class.
- * @addtogroup Database
+ * @ingroup Database
  */
 class MySQLField {
        private $name, $tablename, $default, $max_length, $nullable,
@@ -2298,7 +2328,7 @@ class MySQLField {
 
 /**
  * Database error base class
- * @addtogroup Database
+ * @ingroup Database
  */
 class DBError extends MWException {
        public $db;
@@ -2315,7 +2345,7 @@ class DBError extends MWException {
 }
 
 /**
- * @addtogroup Database
+ * @ingroup Database
  */
 class DBConnectionError extends DBError {
        public $error;
@@ -2435,7 +2465,7 @@ border=\"0\" ALT=\"Google\"></A>
 }
 
 /**
- * @addtogroup Database
+ * @ingroup Database
  */
 class DBQueryError extends DBError {
        public $error, $errno, $sql, $fname;
@@ -2491,14 +2521,14 @@ class DBQueryError extends DBError {
 }
 
 /**
- * @addtogroup Database
+ * @ingroup Database
  */
 class DBUnexpectedError extends DBError {}
 
 
 /**
  * Result wrapper for grabbing data queried by someone else
- * @addtogroup Database
+ * @ingroup Database
  */
 class ResultWrapper implements Iterator {
        var $db, $result, $pos = 0, $currentRow = null;