r62012 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r62011‎ | r62012 | r62013 >
Date:05:29, 5 February 2010
Author:werdna
Status:deferred (Comments)
Tags:
Comment:
LiquidThreads logging updates.
* Add logging table entries for thread merges, subject modifications, splits and sort-key adjustments.
* Resolve bugs where HTML in the wrong language was being sent to IRC (horrible hack that examines the call stack).
Modified paths:
  • /trunk/extensions/LiquidThreads/LiquidThreads.php (modified) (history)
  • /trunk/extensions/LiquidThreads/LqtFunctions.php (modified) (history)
  • /trunk/extensions/LiquidThreads/classes/LogFormatter.php (added) (history)
  • /trunk/extensions/LiquidThreads/classes/Thread.php (modified) (history)
  • /trunk/extensions/LiquidThreads/i18n/Lqt.i18n.php (modified) (history)

Diff [purge]

Index: trunk/extensions/LiquidThreads/LqtFunctions.php
@@ -37,11 +37,6 @@
3838 $original_array = $new_assoc;
3939 }
4040
41 -function lqtFormatMoveLogEntry( $type, $action, $title, $sk, $parameters ) {
42 - return wfMsgExt( 'lqt-log-action-move', 'parseinline',
43 - array( $title->getPrefixedText(), $parameters[0], $parameters[1] ) );
44 -}
45 -
4641 function lqtSetupParserFunctions( &$parser ) {
4742 global $wgLiquidThreadsAllowUserControl;
4843
Index: trunk/extensions/LiquidThreads/i18n/Lqt.i18n.php
@@ -206,6 +206,11 @@
207207 'lqt-log-name' => 'Threaded discussion log',
208208 'lqt-log-header' => 'This log details actions taken on discussion threads.',
209209 'lqt-log-action-move' => 'moved [[$1]] from [[$2]] to [[$3]].',
 210+ 'lqt-log-action-split' => 'split [[$1]] from under [[$3]], with the new subject "$2".',
 211+ 'lqt-log-action-merge-across' => 'moved [[$1]] from under [[$2]] to under [[$3]].',
 212+ 'lqt-log-action-merge-down' => 'merged [[$1]] to underneath [[$3]]',
 213+ 'lqt-log-action-subjectedit' => 'changed the subject of [[$1]] from "$2" to "$3"',
 214+ 'lqt-log-action-resort' => 'modified the sort order of [[$1]]. Changed sort key from $2 to $3.',
210215
211216 // Preferences
212217 'lqt-preference-notify-talk' => 'E-mail me on replies to a thread I am watching',
Index: trunk/extensions/LiquidThreads/LiquidThreads.php
@@ -122,6 +122,7 @@
123123 $wgAutoloadClasses['ThreadHistoryPager'] = "$dir/classes/ThreadHistoryPager.php";
124124 $wgAutoloadClasses['TalkpageHistoryView'] = "$dir/pages/TalkpageHistoryView.php";
125125 $wgAutoloadClasses['LqtHotTopicsController'] = "$dir/classes/HotTopics.php";
 126+$wgAutoloadClasses['LqtLogFormatter'] = "$dir/classes/LogFormatter.php";
126127
127128 // View classes
128129 $wgAutoloadClasses['TalkpageView'] = $dir . 'pages/TalkpageView.php';
@@ -158,8 +159,11 @@
159160 $wgLogTypes[] = 'liquidthreads';
160161 $wgLogNames['liquidthreads'] = 'lqt-log-name';
161162 $wgLogHeaders['liquidthreads'] = 'lqt-log-header';
162 -$wgLogActionsHandlers['liquidthreads/move'] = 'lqtFormatMoveLogEntry';
163163
 164+foreach( array( 'move', 'split', 'merge', 'subjectedit', 'resort' ) as $action ) {
 165+ $wgLogActionsHandlers["liquidthreads/$action"] = 'LqtLogFormatter::formatLogEntry';
 166+}
 167+
164168 // Preferences
165169 $wgDefaultUserOptions['lqtnotifytalk'] = false;
166170 $wgDefaultUserOptions['lqtdisplaydepth'] = 2;
Index: trunk/extensions/LiquidThreads/classes/LogFormatter.php
@@ -0,0 +1,44 @@
 2+<?php
 3+
 4+// Contains formatter functions for all log entry types.
 5+class LqtLogFormatter {
 6+ protected static function isForIRC( ) {
 7+ // FIXME this is a horrific hack, but it's better than spewing HTML in the wrong
 8+ // language to IRC.
 9+ return in_string( '/LogPage::addEntry/', wfGetAllCallers() );
 10+ }
 11+
 12+ static function formatLogEntry( $type, $action, $title, $sk, $parameters ) {
 13+ switch( $action ) {
 14+ case 'merge':
 15+ if ( $parameters[0] ) {
 16+ $msg = 'lqt-log-action-merge-across';
 17+ } else {
 18+ $msg = 'lqt-log-action-merge-down';
 19+ }
 20+ break;
 21+ default:
 22+ $msg = 'lqt-log-action-'.$action;
 23+ break;
 24+ }
 25+
 26+ $options = array('parseinline');
 27+
 28+ $forIRC = self::isForIRC();
 29+
 30+ if ($forIRC) {
 31+ global $wgContLang;
 32+ $options['language'] = $wgContLang->getCode();
 33+ }
 34+
 35+ $replacements = array_merge( array( $title->getPrefixedText() ), $parameters );
 36+
 37+ $html = wfMsgExt( $msg, $options, $replacements );
 38+
 39+ if ($forIRC) {
 40+ $html = StringUtils::delimiterReplace( '<', '>', '', $html );
 41+ }
 42+
 43+ return $html;
 44+ }
 45+}
Index: trunk/extensions/LiquidThreads/classes/Thread.php
@@ -45,6 +45,8 @@
4646
4747 protected $replies;
4848
 49+ public $dbVersion; // A copy of the thread as it exists in the database.
 50+
4951 static $titleCacheById = array();
5052 static $replyCacheById = array();
5153 static $articleCacheById = array();
@@ -133,6 +135,9 @@
134136
135137 // Touch the talk page, too.
136138 $this->article()->getTitle()->invalidateCache();
 139+
 140+ $this->dbVersion = clone $this;
 141+ unset( $this->dbVersion->dbVersion );
137142 }
138143
139144 function setRoot( $article ) {
@@ -157,6 +162,8 @@
158163 if ( $bump ) {
159164 $this->sortkey = wfTimestamp( TS_MW );
160165 }
 166+
 167+ $original = $this->dbVersion;
161168
162169 $this->modified = wfTimestampNow();
163170 $this->updateEditedness( $change_type );
@@ -168,12 +175,51 @@
169176 $topmost->save();
170177
171178 ThreadRevision::create( $this, $change_type, $change_object, $reason );
 179+ $this->logChange( $change_type, $original, $change_object, $reason );
172180
173181 if ( $change_type == Threads::CHANGE_EDITED_ROOT ) {
174182 NewMessages::writeMessageStateForUpdatedThread( $this, $change_type, $wgUser );
175183 }
176184 }
177185
 186+ function logChange( $change_type, $original, $change_object = null, $reason = '' ) {
 187+ $log = new LogPage( 'liquidthreads' );
 188+
 189+ if ( is_null($reason) ) {
 190+ $reason = '';
 191+ }
 192+
 193+ switch( $change_type ) {
 194+ case Threads::CHANGE_MOVED_TALKPAGE:
 195+ $log->addEntry( 'move', $this->title(), $reason,
 196+ array( $original->article()->getTitle(),
 197+ $this->article()->getTitle() ) );
 198+ break;
 199+ case Threads::CHANGE_SPLIT:
 200+ $log->addEntry( 'split', $this->title(), $reason,
 201+ array( $this->subject(),
 202+ $original->superthread()->title()
 203+ ) );
 204+ break;
 205+ case Threads::CHANGE_EDITED_SUBJECT:
 206+ $log->addEntry( 'subjectedit', $this->title(), $reason,
 207+ array( $original->subject(), $this->subject() ) );
 208+ break;
 209+ case Threads::CHANGE_MERGED_TO:
 210+ $oldParent = $change_object->dbVersion->isTopmostThread()
 211+ ? ''
 212+ : $change_object->dbVersion->superthread()->title();
 213+
 214+
 215+ $log->addEntry( 'merge', $this->title(), $reason,
 216+ array( $oldParent, $change_object->superthread()->title() ) );
 217+ break;
 218+ case Threads::CHANGE_ADJUSTED_SORTKEY:
 219+ $log->addEntry( 'resort', $this->title(), $reason,
 220+ array( $original->sortkey(), $this->sortkey() ) );
 221+ }
 222+ }
 223+
178224 function updateEditedness( $change_type ) {
179225 global $wgUser;
180226
@@ -216,6 +262,9 @@
217263
218264 // Touch the talk page, too.
219265 $this->article()->getTitle()->invalidateCache();
 266+
 267+ $this->dbVersion = clone $this;
 268+ unset( $this->dbVersion->dbVersion );
220269 }
221270
222271 function getRow() {
@@ -329,11 +378,9 @@
330379 $this->articleNamespace = $new_articleNamespace;
331380 $this->articleTitle = $new_articleTitle;
332381 $this->articleId = $new_articleID;
 382+ $this->article = null;
 383+
333384 $this->commitRevision( Threads::CHANGE_MOVED_TALKPAGE, null, $reason );
334 -
335 - # Log the move
336 - $log = new LogPage( 'liquidthreads' );
337 - $log->addEntry( 'move', $this->title(), $reason, array( $oldTitle, $newTitle ) );
338385
339386 if ( $leave_trace ) {
340387 $this->leaveTrace( $reason, $oldTitle, $newTitle );
@@ -355,7 +402,7 @@
356403 // Make the article edit.
357404 $traceTitle = Threads::newThreadTitle( $this->subject(), new Article_LQT_Compat( $oldTitle ) );
358405 $redirectArticle = new Article_LQT_Compat( $traceTitle );
359 - $redirectArticle->doEdit( $redirectText, $reason, EDIT_NEW );
 406+ $redirectArticle->doEdit( $redirectText, $reason, EDIT_NEW | EDIT_SUPPRESS_RC );
360407
361408 // Add the trace thread to the tracking table.
362409 $thread = Thread::create( $redirectArticle, new Article_LQT_Compat( $oldTitle ), null,
@@ -478,6 +525,9 @@
479526 }
480527
481528 $this->doLazyUpdates( $line );
 529+
 530+ $this->dbVersion = clone $this;
 531+ unset( $this->dbVersion->dbVersion );
482532 }
483533
484534 // Load a list of threads in bulk, including all subthreads.
@@ -1210,13 +1260,13 @@
12111261
12121262 // On serialization, load all data because it will be different in the DB when we wake up.
12131263 function __sleep() {
1214 -
12151264 $this->loadAllData();
12161265
12171266 $fields = array_keys( get_object_vars( $this ) );
12181267
12191268 // Filter out article objects, there be dragons (or unserialization problems)
1220 - $fields = array_diff( $fields, array( 'root', 'article', 'summary', 'sleeping' ) );
 1269+ $fields = array_diff( $fields, array( 'root', 'article', 'summary', 'sleeping',
 1270+ 'dbVersion' ) );
12211271
12221272 return $fields;
12231273 }
@@ -1301,6 +1351,8 @@
13021352 public function split( $newSubject, $reason = '', $newSortkey = null ) {
13031353 $oldTopThread = $this->topmostThread();
13041354 $oldParent = $this->superthread();
 1355+
 1356+ $original = $this->dbVersion;
13051357
13061358 self::recursiveSet( $this, $newSubject, $this, null );
13071359
@@ -1312,13 +1364,18 @@
13131365 $bump = false;
13141366 }
13151367
 1368+ // For logging purposes, will be reset by the time this call returns.
 1369+ $this->dbVersion = $original;
 1370+
 1371+ $this->commitRevision( Threads::CHANGE_SPLIT, null, $reason, $bump );
13161372 $oldTopThread->commitRevision( Threads::CHANGE_SPLIT_FROM, $this, $reason );
1317 - $this->commitRevision( Threads::CHANGE_SPLIT, null, $reason, $bump );
13181373 }
13191374
13201375 public function moveToParent( $newParent, $reason = '' ) {
13211376 $newSubject = $newParent->subject();
13221377
 1378+ $original = $this->dbVersion;
 1379+
13231380 $oldTopThread = $newParent->topmostThread();
13241381 $oldParent = $this->superthread();
13251382
@@ -1330,6 +1387,8 @@
13311388 $oldParent->removeReply( $this );
13321389 }
13331390
 1391+ $this->dbVersion = $original;
 1392+
13341393 $oldTopThread->commitRevision( Threads::CHANGE_MERGED_FROM, $this, $reason );
13351394 $newParent->commitRevision( Threads::CHANGE_MERGED_TO, $this, $reason );
13361395 }

Comments

#Comment by Werdna (talk | contribs)   04:16, 8 February 2010

Checked.

#Comment by Werdna (talk | contribs)   04:17, 8 February 2010

Incidentally, note that the horrible IRC workaround will be sorted out soon.

Status & tagging log