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