Trim trailing whitespace
[lhc/web/wiklou.git] / includes / 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 */
9 class PatrolLog {
10
11 /**
12 * Record a log event for a change being patrolled
13 *
14 * @param $rc Mixed: change identifier or RecentChange object
15 * @param $auto Boolean: was this patrol event automatic?
16 *
17 * @return bool
18 */
19 public static function record( $rc, $auto = false ) {
20 if( !( $rc instanceof RecentChange ) ) {
21 $rc = RecentChange::newFromId( $rc );
22 if( !is_object( $rc ) )
23 return false;
24 }
25 $title = Title::makeTitleSafe( $rc->getAttribute( 'rc_namespace' ), $rc->getAttribute( 'rc_title' ) );
26 if( is_object( $title ) ) {
27 $params = self::buildParams( $rc, $auto );
28 $log = new LogPage( 'patrol', false, $auto ? "skipUDP" : "UDP" ); # False suppresses RC entries
29 $log->addEntry( 'patrol', $title, '', $params );
30 return true;
31 }
32 return false;
33 }
34
35 /**
36 * Generate the log action text corresponding to a patrol log item
37 *
38 * @param $title Title of the page that was patrolled
39 * @param $params Array: log parameters (from logging.log_params)
40 * @param $lang Language object to use, or false
41 * @return String
42 */
43 public static function makeActionText( $title, $params, $lang ) {
44 list( $cur, /* $prev */, $auto ) = $params;
45 if( is_object( $lang ) ) {
46 # Standard link to the page in question
47 $link = Linker::link( $title );
48 if( $title->exists() ) {
49 # Generate a diff link
50 $query = array(
51 'oldid' => $cur,
52 'diff' => 'prev'
53 );
54
55 $diff = Linker::link(
56 $title,
57 htmlspecialchars( wfMsg( 'patrol-log-diff', $lang->formatNum( $cur, true ) ) ),
58 array(),
59 $query,
60 array( 'known', 'noclasses' )
61 );
62 } else {
63 # Don't bother with a diff link, it's useless
64 $diff = htmlspecialchars( wfMsg( 'patrol-log-diff', $cur ) );
65 }
66 # Indicate whether or not the patrolling was automatic
67 $auto = $auto ? wfMsgHtml( 'patrol-log-auto' ) : '';
68 # Put it all together
69 return wfMsgHtml( 'patrol-log-line', $diff, $link, $auto );
70 } else {
71 $text = $title->getPrefixedText();
72 $diff = htmlspecialchars( wfMsgForContent( 'patrol-log-diff', $cur ) );
73 return wfMsgForContent( 'patrol-log-line', $diff, "[[$text]]", '' );
74 }
75 }
76
77 /**
78 * Prepare log parameters for a patrolled change
79 *
80 * @param $change RecentChange to represent
81 * @param $auto Boolean: whether the patrol event was automatic
82 * @return Array
83 */
84 private static function buildParams( $change, $auto ) {
85 return array(
86 $change->getAttribute( 'rc_this_oldid' ),
87 $change->getAttribute( 'rc_last_oldid' ),
88 (int)$auto
89 );
90 }
91 }