diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2012-05-03 13:01:35 +0200 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2012-05-03 13:01:35 +0200 |
commit | d9022f63880ce039446fba8364f68e656b7bf4cb (patch) | |
tree | 16b40fbf17bf7c9ee6f4ead25b16dd192378050a /includes/logging/PatrolLog.php | |
parent | 27cf83d177256813e2e802241085fce5dd0f3fb9 (diff) |
Update to MediaWiki 1.19.0
Diffstat (limited to 'includes/logging/PatrolLog.php')
-rw-r--r-- | includes/logging/PatrolLog.php | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/includes/logging/PatrolLog.php b/includes/logging/PatrolLog.php new file mode 100644 index 00000000..04fdc4f2 --- /dev/null +++ b/includes/logging/PatrolLog.php @@ -0,0 +1,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 + ); + } + +} |