2 class JSONRCFeedFormatter
implements RCFeedFormatter
{
4 * Generates a notification that can be easily interpreted by a machine.
5 * @see RCFeedFormatter::getLine
7 public function getLine( array $feed, RecentChange
$rc, $actionComment ) {
8 global $wgCanonicalServer, $wgScriptPath, $wgArticlePath, $wgDBname;
9 $attrib = $rc->getAttributes();
12 // Usually, RC ID is exposed only for patrolling purposes,
13 // but there is no real reason not to expose it in other cases,
14 // and I can see how this may be potentially useful for clients.
15 'id' => $attrib['rc_id'],
16 'type' => $attrib['rc_type'],
17 'namespace' => $rc->getTitle()->getNamespace(),
18 'title' => $rc->getTitle()->getPrefixedText(),
19 'comment' => $attrib['rc_comment'],
20 'timestamp' => (int)wfTimestamp( TS_UNIX
, $attrib['rc_timestamp'] ),
21 'user' => $attrib['rc_user_text'],
22 'bot' => (bool)$attrib['rc_bot'],
25 if ( isset( $feed['channel'] ) ) {
26 $packet['channel'] = $feed['channel'];
29 $type = $attrib['rc_type'];
30 if ( $type == RC_EDIT ||
$type == RC_NEW
) {
31 global $wgUseRCPatrol, $wgUseNPPatrol;
33 $packet['minor'] = $attrib['rc_minor'];
34 if ( $wgUseRCPatrol ||
( $type == RC_NEW
&& $wgUseNPPatrol ) ) {
35 $packet['patrolled'] = $attrib['rc_patrolled'];
41 $packet['length'] = array( 'old' => $attrib['rc_old_len'], 'new' => $attrib['rc_new_len'] );
42 $packet['revision'] = array( 'old' => $attrib['rc_last_oldid'], 'new' => $attrib['rc_this_oldid'] );
46 $packet['length'] = array( 'old' => NULL, 'new' => $attrib['rc_new_len'] );
47 $packet['revision'] = array( 'old' => NULL, 'new' => $attrib['rc_this_oldid'] );
51 $packet['log_type'] = $attrib['rc_log_type'];
52 $packet['log_action'] = $attrib['rc_log_action'];
53 if ( $attrib['rc_params'] ) {
55 $params = unserialize( $attrib['rc_params'] );
58 // If it's an actual serialised false...
59 $attrib['rc_params'] == serialize( false ) ||
60 // Or if we did not get false back when trying to unserialise
63 // From ApiQueryLogEvents::addLogParams
65 // Keys like "4::paramname" can't be used for output so we change them to "paramname"
66 foreach ( $params as $key => $value ) {
67 if ( strpos( $key, ':' ) === false ) {
68 $logParams[$key] = $value;
71 $logParam = explode( ':', $key, 3 );
72 $logParams[$logParam[2]] = $value;
74 $packet['log_params'] = $logParams;
76 $packet['log_params'] = explode( "\n", $attrib['rc_params'] );
79 $packet['log_action_comment'] = $actionComment;
83 $packet['server_url'] = $wgCanonicalServer;
84 $packet['server_script_path'] = $wgScriptPath ?
: '/';
85 $packet['wiki'] = $wgDBname;
87 return FormatJson
::encode( $packet );