MediaWiki
REL1_24
|
00001 <?php 00002 00027 abstract class MachineReadableRCFeedFormatter implements RCFeedFormatter { 00028 00034 abstract protected function formatArray( array $packet ); 00035 00040 public function getLine( array $feed, RecentChange $rc, $actionComment ) { 00041 global $wgCanonicalServer, $wgServerName, $wgScriptPath; 00042 00043 $packet = array( 00044 // Usually, RC ID is exposed only for patrolling purposes, 00045 // but there is no real reason not to expose it in other cases, 00046 // and I can see how this may be potentially useful for clients. 00047 'id' => $rc->getAttribute( 'rc_id' ), 00048 'type' => RecentChange::parseFromRCType( $rc->getAttribute( 'rc_type' ) ), 00049 'namespace' => $rc->getTitle()->getNamespace(), 00050 'title' => $rc->getTitle()->getPrefixedText(), 00051 'comment' => $rc->getAttribute( 'rc_comment' ), 00052 'timestamp' => (int)wfTimestamp( TS_UNIX, $rc->getAttribute( 'rc_timestamp' ) ), 00053 'user' => $rc->getAttribute( 'rc_user_text' ), 00054 'bot' => (bool)$rc->getAttribute( 'rc_bot' ), 00055 ); 00056 00057 if ( isset( $feed['channel'] ) ) { 00058 $packet['channel'] = $feed['channel']; 00059 } 00060 00061 $type = $rc->getAttribute( 'rc_type' ); 00062 if ( $type == RC_EDIT || $type == RC_NEW ) { 00063 global $wgUseRCPatrol, $wgUseNPPatrol; 00064 00065 $packet['minor'] = (bool)$rc->getAttribute( 'rc_minor' ); 00066 if ( $wgUseRCPatrol || ( $type == RC_NEW && $wgUseNPPatrol ) ) { 00067 $packet['patrolled'] = (bool)$rc->getAttribute( 'rc_patrolled' ); 00068 } 00069 } 00070 00071 switch ( $type ) { 00072 case RC_EDIT: 00073 $packet['length'] = array( 00074 'old' => $rc->getAttribute( 'rc_old_len' ), 00075 'new' => $rc->getAttribute( 'rc_new_len' ) 00076 ); 00077 $packet['revision'] = array( 00078 'old' => $rc->getAttribute( 'rc_last_oldid' ), 00079 'new' => $rc->getAttribute( 'rc_this_oldid' ) 00080 ); 00081 break; 00082 00083 case RC_NEW: 00084 $packet['length'] = array( 'old' => null, 'new' => $rc->getAttribute( 'rc_new_len' ) ); 00085 $packet['revision'] = array( 'old' => null, 'new' => $rc->getAttribute( 'rc_this_oldid' ) ); 00086 break; 00087 00088 case RC_LOG: 00089 $packet['log_id'] = $rc->getAttribute( 'rc_logid' ); 00090 $packet['log_type'] = $rc->getAttribute( 'rc_log_type' ); 00091 $packet['log_action'] = $rc->getAttribute( 'rc_log_action' ); 00092 if ( $rc->getAttribute( 'rc_params' ) ) { 00093 wfSuppressWarnings(); 00094 $params = unserialize( $rc->getAttribute( 'rc_params' ) ); 00095 wfRestoreWarnings(); 00096 if ( 00097 // If it's an actual serialised false... 00098 $rc->getAttribute( 'rc_params' ) == serialize( false ) || 00099 // Or if we did not get false back when trying to unserialise 00100 $params !== false 00101 ) { 00102 // From ApiQueryLogEvents::addLogParams 00103 $logParams = array(); 00104 // Keys like "4::paramname" can't be used for output so we change them to "paramname" 00105 foreach ( $params as $key => $value ) { 00106 if ( strpos( $key, ':' ) === false ) { 00107 $logParams[$key] = $value; 00108 continue; 00109 } 00110 $logParam = explode( ':', $key, 3 ); 00111 $logParams[$logParam[2]] = $value; 00112 } 00113 $packet['log_params'] = $logParams; 00114 } else { 00115 $packet['log_params'] = explode( "\n", $rc->getAttribute( 'rc_params' ) ); 00116 } 00117 } 00118 $packet['log_action_comment'] = $actionComment; 00119 break; 00120 } 00121 00122 $packet['server_url'] = $wgCanonicalServer; 00123 $packet['server_name'] = $wgServerName; 00124 00125 $packet['server_script_path'] = $wgScriptPath ?: '/'; 00126 $packet['wiki'] = wfWikiID(); 00127 00128 return $this->formatArray( $packet ); 00129 } 00130 }