'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',
'merge/merge' => 'pagemerge-logentry',
'suppress/block' => 'blocklogentry',
'suppress/reblock' => 'reblock-logentry',
- 'patrol/patrol' => 'patrol-log-line',
);
/**
'suppress/revision' => 'DeleteLogFormatter',
'suppress/event' => 'DeleteLogFormatter',
'suppress/delete' => 'DeleteLogFormatter',
+ 'patrol/patrol' => 'PatrolLogFormatter',
);
/**
$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 ) );
* logs of patrol events
*
* @author Rob Church <robchur@gmail.com>
+ * @author Niklas Laxström
*/
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
*
*/
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
);
}
+
}
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 ) {
}
}
}
+
+/**
+ * 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
# 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
'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',
);
'patrol-log' => array(
'patrol-log-page',
'patrol-log-header',
- 'patrol-log-line',
- 'patrol-log-auto',
- 'patrol-log-diff',
'log-show-hide-patrol',
),
'imagedeletion' => array(
'logentry-move-move-noredirect',
'logentry-move-move_redir',
'logentry-move-move_redir-noredirect',
+ 'logentry-patrol-patrol',
+ 'logentry-patrol-patrol-auto',
),
);