r57710 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r57709‎ | r57710 | r57711 >
Date:19:11, 14 October 2009
Author:werdna
Status:deferred
Tags:
Comment:
LiquidThreads history updates
* Add new history type for blanking a post root.
* Add a link to the thread in question on thread permalink views (helps with e.g. split from, merged from).
* Fix bug where wrong diff link was being given for edits to non-toplevel threads.
* Allow must-show threads to be specified in the URL.
* Factor out in-context thread link generation.
Modified paths:
  • /trunk/extensions/LiquidThreads/classes/Hooks.php (modified) (history)
  • /trunk/extensions/LiquidThreads/classes/Thread.php (modified) (history)
  • /trunk/extensions/LiquidThreads/classes/ThreadRevision.php (modified) (history)
  • /trunk/extensions/LiquidThreads/classes/Threads.php (modified) (history)
  • /trunk/extensions/LiquidThreads/classes/View.php (modified) (history)
  • /trunk/extensions/LiquidThreads/i18n/Lqt.i18n.php (modified) (history)
  • /trunk/extensions/LiquidThreads/pages/ThreadHistoricalRevisionView.php (modified) (history)
  • /trunk/extensions/LiquidThreads/pages/ThreadHistoryListingView.php (modified) (history)

Diff [purge]

Index: trunk/extensions/LiquidThreads/i18n/Lqt.i18n.php
@@ -61,21 +61,23 @@
6262 'lqt_hist_merged_from' => 'Reply moved to another thread',
6363 'lqt_hist_merged_to' => 'Reply moved from another thread',
6464 'lqt_hist_split_from' => 'Split to a new thread',
 65+ 'lqt_hist_root_blanked' => 'Removed comment text',
6566
6667 'lqt_revision_as_of' => "Revision as of $2 at $3.",
6768
6869 'lqt_change_new_thread' => 'This is the thread\'s initial revision.',
69 - 'lqt_change_reply_created' => 'The highlighted comment was created in this revision.',
70 - 'lqt_change_edited_root' => 'The highlighted comment was edited in this revision.',
 70+ 'lqt_change_reply_created' => 'The [$1 highlighted comment] was created in this revision.',
 71+ 'lqt_change_edited_root' => 'The [$1 highlighted comment] was edited in this revision.',
7172 'lqt_change_edited_summary' => "The thread's summary was edited",
72 - 'lqt_change_deleted' => 'This thread or a reply to it was deleted',
73 - 'lqt_change_undeleted' => 'The highlighted post was undeleted',
74 - 'lqt_change_moved' => 'This thread was moved to another discussion page',
75 - 'lqt_change_split' => 'This thread was split from another thread',
 73+ 'lqt_change_deleted' => '[$1 This thread] or its parent was deleted',
 74+ 'lqt_change_undeleted' => 'The [$1 highlighted post] was undeleted',
 75+ 'lqt_change_moved' => '[$1 This thread] was moved to another discussion page',
 76+ 'lqt_change_split' => '[$1 This thread] was split from another thread',
7677 'lqt_change_subject_edited' => 'The subject of this thread was changed',
77 - 'lqt_change_merged_from' => 'A reply to this thread was moved to another thread',
78 - 'lqt_change_merged_to' => 'The highlighted reply was moved from another thread',
79 - 'lqt_change_split_from' => 'A subthread of this thread was split into its own thread',
 78+ 'lqt_change_merged_from' => 'A [$1 reply] to this thread was moved to another thread',
 79+ 'lqt_change_merged_to' => 'The [$1 highlighted reply] was moved from another thread',
 80+ 'lqt_change_split_from' => 'A [$1 subthread] of this thread was split into its own thread',
 81+ 'lqt_change_root_blanked' => 'The text of [$1 a comment] was removed.',
8082
8183 'lqt_youhavenewmessages' => 'You have [$1 new messages].',
8284 'lqt_protectedfromreply' => 'This thread has been $1 from being replied to.',
Index: trunk/extensions/LiquidThreads/classes/Threads.php
@@ -22,6 +22,7 @@
2323 const CHANGE_MERGED_FROM = 10;
2424 const CHANGE_MERGED_TO = 11;
2525 const CHANGE_SPLIT_FROM = 12;
 26+ const CHANGE_ROOT_BLANKED = 13;
2627
2728 static $VALID_CHANGE_TYPES = array(
2829 self::CHANGE_EDITED_SUMMARY,
@@ -37,6 +38,7 @@
3839 self::CHANGE_MERGED_FROM,
3940 self::CHANGE_MERGED_TO,
4041 self::CHANGE_SPLIT_FROM,
 42+ self::CHANGE_ROOT_BLANKED,
4143 );
4244
4345 // Possible values of Thread->editedness.
Index: trunk/extensions/LiquidThreads/classes/View.php
@@ -107,9 +107,46 @@
108108 return $sk->link( $title, $text, $attribs, $query );
109109 }
110110
 111+ static function linkInContextData( $thread, $contextType = 'page' ) {
 112+ $query = array();
 113+
 114+ if ( $contextType == 'page' ) {
 115+ $title = clone $thread->article()->getTitle();
 116+
 117+ $dbr = wfGetDB( DB_SLAVE );
 118+ $offset = $thread->topmostThread()->sortkey();
 119+ $offset = wfTimestamp( TS_UNIX, $offset ) + 1;
 120+ $offset = $dbr->timestamp( $offset );
 121+ $query['offset'] = $offset;
 122+ } else {
 123+ $title = clone $thread->title();
 124+ }
 125+
 126+ $query['lqt_mustshow'] = $thread->id();
 127+
 128+ $title->setFragment( '#'.$thread->getAnchorName() );
 129+
 130+ return array( $title, $query );
 131+ }
 132+
 133+ static function linkInContext( $thread, $contextType = 'page', $text = null ) {
 134+ list( $title, $query ) = self::linkInContextData( $thread, $contextType );
 135+
 136+ global $wgUser;
 137+ $sk = $wgUser->getSkin();
 138+
 139+ return $sk->link( $title, $text, array(), $query );
 140+ }
 141+
 142+ static function linkInContextURL( $thread, $contextType = 'page' ) {
 143+ list( $title, $query ) = self::linkInContextData( $thread, $contextType );
 144+
 145+ return $title->getFullURL( $query );
 146+ }
 147+
111148 static function diffQuery( $thread, $revision ) {
112149 $changed_thread = $revision->getChangeObject();
113 - $curr_rev_id = $revision->getThreadObj()->rootRevision();
 150+ $curr_rev_id = $changed_thread->rootRevision();
114151 $curr_rev = Revision::newFromId( $curr_rev_id );
115152 $prev_rev = $curr_rev->getPrevious();
116153 $oldid = $prev_rev ? $prev_rev->getId() : "";
@@ -424,7 +461,8 @@
425462 if ( $e->didSave ) {
426463 $thread = self::postEditUpdates(
427464 $edit_type, $edit_applies_to, $article,
428 - $this->article, $subject, $e->summary, $thread
 465+ $this->article, $subject, $e->summary, $thread,
 466+ $e->textbox1
429467 );
430468 }
431469
@@ -444,7 +482,7 @@
445483 }
446484
447485 static function postEditUpdates( $edit_type, $edit_applies_to, $edit_page, $article,
448 - $subject, $edit_summary, $thread ) {
 486+ $subject, $edit_summary, $thread, $new_text ) {
449487 // Update metadata - create and update thread and thread revision objects as
450488 // appropriate.
451489
@@ -466,8 +504,13 @@
467505 // $this->renameThread( $thread, $subject, $e->summary );
468506 }
469507
 508+ // Use a separate type if the content is blanked.
 509+ $type = strlen( trim( $new_text ) )
 510+ ? Threads::CHANGE_EDITED_ROOT
 511+ : Threads::CHANGE_ROOT_BLANKED;
 512+
470513 // Add the history entry.
471 - $thread->commitRevision( Threads::CHANGE_EDITED_ROOT, $thread, $edit_summary );
 514+ $thread->commitRevision( $type, $thread, $edit_summary );
472515 } else {
473516 $thread = Threads::newThread( $edit_page, $article, null,
474517 Threads::TYPE_NORMAL, $subject );
@@ -1077,11 +1120,19 @@
10781121 }
10791122
10801123 function getMustShowThreads( $threads = array() ) {
1081 - if ( $this->request->getVal( 'lqt_operand' ) ) {
 1124+ if ( $this->request->getCheck( 'lqt_operand' ) ) {
10821125 $operands = explode( ',', $this->request->getVal( 'lqt_operand' ) );
10831126 $threads = array_merge( $threads, $operands );
10841127 }
10851128
 1129+ if ( $this->request->getCheck( 'lqt_mustshow' ) ) {
 1130+ // Check for must-show in the request
 1131+ $specifiedMustShow = $this->request->getVal( 'lqt_mustshow' );
 1132+ $specifiedMustShow = explode( ',', $specifiedMustShow );
 1133+
 1134+ $threads = array_merge( $threads, $specifiedMustShow );
 1135+ }
 1136+
10861137 foreach ( $threads as $walk_thread ) {
10871138 do {
10881139 if ( !is_object( $walk_thread ) ) {
Index: trunk/extensions/LiquidThreads/classes/Hooks.php
@@ -49,7 +49,7 @@
5050 // Make sure it points to the right page. The Pager seems to use the DB
5151 // representation of a timestamp for its offset field, odd.
5252 $dbr = wfGetDB( DB_SLAVE );
53 - $offset = wfTimestamp( TS_UNIX, $thread->topmostThread()->modified() ) + 1;
 53+ $offset = wfTimestamp( TS_UNIX, $thread->topmostThread()->sortkey() ) + 1;
5454 $offset = $dbr->timestamp( $offset );
5555
5656 $thread_link = $changeslist->skin->link( $tmp_title,
Index: trunk/extensions/LiquidThreads/classes/ThreadRevision.php
@@ -4,17 +4,17 @@
55 class ThreadRevision {
66 static $load =
77 array(
8 - 'th_id' => 'mId',
9 - 'th_thread' => 'mThreadId',
 8+ 'th_id' => 'mId',
 9+ 'th_thread' => 'mThreadId',
1010
1111 'th_timestamp' => 'mTimestamp',
1212
13 - 'th_user' => 'mUserId',
 13+ 'th_user' => 'mUserId',
1414 'th_user_text' => 'mUserText',
1515
1616 'th_change_type' => 'mChangeType',
1717 'th_change_object' => 'mChangeObjectId',
18 - 'th_change_comment' => 'mChangeComment',
 18+ 'th_change_comment' => 'mChangeComment',
1919 'th_content' => 'mObjSer',
2020 );
2121
@@ -42,7 +42,7 @@
4343 }
4444
4545 static function create( $thread, $change_type, $change_object = null, $comment = '',
46 - $user = null, $timestamp = null ) {
 46+ $user = null, $timestamp = null ) {
4747 if ( is_null( $user ) ) {
4848 global $wgUser;
4949 $user = $wgUser;
@@ -134,7 +134,13 @@
135135
136136 function getChangeObject() {
137137 if ( !$this->mChangeObject && $this->mChangeObjectId ) {
138 - $this->mChangeObject = Threads::withId( $this->mChangeObjectId );
 138+ $threadObj = $this->getThreadObj();
 139+ $objectId = $this->mChangeObjectId;
 140+ $this->mChangeObject = $threadObj->replyWithId( $objectId );
 141+
 142+ if ( !$this->mChangeObject ) {
 143+ $this->mChangeObject = Threads::withId( $objectId );
 144+ }
139145 }
140146
141147 return $this->mChangeObject;
Index: trunk/extensions/LiquidThreads/classes/Thread.php
@@ -1219,4 +1219,18 @@
12201220
12211221 $this->sortkey = $k;
12221222 }
 1223+
 1224+ function replyWithId( $id ) {
 1225+ if ( $this->id() == $id ) {
 1226+ return $this;
 1227+ }
 1228+
 1229+ foreach( $this->replies() as $reply ) {
 1230+ if ( $obj = $reply->replyWithId($id) ) {
 1231+ return $obj;
 1232+ }
 1233+ }
 1234+
 1235+ return null;
 1236+ }
12231237 }
Index: trunk/extensions/LiquidThreads/pages/ThreadHistoricalRevisionView.php
@@ -35,6 +35,8 @@
3636 Threads::CHANGE_MERGED_TO => 'lqt_change_merged_to',
3737 Threads::CHANGE_SPLIT_FROM => 'lqt_change_split_from',
3838 Threads::CHANGE_EDITED_SUMMARY => 'lqt_change_edited_summary',
 39+ Threads::CHANGE_ROOT_BLANKED => 'lqt_change_root_blanked',
 40+ Threads::CHANGE_EDITED_ROOT => 'lqt_change_edited_root',
3941 );
4042
4143 if ( isset( $messages[$ct] ) ) {
@@ -62,14 +64,25 @@
6365 $ct = $this->mDisplayRevision->getChangeType();
6466
6567 $msg = '';
66 - if ( $ct == Threads::CHANGE_EDITED_ROOT ) {
67 - $diff_link = $this->diffPermalink( $this->thread,
 68+
 69+ $post = $this->mDisplayRevision->getChangeObject();
 70+ $postLinkURL = LqtView::linkInContextURL( $post );
 71+
 72+ $msg = $this->getMessageForChangeType( $ct );
 73+
 74+ if ( $ct == Threads::CHANGE_EDITED_ROOT ||
 75+ $ct == Threads::CHANGE_ROOT_BLANKED ) {
 76+ $diff_link = $this->diffPermalink( $post,
6877 wfMsgExt( 'diff', 'parseinline' ),
6978 $this->mDisplayRevision );
70 - $msg = wfMsgExt( 'lqt_change_edited_root', 'parseinline' ) .
 79+
 80+ $msg = wfMsgExt( $msg,
 81+ array( 'parseinline' ),
 82+ array( $postLinkURL ) ) .
7183 " [$diff_link]";
72 - } else {
73 - $msg = wfMsgExt( $this->getMessageForChangeType( $ct ), 'parseinline' );
 84+ } else {
 85+ $msg = wfMsgExt( $msg, array( 'parseinline' ),
 86+ array( $postLinkURL ) );
7487 }
7588
7689 $html .= $msg;
Index: trunk/extensions/LiquidThreads/pages/ThreadHistoryListingView.php
@@ -46,20 +46,21 @@
4747 $this->view = $view;
4848
4949 self::$change_names =
50 - array(
51 - Threads::CHANGE_EDITED_ROOT => wfMsgNoTrans( 'lqt_hist_comment_edited' ),
52 - Threads::CHANGE_EDITED_SUMMARY => wfMsgNoTrans( 'lqt_hist_summary_changed' ),
53 - Threads::CHANGE_REPLY_CREATED => wfMsgNoTrans( 'lqt_hist_reply_created' ),
54 - Threads::CHANGE_NEW_THREAD => wfMsgNoTrans( 'lqt_hist_thread_created' ),
55 - Threads::CHANGE_DELETED => wfMsgNoTrans( 'lqt_hist_deleted' ),
56 - Threads::CHANGE_UNDELETED => wfMsgNoTrans( 'lqt_hist_undeleted' ),
57 - Threads::CHANGE_MOVED_TALKPAGE => wfMsgNoTrans( 'lqt_hist_moved_talkpage' ),
58 - Threads::CHANGE_EDITED_SUBJECT => wfMsgNoTrans( 'lqt_hist_edited_subject' ),
59 - Threads::CHANGE_SPLIT => wfMsgNoTrans( 'lqt_hist_split' ),
60 - Threads::CHANGE_MERGED_FROM => wfMsgNoTrans( 'lqt_hist_merged_from' ),
61 - Threads::CHANGE_MERGED_TO => wfMsgNoTrans( 'lqt_hist_merged_to' ),
62 - Threads::CHANGE_SPLIT_FROM => wfMsgNoTrans( 'lqt_hist_split_from' ),
63 - );
 50+ array(
 51+ Threads::CHANGE_EDITED_ROOT => wfMsgNoTrans( 'lqt_hist_comment_edited' ),
 52+ Threads::CHANGE_EDITED_SUMMARY => wfMsgNoTrans( 'lqt_hist_summary_changed' ),
 53+ Threads::CHANGE_REPLY_CREATED => wfMsgNoTrans( 'lqt_hist_reply_created' ),
 54+ Threads::CHANGE_NEW_THREAD => wfMsgNoTrans( 'lqt_hist_thread_created' ),
 55+ Threads::CHANGE_DELETED => wfMsgNoTrans( 'lqt_hist_deleted' ),
 56+ Threads::CHANGE_UNDELETED => wfMsgNoTrans( 'lqt_hist_undeleted' ),
 57+ Threads::CHANGE_MOVED_TALKPAGE => wfMsgNoTrans( 'lqt_hist_moved_talkpage' ),
 58+ Threads::CHANGE_EDITED_SUBJECT => wfMsgNoTrans( 'lqt_hist_edited_subject' ),
 59+ Threads::CHANGE_SPLIT => wfMsgNoTrans( 'lqt_hist_split' ),
 60+ Threads::CHANGE_MERGED_FROM => wfMsgNoTrans( 'lqt_hist_merged_from' ),
 61+ Threads::CHANGE_MERGED_TO => wfMsgNoTrans( 'lqt_hist_merged_to' ),
 62+ Threads::CHANGE_SPLIT_FROM => wfMsgNoTrans( 'lqt_hist_split_from' ),
 63+ Threads::CHANGE_ROOT_BLANKED => wfMsgNoTrans( 'lqt_hist_root_blanked' ),
 64+ );
6465 }
6566
6667 function getQueryInfo() {

Status & tagging log