Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 21
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
PatrolLog
0.00% covered (danger)
0.00%
0 / 20
0.00% covered (danger)
0.00%
0 / 2
30
0.00% covered (danger)
0.00%
0 / 1
 record
0.00% covered (danger)
0.00%
0 / 15
0.00% covered (danger)
0.00%
0 / 1
20
 buildParams
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2/**
3 * Specific methods for the patrol log.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 * @author Rob Church <robchur@gmail.com>
22 * @author Niklas Laxström
23 */
24
25namespace MediaWiki\Logging;
26
27use MediaWiki\Page\PageReferenceValue;
28use MediaWiki\RecentChanges\RecentChange;
29use MediaWiki\User\UserIdentity;
30
31/**
32 * Class containing static functions for working with
33 * logs of patrol events
34 */
35class PatrolLog {
36
37    /**
38     * Record a log event for a change being patrolled
39     *
40     * @param int|RecentChange $rc Change identifier or RecentChange object
41     * @param bool $auto Was this patrol event automatic?
42     * @param UserIdentity $user User performing the action
43     * @param string|string[]|null $tags Change tags to add to the patrol log entry
44     *   ($user should be able to add the specified tags before this is called)
45     *
46     * @return bool
47     */
48    public static function record( $rc, $auto, UserIdentity $user, $tags = null ) {
49        // Do not log autopatrol actions: T184485
50        if ( $auto ) {
51            return false;
52        }
53
54        if ( !$rc instanceof RecentChange ) {
55            $rc = RecentChange::newFromId( $rc );
56            if ( !is_object( $rc ) ) {
57                return false;
58            }
59        }
60
61        $entry = new ManualLogEntry( 'patrol', 'patrol' );
62
63        // B/C: ->getPage() on RC will return a page reference or null, reconcile this in
64        //      $entry->setTarget() call so we don't throw.
65        $page = $rc->getPage() ?? PageReferenceValue::localReference( NS_SPECIAL, 'Badtitle' );
66        $entry->setTarget( $page );
67        $entry->setParameters( self::buildParams( $rc ) );
68        $entry->setPerformer( $user );
69        $entry->addTags( $tags );
70        $logid = $entry->insert();
71        $entry->publish( $logid, 'udp' );
72
73        return true;
74    }
75
76    /**
77     * Prepare log parameters for a patrolled change
78     *
79     * @param RecentChange $change RecentChange to represent
80     * @return array
81     */
82    private static function buildParams( $change ) {
83        return [
84            '4::curid' => $change->getAttribute( 'rc_this_oldid' ),
85            '5::previd' => $change->getAttribute( 'rc_last_oldid' ),
86            '6::auto' => 0
87        ];
88    }
89}
90
91/** @deprecated class alias since 1.44 */
92class_alias( PatrolLog::class, 'PatrolLog' );