Converted patrol log to the new system
authorNiklas Laxström <nikerabbit@users.mediawiki.org>
Mon, 19 Sep 2011 14:21:05 +0000 (14:21 +0000)
committerNiklas Laxström <nikerabbit@users.mediawiki.org>
Mon, 19 Sep 2011 14:21:05 +0000 (14:21 +0000)
includes/AutoLoader.php
includes/DefaultSettings.php
includes/LogPage.php
includes/PatrolLog.php
includes/logging/LogEntry.php
includes/logging/LogFormatter.php
languages/messages/MessagesEn.php
maintenance/language/messages.inc

index dca97f1..ae09c7e 100644 (file)
@@ -547,6 +547,7 @@ $wgAutoloadLocalClasses = array(
        'LegacyLogFormatter' => 'includes/logging/LogFormatter.php',
        'DeleteLogFormatter' => 'includes/logging/LogFormatter.php',
        'MoveLogFormatter' => 'includes/logging/LogFormatter.php',
+       'PatrolLogFormatter' => 'includes/logging/LogFormatter.php',
 
        # includes/media
        'BitmapHandler' => 'includes/media/Bitmap.php',
index 207a63d..4a89ea8 100644 (file)
@@ -5063,7 +5063,6 @@ $wgLogActions = array(
        'merge/merge'        => 'pagemerge-logentry',
        'suppress/block'     => 'blocklogentry',
        'suppress/reblock'   => 'reblock-logentry',
-       'patrol/patrol'      => 'patrol-log-line',
 );
 
 /**
@@ -5080,6 +5079,7 @@ $wgLogActionsHandlers = array(
        'suppress/revision' => 'DeleteLogFormatter',
        'suppress/event'    => 'DeleteLogFormatter',
        'suppress/delete'   => 'DeleteLogFormatter',
+       'patrol/patrol'     => 'PatrolLogFormatter',
 );
 
 /**
index 64f9540..995c609 100644 (file)
@@ -225,11 +225,6 @@ class LogPage {
 
                $key = "$type/$action";
 
-               # Defer patrol log to PatrolLog class
-               if( $key == 'patrol/patrol' ) {
-                       return PatrolLog::makeActionText( $title, $params, $langObjOrNull );
-               }
-
                if( isset( $wgLogActions[$key] ) ) {
                        if( is_null( $title ) ) {
                                $rv = wfMsgExt( $wgLogActions[$key], array( 'parsemag', 'escape', 'language' => $langObj ) );
index 9a23b1a..755d165 100644 (file)
@@ -5,6 +5,7 @@
  * logs of patrol events
  *
  * @author Rob Church <robchur@gmail.com>
+ * @author Niklas Laxström
  */
 class PatrolLog {
 
@@ -17,63 +18,28 @@ class PatrolLog {
         * @return bool
         */
        public static function record( $rc, $auto = false ) {
-               if( !( $rc instanceof RecentChange ) ) {
+               if ( !$rc instanceof RecentChange ) {
                        $rc = RecentChange::newFromId( $rc );
-                       if( !is_object( $rc ) )
+                       if ( !is_object( $rc ) ) {
                                return false;
+                       }
                }
+
                $title = Title::makeTitleSafe( $rc->getAttribute( 'rc_namespace' ), $rc->getAttribute( 'rc_title' ) );
-               if( is_object( $title ) ) {
-                       $params = self::buildParams( $rc, $auto );
-                       $log = new LogPage( 'patrol', false, $auto ? "skipUDP" : "UDP" ); # False suppresses RC entries
-                       $log->addEntry( 'patrol', $title, '', $params );
+               if( $title ) {
+                       $entry = new ManualLogEntry( 'patrol', 'patrol' );
+                       $entry->setTarget( $title );
+                       $entry->setParameters( self::buildParams( $rc, $auto ) );
+                       $entry->setPerformer( User::newFromName( $rc->getAttribute( 'rc_user_text' ) ) );
+                       $logid = $entry->insert();
+                       if ( !$auto ) {
+                               $entry->publish( $logid, 'udp' );
+                       }
                        return true;
                }
                return false;
        }
 
-       /**
-        * Generate the log action text corresponding to a patrol log item
-        *
-        * @param $title Title of the page that was patrolled
-        * @param $params Array: log parameters (from logging.log_params)
-        * @param $lang Language object to use, or false
-        * @return String
-        */
-       public static function makeActionText( $title, $params, $lang ) {
-               list( $cur, /* $prev */, $auto ) = $params;
-               if( is_object( $lang ) ) {
-                       # Standard link to the page in question
-                       $link = Linker::link( $title );
-                       if( $title->exists() ) {
-                               # Generate a diff link
-                               $query = array(
-                                       'oldid' => $cur,
-                                       'diff' => 'prev'
-                               );
-
-                               $diff = Linker::link(
-                                       $title,
-                                       htmlspecialchars( wfMsg( 'patrol-log-diff', $lang->formatNum( $cur, true ) ) ),
-                                       array(),
-                                       $query,
-                                       array( 'known', 'noclasses' )
-                               );
-                       } else {
-                               # Don't bother with a diff link, it's useless
-                               $diff = htmlspecialchars( wfMsg( 'patrol-log-diff', $cur ) );
-                       }
-                       # Indicate whether or not the patrolling was automatic
-                       $auto = $auto ? wfMsgHtml( 'patrol-log-auto' ) : '';
-                       # Put it all together
-                       return wfMsgHtml( 'patrol-log-line', $diff, $link, $auto );
-               } else {
-                       $text = $title->getPrefixedText();
-                       $diff = htmlspecialchars( wfMsgForContent( 'patrol-log-diff', $cur ) );
-                       return wfMsgForContent( 'patrol-log-line', $diff, "[[$text]]", '' );
-               }
-       }
-
        /**
         * Prepare log parameters for a patrolled change
         *
@@ -83,9 +49,10 @@ class PatrolLog {
         */
        private static function buildParams( $change, $auto ) {
                return array(
-                       $change->getAttribute( 'rc_this_oldid' ),
-                       $change->getAttribute( 'rc_last_oldid' ),
-                       (int)$auto
+                       '4::curid' => $change->getAttribute( 'rc_this_oldid' ),
+                       '5::previd' => $change->getAttribute( 'rc_last_oldid' ),
+                       '6::auto' => (int)$auto
                );
        }
+
 }
index 7fd268e..221fa2e 100644 (file)
@@ -312,7 +312,7 @@ class ManualLogEntry extends LogEntryBase {
        protected $performer; ///!< @var User
        protected $target; ///!< @var Title
        protected $timestamp; ///!< @var string
-       protected $comment; ///!< @var string
+       protected $comment = ''; ///!< @var string
        protected $deleted; ///!< @var int
 
        public function __construct( $type, $subtype ) {
index 2e86f04..41ebefc 100644 (file)
@@ -417,3 +417,42 @@ class DeleteLogFormatter extends LogFormatter {
                }
        }
 }
+
+/**
+ * This class formats patrol log entries.
+ * @since 1.19
+ */
+class PatrolLogFormatter extends LogFormatter {
+       protected function getMessageKey() {
+               $key = parent::getMessageKey();
+               $params = $this->getMessageParameters();
+               if ( isset( $params[5] ) && $params[5] ) {
+                       $key .= '-auto';
+               }
+               return $key;
+       }
+
+       protected function getMessageParameters() {
+               $params = parent::getMessageParameters();
+               $newParams = array_slice( $params, 0, 3 );
+
+               $target = $this->entry->getTarget();
+               $oldid = $params[3];
+               $revision = $this->context->getLang()->formatNum( $oldid, true );
+
+               if ( $this->plaintext ) {
+                       $revlink = $revision;
+               } elseif ( $target->exists() ) {
+                       $query = array(
+                               'oldid' => $oldid,
+                               'diff' => 'prev'
+                       );
+                       $revlink = Linker::link( $target, htmlspecialchars( $revision ), array(), $query );
+               } else {
+                       $revlink = htmlspecialchars( $revision );
+               }
+
+               $newParams[3] = Message::rawParam( $revlink );
+               return $newParams;
+       }
+}
\ No newline at end of file
index ddbffab..b681d9d 100644 (file)
@@ -3603,9 +3603,6 @@ This is probably caused by a link to a blacklisted external site.',
 # Patrol log
 'patrol-log-page'      => 'Patrol log',
 'patrol-log-header'    => 'This is a log of patrolled revisions.',
-'patrol-log-line'      => 'marked $1 of $2 patrolled $3',
-'patrol-log-auto'      => '(automatic)',
-'patrol-log-diff'      => 'revision $1',
 'log-show-hide-patrol' => '$1 patrol log',
 
 # Image deletion
@@ -4651,5 +4648,7 @@ This site is experiencing technical difficulties.',
 'logentry-move-move-noredirect'       => '$1 {{GENDER:$2|moved}} page $3 to $4 without leaving a redirect',
 'logentry-move-move_redir'            => '$1 {{GENDER:$2|moved}} page $3 to $4 over redirect',
 'logentry-move-move_redir-noredirect' => '$1 {{GENDER:$2|moved}} page $3 to $4 over a redirect without leaving a redirect',
+'logentry-patrol-patrol'              => '$1 {{GENDER:$2|marked}} revision $4 of page $3 patrolled',
+'logentry-patrol-patrol-auto'         => '$1 automatically {{GENDER:$2|marked}} revision $4 of page $3 patrolled',
 
 );
index 987d8aa..5dcead8 100644 (file)
@@ -2556,9 +2556,6 @@ $wgMessageStructure = array(
        'patrol-log' => array(
                'patrol-log-page',
                'patrol-log-header',
-               'patrol-log-line',
-               'patrol-log-auto',
-               'patrol-log-diff',
                'log-show-hide-patrol',
        ),
        'imagedeletion' => array(
@@ -3515,6 +3512,8 @@ $wgMessageStructure = array(
                'logentry-move-move-noredirect',
                'logentry-move-move_redir',
                'logentry-move-move_redir-noredirect',
+               'logentry-patrol-patrol',
+               'logentry-patrol-patrol-auto',
        ),
 );