r26253 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r26252‎ | r26253 | r26254 >
Date:16:38, 30 September 2007
Author:erik
Status:old
Tags:
Comment:
support table prefixes
Modified paths:
  • /branches/liquidthreads/extensions/LqtModel.php (modified) (history)

Diff [purge]

Index: branches/liquidthreads/extensions/LqtModel.php
@@ -818,11 +818,16 @@
819819 }
820820
821821 static function where( $where, $options = array(), $extra_tables = array(), $joins = "" ) {
 822+ global $wgDBprefix;
822823 $dbr = wfGetDB( DB_SLAVE );
823824 if ( is_array($where) ) $where = $dbr->makeList( $where, LIST_AND );
824825 if ( is_array($options) ) $options = implode(',', $options);
825826
826827 if( is_array($extra_tables) && count($extra_tables) != 0 ) {
 828+ if(!empty($wgDBprefix)) {
 829+ foreach($extra_tables as $tablekey=>$extra_table)
 830+ $extra_tables[$tablekey]=$wgDBprefix.$extra_table;
 831+ }
827832 $tables = implode(',', $extra_tables) . ', ';
828833 } else if ( is_string( $extra_tables ) ) {
829834 $tables = $extra_tables . ', ';
@@ -840,7 +845,7 @@
841846 $root_test = str_replace( 'thread.', 'children.', $where ); // TODO fragile?
842847
843848 $sql = <<< SQL
844 -SELECT DISTINCT children.*, child_page.*, ($root_test) as is_root FROM ($tables thread, thread children, page child_page) $joins
 849+SELECT DISTINCT children.*, child_page.*, ($root_test) as is_root FROM ($tables {$wgDBprefix}thread thread, {$wgDBprefix}thread children, {$wgDBprefix}page child_page) $joins
845850 WHERE $where
846851 AND children.thread_path LIKE CONCAT(thread.thread_path, "%")
847852 AND child_page.page_id = children.thread_root
@@ -997,6 +1002,7 @@
9981003 }
9991004
10001005 private static function writeUserMessageState($thread, $user, $timestamp) {
 1006+ global $wgDBprefix;
10011007 if( is_object($thread) ) $thread_id = $thread->id();
10021008 else if( is_integer($thread) ) $thread_id = $thread;
10031009 else throw new MWException("writeUserMessageState expected Thread or integer but got $thread");
@@ -1009,18 +1015,19 @@
10101016
10111017 // use query() directly to pass in 'true' for don't-die-on-errors.
10121018 $dbr =& wfGetDB( DB_MASTER );
1013 - $success = $dbr->query("insert into user_message_state values ($user_id, $thread_id, $timestamp)",
 1019+ $success = $dbr->query("insert into {$wgDBprefix}user_message_state values ($user_id, $thread_id, $timestamp)",
10141020 __METHOD__, true);
10151021
10161022 if( !$success ) {
10171023 // duplicate key; update.
1018 - $dbr->query("update user_message_state set ums_read_timestamp = $timestamp" .
 1024+ $dbr->query("update {$wgDBprefix}user_message_state set ums_read_timestamp = $timestamp" .
10191025 " where ums_thread = $thread_id and ums_user = $user_id",
10201026 __METHOD__);
10211027 }
10221028 }
10231029
10241030 static function writeMessageStateForUpdatedThread($t) {
 1031+ global $wgDBprefix;
10251032 // retrieve all users who are watching t.
10261033 // write a ums for each one.
10271034
@@ -1039,15 +1046,16 @@
10401047
10411048 // it sucks to not have 'on duplicate key update'. first update users who already have a ums for this thread
10421049 // and who have already read it, by setting their state to unread.
1043 - $dbw->query("update user_message_state, watchlist set ums_read_timestamp = null where ums_user = wl_user and ums_thread = {$t->id()} and $where_clause");
 1050+ $dbw->query("update {$wgDBprefix}user_message_state, {$wgDBprefix}watchlist set ums_read_timestamp = null where ums_user = wl_user and ums_thread = {$t->id()} and $where_clause");
10441051
1045 - $dbw->query("insert ignore into user_message_state (ums_user, ums_thread) select user_id, {$t->id()} from user, watchlist where user_id = wl_user and $where_clause;");
 1052+ $dbw->query("insert ignore into {$wgDBprefix}user_message_state (ums_user, ums_thread) select user_id, {$t->id()} from {$wgDBprefix}user, {$wgDBprefix}watchlist where user_id = wl_user and $where_clause;");
10461053 }
10471054
10481055 static function newUserMessages($user) {
 1056+ global $wgDBprefix;
10491057 return Threads::where( array('ums_read_timestamp is null',
10501058 Threads::articleClause(new Article($user->getUserPage()))),
1051 - array(), array(), "left outer join user_message_state on ums_user is null or (ums_user = {$user->getID()} and ums_thread = thread.thread_id)" );
 1059+ array(), array(), "left outer join {$wgDBprefix}user_message_state on ums_user is null or (ums_user = {$user->getID()} and ums_thread = thread.thread_id)" );
10521060 }
10531061
10541062 static function watchedThreadsForUser($user) {

Status & tagging log