From: Tim Starling Date: Sun, 24 Oct 2004 07:10:33 +0000 (+0000) Subject: Correcting bugs due to double-prefixing table names. Removing obsolete Database membe... X-Git-Tag: 1.5.0alpha1~1471 X-Git-Url: http://git.cyclocoop.org/%24self?a=commitdiff_plain;h=412eda051740b525169ffca2666ab18600c56501;p=lhc%2Fweb%2Fwiklou.git Correcting bugs due to double-prefixing table names. Removing obsolete Database member functions. Adding comments to Database.php --- diff --git a/includes/Article.php b/includes/Article.php index 7e87d97408..80474304e5 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -507,7 +507,7 @@ class Article { $this->mTitle->mRestrictions = explode( ',', trim( $s->cur_restrictions ) ); $this->mTitle->mRestrictionsLoaded = true; } else { # oldid set, retrieve historical version - $s = $dbr->getArray( 'old', $this->getOldContentFields(), array( 'old_id' => $oldid ), + $s = $dbr->selectRow( 'old', $this->getOldContentFields(), array( 'old_id' => $oldid ), $fname, $this->getSelectOptions() ); if ( $s === false ) { return; @@ -698,7 +698,7 @@ class Article { $fname = 'Article::loadLastEdit'; $dbr =& $this->getDB(); - $s = $dbr->getArray( 'cur', + $s = $dbr->selectRow( 'cur', array( 'cur_user','cur_user_text','cur_timestamp', 'cur_comment','cur_minor_edit' ), array( 'cur_id' => $this->getID() ), $fname, $this->getSelectOptions() ); @@ -934,7 +934,7 @@ class Article { $isminor = ( $isminor && $wgUser->getID() ) ? 1 : 0; - $dbw->insertArray( 'cur', array( + $dbw->insert( 'cur', array( 'cur_id' => $cur_id, 'cur_namespace' => $ns, 'cur_title' => $ttl, @@ -969,7 +969,7 @@ class Article { # The talk page isn't in the regular link tables, so we need to update manually: $talkns = $ns ^ 1; # talk -> normal; normal -> talk - $dbw->updateArray( 'cur', array('cur_touched' => $dbw->timestamp($now) ), + $dbw->update( 'cur', array('cur_touched' => $dbw->timestamp($now) ), array( 'cur_namespace' => $talkns, 'cur_title' => $ttl ), $fname ); # standard deferred updates @@ -991,7 +991,7 @@ class Article { $dbw =& wfGetDB( DB_MASTER ); $ns = $this->mTitle->getNamespace(); $title = $this->mTitle->getDBkey(); - $obj = $dbw->getArray( 'old', + $obj = $dbw->selectRow( 'old', array( 'old_text','old_flags'), array( 'old_namespace' => $ns, 'old_title' => $title, 'old_timestamp' => $dbw->timestamp($edittime)), @@ -1122,7 +1122,7 @@ class Article { $won = wfInvertTimestamp( $now ); # First update the cur row - $dbw->updateArray( 'cur', + $dbw->update( 'cur', array( /* SET */ 'cur_text' => $text, 'cur_comment' => $summary, @@ -1149,7 +1149,7 @@ class Article { # This overwrites $oldtext if revision compression is on $flags = Article::compressRevisionText( $oldtext ); - $dbw->insertArray( 'old', + $dbw->insert( 'old', array( 'old_id' => $dbw->nextSequenceValue( 'old_old_id_seq' ), 'old_namespace' => $this->mTitle->getNamespace(), @@ -1374,7 +1374,7 @@ class Article { if ( $confirm ) { $dbw =& wfGetDB( DB_MASTER ); - $dbw->updateArray( 'cur', + $dbw->update( 'cur', array( /* SET */ 'cur_touched' => $dbw->timestamp(), 'cur_restrictions' => (string)$limit @@ -1510,7 +1510,7 @@ class Article { $dbr =& $this->getDB(); $ns = $this->mTitle->getNamespace(); $title = $this->mTitle->getDBkey(); - $old = $dbr->getArray( 'old', + $old = $dbr->selectRow( 'old', array( 'old_text', 'old_flags' ), array( 'old_namespace' => $ns, @@ -1525,7 +1525,7 @@ class Article { } # Fetch cur_text - $s = $dbr->getArray( 'cur', + $s = $dbr->selectRow( 'cur', array( 'cur_text' ), array( 'cur_namespace' => $ns, @@ -1764,7 +1764,7 @@ class Article { $linkID = $titleObj->getArticleID(); $brokenLinks[] = array( 'bl_from' => $linkID, 'bl_to' => $t ); } - $dbw->insertArray( 'brokenlinks', $brokenLinks, $fname, 'IGNORE' ); + $dbw->insert( 'brokenlinks', $brokenLinks, $fname, 'IGNORE' ); # Delete live links $dbw->delete( 'links', array( 'l_to' => $id ) ); @@ -1808,7 +1808,7 @@ class Article { $n = $this->mTitle->getNamespace(); # Get the last editor, lock table exclusively - $s = $dbw->getArray( 'cur', + $s = $dbw->selectRow( 'cur', array( 'cur_id','cur_user','cur_user_text','cur_comment' ), array( 'cur_title' => $tt, 'cur_namespace' => $n ), $fname, 'FOR UPDATE' @@ -1838,7 +1838,7 @@ class Article { } # Get the last edit not by this guy - $s = $dbw->getArray( 'old', + $s = $dbw->selectRow( 'old', array( 'old_text','old_user','old_user_text','old_timestamp','old_flags' ), array( 'old_namespace' => $n, @@ -1855,7 +1855,7 @@ class Article { if ( $bot ) { # Mark all reverted edits as bot - $dbw->updateArray( 'recentchanges', + $dbw->update( 'recentchanges', array( /* SET */ 'rc_bot' => 1 ), array( /* WHERE */ @@ -2029,7 +2029,7 @@ class Article { $fname = 'Article::checkTouched'; $id = $this->getID(); $dbr =& $this->getDB(); - $s = $dbr->getArray( 'cur', array( 'cur_touched', 'cur_is_redirect' ), + $s = $dbr->selectRow( 'cur', array( 'cur_touched', 'cur_is_redirect' ), array( 'cur_id' => $id ), $fname, $this->getSelectOptions() ); if( $s !== false ) { $this->mTouched = wfTimestamp(TS_MW,$s->cur_touched); @@ -2093,14 +2093,14 @@ class Article { if ( $numRows ) { # Update article $fields['cur_is_new'] = 0; - $dbw->updateArray( 'cur', $fields, array( 'cur_namespace' => $ns, 'cur_title' => $dbkey ), $fname ); + $dbw->update( 'cur', $fields, array( 'cur_namespace' => $ns, 'cur_title' => $dbkey ), $fname ); } else { # Insert new article $fields['cur_is_new'] = 1; $fields['cur_namespace'] = $ns; $fields['cur_title'] = $dbkey; $fields['cur_random'] = $rand = wfRandom(); - $dbw->insertArray( 'cur', $fields, $fname ); + $dbw->insert( 'cur', $fields, $fname ); } wfProfileOut( $fname ); } diff --git a/includes/Block.php b/includes/Block.php index 6dab0d3abf..5a85153745 100644 --- a/includes/Block.php +++ b/includes/Block.php @@ -195,7 +195,7 @@ class Block function insert() { $dbw =& wfGetDB( DB_MASTER ); - $dbw->insertArray( 'ipblocks', + $dbw->insert( 'ipblocks', array( 'ipb_address' => $this->mAddress, 'ipb_user' => $this->mUser, @@ -241,7 +241,7 @@ class Block $this->mExpiry = Block::getAutoblockExpiry( $this->mTimestamp ); $dbw =& wfGetDB( DB_MASTER ); - $dbw->updateArray( 'ipblocks', + $dbw->update( 'ipblocks', array( /* SET */ 'ipb_timestamp' => $dbw->timestamp($this->mTimestamp), 'ipb_expiry' => $dbw->timestamp($this->mExpiry), diff --git a/includes/Database.php b/includes/Database.php index 0360ee0ee0..0fcb4e9fa3 100644 --- a/includes/Database.php +++ b/includes/Database.php @@ -11,13 +11,10 @@ */ require_once( 'CacheManager.php' ); -/** @todo document */ +/** See Database::makeList() */ define( 'LIST_COMMA', 0 ); -/** @todo document */ define( 'LIST_AND', 1 ); -/** @todo document */ define( 'LIST_SET', 2 ); -/** @todo document */ define( 'LIST_NAMES', 3); /** Number of times to re-try an operation in case of deadlock */ @@ -450,7 +447,7 @@ class Database { * @param mixed $res A SQL result */ /** - * @todo document + * Free a result object */ function freeResult( $res ) { if ( !@/**/mysql_free_result( $res ) ) { @@ -459,11 +456,10 @@ class Database { } /** - * @todo FIXME: HACK HACK HACK HACK debug + * Fetch the next row from the given result object, in object form */ function fetchObject( $res ) { @/**/$row = mysql_fetch_object( $res ); - # FIXME: HACK HACK HACK HACK debug if( mysql_errno() ) { wfDebugDieBacktrace( 'Error in fetchObject(): ' . htmlspecialchars( mysql_error() ) ); } @@ -471,7 +467,8 @@ class Database { } /** - * @todo document + * Fetch the next row from the given result object + * Returns an array */ function fetchRow( $res ) { @/**/$row = mysql_fetch_array( $res ); @@ -482,7 +479,7 @@ class Database { } /** - * @todo document + * Get the number of rows in a result object */ function numRows( $res ) { @/**/$n = mysql_num_rows( $res ); @@ -493,32 +490,50 @@ class Database { } /** - * @todo document + * Get the number of fields in a result object + * See documentation for mysql_num_fields() */ function numFields( $res ) { return mysql_num_fields( $res ); } /** - * @todo document + * Get a field name in a result object + * See documentation for mysql_field_name() */ function fieldName( $res, $n ) { return mysql_field_name( $res, $n ); } + /** - * @todo document + * Get the inserted value of an auto-increment row + * + * The value inserted should be fetched from nextSequenceValue() + * + * Example: + * $id = $dbw->nextSequenceValue('cur_cur_id_seq'); + * $dbw->insert('cur',array('cur_id' => $id)); + * $id = $dbw->insertId(); */ function insertId() { return mysql_insert_id( $this->mConn ); } + /** - * @todo document + * Change the position of the cursor in a result object + * See mysql_data_seek() */ function dataSeek( $res, $row ) { return mysql_data_seek( $res, $row ); } + /** - * @todo document + * Get the last error number + * See mysql_errno() */ function lastErrno() { return mysql_errno(); } + /** - * @todo document + * Get a description of the last error + * See mysql_error() for more details */ function lastError() { return mysql_error(); } + /** - * @todo document + * Get the number of rows affected by the last write query + * See mysql_affected_rows() for more details */ function affectedRows() { return mysql_affected_rows( $this->mConn ); } /**#@-*/ // end of template : @param $result @@ -539,13 +554,6 @@ class Database { return !!$this->query( $sql, DB_MASTER, $fname ); } - /** - * @todo document - */ - function getField( $table, $var, $cond='', $fname = 'Database::getField', $options = array() ) { - return $this->selectField( $table, $var, $cond, $fname = 'Database::get', $options = array() ); - } - /** * Simple SELECT wrapper, returns a single field, input must be encoded * Usually aborts on failure @@ -632,14 +640,6 @@ class Database { } return $this->query( $sql, $fname ); } - - /** - * @todo document - */ - function getArray( $table, $vars, $conds, $fname = 'Database::getArray', $options = array() ) { - return $this->selectRow( $table, $vars, $conds, $fname, $options ); - } - /** * Single row SELECT wrapper @@ -732,7 +732,8 @@ class Database { /** - * @todo document + * Get information about an index into an object + * Returns false if the index does not exist */ function indexInfo( $table, $index, $fname = 'Database::indexInfo' ) { # SHOW INDEX works in MySQL 3.23.58, but SHOW INDEXES does not. @@ -754,8 +755,7 @@ class Database { } /** - * @param $table - * @todo document + * Query whether a given table exists */ function tableExists( $table ) { $table = $this->tableName( $table ); @@ -771,9 +771,11 @@ class Database { } /** + * mysql_fetch_field() wrapper + * Returns false if the field doesn't exist + * * @param $table * @param $field - * @todo document */ function fieldInfo( $table, $field ) { $table = $this->tableName( $table ); @@ -789,14 +791,14 @@ class Database { } /** - * @todo document + * mysql_field_type() wrapper */ function fieldType( $res, $index ) { return mysql_field_type( $res, $index ); } /** - * @todo document + * Determines if a given index is unique */ function indexUnique( $table, $index ) { $indexInfo = $this->indexInfo( $table, $index ); @@ -806,13 +808,6 @@ class Database { return !$indexInfo->Non_unique; } - /** - * @todo document - */ - function insertArray( $table, $a, $fname = 'Database::insertArray', $options = array() ) { - return $this->insert( $table, $a, $fname, $options ); - } - /** * INSERT wrapper, inserts an array into a table * @@ -859,13 +854,6 @@ class Database { return !!$this->query( $sql, $fname ); } - /** - * @todo document - */ - function updateArray( $table, $values, $conds, $fname = 'Database::updateArray' ) { - return $this->update( $table, $values, $conds, $fname ); - } - /** * UPDATE wrapper, takes a condition array and a SET array */ @@ -915,7 +903,7 @@ class Database { } /** - * @todo document + * Change the current database */ function selectDB( $db ) { $this->mDBname = $db; @@ -923,7 +911,7 @@ class Database { } /** - * @todo document + * Starts a timer which will kill the DB thread after $timeout seconds */ function startTimer( $timeout ) { global $IP; @@ -935,14 +923,23 @@ class Database { } /** - * Does nothing at all - * @todo document + * Stop a timer started by startTimer() + * Currently unimplemented. + * */ function stopTimer() { } /** + * Format a table name ready for use in constructing an SQL query + * + * This does two important things: it quotes table names which as necessary, + * and it adds a table prefix if there is one. + * + * All functions of this object which require a table name call this function + * themselves. Pass the canonical name to such functions. This is only needed + * when calling query() directly. + * * @param string $name database table name - * @todo document */ function tableName( $name ) { global $wgSharedDB; @@ -958,7 +955,13 @@ class Database { } /** - * @todo document + * Fetch a number of table names into an array + * This is handy when you need to construct SQL for joins + * + * Example: + * extract($dbr->tableNames('user','watchlist')); + * $sql = "SELECT wl_namespace,wl_title FROM $watchlist,$user + * WHERE wl_user=user_id AND wl_user=$nameWithQuotes"; */ function tableNames() { $inArray = func_get_args(); @@ -1102,8 +1105,9 @@ class Database { } /** + * DELETE query wrapper + * * Use $conds == "*" to delete all rows - * @todo document */ function delete( $table, $conds, $fname = 'Database::delete' ) { if ( !$conds ) { @@ -1136,7 +1140,8 @@ class Database { } /** - * @todo document + * Construct a LIMIT query with optional offset + * This is used for query pages */ function limitResult($limit,$offset) { return ' LIMIT '.(is_numeric($offset)?"{$offset},":"")."{$limit} "; @@ -1156,14 +1161,27 @@ class Database { } /** - * @todo document + * Determines if the last failure was due to a deadlock */ function wasDeadlock() { return $this->lastErrno() == 1213; } /** - * @todo document + * Perform a deadlock-prone transaction. + * + * This function invokes a callback function to perform a set of write + * queries. If a deadlock occurs during the processing, the transaction + * will be rolled back and the callback function will be called again. + * + * Usage: + * $dbw->deadlockLoop( callback, ... ); + * + * Extra arguments are passed through to the specified callback function. + * + * Returns whatever the callback function returned on its successful, + * iteration, or false on error, for example if the retry limit was + * reached. */ function deadlockLoop() { $myFname = 'Database::deadlockLoop'; @@ -1206,7 +1224,10 @@ class Database { /** * Do a SELECT MASTER_POS_WAIT() - * @todo document + * + * @param string $file the binlog file + * @param string $pos the binlog position + * @param integer $timeout the maximum number of seconds to wait for synchronisation */ function masterPosWait( $file, $pos, $timeout ) { $encFile = $this->strencode( $file ); diff --git a/includes/DatabaseFunctions.php b/includes/DatabaseFunctions.php index dadc751460..9904cd0144 100644 --- a/includes/DatabaseFunctions.php +++ b/includes/DatabaseFunctions.php @@ -272,7 +272,7 @@ function wfGetSQL( $table, $var, $cond='', $dbi = DB_LAST ) { $db =& wfGetDB( $dbi ); if ( $db !== false ) { - return $db->getField( $table, $var, $cond ); + return $db->selectField( $table, $var, $cond ); } else { return false; } @@ -308,7 +308,7 @@ function wfIndexExists( $table, $index, $dbi = DB_LAST ) { function wfInsertArray( $table, $array, $fname = 'wfInsertArray', $dbi = DB_MASTER ) { $db =& wfGetDB( $dbi ); if ( $db !== false ) { - return $db->insertArray( $table, $array, $fname ); + return $db->insert( $table, $array, $fname ); } else { return false; } @@ -332,7 +332,7 @@ function wfGetArray( $table, $vars, $conds, $fname = 'wfGetArray', $dbi = DB_LAS function wfUpdateArray( $table, $values, $conds, $fname = 'wfUpdateArray', $dbi = DB_MASTER ) { $db =& wfGetDB( $dbi ); if ( $db !== false ) { - $db->updateArray( $table, $values, $conds, $fname ); + $db->update( $table, $values, $conds, $fname ); return true; } else { return false; diff --git a/includes/DatabasePostgreSQL.php b/includes/DatabasePostgreSQL.php index d2b8599e04..acaf7e2242 100644 --- a/includes/DatabasePostgreSQL.php +++ b/includes/DatabasePostgreSQL.php @@ -203,7 +203,7 @@ class DatabasePgsql extends Database { return false;*/ } - function insertArray( $table, $a, $fname = 'Database::insertArray', $options = array() ) { + function insert( $table, $a, $fname = 'Database::insert', $options = array() ) { # PostgreSQL doesn't support options # We have a go at faking one of them # TODO: DELAYED, LOW_PRIORITY @@ -221,7 +221,7 @@ class DatabasePgsql extends Database { $a = array( $a ); } foreach ( $a as $row ) { - parent::insertArray( $table, $row, $fname, array() ); + parent::insert( $table, $row, $fname, array() ); } $this->ignoreErrors( $oldIgnore ); $retVal = true; @@ -263,7 +263,7 @@ class DatabasePgsql extends Database { * Return the next in a sequence, save the value for retrieval via insertId() */ function nextSequenceValue( $seqName ) { - $value = $this->getField(''," nextval('" . $seqName . "')"); + $value = $this->selectField(''," nextval('" . $seqName . "')"); $this->mInsertId = $value; return $value; } diff --git a/includes/DifferenceEngine.php b/includes/DifferenceEngine.php index c5d3e90aca..e1cfa32941 100644 --- a/includes/DifferenceEngine.php +++ b/includes/DifferenceEngine.php @@ -259,7 +259,7 @@ class DifferenceEngine { $this->mNewtitle = "{$this->mPagetitle}"; $id = $wgTitle->getArticleID(); - $s = $dbr->getArray( 'cur', array( 'cur_text', 'cur_user_text', 'cur_comment' ), + $s = $dbr->selectRow( 'cur', array( 'cur_text', 'cur_user_text', 'cur_comment' ), array( 'cur_id' => $id ), $fname ); if ( $s === false ) { wfDebug( "Unable to load cur_id $id\n" ); @@ -271,7 +271,7 @@ class DifferenceEngine { $this->mNewUser = $s->cur_user_text; $this->mNewComment = $s->cur_comment; } else { - $s = $dbr->getArray( 'old', array( 'old_namespace','old_title','old_timestamp', 'old_text', + $s = $dbr->selectRow( 'old', array( 'old_namespace','old_title','old_timestamp', 'old_text', 'old_flags','old_user_text','old_comment' ), array( 'old_id' => $this->mNewid ), $fname ); if ( $s === false ) { @@ -290,7 +290,7 @@ class DifferenceEngine { $this->mNewComment = $s->old_comment; } if ( 0 == $this->mOldid ) { - $s = $dbr->getArray( 'old', + $s = $dbr->selectRow( 'old', array( 'old_namespace','old_title','old_timestamp','old_text', 'old_flags','old_user_text','old_comment' ), array( /* WHERE */ 'old_namespace' => $this->mNewPage->getNamespace(), @@ -302,7 +302,7 @@ class DifferenceEngine { return false; } } else { - $s = $dbr->getArray( 'old', + $s = $dbr->selectRow( 'old', array( 'old_namespace','old_title','old_timestamp','old_text','old_flags','old_user_text','old_comment'), array( 'old_id' => $this->mOldid ), $fname diff --git a/includes/EditPage.php b/includes/EditPage.php index 05c6b9a551..552aaa5ca8 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -619,13 +619,13 @@ htmlspecialchars( $wgContLang->recodeForEdit( $this->textbox1 ) ) . $fname = 'EditPage::mergeChangesInto'; $oldDate = $this->edittime; $dbw =& wfGetDB( DB_MASTER ); - $obj = $dbw->getArray( 'cur', array( 'cur_text' ), array( 'cur_id' => $this->mTitle->getArticleID() ), + $obj = $dbw->selectRow( 'cur', array( 'cur_text' ), array( 'cur_id' => $this->mTitle->getArticleID() ), $fname, 'FOR UPDATE' ); $yourtext = $obj->cur_text; $ns = $this->mTitle->getNamespace(); $title = $this->mTitle->getDBkey(); - $obj = $dbw->getArray( 'old', + $obj = $dbw->selectRow( 'old', array( 'old_text','old_flags'), array( 'old_namespace' => $ns, 'old_title' => $title, 'old_timestamp' => $dbw->timestamp($oldDate)), diff --git a/includes/Image.php b/includes/Image.php index 6d5f369a1a..fcc9e6ccc1 100644 --- a/includes/Image.php +++ b/includes/Image.php @@ -660,7 +660,7 @@ function wfRecordUpload( $name, $oldver, $size, $desc, $copyStatus = "", $source # Test to see if the row exists using INSERT IGNORE # This avoids race conditions by locking the row until the commit, and also # doesn't deadlock. SELECT FOR UPDATE causes a deadlock for every race condition. - $dbw->insertArray( 'image', + $dbw->insert( 'image', array( 'img_name' => $name, 'img_size'=> $size, @@ -678,7 +678,7 @@ function wfRecordUpload( $name, $oldver, $size, $desc, $copyStatus = "", $source if ( $id == 0 ) { $seqVal = $dbw->nextSequenceValue( 'cur_cur_id_seq' ); - $dbw->insertArray( 'cur', + $dbw->insert( 'cur', array( 'cur_id' => $seqVal, 'cur_namespace' => NS_IMAGE, @@ -703,11 +703,11 @@ function wfRecordUpload( $name, $oldver, $size, $desc, $copyStatus = "", $source } else { # Collision, this is an update of an image # Get current image row for update - $s = $dbw->getArray( 'image', array( 'img_name','img_size','img_timestamp','img_description', + $s = $dbw->selectRow( 'image', array( 'img_name','img_size','img_timestamp','img_description', 'img_user','img_user_text' ), array( 'img_name' => $name ), $fname, 'FOR UPDATE' ); # Insert it into oldimage - $dbw->insertArray( 'oldimage', + $dbw->insert( 'oldimage', array( 'oi_name' => $s->img_name, 'oi_archive_name' => $oldver, @@ -720,7 +720,7 @@ function wfRecordUpload( $name, $oldver, $size, $desc, $copyStatus = "", $source ); # Update the current image row - $dbw->updateArray( 'image', + $dbw->update( 'image', array( /* SET */ 'img_size' => $size, 'img_timestamp' => $dbw->timestamp(), diff --git a/includes/ImagePage.php b/includes/ImagePage.php index 5c9f34294b..e251b9313d 100644 --- a/includes/ImagePage.php +++ b/includes/ImagePage.php @@ -343,7 +343,7 @@ class ImagePage extends Article { $oldver = wfTimestampNow() . "!{$name}"; $dbr =& wfGetDB( DB_SLAVE ); - $size = $dbr->getField( 'oldimage', 'oi_size', 'oi_archive_name=\'' . + $size = $dbr->selectField( 'oldimage', 'oi_size', 'oi_archive_name=\'' . $dbr->strencode( $oldimage ) . "'" ); if ( ! rename( $curfile, "${archive}/{$oldver}" ) ) { diff --git a/includes/LinkCache.php b/includes/LinkCache.php index 9da6807671..b4bb7576eb 100644 --- a/includes/LinkCache.php +++ b/includes/LinkCache.php @@ -147,7 +147,7 @@ class LinkCache { $options = array(); } - $id = $db->getField( 'cur', 'cur_id', array( 'cur_namespace' => $ns, 'cur_title' => $t ), $fname, $options ); + $id = $db->selectField( 'cur', 'cur_id', array( 'cur_namespace' => $ns, 'cur_title' => $t ), $fname, $options ); if ( !$id ) { $id = 0; } @@ -304,7 +304,7 @@ class LinkCache { $db =& wfGetDB( DB_SLAVE ); $options = ''; } - $raw = $db->getField( 'linkscc', 'lcc_cacheobj', array( 'lcc_pageid' => $id ), $fname, $options ); + $raw = $db->selectField( 'linkscc', 'lcc_cacheobj', array( 'lcc_pageid' => $id ), $fname, $options ); if ( $raw === false ) { return false; } diff --git a/includes/LinksUpdate.php b/includes/LinksUpdate.php index 3db1577ae6..83ac56967e 100644 --- a/includes/LinksUpdate.php +++ b/includes/LinksUpdate.php @@ -76,7 +76,7 @@ class LinksUpdate { # The link cache was constructed without FOR UPDATE, so there may be collisions # Ignoring for now, I'm not sure if that causes problems or not, but I'm fairly # sure it's better than without IGNORE - $dbw->insertArray('links', $arr, $fname, array('IGNORE')); + $dbw->insert('links', $arr, $fname, array('IGNORE')); } #------------------------------------------------------------------------------ @@ -116,7 +116,7 @@ class LinksUpdate { 'bl_from'=>$this->mId, 'bl_to'=>$blt)); } - $dbw->insertArray( 'brokenlinks',$arr,$fname,array('IGNORE')); + $dbw->insert( 'brokenlinks',$arr,$fname,array('IGNORE')); } #------------------------------------------------------------------------------ @@ -141,7 +141,7 @@ class LinksUpdate { 'il_from'=>$this->mId, 'il_to'=>$iname)); } - $dbw->insertArray($imagelinks, $arr, $fname, array('IGNORE')); + $dbw->insert('imagelinks', $arr, $fname, array('IGNORE')); } #------------------------------------------------------------------------------ @@ -166,7 +166,7 @@ class LinksUpdate { 'cl_to'=>$dbw->strencode( $cname ), 'cl_sortkey'=>$dbw->strencode( $sortkey ))); } - $dbw->insertArray($categorylinks,$arr,$fname,array('IGNORE')); + $dbw->insert('categorylinks',$arr,$fname,array('IGNORE')); } } @@ -204,7 +204,7 @@ class LinksUpdate { 'l_from'=>$this->mId, 'l_to'=>$lid)); } - $dbw->insertArray($links,$arr,$fname,array('IGNORE')); + $dbw->insert('links',$arr,$fname,array('IGNORE')); } $sql = "DELETE FROM $brokenlinks WHERE bl_from={$this->mId}"; @@ -219,7 +219,7 @@ class LinksUpdate { 'bl_from'=>$this->mId, 'bl_to'=>$blt)); } - $dbw->insertArray($brokenlinks,$arr,$fname,array('IGNORE')); + $dbw->insert('brokenlinks',$arr,$fname,array('IGNORE')); } $sql = "DELETE FROM $imagelinks WHERE il_from={$this->mId}"; @@ -233,7 +233,7 @@ class LinksUpdate { array_push($arr,array( 'il_from'=>$this->mId, 'il_to'=>$dbw->strencode( $iname ))); - $dbw->insertArray($imagelinks,$arr,$fname,array('IGNORE')); + $dbw->insert('imagelinks',$arr,$fname,array('IGNORE')); } if( $wgUseCategoryMagic ) { @@ -257,7 +257,7 @@ class LinksUpdate { 'cl_to'=>$dbw->strencode( $cname ), 'cl_sortkey'=>$dbw->strencode( $sortkey ))); } - $dbw->insertArray($categorylinks,$arr,$fname,array('IGNORE')); + $dbw->insert('categorylinks',$arr,$fname,array('IGNORE')); } } $this->fixBrokenLinks(); @@ -279,8 +279,6 @@ class LinksUpdate { $fname, 'FOR UPDATE' ); if ( 0 == $dbw->numRows( $res ) ) { return; } - # Ignore errors. If a link existed in both the brokenlinks table and the links - # table, that's an error which can be fixed at this stage by simply ignoring collisions $arr=array(); $now = $dbw->timestamp(); $sql2 = "UPDATE $cur SET cur_touched='{$now}' WHERE cur_id IN ("; @@ -292,7 +290,10 @@ class LinksUpdate { $sql2 .= $row->bl_from; } $sql2 .= ')'; - $dbw->insertArray($links,$arr,$fname,array('IGNORE')); + + # Ignore errors. If a link existed in both the brokenlinks table and the links + # table, that's an error which can be fixed at this stage by simply ignoring collisions + $dbw->insert('links',$arr,$fname,array('IGNORE')); $dbw->query( $sql2, $fname ); $dbw->delete( 'brokenlinks', array( 'bl_to' => $this->mTitle ), $fname ); } diff --git a/includes/LogPage.php b/includes/LogPage.php index 3f7fb0bf1a..1923048e68 100644 --- a/includes/LogPage.php +++ b/includes/LogPage.php @@ -51,7 +51,7 @@ class LogPage { $uid = $wgUser->getID(); $this->timestamp = $now = wfTimestampNow(); - $dbw->insertArray( 'logging', + $dbw->insert( 'logging', array( 'log_type' => $this->type, 'log_action' => $this->action, diff --git a/includes/Math.php b/includes/Math.php index 1f1ff1c2cf..bfe6da1dc2 100644 --- a/includes/Math.php +++ b/includes/Math.php @@ -156,7 +156,7 @@ class MathRenderer { $this->md5 = md5( $this->tex ); $dbr =& wfGetDB( DB_SLAVE ); - $rpage = $dbr->getArray( 'math', + $rpage = $dbr->selectRow( 'math', array( 'math_outputhash','math_html_conservativeness','math_html','math_mathml' ), array( 'math_inputhash' => pack("H32", $this->md5)), # Binary packed, not hex $fname diff --git a/includes/MessageCache.php b/includes/MessageCache.php index eb56bf1b9c..365a857c36 100755 --- a/includes/MessageCache.php +++ b/includes/MessageCache.php @@ -244,7 +244,7 @@ class MessageCache # If it wasn't in the cache, load each message from the DB individually if ( !$message ) { $dbr =& wfGetDB( DB_SLAVE ); - $result = $dbr->getArray( 'cur', array('cur_text'), + $result = $dbr->selectRow( 'cur', array('cur_text'), array( 'cur_namespace' => NS_MEDIAWIKI, 'cur_title' => $title ), 'MessageCache::get' ); if ( $result ) { diff --git a/includes/Parser.php b/includes/Parser.php index 80dd1a7834..42c85acab5 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -3129,7 +3129,7 @@ function wfLoadSiteStats() { if ( -1 != $wgNumberOfArticles ) return; $dbr =& wfGetDB( DB_SLAVE ); - $s = $dbr->getArray( 'site_stats', + $s = $dbr->selectRow( 'site_stats', array( 'ss_total_views', 'ss_total_edits', 'ss_good_articles' ), array( 'ss_row_id' => 1 ), $fname ); diff --git a/includes/Profiling.php b/includes/Profiling.php index cf0cc4201d..6928aab9a6 100755 --- a/includes/Profiling.php +++ b/includes/Profiling.php @@ -189,7 +189,7 @@ class Profiler $rc = $dbw->affectedRows(); if( $rc == 0) { - $dbw->insertArray($profiling,array( + $dbw->insert('profiling',array( 'pf_name'=>$name, 'pf_count'=>$eventCount, 'pf_time'=>$timeSum), diff --git a/includes/RecentChange.php b/includes/RecentChange.php index 1dba1ea679..7b96bbd5f7 100644 --- a/includes/RecentChange.php +++ b/includes/RecentChange.php @@ -114,7 +114,7 @@ class RecentChange $this->mAttribs['rc_cur_time']=$dbw->timestamp($this->mAttribs['rc_cur_time']); # Insert new row - $dbw->insertArray( 'recentchanges', $this->mAttribs, $fname ); + $dbw->insert( 'recentchanges', $this->mAttribs, $fname ); # Update old rows, if necessary if ( $this->mAttribs['rc_type'] == RC_EDIT ) { @@ -126,7 +126,7 @@ class RecentChange $curId = $this->mAttribs['rc_cur_id']; # Update rc_this_oldid for the entries which were current - $dbw->updateArray( 'recentchanges', + $dbw->update( 'recentchanges', array( /* SET */ 'rc_this_oldid' => $oldid ), array( /* WHERE */ @@ -137,7 +137,7 @@ class RecentChange ); # Update rc_cur_time - $dbw->updateArray( 'recentchanges', array( 'rc_cur_time' => $now ), + $dbw->update( 'recentchanges', array( 'rc_cur_time' => $now ), array( 'rc_cur_id' => $curId ), $fname ); } @@ -159,7 +159,7 @@ class RecentChange $dbw =& wfGetDB( DB_MASTER ); - $dbw->updateArray( 'recentchanges', + $dbw->update( 'recentchanges', array( /* SET */ 'rc_patrolled' => 1 ), array( /* WHERE */ diff --git a/includes/SearchUpdate.php b/includes/SearchUpdate.php index e50429b22f..859cccc4f1 100644 --- a/includes/SearchUpdate.php +++ b/includes/SearchUpdate.php @@ -105,12 +105,12 @@ class SearchUpdate { # Strip wiki '' and ''' $text = preg_replace( "/''[']*/", " ", $text ); wfProfileOut( "$fname-regexps" ); - $db->replace( $searchindex, array(array('si_page')), - array( - 'si_page' => $this->mId, - 'si_title' => $db->strencode( Title::indexTitle( $this->mNamespace, $this->mTitle ) ), - 'si_text' => $db->strencode( $text ) - ), 'SearchUpdate::doUpdate' ); + $db->replace( 'searchindex', array(array('si_page')), + array( + 'si_page' => $this->mId, + 'si_title' => $db->strencode( Title::indexTitle( $this->mNamespace, $this->mTitle ) ), + 'si_text' => $db->strencode( $text ) + ), 'SearchUpdate::doUpdate' ); wfProfileOut( $fname ); } } diff --git a/includes/SpecialUndelete.php b/includes/SpecialUndelete.php index 02527604d8..d450960895 100644 --- a/includes/SpecialUndelete.php +++ b/includes/SpecialUndelete.php @@ -168,7 +168,7 @@ class PageArchive { $redir = $redirect->matchStart( $text ) ? 1 : 0; $rand = wfRandom(); - $dbw->insertArray( 'cur', array( + $dbw->insert( 'cur', array( 'cur_id' => $dbw->nextSequenceValue( 'cur_cur_id_seq' ), 'cur_namespace' => $namespace, 'cur_title' => $ttl, diff --git a/includes/Title.php b/includes/Title.php index dd2fd81e37..c8ece2a8ad 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -157,7 +157,7 @@ class Title { /* static */ function newFromID( $id ) { $fname = 'Title::newFromID'; $dbr =& wfGetDB( DB_SLAVE ); - $row = $dbr->getArray( 'cur', array( 'cur_namespace', 'cur_title' ), + $row = $dbr->selectRow( 'cur', array( 'cur_namespace', 'cur_title' ), array( 'cur_id' => $id ), $fname ); if ( $row !== false ) { $title = Title::makeTitle( $row->cur_namespace, $row->cur_title ); @@ -265,7 +265,7 @@ class Title { $fname = 'Title::nameOf'; $dbr =& wfGetDB( DB_SLAVE ); - $s = $dbr->getArray( 'cur', array( 'cur_namespace','cur_title' ), array( 'cur_id' => $id ), $fname ); + $s = $dbr->selectRow( 'cur', array( 'cur_namespace','cur_title' ), array( 'cur_id' => $id ), $fname ); if ( $s === false ) { return NULL; } $n = Title::makeName( $s->cur_namespace, $s->cur_title ); @@ -851,7 +851,7 @@ class Title { if ( ! $this->mRestrictionsLoaded ) { $dbr =& wfGetDB( DB_SLAVE ); - $res = $dbr->getField( 'cur', 'cur_restrictions', 'cur_id='.$id ); + $res = $dbr->selectField( 'cur', 'cur_restrictions', 'cur_id='.$id ); $this->mRestrictions = explode( ',', trim( $res ) ); $this->mRestrictionsLoaded = true; } @@ -866,7 +866,7 @@ class Title { function isDeleted() { $fname = 'Title::isDeleted'; $dbr =& wfGetDB( DB_SLAVE ); - $n = $dbr->getField( 'archive', 'COUNT(*)', array( 'ar_namespace' => $this->getNamespace(), + $n = $dbr->selectField( 'archive', 'COUNT(*)', array( 'ar_namespace' => $this->getNamespace(), 'ar_title' => $this->getDBkey() ), $fname ); return (int)$n; } @@ -923,7 +923,7 @@ class Title { function invalidateCache() { $now = wfTimestampNow(); $dbw =& wfGetDB( DB_MASTER ); - $success = $dbw->updateArray( 'cur', + $success = $dbw->update( 'cur', array( /* SET */ 'cur_touched' => $dbw->timestamp() ), array( /* WHERE */ @@ -1312,7 +1312,7 @@ class Title { $links = $dbw->tableName( 'links' ); # Change the name of the target page: - $dbw->updateArray( 'cur', + $dbw->update( 'cur', /* SET */ array( 'cur_touched' => $dbw->timestamp($now), 'cur_namespace' => $nt->getNamespace(), @@ -1327,7 +1327,7 @@ class Title { # by definition if we've got here it's rather uninteresting. $redirectText = $wgMwRedir->getSynonym( 0 ) . ' [[' . $nt->getPrefixedText() . "]]\n"; - $dbw->updateArray( 'cur', + $dbw->update( 'cur', /* SET */ array( 'cur_touched' => $dbw->timestamp($now), 'cur_timestamp' => $dbw->timestamp($now), @@ -1352,7 +1352,7 @@ class Title { # Fix the redundant names for the past revisions of the target page. # The redirect should have no old revisions. - $dbw->updateArray( + $dbw->update( /* table */ 'old', /* SET */ array( 'old_namespace' => $nt->getNamespace(), @@ -1410,7 +1410,7 @@ class Title { # Now, we record the link from the redirect to the new title. # It should have no other outgoing links... $dbw->delete( 'links', array( 'l_from' => $newid ) ); - $dbw->insertArray( 'links', array( 'l_from' => $newid, 'l_to' => $oldid ) ); + $dbw->insert( 'links', array( 'l_from' => $newid, 'l_to' => $oldid ) ); # Clear linkscc LinkCache::linksccClearLinksTo( $oldid ); @@ -1444,7 +1444,7 @@ class Title { $rand = wfRandom(); # Rename cur entry - $dbw->updateArray( 'cur', + $dbw->update( 'cur', /* SET */ array( 'cur_touched' => $now, 'cur_namespace' => $nt->getNamespace(), @@ -1457,7 +1457,7 @@ class Title { $wgLinkCache->clearLink( $nt->getPrefixedDBkey() ); # Insert redirect - $dbw->insertArray( 'cur', array( + $dbw->insert( 'cur', array( 'cur_id' => $dbw->nextSequenceValue('cur_cur_id_seq'), 'cur_namespace' => $this->getNamespace(), 'cur_title' => $this->getDBkey(), @@ -1476,7 +1476,7 @@ class Title { $wgLinkCache->clearLink( $this->getPrefixedDBkey() ); # Rename old entries - $dbw->updateArray( + $dbw->update( /* table */ 'old', /* SET */ array( 'old_namespace' => $nt->getNamespace(), @@ -1495,11 +1495,11 @@ class Title { Article::onArticleCreate( $nt ); # Any text links to the old title must be reassigned to the redirect - $dbw->updateArray( 'links', array( 'l_to' => $newid ), array( 'l_to' => $oldid ), $fname ); + $dbw->update( 'links', array( 'l_to' => $newid ), array( 'l_to' => $oldid ), $fname ); LinkCache::linksccClearLinksTo( $oldid ); # Record the just-created redirect's linking to the page - $dbw->insertArray( 'links', array( 'l_from' => $newid, 'l_to' => $oldid ), $fname ); + $dbw->insert( 'links', array( 'l_from' => $newid, 'l_to' => $oldid ), $fname ); # Non-existent target may have had broken links to it; these must # now be removed and made into good links. @@ -1532,7 +1532,7 @@ class Title { # Is it a redirect? $id = $nt->getArticleID(); - $obj = $dbw->getArray( 'cur', array( 'cur_is_redirect','cur_text' ), + $obj = $dbw->selectRow( 'cur', array( 'cur_is_redirect','cur_text' ), array( 'cur_id' => $id ), $fname, 'FOR UPDATE' ); if ( !$obj || 0 == $obj->cur_is_redirect ) { @@ -1550,7 +1550,7 @@ class Title { } # Does the article have a history? - $row = $dbw->getArray( 'old', array( 'old_id' ), + $row = $dbw->selectRow( 'old', array( 'old_id' ), array( 'old_namespace' => $nt->getNamespace(), 'old_title' => $nt->getDBkey() @@ -1582,7 +1582,7 @@ class Title { $won = wfInvertTimestamp( $now ); $seqVal = $dbw->nextSequenceValue( 'cur_cur_id_seq' ); - $dbw->insertArray( 'cur', array( + $dbw->insert( 'cur', array( 'cur_id' => $seqVal, 'cur_namespace' => $this->getNamespace(), 'cur_title' => $this->getDBkey(), @@ -1601,14 +1601,14 @@ class Title { # Link table if ( $dest->getArticleID() ) { - $dbw->insertArray( 'links', + $dbw->insert( 'links', array( 'l_to' => $dest->getArticleID(), 'l_from' => $newid ), $fname ); } else { - $dbw->insertArray( 'brokenlinks', + $dbw->insert( 'brokenlinks', array( 'bl_to' => $dest->getPrefixedDBkey(), 'bl_from' => $newid diff --git a/maintenance/rebuildInterwiki.inc b/maintenance/rebuildInterwiki.inc index 0f1f75bef5..e102bb07d9 100644 --- a/maintenance/rebuildInterwiki.inc +++ b/maintenance/rebuildInterwiki.inc @@ -80,7 +80,7 @@ function getRebuildInterwikiSQL() { # Extract the intermap from meta $dbr =& wfGetDB( DB_WRITE ); - $row = $dbr->getArray( "metawiki.cur", array( "cur_text" ), + $row = $dbr->selectRow( "metawiki.cur", array( "cur_text" ), array( "cur_namespace" => 0, "cur_title" => "Interwiki_map" ) ); if ( !$row ) { diff --git a/texvc.phtml b/texvc.phtml index 108dcbda63..7f427d8916 100644 --- a/texvc.phtml +++ b/texvc.phtml @@ -42,7 +42,7 @@ function texvc_cgi_renderMath( $tex ) $md5_sql = pack("H32", $md5); $mathTable = $dbr->tableName( 'math' ); - $rpage = $dbr->getArray( 'math', array('math_outputhash','math_html_conservativeness','math_html','math_mathml'), + $rpage = $dbr->selectRow( 'math', array('math_outputhash','math_html_conservativeness','math_html','math_mathml'), array( 'math_inputhash' => $md5_sql ) ); if ( $rpage === false ) @@ -114,7 +114,7 @@ function texvc_cgi_renderMath( $tex ) # Someone may have inserted the same hash since the SELECT, but that's no big deal, just ignore errors $dbw =& wfGetDB( DB_MASTER ); - $dbw->insertArray( 'math', + $dbw->insert( 'math', array( 'math_inputhash' => $md5_sql, 'math_outputhash' => $outmd5_sql, @@ -126,7 +126,6 @@ function texvc_cgi_renderMath( $tex ) // we don't really care if it fails } else { - $rpage = $dbr->fetchObject ( $res ); $outmd5 = unpack ("H32md5", $rpage->math_outputhash); $outmd5 = $outmd5 ['md5']; $outhtml = $rpage->math_html;