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

Revision: 97495
Author:   nikerabbit
Date:     2011-09-19 14:21:05 +0000 (Mon, 19 Sep 2011)
Log Message:
-----------
Converted patrol log to the new system

Modified Paths:
--------------
    trunk/phase3/includes/AutoLoader.php
    trunk/phase3/includes/DefaultSettings.php
    trunk/phase3/includes/LogPage.php
    trunk/phase3/includes/PatrolLog.php
    trunk/phase3/includes/logging/LogEntry.php
    trunk/phase3/includes/logging/LogFormatter.php
    trunk/phase3/languages/messages/MessagesEn.php
    trunk/phase3/maintenance/language/messages.inc

Modified: trunk/phase3/includes/AutoLoader.php
===================================================================
--- trunk/phase3/includes/AutoLoader.php        2011-09-19 14:09:04 UTC (rev 
97494)
+++ trunk/phase3/includes/AutoLoader.php        2011-09-19 14:21:05 UTC (rev 
97495)
@@ -547,6 +547,7 @@
        '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',

Modified: trunk/phase3/includes/DefaultSettings.php
===================================================================
--- trunk/phase3/includes/DefaultSettings.php   2011-09-19 14:09:04 UTC (rev 
97494)
+++ trunk/phase3/includes/DefaultSettings.php   2011-09-19 14:21:05 UTC (rev 
97495)
@@ -5063,7 +5063,6 @@
        'merge/merge'        => 'pagemerge-logentry',
        'suppress/block'     => 'blocklogentry',
        'suppress/reblock'   => 'reblock-logentry',
-       'patrol/patrol'      => 'patrol-log-line',
 );
 
 /**
@@ -5080,6 +5079,7 @@
        'suppress/revision' => 'DeleteLogFormatter',
        'suppress/event'    => 'DeleteLogFormatter',
        'suppress/delete'   => 'DeleteLogFormatter',
+       'patrol/patrol'     => 'PatrolLogFormatter',
 );
 
 /**

Modified: trunk/phase3/includes/LogPage.php
===================================================================
--- trunk/phase3/includes/LogPage.php   2011-09-19 14:09:04 UTC (rev 97494)
+++ trunk/phase3/includes/LogPage.php   2011-09-19 14:21:05 UTC (rev 97495)
@@ -225,11 +225,6 @@
 
                $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 ) );

Modified: trunk/phase3/includes/PatrolLog.php
===================================================================
--- trunk/phase3/includes/PatrolLog.php 2011-09-19 14:09:04 UTC (rev 97494)
+++ trunk/phase3/includes/PatrolLog.php 2011-09-19 14:21:05 UTC (rev 97495)
@@ -5,6 +5,7 @@
  * logs of patrol events
  *
  * @author Rob Church <[email protected]>
+ * @author Niklas Laxström
  */
 class PatrolLog {
 
@@ -17,64 +18,29 @@
         * @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
         *
         * @param $change RecentChange to represent
@@ -83,9 +49,10 @@
         */
        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
                );
        }
+
 }

Modified: trunk/phase3/includes/logging/LogEntry.php
===================================================================
--- trunk/phase3/includes/logging/LogEntry.php  2011-09-19 14:09:04 UTC (rev 
97494)
+++ trunk/phase3/includes/logging/LogEntry.php  2011-09-19 14:21:05 UTC (rev 
97495)
@@ -312,7 +312,7 @@
        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 ) {

Modified: trunk/phase3/includes/logging/LogFormatter.php
===================================================================
--- trunk/phase3/includes/logging/LogFormatter.php      2011-09-19 14:09:04 UTC 
(rev 97494)
+++ trunk/phase3/includes/logging/LogFormatter.php      2011-09-19 14:21:05 UTC 
(rev 97495)
@@ -417,3 +417,42 @@
                }
        }
 }
+
+/**
+ * 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

Modified: trunk/phase3/languages/messages/MessagesEn.php
===================================================================
--- trunk/phase3/languages/messages/MessagesEn.php      2011-09-19 14:09:04 UTC 
(rev 97494)
+++ trunk/phase3/languages/messages/MessagesEn.php      2011-09-19 14:21:05 UTC 
(rev 97495)
@@ -3603,9 +3603,6 @@
 # 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 @@
 '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',
 
 );

Modified: trunk/phase3/maintenance/language/messages.inc
===================================================================
--- trunk/phase3/maintenance/language/messages.inc      2011-09-19 14:09:04 UTC 
(rev 97494)
+++ trunk/phase3/maintenance/language/messages.inc      2011-09-19 14:21:05 UTC 
(rev 97495)
@@ -2556,9 +2556,6 @@
        '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 @@
                'logentry-move-move-noredirect',
                'logentry-move-move_redir',
                'logentry-move-move_redir-noredirect',
+               'logentry-patrol-patrol',
+               'logentry-patrol-patrol-auto',
        ),
 );
 


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to