2007-01-16 17:05:30 +00:00
|
|
|
<?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
|
2007-01-16 17:05:30 +00:00
|
|
|
*/
|
|
|
|
|
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?
|
2011-07-24 21:36:04 +00:00
|
|
|
*
|
|
|
|
|
* @return bool
|
2007-01-16 17:05:30 +00:00
|
|
|
*/
|
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 ) ) {
|
2007-01-16 17:05:30 +00:00
|
|
|
return false;
|
2011-09-19 14:21:05 +00:00
|
|
|
}
|
2007-01-16 17:05:30 +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 ) );
|
2011-09-20 08:18:20 +00:00
|
|
|
$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' );
|
|
|
|
|
}
|
2007-01-16 17:05:30 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
2009-01-09 17:57:22 +00:00
|
|
|
return false;
|
2007-01-16 17:05:30 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-01-16 17:05:30 +00:00
|
|
|
/**
|
|
|
|
|
* 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
|
2007-01-16 17:05:30 +00:00
|
|
|
*/
|
|
|
|
|
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
|
2007-01-16 17:05:30 +00:00
|
|
|
);
|
|
|
|
|
}
|
2011-09-19 14:21:05 +00:00
|
|
|
|
2007-01-16 17:05:30 +00:00
|
|
|
}
|