2007-01-16 17:05:30 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
2012-04-30 07:16:10 +00:00
|
|
|
* Specific methods for the patrol log.
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
2007-01-16 17:05:30 +00:00
|
|
|
*
|
2012-04-30 07:16:10 +00:00
|
|
|
* @file
|
2007-01-16 17:05:30 +00:00
|
|
|
* @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
|
|
|
*/
|
2012-04-30 07:16:10 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Class containing static functions for working with
|
|
|
|
|
* logs of patrol events
|
|
|
|
|
*/
|
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?
|
2012-07-10 14:58:52 +00:00
|
|
|
* @param $user User: user performing the action or null to use $wgUser
|
2011-07-24 21:36:04 +00:00
|
|
|
*
|
|
|
|
|
* @return bool
|
2007-01-16 17:05:30 +00:00
|
|
|
*/
|
2012-02-21 22:27:33 +00:00
|
|
|
public static function record( $rc, $auto = false, User $user = null ) {
|
2013-05-08 06:31:55 +00:00
|
|
|
global $wgLogAutopatrol;
|
|
|
|
|
|
|
|
|
|
// do not log autopatrolled edits if setting disables it
|
|
|
|
|
if ( $auto && !$wgLogAutopatrol ) {
|
|
|
|
|
return 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
|
|
|
|
2012-06-30 19:27:41 +00:00
|
|
|
if ( !$user ) {
|
|
|
|
|
global $wgUser;
|
|
|
|
|
$user = $wgUser;
|
|
|
|
|
}
|
2012-02-20 21:36:07 +00:00
|
|
|
|
2012-06-30 19:27:41 +00:00
|
|
|
$entry = new ManualLogEntry( 'patrol', 'patrol' );
|
|
|
|
|
$entry->setTarget( $rc->getTitle() );
|
|
|
|
|
$entry->setParameters( self::buildParams( $rc, $auto ) );
|
|
|
|
|
$entry->setPerformer( $user );
|
|
|
|
|
$logid = $entry->insert();
|
|
|
|
|
if ( !$auto ) {
|
|
|
|
|
$entry->publish( $logid, 'udp' );
|
2007-01-16 17:05:30 +00:00
|
|
|
}
|
2012-06-30 19:27:41 +00:00
|
|
|
return true;
|
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
|
|
|
}
|