From: Niklas Laxström Date: Mon, 19 Sep 2011 14:21:05 +0000 (+0000) Subject: Converted patrol log to the new system X-Git-Tag: 1.31.0-rc.0~27561 X-Git-Url: http://git.cyclocoop.org//%27http:/code.google.com/p/ie7-js//%27?a=commitdiff_plain;h=1a05f8faf78675dc85984f27f355b8825b43efff;p=lhc%2Fweb%2Fwiklou.git Converted patrol log to the new system --- diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php index dca97f1c70..ae09c7e24b 100644 --- a/includes/AutoLoader.php +++ b/includes/AutoLoader.php @@ -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', diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 207a63d627..4a89ea8b0d 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -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', ); /** diff --git a/includes/LogPage.php b/includes/LogPage.php index 64f9540726..995c609177 100644 --- a/includes/LogPage.php +++ b/includes/LogPage.php @@ -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 ) ); diff --git a/includes/PatrolLog.php b/includes/PatrolLog.php index 9a23b1a91c..755d165bca 100644 --- a/includes/PatrolLog.php +++ b/includes/PatrolLog.php @@ -5,6 +5,7 @@ * logs of patrol events * * @author Rob Church + * @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 ); } + } diff --git a/includes/logging/LogEntry.php b/includes/logging/LogEntry.php index 7fd268ec28..221fa2ec4f 100644 --- a/includes/logging/LogEntry.php +++ b/includes/logging/LogEntry.php @@ -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 ) { diff --git a/includes/logging/LogFormatter.php b/includes/logging/LogFormatter.php index 2e86f04f37..41ebefcaf0 100644 --- a/includes/logging/LogFormatter.php +++ b/includes/logging/LogFormatter.php @@ -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 diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index ddbffabf7d..b681d9d803 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -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', ); diff --git a/maintenance/language/messages.inc b/maintenance/language/messages.inc index 987d8aa55b..5dcead8b97 100644 --- a/maintenance/language/messages.inc +++ b/maintenance/language/messages.inc @@ -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', ), );