Index: branches/liquidthreads/maintenance/lqt.sql |
— | — | @@ -1,14 +1,21 @@ |
2 | 2 | CREATE TABLE /*$wgDBprefix*/thread ( |
3 | 3 | thread_id int(8) unsigned NOT NULL auto_increment, |
4 | 4 | thread_root int(8) unsigned UNIQUE NOT NULL, |
5 | | - thread_article int(8) unsigned NOT NULL, |
| 5 | + thread_article int(8) unsigned NOT NULL default 0, |
6 | 6 | thread_path text NOT NULL, |
7 | 7 | thread_summary_page int(8) unsigned NULL, |
8 | 8 | thread_timestamp char(14) binary NOT NULL default '', |
9 | 9 | thread_revision int(8) unsigned NOT NULL default 1, |
10 | 10 | |
| 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, |
| 15 | + |
11 | 16 | PRIMARY KEY thread_id (thread_id), |
12 | 17 | UNIQUE INDEX thread_id (thread_id), |
| 18 | + INDEX thread_article (thread_article), |
| 19 | + INDEX thread_article_title (thread_article_namespace, thread_article_title), |
13 | 20 | INDEX( thread_path(255) ), |
14 | 21 | INDEX thread_timestamp (thread_timestamp) |
15 | 22 | ) TYPE=InnoDB; |
— | — | @@ -24,13 +31,12 @@ |
25 | 32 | |
26 | 33 | -- Because hthreads are only stored one per root, this lists |
27 | 34 | -- the subthreads that can be found within each one. |
28 | | -CREATE TABLE /*$wgDBprefix*/hthread_contents { |
| 35 | +CREATE TABLE /*$wgDBprefix*/hthread_contents ( |
29 | 36 | htcontents_child int(8) unsigned NOT NULL, |
30 | 37 | htcontents_hthread int(8) unsigned NOT NULL, |
31 | 38 | htcontents_rev_start int(8) unsigned NOT NULL, |
32 | | - htcontents_rev_end int(8) unsigned NULL, |
33 | | - PRIMARY KEY |
34 | | -} |
| 39 | + htcontents_rev_end int(8) unsigned NULL |
| 40 | +) TYPE=InnoDB; |
35 | 41 | |
36 | 42 | /* |
37 | 43 | old_superthread and old_article are mutually exclusive. |
Index: branches/liquidthreads/extensions/LqtExtension.php |
— | — | @@ -83,14 +83,20 @@ |
84 | 84 | $g = new QueryGroup(); |
85 | 85 | $startdate = Date::now()->nDaysAgo($this->archive_start_days)->midnight(); |
86 | 86 | $recentstartdate = $startdate->nDaysAgo($this->archive_recent_days); |
| 87 | + $article_clause = <<<SQL |
| 88 | + IF(thread.thread_article = 0, |
| 89 | + thread.thread_article_title = "{$this->article->getTitle()->getDBkey()}" |
| 90 | + AND thread.thread_article_namespace = {$this->article->getTitle()->getNamespace()} |
| 91 | + , thread.thread_article = {$this->article->getID()}) |
| 92 | +SQL; |
87 | 93 | $g->addQuery('fresh', |
88 | | - array('thread.thread_article' => $this->article->getID(), |
| 94 | + array($article_clause, |
89 | 95 | 'instr(thread.thread_path, ".")' => '0', |
90 | 96 | '(thread.thread_timestamp >= ' . $startdate->text() . |
91 | 97 | ' OR thread.thread_summary_page is NULL)'), |
92 | 98 | array('ORDER BY thread.thread_timestamp DESC')); |
93 | 99 | $g->addQuery('archived', |
94 | | - array('thread.thread_article' => $this->article->getID(), |
| 100 | + array($article_clause, |
95 | 101 | 'instr(thread.thread_path, ".")' => '0', |
96 | 102 | 'thread.thread_summary_page is not null', |
97 | 103 | 'thread.thread_timestamp < ' . $startdate->text()), |
— | — | @@ -844,6 +850,7 @@ |
845 | 851 | $this->article = $t->article(); # for creating reply threads. |
846 | 852 | |
847 | 853 | // Make a link back to the talk page, including the correct archive month. |
| 854 | + // TODO this is obsolete. |
848 | 855 | if (Date::now()->nDaysAgo(30)->midnight()->isBefore( new Date($t->timestamp()) )) |
849 | 856 | $query = ''; |
850 | 857 | else |
Index: branches/liquidthreads/extensions/LqtModel.php |
— | — | @@ -109,6 +109,10 @@ |
110 | 110 | protected $rootId; |
111 | 111 | protected $articleId; |
112 | 112 | protected $summaryId; |
| 113 | + |
| 114 | + /* These are only used in the case of a non-existant article. */ |
| 115 | + protected $articleNamespace; |
| 116 | + protected $articleTitle; |
113 | 117 | |
114 | 118 | /* Actual objects loaded on demand from the above when accessors are called: */ |
115 | 119 | protected $root; |
— | — | @@ -150,12 +154,14 @@ |
151 | 155 | $this->id = $line->thread_id; |
152 | 156 | $this->rootId = $line->thread_root; |
153 | 157 | $this->articleId = $line->thread_article; |
| 158 | + $this->articleNamespace = $line->thread_article_namespace; |
| 159 | + $this->articleTitle = $line->thread_article_title; |
154 | 160 | $this->summaryId = $line->thread_summary_page; |
155 | 161 | $this->path = $line->thread_path; |
156 | 162 | $this->timestamp = $line->thread_timestamp; |
157 | 163 | $this->revisionNumber = $line->thread_revision; |
158 | 164 | $this->replies = $children; |
159 | | - //$this->double = clone $this; |
| 165 | + $this->double = clone $this; |
160 | 166 | } |
161 | 167 | |
162 | 168 | function setSuperthread($thread) { |
— | — | @@ -189,13 +195,19 @@ |
190 | 196 | |
191 | 197 | function setArticle($a) { |
192 | 198 | $this->articleId = $a->getID(); |
| 199 | + $this->articleNamespace = $a->getTitle()->getNamespace(); |
| 200 | + $this->articleTitle = $a->getTitle()->getDBkey(); |
193 | 201 | $this->touch(); |
194 | 202 | } |
195 | 203 | |
196 | 204 | function article() { |
197 | | - if ( !$this->articleId ) return null; |
198 | | - if ( !$this->article ) $this->article = new Article(Title::newFromID($this->articleId)); |
199 | | - return $this->article; |
| 205 | + if ( $this->article ) return $this->article; |
| 206 | + $a = new Article(Title::newFromID($this->articleId)); |
| 207 | + if ($a->exists()) { |
| 208 | + return $a; |
| 209 | + } else { |
| 210 | + return new Article( Title::makeTitle($this->articleNamespace, $this->articleTitle) ); |
| 211 | + } |
200 | 212 | } |
201 | 213 | |
202 | 214 | function id() { |
— | — | @@ -268,19 +280,6 @@ |
269 | 281 | function timestamp() { |
270 | 282 | return $this->timestamp; |
271 | 283 | } |
272 | | - |
273 | | - protected function updateRecord() { |
274 | | - $dbr =& wfGetDB( DB_MASTER ); |
275 | | - $res = $dbr->update( 'lqt_thread', |
276 | | - /* SET */ array( 'thread_root_post' => $this->rootId, |
277 | | - 'thread_article' => $this->articleId, |
278 | | - 'thread_subthread_of' => $this->superthreadId, |
279 | | - 'thread_summary_page' => $this->summaryId, |
280 | | - 'thread_subject' => $this->subject, |
281 | | - 'thread_timestamp' => $this->timestamp ), |
282 | | - /* WHERE */ array( 'thread_id' => $this->id, ), |
283 | | - __METHOD__); |
284 | | - } |
285 | 284 | } |
286 | 285 | |
287 | 286 | /** Module of factory methods. */ |
— | — | @@ -290,10 +289,17 @@ |
291 | 290 | |
292 | 291 | static function newThread( $root, $article, $superthread = null ) { |
293 | 292 | $dbr =& wfGetDB( DB_MASTER ); |
| 293 | + |
| 294 | + if( $article->exists() ) { |
| 295 | + $aclause = array("thread_article" => $article->getID()); |
| 296 | + } else { |
| 297 | + $aclause = array("thread_article_namespace" => $article->getTitle()->getNamespace(), |
| 298 | + "thread_article_title" => $article->getTitle()->getDBkey()); |
| 299 | + } |
| 300 | + |
294 | 301 | $res = $dbr->insert('thread', |
295 | | - array('thread_article' => $article->getID(), |
296 | | - 'thread_root' => $root->getID(), |
297 | | - 'thread_timestamp' => wfTimestampNow()), |
| 302 | + array('thread_root' => $root->getID(), |
| 303 | + 'thread_timestamp' => wfTimestampNow()) + $aclause, |
298 | 304 | __METHOD__); |
299 | 305 | |
300 | 306 | $newid = $dbr->insertId(); |