Index: branches/liquidthreads/extensions/LqtModel.php |
— | — | @@ -818,11 +818,16 @@ |
819 | 819 | } |
820 | 820 | |
821 | 821 | static function where( $where, $options = array(), $extra_tables = array(), $joins = "" ) { |
| 822 | + global $wgDBprefix; |
822 | 823 | $dbr = wfGetDB( DB_SLAVE ); |
823 | 824 | if ( is_array($where) ) $where = $dbr->makeList( $where, LIST_AND ); |
824 | 825 | if ( is_array($options) ) $options = implode(',', $options); |
825 | 826 | |
826 | 827 | 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 | + } |
827 | 832 | $tables = implode(',', $extra_tables) . ', '; |
828 | 833 | } else if ( is_string( $extra_tables ) ) { |
829 | 834 | $tables = $extra_tables . ', '; |
— | — | @@ -840,7 +845,7 @@ |
841 | 846 | $root_test = str_replace( 'thread.', 'children.', $where ); // TODO fragile? |
842 | 847 | |
843 | 848 | $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 |
845 | 850 | WHERE $where |
846 | 851 | AND children.thread_path LIKE CONCAT(thread.thread_path, "%") |
847 | 852 | AND child_page.page_id = children.thread_root |
— | — | @@ -997,6 +1002,7 @@ |
998 | 1003 | } |
999 | 1004 | |
1000 | 1005 | private static function writeUserMessageState($thread, $user, $timestamp) { |
| 1006 | + global $wgDBprefix; |
1001 | 1007 | if( is_object($thread) ) $thread_id = $thread->id(); |
1002 | 1008 | else if( is_integer($thread) ) $thread_id = $thread; |
1003 | 1009 | else throw new MWException("writeUserMessageState expected Thread or integer but got $thread"); |
— | — | @@ -1009,18 +1015,19 @@ |
1010 | 1016 | |
1011 | 1017 | // use query() directly to pass in 'true' for don't-die-on-errors. |
1012 | 1018 | $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)", |
1014 | 1020 | __METHOD__, true); |
1015 | 1021 | |
1016 | 1022 | if( !$success ) { |
1017 | 1023 | // 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" . |
1019 | 1025 | " where ums_thread = $thread_id and ums_user = $user_id", |
1020 | 1026 | __METHOD__); |
1021 | 1027 | } |
1022 | 1028 | } |
1023 | 1029 | |
1024 | 1030 | static function writeMessageStateForUpdatedThread($t) { |
| 1031 | + global $wgDBprefix; |
1025 | 1032 | // retrieve all users who are watching t. |
1026 | 1033 | // write a ums for each one. |
1027 | 1034 | |
— | — | @@ -1039,15 +1046,16 @@ |
1040 | 1047 | |
1041 | 1048 | // it sucks to not have 'on duplicate key update'. first update users who already have a ums for this thread |
1042 | 1049 | // 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"); |
1044 | 1051 | |
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;"); |
1046 | 1053 | } |
1047 | 1054 | |
1048 | 1055 | static function newUserMessages($user) { |
| 1056 | + global $wgDBprefix; |
1049 | 1057 | return Threads::where( array('ums_read_timestamp is null', |
1050 | 1058 | 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)" ); |
1052 | 1060 | } |
1053 | 1061 | |
1054 | 1062 | static function watchedThreadsForUser($user) { |