]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - includes/PatrolLog.php
MediaWiki 1.11.0
[autoinstallsdev/mediawiki.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 mixed $change Change identifier or RecentChange object
15          * @param bool $auto Was this patrol event automatic?
16          */
17         public static function record( $change, $auto = false ) {
18                 if( !( is_object( $change ) && $change instanceof RecentChange ) ) {
19                         $change = RecentChange::newFromId( $change );
20                         if( !is_object( $change ) )
21                                 return false;
22                 }
23                 $title = Title::makeTitleSafe( $change->getAttribute( 'rc_namespace' ),
24                                         $change->getAttribute( 'rc_title' ) );
25                 if( is_object( $title ) ) {
26                         $params = self::buildParams( $change, $auto );
27                         $log = new LogPage( 'patrol', false ); # False suppresses RC entries
28                         $log->addEntry( 'patrol', $title, '', $params );
29                         return true;
30                 } else {
31                         return false;
32                 }
33         }
34         
35         /**
36          * Generate the log action text corresponding to a patrol log item
37          *
38          * @param Title $title Title of the page that was patrolled
39          * @param array $params Log parameters (from logging.log_params)
40          * @param Skin $skin Skin to use for building links, etc.
41          * @return string
42          */
43         public static function makeActionText( $title, $params, $skin ) {
44                 # This is a bit of a hack, but...if $skin is not a Skin, then *do nothing*
45                 # -- this is fine, because the action text we would be queried for under
46                 # these conditions would have gone into recentchanges, which we aren't
47                 # supposed to be updating
48                 if( is_object( $skin ) ) {
49                         list( $cur, /* $prev */, $auto ) = $params;
50                         # Standard link to the page in question
51                         $link = $skin->makeLinkObj( $title );
52                         if( $title->exists() ) {
53                                 # Generate a diff link
54                                 $bits[] = 'oldid=' . urlencode( $cur );
55                                 $bits[] = 'diff=prev';
56                                 $bits = implode( '&', $bits );
57                                 $diff = $skin->makeKnownLinkObj( $title, htmlspecialchars( wfMsg( 'patrol-log-diff', $cur ) ), $bits );
58                         } else {
59                                 # Don't bother with a diff link, it's useless
60                                 $diff = htmlspecialchars( wfMsg( 'patrol-log-diff', $cur ) );
61                         }
62                         # Indicate whether or not the patrolling was automatic
63                         $auto = $auto ? wfMsgHtml( 'patrol-log-auto' ) : '';
64                         # Put it all together
65                         return wfMsgHtml( 'patrol-log-line', $diff, $link, $auto );
66                 } else {
67                         return '';
68                 }
69         }
70         
71         /**
72          * Prepare log parameters for a patrolled change
73          *
74          * @param RecentChange $change RecentChange to represent
75          * @param bool $auto Whether the patrol event was automatic
76          * @return array
77          */
78         private static function buildParams( $change, $auto ) {
79                 return array(
80                         $change->getAttribute( 'rc_this_oldid' ),
81                         $change->getAttribute( 'rc_last_oldid' ),
82                         (int)$auto
83                 );
84         }
85
86 }
87