r25931 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r25930‎ | r25931 | r25932 >
Date:06:21, 19 September 2007
Author:david
Status:old
Tags:
Comment:
More watchlist noodling -- schema change whose purpose will become apparent in tomorrow's episode. Source maintenance/lqt-schema-change-1.sql.
Modified paths:
  • /branches/liquidthreads/extensions/LqtModel.php (modified) (history)
  • /branches/liquidthreads/extensions/LqtPages.php (modified) (history)
  • /branches/liquidthreads/includes/SpecialWatchlist.php (modified) (history)
  • /branches/liquidthreads/maintenance/lqt-schema-change-1.sql (added) (history)
  • /branches/liquidthreads/maintenance/lqt.sql (modified) (history)
  • /branches/liquidthreads/skins/monobook/main.css (modified) (history)

Diff [purge]

Index: branches/liquidthreads/maintenance/lqt-schema-change-1.sql
@@ -0,0 +1,5 @@
 2+update thread, page set thread_article_title=page_title, thread_article_namespace=page_namespace where page_id=thread_article and thread_article is not null and thread_article != 0;
 3+
 4+alter table thread drop column thread_article;
 5+alter table thread modify thread_article_namespace not null;
 6+alter table thread modify thread_article_title varchar(255) binary not null;
Index: branches/liquidthreads/maintenance/lqt.sql
@@ -1,16 +1,13 @@
22 CREATE TABLE /*$wgDBprefix*/thread (
33 thread_id int(8) unsigned NOT NULL auto_increment,
44 thread_root int(8) unsigned UNIQUE NOT NULL,
5 - thread_article int(8) unsigned NOT NULL default 0,
65 thread_path text NOT NULL,
76 thread_summary_page int(8) unsigned NULL,
87 thread_timestamp char(14) binary NOT NULL default '',
98 thread_revision int(8) unsigned NOT NULL default 1,
109
11 - -- The following are used only for non-existant article where
12 - -- thread_article = 0. They should be ignored if thread_article != 0.
13 - thread_article_namespace int NULL,
14 - thread_article_title varchar(255) binary NULL,
 10+ thread_article_namespace int NOT NULL,
 11+ thread_article_title varchar(255) binary NOT NULL,
1512
1613 -- Special thread types such as schrodinger's thread:
1714 thread_type int(4) unsigned NOT NULL default 0,
@@ -23,7 +20,6 @@
2421
2522 PRIMARY KEY thread_id (thread_id),
2623 UNIQUE INDEX thread_id (thread_id),
27 - INDEX thread_article (thread_article),
2824 INDEX thread_article_title (thread_article_namespace, thread_article_title),
2925 INDEX( thread_path(255) ),
3026 INDEX thread_timestamp (thread_timestamp)
Index: branches/liquidthreads/skins/monobook/main.css
@@ -31,6 +31,17 @@
3232 margin-bottom: .1em;
3333 }*/
3434
 35+.lqt_watchlist_messages_notice {
 36+ background-color: #eee;
 37+ border: 1px solid #ddd;
 38+ margin: 1em 0;
 39+ margin-right: 0;
 40+ padding: .5em 1em;
 41+
 42+ display: table;
 43+ width: auto;
 44+}
 45+
3546 .lqt_newmessages_section {
3647 border-bottom: 0px;
3748 }
Index: branches/liquidthreads/extensions/LqtPages.php
@@ -163,7 +163,7 @@
164164 function loadQueryFromRequest() {
165165 // Begin with with the requirements for being *in* the archive.
166166 $startdate = Date::now()->nDaysAgo($this->archive_start_days)->midnight();
167 - $where = array('thread.thread_article' => $this->article->getID(),
 167+ $where = array(Threads::articleClause($this->article),
168168 'instr(thread.thread_path, ".")' => '0',
169169 '(thread.thread_summary_page is not null' .
170170 ' OR thread.thread_type = '.Threads::TYPE_MOVED.')',
@@ -1008,19 +1008,28 @@
10091009 }
10101010
10111011
1012 -function wfLqtBeforeWatchlistHook( $options, $user ) {
 1012+function wfLqtBeforeWatchlistHook( $options, $user, &$hook_sql ) {
10131013 global $wgOut;
10141014
 1015+ $hook_sql = "AND page_namespace != " . NS_LQT_THREAD;
 1016+
10151017 $user_messages = NewMessages::newUserMessages($user);
10161018 $n = count($user_messages);
10171019
 1020+ if( $n == 0 )
 1021+ return true;
 1022+
 1023+ if ( $n == 1 ) $phrase = "is 1 message";
 1024+ else $phrase = "are $n messages";
 1025+
 1026+ $messages_url = SpecialPage::getPage('Newmessages')->getTitle()->getFullURL();
10181027 $wgOut->addHTML(<<< HTML
1019 - <div class="lqt_watchlist_messages_notice">
1020 - There are $n messages for you.
1021 - </div>
 1028+ <a href="$messages_url" class="lqt_watchlist_messages_notice">
 1029+ &#x2712; There $phrase for you.
 1030+ </a>
10221031 HTML
10231032 );
1024 -
 1033+
10251034 return true;
10261035 }
10271036
Index: branches/liquidthreads/extensions/LqtModel.php
@@ -338,7 +338,6 @@
339339 $dbr =& wfGetDB( DB_MASTER );
340340 $res = $dbr->update( 'thread',
341341 /* SET */array( 'thread_root' => $this->rootId,
342 - 'thread_article' => $this->articleId,
343342 'thread_path' => $this->path,
344343 'thread_type' => $this->type,
345344 'thread_summary_page' => $this->summaryId,
@@ -354,6 +353,9 @@
355354 ),
356355 /* WHERE */ array( 'thread_id' => $this->id, ),
357356 __METHOD__);
 357+
 358+ NewMessages::checkWatchlistsForThread($this);
 359+
358360
359361 // RecentChange::notifyEdit( wfTimestampNow(), $this->root(), /*minor*/false, $wgUser, $summary,
360362 // $lastRevision, $this->getTimestamp(), $bot, '', $oldsize, $newsize,
@@ -388,7 +390,6 @@
389391 $res = $dbr->update( 'thread',
390392 /* SET */array(
391393 'thread_revision' => $r->revisionNumber() + 1,
392 - 'thread_article' => $new_articleId,
393394 'thread_article_namespace' => $new_articleNamespace,
394395 'thread_article_title' => $new_articleTitle),
395396 /* WHERE */ array( 'thread_id' => $r->id(), ),
@@ -452,7 +453,6 @@
453454
454455 $this->id = $line->thread_id;
455456 $this->rootId = $line->thread_root;
456 - $this->articleId = $line->thread_article;
457457 $this->articleNamespace = $line->thread_article_namespace;
458458 $this->articleTitle = $line->thread_article_title;
459459 $this->summaryId = $line->thread_summary_page;
@@ -777,13 +777,6 @@
778778 throw new MWException(__METHOD__ . ": invalid type $type.");
779779 }
780780
781 - if( $article->exists() ) {
782 - $aclause = array("thread_article" => $article->getID());
783 - } else {
784 - $aclause = array("thread_article_namespace" => $article->getTitle()->getNamespace(),
785 - "thread_article_title" => $article->getTitle()->getDBkey());
786 - }
787 -
788781 if ($superthread) {
789782 $change_type = self::CHANGE_REPLY_CREATED;
790783 } else {
@@ -794,6 +787,8 @@
795788
796789 $res = $dbr->insert('thread',
797790 array('thread_root' => $root->getID(),
 791+ 'thread_article_namespace' => $article->getTitle()->getNamespace(),
 792+ 'thread_article_title' => $article->getTitle()->getDBkey(),
798793 'thread_timestamp' => wfTimestampNow(),
799794 'thread_change_type' => $change_type,
800795 'thread_change_comment' => "", // TODO
@@ -822,6 +817,9 @@
823818 if($superthread) {
824819 $superthread->addReply( $newthread );
825820 }
 821+
 822+ NewMessages::checkWatchlistsForThread($newthread);
 823+
826824 return $newthread;
827825 }
828826
@@ -929,7 +927,7 @@
930928 * Horrible, horrible!
931929 * List of months in which there are >0 threads, suitable for threadsOfArticleInMonth. */
932930 static function monthsWhereArticleHasThreads( $article ) {
933 - $threads = Threads::where( array('thread.thread_article' => $article->getID()) );
 931+ $threads = Threads::where( Threads::articleClause($article) );
934932 $months = array();
935933 foreach( $threads as $t ) {
936934 $m = substr( $t->timestamp(), 0, 6 );
@@ -942,10 +940,8 @@
943941
944942 static function articleClause($article) {
945943 return <<<SQL
946 - IF(thread.thread_article = 0,
947 - thread.thread_article_title = "{$article->getTitle()->getDBkey()}"
948 - AND thread.thread_article_namespace = {$article->getTitle()->getNamespace()}
949 - , thread.thread_article = {$article->getID()})
 944+(thread.thread_article_title = "{$article->getTitle()->getDBkey()}"
 945+ AND thread.thread_article_namespace = {$article->getTitle()->getNamespace()})
950946 SQL;
951947 }
952948
@@ -1021,6 +1017,10 @@
10221018 }
10231019 }
10241020
 1021+ static function checkWatchlistsForThread($t) {
 1022+
 1023+ }
 1024+
10251025 static function newUserMessages($user) {
10261026
10271027 $ts = Threads::where( array('ums_read_timestamp is null',
Index: branches/liquidthreads/includes/SpecialWatchlist.php
@@ -122,7 +122,8 @@
123123 wfAppendToArrayIfNotDefault( 'hideMinor', (int)$hideMinor, $defaults, $nondefaults );
124124 wfAppendToArrayIfNotDefault('namespace', $nameSpace , $defaults, $nondefaults);
125125
126 - if( ! wfRunHooks('BeforeWatchlist', array($nondefaults, $wgUser)) ) {
 126+ $hookSql = "";
 127+ if( ! wfRunHooks('BeforeWatchlist', array($nondefaults, $wgUser, &$hookSql)) ) {
127128 return;
128129 }
129130
@@ -197,6 +198,7 @@
198199 $andHideBots
199200 $andHideMinor
200201 $nameSpaceClause
 202+ $hookSql
201203 ORDER BY rc_timestamp DESC
202204 $limitWatchlist";
203205

Status & tagging log