r72707 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r72706‎ | r72707 | r72708 >
Date:10:13, 10 September 2010
Author:werdna
Status:resolved (Comments)
Tags:schema 
Comment:
More or less rewrote Special:NewMessages. Only user-visible change is that it is now paged.
Modified paths:
  • /trunk/extensions/LiquidThreads/LiquidThreads.php (modified) (history)
  • /trunk/extensions/LiquidThreads/classes/Hooks.php (modified) (history)
  • /trunk/extensions/LiquidThreads/lqt.sql (modified) (history)
  • /trunk/extensions/LiquidThreads/pages/NewUserMessagesView.php (modified) (history)
  • /trunk/extensions/LiquidThreads/pages/SpecialNewMessages.php (modified) (history)

Diff [purge]

Index: trunk/extensions/LiquidThreads/LiquidThreads.php
@@ -154,6 +154,9 @@
155155 $wgAutoloadClasses['SummaryPageView'] = $dir . 'pages/SummaryPageView.php';
156156 $wgAutoloadClasses['NewUserMessagesView'] = $dir . 'pages/NewUserMessagesView.php';
157157
 158+// Pagers
 159+$wgAutoloadClasses['LqtDiscussionPager'] = $dir . "pages/TalkpageView.php";
 160+
158161 // Special pages
159162 $wgAutoloadClasses['ThreadActionPage'] = $dir . 'pages/ThreadActionPage.php';
160163 $wgAutoloadClasses['SpecialMoveThread'] = $dir . 'pages/SpecialMoveThread.php';
Index: trunk/extensions/LiquidThreads/classes/Hooks.php
@@ -329,6 +329,7 @@
330330 $wgExtNewFields[] = array( 'thread', 'thread_replies', "$dir/schema-changes/store_reply_count.sql" );
331331 $wgExtNewFields[] = array( 'thread', 'thread_article_id', "$dir/schema-changes/store_article_id.sql" );
332332 $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" );
333334
334335 $wgExtNewIndexes[] = array( 'thread', 'thread_summary_page', '(thread_summary_page)' );
335336
Index: trunk/extensions/LiquidThreads/lqt.sql
@@ -57,11 +57,12 @@
5858 CREATE TABLE /*$wgDBprefix*/user_message_state (
5959 ums_user int unsigned NOT NULL,
6060 ums_thread int(8) unsigned NOT NULL,
 61+ ums_conversation int(8) unsigned NOT NULL DEFAULT 0,
6162 ums_read_timestamp varbinary(14),
6263
6364 PRIMARY KEY (ums_user, ums_thread)
6465 ) /*$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);
6667
6768 -- "New" storage location for history data.
6869 CREATE TABLE /*_*/thread_history (
Index: trunk/extensions/LiquidThreads/pages/NewUserMessagesView.php
@@ -2,10 +2,10 @@
33 if ( !defined( 'MEDIAWIKI' ) ) die;
44
55 class NewUserMessagesView extends LqtView {
6 - protected $threads;
7 - protected $tops;
8 - protected $targets;
96
 7+ protected $highlightedThreads;
 8+ protected $messagesInfo;
 9+
1010 protected function htmlForReadButton( $label, $title, $class, $ids ) {
1111 $ids_s = implode( ',', $ids );
1212 $html = '';
@@ -24,14 +24,13 @@
2525 return $html;
2626 }
2727
28 - function getReadAllButton( $threads ) {
 28+ function getReadAllButton( ) {
2929 wfLoadExtensionMessages( 'LiquidThreads' );
30 - $ids = array_map( create_function( '$t', 'return $t->id();' ), $threads ); // ew
3130 return $this->htmlForReadButton(
3231 wfMsg( 'lqt-read-all' ),
3332 wfMsg( 'lqt-read-all-tooltip' ),
3433 "lqt_newmessages_read_all_button",
35 - $ids
 34+ array('all')
3635 );
3736 }
3837
@@ -73,10 +72,7 @@
7473 function postDivClass( $thread ) {
7574 $origClass = parent::postDivClass( $thread );
7675
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 ) )
8177 return "$origClass lqt_post_new_message";
8278
8379 return $origClass;
@@ -92,8 +88,9 @@
9389
9490 if ( $ids !== false ) {
9591 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 );
9895 }
9996 $this->output->redirect( $this->title->getFullURL() );
10097 }
@@ -101,9 +98,13 @@
10299 $ids = explode( ',', $this->request->getVal( 'lqt_operand' ) );
103100 if ( $ids !== false ) {
104101 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+ }
108109 }
109110 $query = 'lqt_method=undo_mark_as_read&lqt_operand=' . implode( ',', $ids );
110111 $this->output->redirect( $this->title->getFullURL( $query ) );
@@ -115,40 +116,32 @@
116117 }
117118
118119 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;
121126 }
 127+
 128+ $this->output->addHTML( $this->getReadAllButton() );
 129+ $this->output->addHTML( $pager->getNavigationBar() );
122130
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 -
142131 $this->output->addHTML( '<table class="lqt-new-messages"><tbody>' );
143132
144 - foreach ( $this->tops as $t ) {
 133+ foreach ( $this->messagesInfo as $info ) {
145134 // It turns out that with lqtviews composed of threads from various talkpages,
146135 // 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();
148139
149 - $this->showWrappedThread( $t );
 140+ $this->showWrappedThread( $thread );
150141 }
151142
152143 $this->output->addHTML( '</tbody></table>' );
 144+
 145+ $this->output->addHTML( $pager->getNavigationBar() );
153146
154147 return false;
155148 }
@@ -160,7 +153,7 @@
161154 wfMsg( 'lqt-read-message' ),
162155 wfMsg( 'lqt-read-message-tooltip' ),
163156 'lqt_newmessages_read_button',
164 - $this->targets[$t->id()] );
 157+ $this->highlightThreads );
165158
166159 // Left-hand column read button and context link to the full thread.
167160 global $wgUser;
@@ -198,7 +191,7 @@
199192 $html = "<tr>$leftColumn<td class='lqt-newmessages-right'>";
200193 $this->output->addHTML( $html );
201194
202 - $mustShowThreads = $this->targets[$t->id()];
 195+ $mustShowThreads = $this->highlightThreads;
203196
204197 $this->showThread( $t, 1, 1, array( 'mustShowThreads' => $mustShowThreads ) );
205198 static $scriptDone = false;
@@ -209,8 +202,85 @@
210203 }
211204 $this->output->addHTML( "</td></tr>" );
212205 }
 206+}
213207
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 );
216215 }
 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+ }
217287 }
Index: trunk/extensions/LiquidThreads/pages/SpecialNewMessages.php
@@ -42,35 +42,6 @@
4343
4444 $view->showOnce(); // handles POST etc.
4545
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 );
6746 $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();
7647 }
7748 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r72708svn add schema-changes/ums-conversation.sqlwerdna10:43, 10 September 2010
r72807Fix "1051: Unknown table 'thread'" when tables use a prefix.siebrand14:26, 11 September 2010
r72812Follow-up r72707: removed messages that were only used in removed code in Spe...siebrand15:02, 11 September 2010
r97811Fix ums_conversation.sql patch per changes on r72707...reedy12:33, 22 September 2011

Comments

#Comment by Nikerabbit (talk | contribs)   14:56, 11 September 2010

Schema patch file added in r72708. Failing sql queries fixed in 72807.

User visible changes include:

  1. No distinction between user page and other pages (reported by Siebrand)
  2. Sort order of threads is reversed (not necessarily bad thing)
#Comment by Brion VIBBER (talk | contribs)   18:28, 27 April 2011

This commit & friends may need to be merged to 1.17 in order to fix bug 27983 (Special:NewMessages is still unpaginated on 1.17, making it useless for anyone who's got too many messages queued up to display at once).

I'm not tagging it as 1.17 or 1.17wmf since it's currently tagged 1.18, which may indicate it wasn't considered deployment-ready in February?

We're now seven months out from the original change and two months out from initial 1.17 deployment, so it would be nice to get it deployed and the bug fixed soon.

#Comment by Catrope (talk | contribs)   18:30, 27 April 2011

Andrew, can this be merged? If yes, please tag it with 1.17 and/or 1.17wmf1 as appropriate, or do the merges yourself.

#Comment by Werdna (talk | contribs)   11:55, 1 May 2011

Unfortunately, it needs a schema change on LiquidThreads' biggest table, user_message_state. I'm probably not willing to apply the schema change myself, I should have snuck it in with the 1.17 schema changes but I forgot about it (it's not an obvious schema change).

#Comment by Werdna (talk | contribs)   14:13, 4 September 2011

Niklas, is this still FIXME for a reason?

#Comment by Nikerabbit (talk | contribs)   16:40, 4 September 2011

Whatever the reason was, we have lived it with long enough. Please finish lqt3 soon :)

Status & tagging log