Index: trunk/extensions/LiquidThreads/LiquidThreads.php |
— | — | @@ -154,6 +154,9 @@ |
155 | 155 | $wgAutoloadClasses['SummaryPageView'] = $dir . 'pages/SummaryPageView.php'; |
156 | 156 | $wgAutoloadClasses['NewUserMessagesView'] = $dir . 'pages/NewUserMessagesView.php'; |
157 | 157 | |
| 158 | +// Pagers |
| 159 | +$wgAutoloadClasses['LqtDiscussionPager'] = $dir . "pages/TalkpageView.php"; |
| 160 | + |
158 | 161 | // Special pages |
159 | 162 | $wgAutoloadClasses['ThreadActionPage'] = $dir . 'pages/ThreadActionPage.php'; |
160 | 163 | $wgAutoloadClasses['SpecialMoveThread'] = $dir . 'pages/SpecialMoveThread.php'; |
Index: trunk/extensions/LiquidThreads/classes/Hooks.php |
— | — | @@ -329,6 +329,7 @@ |
330 | 330 | $wgExtNewFields[] = array( 'thread', 'thread_replies', "$dir/schema-changes/store_reply_count.sql" ); |
331 | 331 | $wgExtNewFields[] = array( 'thread', 'thread_article_id', "$dir/schema-changes/store_article_id.sql" ); |
332 | 332 | $wgExtNewFields[] = array( 'thread', 'thread_signature', "$dir/schema-changes/thread_signature.sql" ); |
| 333 | + $wgExtNewFields[] = array( 'user_message_state', 'ums_conversation', "$dir/schema-changes/ums_conversation.sql" ); |
333 | 334 | |
334 | 335 | $wgExtNewIndexes[] = array( 'thread', 'thread_summary_page', '(thread_summary_page)' ); |
335 | 336 | |
Index: trunk/extensions/LiquidThreads/lqt.sql |
— | — | @@ -57,11 +57,12 @@ |
58 | 58 | CREATE TABLE /*$wgDBprefix*/user_message_state ( |
59 | 59 | ums_user int unsigned NOT NULL, |
60 | 60 | ums_thread int(8) unsigned NOT NULL, |
| 61 | + ums_conversation int(8) unsigned NOT NULL DEFAULT 0, |
61 | 62 | ums_read_timestamp varbinary(14), |
62 | 63 | |
63 | 64 | PRIMARY KEY (ums_user, ums_thread) |
64 | 65 | ) /*$wgDBTableOptions*/; |
65 | | -CREATE INDEX ums_user_read ON /*$wgDBprefix*/user_message_state (ums_user,ums_read_timestamp); |
| 66 | +CREATE INDEX ums_user_conversation ON /*$wgDBprefix*/user_message_state (ums_user,ums_conversation); |
66 | 67 | |
67 | 68 | -- "New" storage location for history data. |
68 | 69 | CREATE TABLE /*_*/thread_history ( |
Index: trunk/extensions/LiquidThreads/pages/NewUserMessagesView.php |
— | — | @@ -2,10 +2,10 @@ |
3 | 3 | if ( !defined( 'MEDIAWIKI' ) ) die; |
4 | 4 | |
5 | 5 | class NewUserMessagesView extends LqtView { |
6 | | - protected $threads; |
7 | | - protected $tops; |
8 | | - protected $targets; |
9 | 6 | |
| 7 | + protected $highlightedThreads; |
| 8 | + protected $messagesInfo; |
| 9 | + |
10 | 10 | protected function htmlForReadButton( $label, $title, $class, $ids ) { |
11 | 11 | $ids_s = implode( ',', $ids ); |
12 | 12 | $html = ''; |
— | — | @@ -24,14 +24,13 @@ |
25 | 25 | return $html; |
26 | 26 | } |
27 | 27 | |
28 | | - function getReadAllButton( $threads ) { |
| 28 | + function getReadAllButton( ) { |
29 | 29 | wfLoadExtensionMessages( 'LiquidThreads' ); |
30 | | - $ids = array_map( create_function( '$t', 'return $t->id();' ), $threads ); // ew |
31 | 30 | return $this->htmlForReadButton( |
32 | 31 | wfMsg( 'lqt-read-all' ), |
33 | 32 | wfMsg( 'lqt-read-all-tooltip' ), |
34 | 33 | "lqt_newmessages_read_all_button", |
35 | | - $ids |
| 34 | + array('all') |
36 | 35 | ); |
37 | 36 | } |
38 | 37 | |
— | — | @@ -73,10 +72,7 @@ |
74 | 73 | function postDivClass( $thread ) { |
75 | 74 | $origClass = parent::postDivClass( $thread ); |
76 | 75 | |
77 | | - $topid = $thread->topmostThread()->id(); |
78 | | - |
79 | | - if ( isset( $this->targets[$topid] ) && is_array( $this->targets[$topid] ) && |
80 | | - in_array( $thread->id(), $this->targets[$topid] ) ) |
| 76 | + if ( in_array( $thread->id(), $this->highlightThreads ) ) |
81 | 77 | return "$origClass lqt_post_new_message"; |
82 | 78 | |
83 | 79 | return $origClass; |
— | — | @@ -92,8 +88,9 @@ |
93 | 89 | |
94 | 90 | if ( $ids !== false ) { |
95 | 91 | foreach ( $ids as $id ) { |
96 | | - $tmp_thread = Threads::withId( $id ); if ( $tmp_thread ) |
97 | | - NewMessages::markThreadAsUnReadByUser( $tmp_thread, $this->user ); |
| 92 | + $tmp_thread = Threads::withId( $id ); |
| 93 | + if ( $tmp_thread ) |
| 94 | + NewMessages::markThreadAsUnReadByUser( $tmp_thread, $this->user ); |
98 | 95 | } |
99 | 96 | $this->output->redirect( $this->title->getFullURL() ); |
100 | 97 | } |
— | — | @@ -101,9 +98,13 @@ |
102 | 99 | $ids = explode( ',', $this->request->getVal( 'lqt_operand' ) ); |
103 | 100 | if ( $ids !== false ) { |
104 | 101 | foreach ( $ids as $id ) { |
105 | | - $tmp_thread = Threads::withId( $id ); |
106 | | - if ( $tmp_thread ) |
107 | | - NewMessages::markThreadAsReadByUser( $tmp_thread, $this->user ); |
| 102 | + if ( $id == 'all' ) { |
| 103 | + NewMessages::markAllReadByUser( $this->user ); |
| 104 | + } else { |
| 105 | + $tmp_thread = Threads::withId( $id ); |
| 106 | + if ( $tmp_thread ) |
| 107 | + NewMessages::markThreadAsReadByUser( $tmp_thread, $this->user ); |
| 108 | + } |
108 | 109 | } |
109 | 110 | $query = 'lqt_method=undo_mark_as_read&lqt_operand=' . implode( ',', $ids ); |
110 | 111 | $this->output->redirect( $this->title->getFullURL( $query ) ); |
— | — | @@ -115,40 +116,32 @@ |
116 | 117 | } |
117 | 118 | |
118 | 119 | function show() { |
119 | | - if ( ! is_array( $this->threads ) ) { |
120 | | - throw new MWException( 'You must use NewUserMessagesView::setThreads() before calling NewUserMessagesView::show().' ); |
| 120 | + $pager = new LqtNewMessagesPager( $this->user ); |
| 121 | + $this->messagesInfo = $pager->getThreads(); |
| 122 | + |
| 123 | + if ( ! $this->messagesInfo ) { |
| 124 | + $this->output->addWikiMsg( 'lqt-no-new-messages' ); |
| 125 | + return false; |
121 | 126 | } |
| 127 | + |
| 128 | + $this->output->addHTML( $this->getReadAllButton() ); |
| 129 | + $this->output->addHTML( $pager->getNavigationBar() ); |
122 | 130 | |
123 | | - // Do everything by id, because we can't depend on reference identity; a simple Thread::withId |
124 | | - // can change the cached value and screw up your references. |
125 | | - |
126 | | - $this->targets = array(); |
127 | | - $this->tops = array(); |
128 | | - foreach ( $this->threads as $t ) { |
129 | | - $top = $t->topmostThread(); |
130 | | - |
131 | | - // It seems that in some cases $top is zero. |
132 | | - if ( !$top ) |
133 | | - throw new MWException( "{$t->id()} seems to have no topmost thread" ); |
134 | | - |
135 | | - if ( !array_key_exists( $top->id(), $this->tops ) ) |
136 | | - $this->tops[$top->id()] = $top; |
137 | | - if ( !array_key_exists( $top->id(), $this->targets ) ) |
138 | | - $this->targets[$top->id()] = array(); |
139 | | - $this->targets[$top->id()][] = $t->id(); |
140 | | - } |
141 | | - |
142 | 131 | $this->output->addHTML( '<table class="lqt-new-messages"><tbody>' ); |
143 | 132 | |
144 | | - foreach ( $this->tops as $t ) { |
| 133 | + foreach ( $this->messagesInfo as $info ) { |
145 | 134 | // It turns out that with lqtviews composed of threads from various talkpages, |
146 | 135 | // each thread is going to have a different article... this is pretty ugly. |
147 | | - $this->article = $t->article(); |
| 136 | + $thread = $info['top']; |
| 137 | + $this->highlightThreads = $info['posts']; |
| 138 | + $this->article = $thread->article(); |
148 | 139 | |
149 | | - $this->showWrappedThread( $t ); |
| 140 | + $this->showWrappedThread( $thread ); |
150 | 141 | } |
151 | 142 | |
152 | 143 | $this->output->addHTML( '</tbody></table>' ); |
| 144 | + |
| 145 | + $this->output->addHTML( $pager->getNavigationBar() ); |
153 | 146 | |
154 | 147 | return false; |
155 | 148 | } |
— | — | @@ -160,7 +153,7 @@ |
161 | 154 | wfMsg( 'lqt-read-message' ), |
162 | 155 | wfMsg( 'lqt-read-message-tooltip' ), |
163 | 156 | 'lqt_newmessages_read_button', |
164 | | - $this->targets[$t->id()] ); |
| 157 | + $this->highlightThreads ); |
165 | 158 | |
166 | 159 | // Left-hand column read button and context link to the full thread. |
167 | 160 | global $wgUser; |
— | — | @@ -198,7 +191,7 @@ |
199 | 192 | $html = "<tr>$leftColumn<td class='lqt-newmessages-right'>"; |
200 | 193 | $this->output->addHTML( $html ); |
201 | 194 | |
202 | | - $mustShowThreads = $this->targets[$t->id()]; |
| 195 | + $mustShowThreads = $this->highlightThreads; |
203 | 196 | |
204 | 197 | $this->showThread( $t, 1, 1, array( 'mustShowThreads' => $mustShowThreads ) ); |
205 | 198 | static $scriptDone = false; |
— | — | @@ -209,8 +202,85 @@ |
210 | 203 | } |
211 | 204 | $this->output->addHTML( "</td></tr>" ); |
212 | 205 | } |
| 206 | +} |
213 | 207 | |
214 | | - function setThreads( $threads ) { |
215 | | - $this->threads = $threads; |
| 208 | +class LqtNewMessagesPager extends LqtDiscussionPager { |
| 209 | + private $user; |
| 210 | + |
| 211 | + function __construct( $user ) { |
| 212 | + $this->user = $user; |
| 213 | + |
| 214 | + parent::__construct( false, false ); |
216 | 215 | } |
| 216 | + |
| 217 | + /** |
| 218 | + * Returns an array of structures. Each structure has the keys 'top' and 'posts'. |
| 219 | + * 'top' contains the top-level thread to display. |
| 220 | + * 'posts' contains an array of integer post IDs which should be highlighted. |
| 221 | + */ |
| 222 | + function getThreads() { |
| 223 | + $rows = $this->getRows(); |
| 224 | + |
| 225 | + if ( ! count($rows) ) { |
| 226 | + return false; |
| 227 | + } |
| 228 | + |
| 229 | + $threads = Thread::bulkLoad( $rows ); |
| 230 | + $thread_ids = array_keys( $threads ); |
| 231 | + $output = array(); |
| 232 | + |
| 233 | + foreach( $threads as $id => $thread ) { |
| 234 | + $output[$id] = array( 'top' => $thread, 'posts' => array() ); |
| 235 | + } |
| 236 | + |
| 237 | + $dbr = wfGetDB( DB_SLAVE ); |
| 238 | + |
| 239 | + $res = $dbr->select( array( 'user_message_state' ), |
| 240 | + array( 'ums_thread', 'ums_conversation' ), |
| 241 | + array( |
| 242 | + 'ums_user' => $this->user->getId(), |
| 243 | + 'ums_conversation' => $thread_ids |
| 244 | + ), |
| 245 | + __METHOD__ |
| 246 | + ); |
| 247 | + |
| 248 | + foreach( $res as $row ) { |
| 249 | + $top = $row->ums_conversation; |
| 250 | + $thread = $row->ums_thread; |
| 251 | + $output[$top]['posts'][] = $thread; |
| 252 | + } |
| 253 | + |
| 254 | + return $output; |
| 255 | + } |
| 256 | + |
| 257 | + function getQueryInfo() { |
| 258 | + $queryInfo = array( |
| 259 | + 'tables' => array( 'thread', 'user_message_state' ), |
| 260 | + 'fields' => array( 'thread.*', 'ums_conversation' ), |
| 261 | + 'conds' => array( |
| 262 | + 'ums_user' => $this->user->getId(), |
| 263 | + 'thread_type != ' . $this->mDb->addQuotes( Threads::TYPE_DELETED ), |
| 264 | + ), |
| 265 | + 'join_conds' => array( |
| 266 | + 'thread' => array( 'join', 'ums_conversation=thread_id' ) |
| 267 | + ), |
| 268 | + 'options' => array( |
| 269 | + 'group by' => 'ums_conversation' |
| 270 | + ) |
| 271 | + ); |
| 272 | + |
| 273 | + return $queryInfo; |
| 274 | + } |
| 275 | + |
| 276 | + function getPageLimit() { |
| 277 | + return 25; |
| 278 | + } |
| 279 | + |
| 280 | + function getDefaultDirections() { |
| 281 | + return true; // Descending |
| 282 | + } |
| 283 | + |
| 284 | + function getIndexField() { |
| 285 | + return array('ums_conversation'); |
| 286 | + } |
217 | 287 | } |
Index: trunk/extensions/LiquidThreads/pages/SpecialNewMessages.php |
— | — | @@ -42,35 +42,6 @@ |
43 | 43 | |
44 | 44 | $view->showOnce(); // handles POST etc. |
45 | 45 | |
46 | | - $first_set = NewMessages::newUserMessages( $this->user ); |
47 | | - $second_set = NewMessages::watchedThreadsForUser( $this->user ); |
48 | | - $both_sets = array_merge( $first_set, $second_set ); |
49 | | - if ( count( $both_sets ) == 0 ) { |
50 | | - $wgOut->addWikitext( wfMsg( 'lqt-no-new-messages' ) ); |
51 | | - return; |
52 | | - } |
53 | | - |
54 | | - $html = ''; |
55 | | - |
56 | | - $html .= $view->getReadAllButton( $both_sets ); |
57 | | - |
58 | | - $view->setHeaderLevel( 3 ); |
59 | | - |
60 | | - $html .= Xml::tags( |
61 | | - 'h2', |
62 | | - array( 'class' => 'lqt_newmessages_section' ), |
63 | | - wfMsgExt( 'lqt-messages-sent', 'parseinline' ) |
64 | | - ); |
65 | | - $wgOut->addHTML( $html ); |
66 | | - $view->setThreads( $first_set ); |
67 | 46 | $view->show(); |
68 | | - |
69 | | - $wgOut->addHTML( Xml::tags( |
70 | | - 'h2', |
71 | | - array( 'class' => 'lqt_newmessages_section' ), |
72 | | - wfMsgExt( 'lqt-other-messages', 'parseinline' ) |
73 | | - ) ); |
74 | | - $view->setThreads( $second_set ); |
75 | | - $view->show(); |
76 | 47 | } |
77 | 48 | } |