http://www.mediawiki.org/wiki/Special:Code/MediaWiki/62012

Revision: 62012
Author:   werdna
Date:     2010-02-05 05:29:15 +0000 (Fri, 05 Feb 2010)

Log Message:
-----------
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
    trunk/extensions/LiquidThreads/LqtFunctions.php
    trunk/extensions/LiquidThreads/classes/Thread.php
    trunk/extensions/LiquidThreads/i18n/Lqt.i18n.php

Added Paths:
-----------
    trunk/extensions/LiquidThreads/classes/LogFormatter.php

Modified: trunk/extensions/LiquidThreads/LiquidThreads.php
===================================================================
--- trunk/extensions/LiquidThreads/LiquidThreads.php    2010-02-05 04:40:57 UTC 
(rev 62011)
+++ trunk/extensions/LiquidThreads/LiquidThreads.php    2010-02-05 05:29:15 UTC 
(rev 62012)
@@ -122,6 +122,7 @@
 $wgAutoloadClasses['ThreadHistoryPager'] = 
"$dir/classes/ThreadHistoryPager.php";
 $wgAutoloadClasses['TalkpageHistoryView'] = 
"$dir/pages/TalkpageHistoryView.php";
 $wgAutoloadClasses['LqtHotTopicsController'] = "$dir/classes/HotTopics.php";
+$wgAutoloadClasses['LqtLogFormatter'] = "$dir/classes/LogFormatter.php";
 
 // View classes
 $wgAutoloadClasses['TalkpageView'] = $dir . 'pages/TalkpageView.php';
@@ -158,8 +159,11 @@
 $wgLogTypes[] = 'liquidthreads';
 $wgLogNames['liquidthreads']          = 'lqt-log-name';
 $wgLogHeaders['liquidthreads']        = 'lqt-log-header';
-$wgLogActionsHandlers['liquidthreads/move'] = 'lqtFormatMoveLogEntry';
 
+foreach( array( 'move', 'split', 'merge', 'subjectedit', 'resort' ) as $action 
) {
+       $wgLogActionsHandlers["liquidthreads/$action"] = 
'LqtLogFormatter::formatLogEntry';
+}
+
 // Preferences
 $wgDefaultUserOptions['lqtnotifytalk'] = false;
 $wgDefaultUserOptions['lqtdisplaydepth'] = 2;

Modified: trunk/extensions/LiquidThreads/LqtFunctions.php
===================================================================
--- trunk/extensions/LiquidThreads/LqtFunctions.php     2010-02-05 04:40:57 UTC 
(rev 62011)
+++ trunk/extensions/LiquidThreads/LqtFunctions.php     2010-02-05 05:29:15 UTC 
(rev 62012)
@@ -37,11 +37,6 @@
        $original_array = $new_assoc;
 }
 
-function lqtFormatMoveLogEntry( $type, $action, $title, $sk, $parameters ) {
-       return wfMsgExt( 'lqt-log-action-move', 'parseinline',
-                                       array( $title->getPrefixedText(), 
$parameters[0], $parameters[1] ) );
-}
-
 function lqtSetupParserFunctions( &$parser ) {
        global $wgLiquidThreadsAllowUserControl;
        

Added: trunk/extensions/LiquidThreads/classes/LogFormatter.php
===================================================================
--- trunk/extensions/LiquidThreads/classes/LogFormatter.php                     
        (rev 0)
+++ trunk/extensions/LiquidThreads/classes/LogFormatter.php     2010-02-05 
05:29:15 UTC (rev 62012)
@@ -0,0 +1,44 @@
+<?php
+
+// Contains formatter functions for all log entry types.
+class LqtLogFormatter {
+       protected static function isForIRC( ) {
+               // FIXME this is a horrific hack, but it's better than spewing 
HTML in the wrong
+               //  language to IRC.
+               return in_string( '/LogPage::addEntry/', wfGetAllCallers() );
+       }
+
+       static function formatLogEntry( $type, $action, $title, $sk, 
$parameters ) {
+               switch( $action ) {
+                       case 'merge':
+                               if ( $parameters[0] ) {
+                                       $msg = 'lqt-log-action-merge-across';
+                               } else {
+                                       $msg = 'lqt-log-action-merge-down';
+                               }
+                               break;
+                       default:
+                               $msg = 'lqt-log-action-'.$action;
+                               break;
+               }
+       
+               $options = array('parseinline');
+               
+               $forIRC = self::isForIRC();
+               
+               if ($forIRC) {
+                       global $wgContLang;
+                       $options['language'] = $wgContLang->getCode();
+               }
+               
+               $replacements = array_merge( array( $title->getPrefixedText() 
), $parameters );
+               
+               $html = wfMsgExt( $msg, $options, $replacements );
+                               
+               if ($forIRC) {
+                       $html = StringUtils::delimiterReplace( '<', '>', '', 
$html );
+               }
+                               
+               return $html;
+       }
+}

Modified: trunk/extensions/LiquidThreads/classes/Thread.php
===================================================================
--- trunk/extensions/LiquidThreads/classes/Thread.php   2010-02-05 04:40:57 UTC 
(rev 62011)
+++ trunk/extensions/LiquidThreads/classes/Thread.php   2010-02-05 05:29:15 UTC 
(rev 62012)
@@ -45,6 +45,8 @@
 
        protected $replies;
        
+       public $dbVersion; // A copy of the thread as it exists in the database.
+       
        static $titleCacheById = array();
        static $replyCacheById = array();
        static $articleCacheById = array();
@@ -133,6 +135,9 @@
                
                // Touch the talk page, too.
                $this->article()->getTitle()->invalidateCache();
+               
+               $this->dbVersion = clone $this;
+               unset( $this->dbVersion->dbVersion );
        }
        
        function setRoot( $article ) {
@@ -157,6 +162,8 @@
                if ( $bump ) {
                        $this->sortkey = wfTimestamp( TS_MW );
                }
+               
+               $original = $this->dbVersion;
 
                $this->modified = wfTimestampNow();
                $this->updateEditedness( $change_type );
@@ -168,12 +175,51 @@
                $topmost->save();
                
                ThreadRevision::create( $this, $change_type, $change_object, 
$reason );
+               $this->logChange( $change_type, $original, $change_object, 
$reason );
 
                if ( $change_type == Threads::CHANGE_EDITED_ROOT ) {
                        NewMessages::writeMessageStateForUpdatedThread( $this, 
$change_type, $wgUser );
                }
        }
        
+       function logChange( $change_type, $original, $change_object = null, 
$reason = '' ) {
+               $log = new LogPage( 'liquidthreads' );
+               
+               if ( is_null($reason) ) {
+                       $reason = '';
+               }
+               
+               switch( $change_type ) {
+                       case Threads::CHANGE_MOVED_TALKPAGE:
+                               $log->addEntry( 'move', $this->title(), $reason,
+                                       array( $original->article()->getTitle(),
+                                               $this->article()->getTitle() ) 
);
+                               break;
+                       case Threads::CHANGE_SPLIT:
+                               $log->addEntry( 'split', $this->title(), 
$reason,
+                                       array( $this->subject(),
+                                               
$original->superthread()->title()
+                                       ) );
+                               break;
+                       case Threads::CHANGE_EDITED_SUBJECT:
+                               $log->addEntry( 'subjectedit', $this->title(), 
$reason,
+                                       array( $original->subject(), 
$this->subject() ) );
+                               break;
+                       case Threads::CHANGE_MERGED_TO:
+                               $oldParent = 
$change_object->dbVersion->isTopmostThread()
+                                               ? ''
+                                               : 
$change_object->dbVersion->superthread()->title();
+                               
+                               
+                               $log->addEntry( 'merge', $this->title(), 
$reason,
+                                       array( $oldParent, 
$change_object->superthread()->title() ) );
+                               break;
+                       case Threads::CHANGE_ADJUSTED_SORTKEY:
+                               $log->addEntry( 'resort', $this->title(), 
$reason,
+                                       array( $original->sortkey(), 
$this->sortkey() ) );
+               }
+       }
+       
        function updateEditedness( $change_type ) {
                global $wgUser;
                
@@ -216,6 +262,9 @@
                
                // Touch the talk page, too.
                $this->article()->getTitle()->invalidateCache();
+               
+               $this->dbVersion = clone $this;
+               unset( $this->dbVersion->dbVersion );
        }
        
        function getRow() {
@@ -329,11 +378,9 @@
                $this->articleNamespace = $new_articleNamespace;
                $this->articleTitle = $new_articleTitle;
                $this->articleId = $new_articleID;
+               $this->article = null;
+               
                $this->commitRevision( Threads::CHANGE_MOVED_TALKPAGE, null, 
$reason );
-               
-               # Log the move
-               $log = new LogPage( 'liquidthreads' );
-               $log->addEntry( 'move', $this->title(), $reason, array( 
$oldTitle, $newTitle ) );
 
                if ( $leave_trace ) {
                        $this->leaveTrace( $reason, $oldTitle, $newTitle );
@@ -355,7 +402,7 @@
                // Make the article edit.
                $traceTitle = Threads::newThreadTitle( $this->subject(), new 
Article_LQT_Compat( $oldTitle ) );
                $redirectArticle = new Article_LQT_Compat( $traceTitle );
-               $redirectArticle->doEdit( $redirectText, $reason, EDIT_NEW );
+               $redirectArticle->doEdit( $redirectText, $reason, EDIT_NEW | 
EDIT_SUPPRESS_RC );
 
                // Add the trace thread to the tracking table.
                $thread = Thread::create( $redirectArticle, new 
Article_LQT_Compat( $oldTitle ), null,
@@ -478,6 +525,9 @@
                }
                
                $this->doLazyUpdates( $line );
+               
+               $this->dbVersion = clone $this;
+               unset( $this->dbVersion->dbVersion );
        }
        
        // Load a list of threads in bulk, including all subthreads.
@@ -1210,13 +1260,13 @@
        
        // On serialization, load all data because it will be different in the 
DB when we wake up.
        function __sleep() {
-               
                $this->loadAllData();
                
                $fields = array_keys( get_object_vars( $this ) );
                
                // Filter out article objects, there be dragons (or 
unserialization problems)
-               $fields = array_diff( $fields, array( 'root', 'article', 
'summary', 'sleeping' ) );
+               $fields = array_diff( $fields, array( 'root', 'article', 
'summary', 'sleeping',
+                                                       'dbVersion' ) );
                
                return $fields;
        }
@@ -1301,6 +1351,8 @@
        public function split( $newSubject, $reason = '', $newSortkey = null ) {
                $oldTopThread = $this->topmostThread();
                $oldParent = $this->superthread();
+               
+               $original = $this->dbVersion;
                        
                self::recursiveSet( $this, $newSubject, $this, null );
                
@@ -1312,13 +1364,18 @@
                        $bump = false;
                }
                
+               // For logging purposes, will be reset by the time this call 
returns.
+               $this->dbVersion = $original;
+               
+               $this->commitRevision( Threads::CHANGE_SPLIT, null, $reason, 
$bump );
                $oldTopThread->commitRevision( Threads::CHANGE_SPLIT_FROM, 
$this, $reason );
-               $this->commitRevision( Threads::CHANGE_SPLIT, null, $reason, 
$bump );
        }
        
        public function moveToParent( $newParent, $reason = '' ) {
                $newSubject = $newParent->subject();
                
+               $original = $this->dbVersion;
+               
                $oldTopThread = $newParent->topmostThread();
                $oldParent = $this->superthread();
                        
@@ -1330,6 +1387,8 @@
                        $oldParent->removeReply( $this );
                }
                
+               $this->dbVersion = $original;
+               
                $oldTopThread->commitRevision( Threads::CHANGE_MERGED_FROM, 
$this, $reason );
                $newParent->commitRevision( Threads::CHANGE_MERGED_TO, $this, 
$reason );
        }

Modified: trunk/extensions/LiquidThreads/i18n/Lqt.i18n.php
===================================================================
--- trunk/extensions/LiquidThreads/i18n/Lqt.i18n.php    2010-02-05 04:40:57 UTC 
(rev 62011)
+++ trunk/extensions/LiquidThreads/i18n/Lqt.i18n.php    2010-02-05 05:29:15 UTC 
(rev 62012)
@@ -206,6 +206,11 @@
        'lqt-log-name' => 'Threaded discussion log',
        'lqt-log-header' => 'This log details actions taken on discussion 
threads.',
        'lqt-log-action-move' => 'moved [[$1]] from [[$2]] to [[$3]].',
+       'lqt-log-action-split' => 'split [[$1]] from under [[$3]], with the new 
subject "$2".',
+       'lqt-log-action-merge-across' => 'moved [[$1]] from under [[$2]] to 
under [[$3]].',
+       'lqt-log-action-merge-down' => 'merged [[$1]] to underneath [[$3]]',
+       'lqt-log-action-subjectedit' => 'changed the subject of [[$1]] from 
"$2" to "$3"',
+       'lqt-log-action-resort' => 'modified the sort order of [[$1]]. Changed 
sort key from $2 to $3.',
 
        // Preferences
        'lqt-preference-notify-talk' => 'E-mail me on replies to a thread I am 
watching',



_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to