wiki.techinc.nl/includes/logging/PatrolLog.php

59 lines
1.5 KiB
PHP
Raw Normal View History

<?php
/**
* Class containing static functions for working with
* logs of patrol events
*
* @author Rob Church <robchur@gmail.com>
2011-09-19 14:21:05 +00:00
* @author Niklas Laxström
*/
class PatrolLog {
/**
* Record a log event for a change being patrolled
*
2010-01-22 19:58:13 +00:00
* @param $rc Mixed: change identifier or RecentChange object
* @param $auto Boolean: was this patrol event automatic?
*
* @return bool
*/
2009-01-09 17:57:22 +00:00
public static function record( $rc, $auto = false ) {
2011-09-19 14:21:05 +00:00
if ( !$rc instanceof RecentChange ) {
2009-01-09 17:57:22 +00:00
$rc = RecentChange::newFromId( $rc );
2011-09-19 14:21:05 +00:00
if ( !is_object( $rc ) ) {
return false;
2011-09-19 14:21:05 +00:00
}
}
2011-09-19 14:21:05 +00:00
2009-01-09 17:57:22 +00:00
$title = Title::makeTitleSafe( $rc->getAttribute( 'rc_namespace' ), $rc->getAttribute( 'rc_title' ) );
2011-09-19 14:21:05 +00:00
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' ), false ) );
2011-09-19 14:21:05 +00:00
$logid = $entry->insert();
if ( !$auto ) {
$entry->publish( $logid, 'udp' );
}
return true;
}
2009-01-09 17:57:22 +00:00
return false;
}
/**
* Prepare log parameters for a patrolled change
*
2010-01-22 19:58:13 +00:00
* @param $change RecentChange to represent
* @param $auto Boolean: whether the patrol event was automatic
* @return Array
*/
private static function buildParams( $change, $auto ) {
return array(
2011-09-19 14:21:05 +00:00
'4::curid' => $change->getAttribute( 'rc_this_oldid' ),
'5::previd' => $change->getAttribute( 'rc_last_oldid' ),
'6::auto' => (int)$auto
);
}
2011-09-19 14:21:05 +00:00
}