(bug 19441) Updated date formatting for Lithuanian
[mediawiki.git] / includes / PatrolLog.php
blob117ed4e6b91dd444d01eaa6b2159201c5880ec5f
1 <?php
3 /**
4 * Class containing static functions for working with
5 * logs of patrol events
7 * @author Rob Church <robchur@gmail.com>
8 */
9 class PatrolLog {
11 /**
12 * Record a log event for a change being patrolled
14 * @param mixed $change Change identifier or RecentChange object
15 * @param bool $auto Was this patrol event automatic?
17 public static function record( $rc, $auto = false ) {
18 if( !( $rc instanceof RecentChange ) ) {
19 $rc = RecentChange::newFromId( $rc );
20 if( !is_object( $rc ) )
21 return false;
23 $title = Title::makeTitleSafe( $rc->getAttribute( 'rc_namespace' ), $rc->getAttribute( 'rc_title' ) );
24 if( is_object( $title ) ) {
25 $params = self::buildParams( $rc, $auto );
26 $log = new LogPage( 'patrol', false, $auto ? "skipUDP" : "UDP" ); # False suppresses RC entries
27 $log->addEntry( 'patrol', $title, '', $params );
28 return true;
30 return false;
33 /**
34 * Generate the log action text corresponding to a patrol log item
36 * @param Title $title Title of the page that was patrolled
37 * @param array $params Log parameters (from logging.log_params)
38 * @param Skin $skin Skin to use for building links, etc.
39 * @return string
41 public static function makeActionText( $title, $params, $skin ) {
42 list( $cur, /* $prev */, $auto ) = $params;
43 if( is_object( $skin ) ) {
44 # Standard link to the page in question
45 $link = $skin->link( $title );
46 if( $title->exists() ) {
47 # Generate a diff link
48 $query = array(
49 'oldid' => $cur,
50 'diff' => 'prev'
53 $diff = $skin->link(
54 $title,
55 htmlspecialchars( wfMsg( 'patrol-log-diff', $cur ) ),
56 array(),
57 $query,
58 array( 'known', 'noclasses' )
60 } else {
61 # Don't bother with a diff link, it's useless
62 $diff = htmlspecialchars( wfMsg( 'patrol-log-diff', $cur ) );
64 # Indicate whether or not the patrolling was automatic
65 $auto = $auto ? wfMsgHtml( 'patrol-log-auto' ) : '';
66 # Put it all together
67 return wfMsgHtml( 'patrol-log-line', $diff, $link, $auto );
68 } else {
69 $text = $title->getPrefixedText();
70 return wfMsgForContent( 'patrol-log-line', wfMsgHtml('patrol-log-diff',$cur), "[[$text]]", '' );
74 /**
75 * Prepare log parameters for a patrolled change
77 * @param RecentChange $change RecentChange to represent
78 * @param bool $auto Whether the patrol event was automatic
79 * @return array
81 private static function buildParams( $change, $auto ) {
82 return array(
83 $change->getAttribute( 'rc_this_oldid' ),
84 $change->getAttribute( 'rc_last_oldid' ),
85 (int)$auto