r24572 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r24571‎ | r24572 | r24573 >
Date:10:27, 4 August 2007
Author:david
Status:old
Tags:
Comment:
change type works and is shown in history
Modified paths:
  • /branches/liquidthreads/extensions/LqtExtension.php (modified) (history)
  • /branches/liquidthreads/extensions/LqtModel.php (modified) (history)
  • /branches/liquidthreads/maintenance/lqt.sql (modified) (history)

Diff [purge]

Index: branches/liquidthreads/maintenance/lqt.sql
@@ -15,7 +15,7 @@
1616 -- Special thread types such as schrodinger's thread:
1717 thread_type int(4) unsigned NOT NULL default 0,
1818
19 - thread_change_type int(4) unsigned NOT NULL default 0,
 19+ thread_change_type int(4) unsigned NOT NULL,
2020 thread_change_object int(8) unsigned NULL,
2121
2222 PRIMARY KEY thread_id (thread_id),
@@ -32,7 +32,7 @@
3333 hthread_id int(8) unsigned NOT NULL,
3434 hthread_revision int(8) unsigned NOT NULL,
3535 hthread_contents BLOB NOT NULL,
36 - hthread_change_type int(4) unsigned NOT NULL default 0,
 36+ hthread_change_type int(4) unsigned NOT NULL,
3737 hthread_change_object int(8) unsigned NULL,
3838 PRIMARY KEY hthread_id_revision (hthread_id, hthread_revision)
3939 ) TYPE=InnoDB;
Index: branches/liquidthreads/extensions/LqtExtension.php
@@ -309,7 +309,7 @@
310310 if ($edit_type != 'editExisting' && $edit_type != 'summarize' && $e->didSave) {
311311 if ( $edit_type == 'reply' ) {
312312 $thread = Threads::newThread( $article, $this->article, $edit_applies_to );
313 - $edit_applies_to->commitRevision();
 313+ $edit_applies_to->commitRevision(Threads::CHANGE_REPLY_CREATED, $thread);
314314 } else {
315315 $thread = Threads::newThread( $article, $this->article );
316316 }
@@ -317,7 +317,7 @@
318318
319319 if ($edit_type == 'summarize' && $e->didSave) {
320320 $edit_applies_to->setSummary( $article );
321 - $edit_applies_to->commitRevision();
 321+ $edit_applies_to->commitRevision(Threads::CHANGE_EDITED_SUMMARY, $edit_applies_to);
322322 }
323323
324324 // Move the thread and replies if subject changed.
@@ -329,7 +329,7 @@
330330 }
331331 // this is unrelated to the subject change and is for all edits:
332332 $thread->setRootRevision( Revision::newFromTitle($thread->root()->getTitle()) );
333 - $thread->commitRevision();
 333+ $thread->commitRevision( Threads::CHANGE_EDITED_ROOT, $thread );
334334 }
335335 }
336336
@@ -955,7 +955,7 @@
956956 function getQueryInfo() {
957957 return array(
958958 'tables' => 'historical_thread',
959 - 'fields' => 'hthread_id, hthread_revision, hthread_contents',
 959+ 'fields' => 'hthread_id, hthread_revision, hthread_contents, hthread_change_type, hthread_change_object',
960960 'conds' => array('hthread_id' => $this->thread->id() ),
961961 'options' => array()
962962 );
@@ -979,8 +979,15 @@
980980 function historyLine( $row, $next, $counter = '', $notificationtimestamp = false, $latest = false, $firstInList = false ) {
981981 /* TODO: best not to refer to LqtView class directly. */
982982 /* We don't use oldid because that has side-effects. */
 983+ $result = array();
 984+ $change_names = array(Threads::CHANGE_EDITED_ROOT => "Comment text edited",
 985+ Threads::CHANGE_EDITED_SUMMARY => "Summary changed",
 986+ Threads::CHANGE_REPLY_CREATED => "New reply created",
 987+ Threads::CHANGE_NEW_THREAD => "New thread created");
983988 $url = LqtView::permalinkUrlWithQuery( $this->thread, 'lqt_oldid=' . $row->hthread_revision );
984 - return "<tr><td><a href=\"$url\">" . $row->hthread_revision . '</a></td></tr>';
 989+ $result[] = "<tr><td><a href=\"$url\">" . $row->hthread_revision . '</a></td></tr>';
 990+ $result[] = "<tr><td>Revision type: {$change_names[$row->hthread_change_type]}.";
 991+ return implode('', $result);
985992 }
986993 function getNotificationTimestamp() {
987994 return "foo";
Index: branches/liquidthreads/extensions/LqtModel.php
@@ -110,6 +110,8 @@
111111 $this->path = $t->path;
112112 $this->id = $t->id;
113113 $this->revisionNumber = $t->revisionNumber;
 114+ $this->changeType = $t->changeType;
 115+ $this->changeObject = $t->changeObject;
114116
115117 $this->replies = array();
116118 foreach ($t->replies as $r) {
@@ -130,7 +132,9 @@
131133 $res = $dbr->insert( 'historical_thread', array(
132134 'hthread_id'=>$tmt->id(),
133135 'hthread_revision'=>$tmt->revisionNumber(),
134 - 'hthread_contents'=>$contents), __METHOD__ );
 136+ 'hthread_contents'=>$contents,
 137+ 'hthread_change_type'=>$tmt->changeType(),
 138+ 'hthread_change_object'=>$tmt->changeObject()), __METHOD__ );
135139 }
136140 static function withIdAtRevision( $id, $rev ) {
137141 $dbr =& wfGetDB( DB_SLAVE );
@@ -144,7 +148,9 @@
145149 else
146150 return null;
147151 }
148 - function isHistorical() { return true; }
 152+ function isHistorical() {
 153+ return true;
 154+ }
149155 }
150156
151157 class Thread {
@@ -172,6 +178,9 @@
173179 protected $revisionNumber;
174180 protected $type;
175181
 182+ protected $changeType;
 183+ protected $changeObject;
 184+
176185 /* Only used by $double to be saved into a historical thread. */
177186 protected $rootRevision;
178187
@@ -181,7 +190,9 @@
182191
183192 protected $replies;
184193
185 - function isHistorical() {return false;}
 194+ function isHistorical() {
 195+ return false;
 196+ }
186197
187198 function revisionNumber() {
188199 return $this->revisionNumber;
@@ -205,25 +216,30 @@
206217 return $results;
207218 }
208219
209 - private function bumpRevisions() {
210 - $this->revisionNumber += 1;
 220+ private function bumpRevisionsOnAncestors($change_type, $change_object) {
 221+ $this->revisionNumber += 1;
 222+ $this->setChangeType($change_type);
 223+ $this->setChangeObject($change_object);
 224+
211225 if( $this->hasSuperthread() )
212 - $this->superthread()->bumpRevisions();
 226+ $this->superthread()->bumpRevisionsOnAncestors($change_type, $change_object);
213227 $dbr =& wfGetDB( DB_MASTER );
214228 $res = $dbr->update( 'thread',
215 - /* SET */ array('thread_revision' => $this->revisionNumber),
 229+ /* SET */ array('thread_revision' => $this->revisionNumber,
 230+ 'thread_change_type'=>$this->changeType,
 231+ 'thread_change_object'=>$this->changeObject),
216232 /* WHERE */ array( 'thread_id' => $this->id ),
217233 __METHOD__);
218234 }
219235
220 - function commitRevision() {
 236+ function commitRevision($change_type, $change_object = null) {
221237 global $wgUser; // TODO global.
222238
223239 // TODO open a transaction.
224240 HistoricalThread::create( $this->double );
225241
226 - $this->bumpRevisions();
227 -
 242+ $this->bumpRevisionsOnAncestors($change_type, $change_object);
 243+
228244 $dbr =& wfGetDB( DB_MASTER );
229245 $res = $dbr->update( 'thread',
230246 /* SET */array( 'thread_root' => $this->rootId,
@@ -233,7 +249,9 @@
234250 'thread_timestamp' => wfTimestampNow(),
235251 'thread_revision' => $this->revisionNumber,
236252 'thread_article_namespace' => $this->articleNamespace,
237 - 'thread_article_title' => $this->articleTitle),
 253+ 'thread_article_title' => $this->articleTitle,
 254+ 'thread_change_type' => $this->changeType,
 255+ 'thread_change_object' => $this->changeObject),
238256 /* WHERE */ array( 'thread_id' => $this->id, ),
239257 __METHOD__);
240258
@@ -329,8 +347,10 @@
330348 $this->timestamp = $line->thread_timestamp;
331349 $this->revisionNumber = $line->thread_revision;
332350 $this->type = $line->thread_type;
 351+ $this->changeType = $line->thread_change_type;
 352+ $this->changeObject = $line->thread_change_object;
 353+
333354 $this->replies = $children;
334 -
335355
336356 $this->double = clone $this;
337357
@@ -511,31 +531,75 @@
512532 function type() {
513533 return $this->type;
514534 }
 535+
 536+ function changeType() {
 537+ return $this->changeType;
 538+ }
 539+
 540+ function changeObject() {
 541+ return $this->changeObject;
 542+ }
 543+
 544+ function setChangeType($t) {
 545+ if (in_array($t, Threads::$VALID_CHANGE_TYPES)) {
 546+ $this->changeType = $t;
 547+ } else {
 548+ throw new MWException( __METHOD__ . ": invalid changeType $t." );
 549+ }
 550+ }
 551+
 552+ function setChangeObject($o) {
 553+ # we assume $o to be a Thread.
 554+ if($o === null) {
 555+ $this->changeObject = null;
 556+ } else {
 557+ $this->changeObject = $o->id();
 558+ }
 559+ }
515560 }
516561
 562+
517563 /** Module of factory methods. */
518564 class Threads {
519565
520566 const TYPE_NORMAL = 0;
521567 const TYPE_MOVED = 1;
 568+ static $VALID_TYPES = array(self::TYPE_NORMAL, self::TYPE_MOVED);
 569+
 570+ const CHANGE_NEW_THREAD = 0;
 571+ const CHANGE_REPLY_CREATED = 1;
 572+ const CHANGE_EDITED_ROOT = 2;
 573+ const CHANGE_EDITED_SUMMARY = 3;
 574+ static $VALID_CHANGE_TYPES = array(self::CHANGE_EDITED_SUMMARY, self::CHANGE_EDITED_ROOT,
 575+ self::CHANGE_REPLY_CREATED, self::CHANGE_NEW_THREAD);
522576
523577 static $loadedThreads = array();
524578
525 - static function newThread( $root, $article, $superthread = null,
526 - $type = self::TYPE_NORMAL, $log = null ) {
527 - /* TODO log is ignored. */
 579+ static function newThread( $root, $article, $superthread = null, $type = self::TYPE_NORMAL ) {
 580+
528581 $dbr =& wfGetDB( DB_MASTER );
529 -
 582+
 583+ if ( !in_array($type, self::$VALID_TYPES) ) {
 584+ throw new MWException(__METHOD__ . ": invalid type $type.");
 585+ }
 586+
530587 if( $article->exists() ) {
531588 $aclause = array("thread_article" => $article->getID());
532589 } else {
533590 $aclause = array("thread_article_namespace" => $article->getTitle()->getNamespace(),
534591 "thread_article_title" => $article->getTitle()->getDBkey());
535592 }
 593+
 594+ if ($superthread) {
 595+ $change_type = self::CHANGE_REPLY_CREATED;
 596+ } else {
 597+ $change_type = self::CHANGE_NEW_THREAD;
 598+ }
536599
537600 $res = $dbr->insert('thread',
538601 array('thread_root' => $root->getID(),
539602 'thread_timestamp' => wfTimestampNow(),
 603+ 'thread_change_type' => $change_type,
540604 'thread_type' => $type) + $aclause,
541605 __METHOD__);
542606
@@ -543,11 +607,14 @@
544608
545609 if( $superthread ) {
546610 $newpath = $superthread->path() . '.' . $newid;
 611+ $change_object_clause = 'thread_change_object = ' . $newid;
547612 } else {
548613 $newpath = $newid;
 614+ $change_object_clause = 'thread_change_object = null';
549615 }
550616 $res = $dbr->update( 'thread',
551 - /* SET */ array( 'thread_path' => $newpath ),
 617+ /* SET */ array( 'thread_path' => $newpath,
 618+ $change_object_clause ),
552619 /* WHERE */ array( 'thread_id' => $newid, ),
553620 __METHOD__);
554621

Status & tagging log