1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
<?php
/**
* Class containing static functions for working with
* logs of patrol events
*
* @author Rob Church <robchur@gmail.com>
* @author Niklas Laxström
*/
class PatrolLog {
/**
* Record a log event for a change being patrolled
*
* @param $rc Mixed: change identifier or RecentChange object
* @param $auto Boolean: was this patrol event automatic?
*
* @return bool
*/
public static function record( $rc, $auto = false ) {
if ( !$rc instanceof RecentChange ) {
$rc = RecentChange::newFromId( $rc );
if ( !is_object( $rc ) ) {
return false;
}
}
$title = Title::makeTitleSafe( $rc->getAttribute( 'rc_namespace' ), $rc->getAttribute( 'rc_title' ) );
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 ) );
$logid = $entry->insert();
if ( !$auto ) {
$entry->publish( $logid, 'udp' );
}
return true;
}
return false;
}
/**
* Prepare log parameters for a patrolled change
*
* @param $change RecentChange to represent
* @param $auto Boolean: whether the patrol event was automatic
* @return Array
*/
private static function buildParams( $change, $auto ) {
return array(
'4::curid' => $change->getAttribute( 'rc_this_oldid' ),
'5::previd' => $change->getAttribute( 'rc_last_oldid' ),
'6::auto' => (int)$auto
);
}
}
|