diff options
Diffstat (limited to 'includes/RecentChange.php')
-rw-r--r-- | includes/RecentChange.php | 235 |
1 files changed, 139 insertions, 96 deletions
diff --git a/includes/RecentChange.php b/includes/RecentChange.php index 332d0390..d7cf995c 100644 --- a/includes/RecentChange.php +++ b/includes/RecentChange.php @@ -55,6 +55,7 @@ * lang the interwiki prefix, automatically set in save() * oldSize text size before the change * newSize text size after the change + * pageStatus status of the page: created, deleted, moved, restored, changed * * temporary: not stored in the database * notificationtimestamp @@ -79,7 +80,7 @@ class RecentChange { * @var Title */ var $mMovedToTitle = false; - var $numberofWatchingusers = 0 ; # Dummy to prevent error message in SpecialRecentchangeslinked + var $numberofWatchingusers = 0; # Dummy to prevent error message in SpecialRecentchangeslinked var $notificationtimestamp; # Factory methods @@ -109,7 +110,7 @@ class RecentChange { /** * Obtain the recent change with a given rc_id value * - * @param $rcid Int rc_id value to retrieve + * @param int $rcid rc_id value to retrieve * @return RecentChange */ public static function newFromId( $rcid ) { @@ -119,13 +120,13 @@ class RecentChange { /** * Find the first recent change matching some specific conditions * - * @param $conds Array of conditions + * @param array $conds of conditions * @param $fname Mixed: override the method name in profiling/logs * @return RecentChange */ public static function newFromConds( $conds, $fname = __METHOD__ ) { $dbr = wfGetDB( DB_SLAVE ); - $row = $dbr->selectRow( 'recentchanges', '*', $conds, $fname ); + $row = $dbr->selectRow( 'recentchanges', self::selectFields(), $conds, $fname ); if ( $row !== false ) { return self::newFromRow( $row ); } else { @@ -133,6 +134,40 @@ class RecentChange { } } + /** + * Return the list of recentchanges fields that should be selected to create + * a new recentchanges object. + * @return array + */ + public static function selectFields() { + return array( + 'rc_id', + 'rc_timestamp', + 'rc_cur_time', + 'rc_user', + 'rc_user_text', + 'rc_namespace', + 'rc_title', + 'rc_comment', + 'rc_minor', + 'rc_bot', + 'rc_new', + 'rc_cur_id', + 'rc_this_oldid', + 'rc_last_oldid', + 'rc_type', + 'rc_patrolled', + 'rc_ip', + 'rc_old_len', + 'rc_new_len', + 'rc_deleted', + 'rc_logid', + 'rc_log_type', + 'rc_log_action', + 'rc_params', + ); + } + # Accessors /** @@ -154,26 +189,13 @@ class RecentChange { * @return Title */ public function &getTitle() { - if( $this->mTitle === false ) { + if ( $this->mTitle === false ) { $this->mTitle = Title::makeTitle( $this->mAttribs['rc_namespace'], $this->mAttribs['rc_title'] ); - # Make sure the correct page ID is process cached - $this->mTitle->resetArticleID( $this->mAttribs['rc_cur_id'] ); } return $this->mTitle; } /** - * @return bool|Title - */ - public function getMovedToTitle() { - if( $this->mMovedToTitle === false ) { - $this->mMovedToTitle = Title::makeTitle( $this->mAttribs['rc_moved_to_ns'], - $this->mAttribs['rc_moved_to_title'] ); - } - return $this->mMovedToTitle; - } - - /** * Get the User object of the person who performed this change. * * @return User @@ -197,30 +219,33 @@ class RecentChange { global $wgLocalInterwiki, $wgPutIPinRC, $wgUseEnotif, $wgShowUpdatedMarker, $wgContLang; $dbw = wfGetDB( DB_MASTER ); - if( !is_array($this->mExtra) ) { + if ( !is_array( $this->mExtra ) ) { $this->mExtra = array(); } $this->mExtra['lang'] = $wgLocalInterwiki; - if( !$wgPutIPinRC ) { + if ( !$wgPutIPinRC ) { $this->mAttribs['rc_ip'] = ''; } # If our database is strict about IP addresses, use NULL instead of an empty string - if( $dbw->strictIPs() and $this->mAttribs['rc_ip'] == '' ) { + if ( $dbw->strictIPs() and $this->mAttribs['rc_ip'] == '' ) { unset( $this->mAttribs['rc_ip'] ); } + # Trim spaces on user supplied text + $this->mAttribs['rc_comment'] = trim( $this->mAttribs['rc_comment'] ); + # Make sure summary is truncated (whole multibyte characters) $this->mAttribs['rc_comment'] = $wgContLang->truncate( $this->mAttribs['rc_comment'], 255 ); # Fixup database timestamps - $this->mAttribs['rc_timestamp'] = $dbw->timestamp($this->mAttribs['rc_timestamp']); - $this->mAttribs['rc_cur_time'] = $dbw->timestamp($this->mAttribs['rc_cur_time']); + $this->mAttribs['rc_timestamp'] = $dbw->timestamp( $this->mAttribs['rc_timestamp'] ); + $this->mAttribs['rc_cur_time'] = $dbw->timestamp( $this->mAttribs['rc_cur_time'] ); $this->mAttribs['rc_id'] = $dbw->nextSequenceValue( 'recentchanges_rc_id_seq' ); ## If we are using foreign keys, an entry of 0 for the page_id will fail, so use NULL - if( $dbw->cascadingDeletes() and $this->mAttribs['rc_cur_id']==0 ) { + if ( $dbw->cascadingDeletes() and $this->mAttribs['rc_cur_id'] == 0 ) { unset( $this->mAttribs['rc_cur_id'] ); } @@ -239,18 +264,19 @@ class RecentChange { } # E-mail notifications - if( $wgUseEnotif || $wgShowUpdatedMarker ) { + if ( $wgUseEnotif || $wgShowUpdatedMarker ) { $editor = $this->getPerformer(); $title = $this->getTitle(); - if ( wfRunHooks( 'AbortEmailNotification', array($editor, $title) ) ) { + if ( wfRunHooks( 'AbortEmailNotification', array( $editor, $title ) ) ) { # @todo FIXME: This would be better as an extension hook $enotif = new EmailNotification(); $enotif->notifyOnPageChange( $editor, $title, $this->mAttribs['rc_timestamp'], $this->mAttribs['rc_comment'], $this->mAttribs['rc_minor'], - $this->mAttribs['rc_last_oldid'] ); + $this->mAttribs['rc_last_oldid'], + $this->mExtra['pageStatus'] ); } } } @@ -258,7 +284,7 @@ class RecentChange { public function notifyRC2UDP() { global $wgRC2UDPAddress, $wgRC2UDPOmitBots; # Notify external application via UDP - if( $wgRC2UDPAddress && ( !$this->mAttribs['rc_bot'] || !$wgRC2UDPOmitBots ) ) { + if ( $wgRC2UDPAddress && ( !$this->mAttribs['rc_bot'] || !$wgRC2UDPOmitBots ) ) { self::sendToUDP( $this->getIRCLine() ); } } @@ -266,10 +292,10 @@ class RecentChange { /** * Send some text to UDP. * @see RecentChange::cleanupForIRC - * @param $line String: text to send - * @param $address String: defaults to $wgRC2UDPAddress. - * @param $prefix String: defaults to $wgRC2UDPPrefix. - * @param $port Int: defaults to $wgRC2UDPPort. (Since 1.17) + * @param string $line text to send + * @param string $address defaults to $wgRC2UDPAddress. + * @param string $prefix defaults to $wgRC2UDPPrefix. + * @param int $port defaults to $wgRC2UDPPort. (Since 1.17) * @return Boolean: success */ public static function sendToUDP( $line, $address = '', $prefix = '', $port = '' ) { @@ -279,12 +305,12 @@ class RecentChange { $prefix = $prefix ? $prefix : $wgRC2UDPPrefix; $port = $port ? $port : $wgRC2UDPPort; # Notify external application via UDP - if( $address ) { + if ( $address ) { $conn = socket_create( AF_INET, SOCK_DGRAM, SOL_UDP ); - if( $conn ) { + if ( $conn ) { $line = $prefix . $line; wfDebug( __METHOD__ . ": sending UDP line: $line\n" ); - socket_sendto( $conn, $line, strlen($line), 0, $address, $port ); + socket_sendto( $conn, $line, strlen( $line ), 0, $address, $port ); socket_close( $conn ); return true; } else { @@ -295,7 +321,7 @@ class RecentChange { } /** - * Remove newlines, carriage returns and decode html entites + * Remove newlines, carriage returns and decode html entities * @param $text String * @return String */ @@ -315,9 +341,9 @@ class RecentChange { $change = $change instanceof RecentChange ? $change - : RecentChange::newFromId($change); + : RecentChange::newFromId( $change ); - if( !$change instanceof RecentChange ) { + if ( !$change instanceof RecentChange ) { return null; } return $change->doMarkPatrolled( $wgUser, $auto ); @@ -336,32 +362,32 @@ class RecentChange { $errors = array(); // If recentchanges patrol is disabled, only new pages // can be patrolled - if( !$wgUseRCPatrol && ( !$wgUseNPPatrol || $this->getAttribute('rc_type') != RC_NEW ) ) { - $errors[] = array('rcpatroldisabled'); + if ( !$wgUseRCPatrol && ( !$wgUseNPPatrol || $this->getAttribute( 'rc_type' ) != RC_NEW ) ) { + $errors[] = array( 'rcpatroldisabled' ); } // Automatic patrol needs "autopatrol", ordinary patrol needs "patrol" $right = $auto ? 'autopatrol' : 'patrol'; $errors = array_merge( $errors, $this->getTitle()->getUserPermissionsErrors( $right, $user ) ); - if( !wfRunHooks('MarkPatrolled', array($this->getAttribute('rc_id'), &$user, false)) ) { - $errors[] = array('hookaborted'); + if ( !wfRunHooks( 'MarkPatrolled', array( $this->getAttribute( 'rc_id' ), &$user, false ) ) ) { + $errors[] = array( 'hookaborted' ); } // Users without the 'autopatrol' right can't patrol their // own revisions - if( $user->getName() == $this->getAttribute('rc_user_text') && !$user->isAllowed('autopatrol') ) { - $errors[] = array('markedaspatrollederror-noautopatrol'); + if ( $user->getName() == $this->getAttribute( 'rc_user_text' ) && !$user->isAllowed( 'autopatrol' ) ) { + $errors[] = array( 'markedaspatrollederror-noautopatrol' ); } - if( $errors ) { + if ( $errors ) { return $errors; } // If the change was patrolled already, do nothing - if( $this->getAttribute('rc_patrolled') ) { + if ( $this->getAttribute( 'rc_patrolled' ) ) { return array(); } // Actually set the 'patrolled' flag in RC $this->reallyMarkPatrolled(); // Log this patrol event PatrolLog::record( $this, $auto, $user ); - wfRunHooks( 'MarkPatrolledComplete', array($this->getAttribute('rc_id'), &$user, false) ); + wfRunHooks( 'MarkPatrolledComplete', array( $this->getAttribute( 'rc_id' ), &$user, false ) ); return array(); } @@ -377,7 +403,7 @@ class RecentChange { 'rc_patrolled' => 1 ), array( - 'rc_id' => $this->getAttribute('rc_id') + 'rc_id' => $this->getAttribute( 'rc_id' ) ), __METHOD__ ); @@ -403,7 +429,7 @@ class RecentChange { * @return RecentChange */ public static function notifyEdit( $timestamp, &$title, $minor, &$user, $comment, $oldId, - $lastTimestamp, $bot, $ip='', $oldSize=0, $newSize=0, $newId=0, $patrol=0 ) { + $lastTimestamp, $bot, $ip = '', $oldSize = 0, $newSize = 0, $newId = 0, $patrol = 0 ) { $rc = new RecentChange; $rc->mTitle = $title; $rc->mPerformer = $user; @@ -421,10 +447,8 @@ class RecentChange { 'rc_this_oldid' => $newId, 'rc_last_oldid' => $oldId, 'rc_bot' => $bot ? 1 : 0, - 'rc_moved_to_ns' => 0, - 'rc_moved_to_title' => '', 'rc_ip' => self::checkIPAddress( $ip ), - 'rc_patrolled' => intval($patrol), + 'rc_patrolled' => intval( $patrol ), 'rc_new' => 0, # obsolete 'rc_old_len' => $oldSize, 'rc_new_len' => $newSize, @@ -435,11 +459,12 @@ class RecentChange { 'rc_params' => '' ); - $rc->mExtra = array( + $rc->mExtra = array( 'prefixedDBkey' => $title->getPrefixedDBkey(), 'lastTimestamp' => $lastTimestamp, 'oldSize' => $oldSize, 'newSize' => $newSize, + 'pageStatus' => 'changed' ); $rc->save(); return $rc; @@ -463,7 +488,7 @@ class RecentChange { * @return RecentChange */ public static function notifyNew( $timestamp, &$title, $minor, &$user, $comment, $bot, - $ip='', $size=0, $newId=0, $patrol=0 ) { + $ip = '', $size = 0, $newId = 0, $patrol = 0 ) { $rc = new RecentChange; $rc->mTitle = $title; $rc->mPerformer = $user; @@ -481,10 +506,8 @@ class RecentChange { 'rc_this_oldid' => $newId, 'rc_last_oldid' => 0, 'rc_bot' => $bot ? 1 : 0, - 'rc_moved_to_ns' => 0, - 'rc_moved_to_title' => '', 'rc_ip' => self::checkIPAddress( $ip ), - 'rc_patrolled' => intval($patrol), + 'rc_patrolled' => intval( $patrol ), 'rc_new' => 1, # obsolete 'rc_old_len' => 0, 'rc_new_len' => $size, @@ -495,11 +518,12 @@ class RecentChange { 'rc_params' => '' ); - $rc->mExtra = array( + $rc->mExtra = array( 'prefixedDBkey' => $title->getPrefixedDBkey(), 'lastTimestamp' => 0, 'oldSize' => 0, - 'newSize' => $size + 'newSize' => $size, + 'pageStatus' => 'created' ); $rc->save(); return $rc; @@ -521,11 +545,11 @@ class RecentChange { * @return bool */ public static function notifyLog( $timestamp, &$title, &$user, $actionComment, $ip, $type, - $action, $target, $logComment, $params, $newId=0, $actionCommentIRC='' ) + $action, $target, $logComment, $params, $newId = 0, $actionCommentIRC = '' ) { global $wgLogRestrictions; # Don't add private logs to RC! - if( isset($wgLogRestrictions[$type]) && $wgLogRestrictions[$type] != '*' ) { + if ( isset( $wgLogRestrictions[$type] ) && $wgLogRestrictions[$type] != '*' ) { return false; } $rc = self::newLogEntry( $timestamp, $title, $user, $actionComment, $ip, $type, $action, @@ -550,9 +574,30 @@ class RecentChange { * @return RecentChange */ public static function newLogEntry( $timestamp, &$title, &$user, $actionComment, $ip, - $type, $action, $target, $logComment, $params, $newId=0, $actionCommentIRC='' ) { + $type, $action, $target, $logComment, $params, $newId = 0, $actionCommentIRC = '' ) { global $wgRequest; + ## Get pageStatus for email notification + switch ( $type . '-' . $action ) { + case 'delete-delete': + $pageStatus = 'deleted'; + break; + case 'move-move': + case 'move-move_redir': + $pageStatus = 'moved'; + break; + case 'delete-restore': + $pageStatus = 'restored'; + break; + case 'upload-upload': + $pageStatus = 'created'; + break; + case 'upload-overwrite': + default: + $pageStatus = 'changed'; + break; + } + $rc = new RecentChange; $rc->mTitle = $target; $rc->mPerformer = $user; @@ -570,8 +615,6 @@ class RecentChange { 'rc_this_oldid' => 0, 'rc_last_oldid' => 0, 'rc_bot' => $user->isAllowed( 'bot' ) ? $wgRequest->getBool( 'bot', true ) : 0, - 'rc_moved_to_ns' => 0, - 'rc_moved_to_title' => '', 'rc_ip' => self::checkIPAddress( $ip ), 'rc_patrolled' => 1, 'rc_new' => 0, # obsolete @@ -584,10 +627,11 @@ class RecentChange { 'rc_params' => $params ); - $rc->mExtra = array( + $rc->mExtra = array( 'prefixedDBkey' => $title->getPrefixedDBkey(), 'lastTimestamp' => 0, 'actionComment' => $actionComment, // the comment appended to the action, passed from LogPage + 'pageStatus' => $pageStatus, 'actionCommentIRC' => $actionCommentIRC ); return $rc; @@ -600,7 +644,7 @@ class RecentChange { */ public function loadFromRow( $row ) { $this->mAttribs = get_object_vars( $row ); - $this->mAttribs['rc_timestamp'] = wfTimestamp(TS_MW, $this->mAttribs['rc_timestamp']); + $this->mAttribs['rc_timestamp'] = wfTimestamp( TS_MW, $this->mAttribs['rc_timestamp'] ); $this->mAttribs['rc_deleted'] = $row->rc_deleted; // MUST be set } @@ -611,7 +655,7 @@ class RecentChange { */ public function loadFromCurRow( $row ) { $this->mAttribs = array( - 'rc_timestamp' => wfTimestamp(TS_MW, $row->rev_timestamp), + 'rc_timestamp' => wfTimestamp( TS_MW, $row->rev_timestamp ), 'rc_cur_time' => $row->rev_timestamp, 'rc_user' => $row->rev_user, 'rc_user_text' => $row->rev_user_text, @@ -621,21 +665,19 @@ class RecentChange { 'rc_minor' => $row->rev_minor_edit ? 1 : 0, 'rc_type' => $row->page_is_new ? RC_NEW : RC_EDIT, 'rc_cur_id' => $row->page_id, - 'rc_this_oldid' => $row->rev_id, - 'rc_last_oldid' => isset($row->rc_last_oldid) ? $row->rc_last_oldid : 0, - 'rc_bot' => 0, - 'rc_moved_to_ns' => 0, - 'rc_moved_to_title' => '', + 'rc_this_oldid' => $row->rev_id, + 'rc_last_oldid' => isset( $row->rc_last_oldid ) ? $row->rc_last_oldid : 0, + 'rc_bot' => 0, 'rc_ip' => '', 'rc_id' => $row->rc_id, 'rc_patrolled' => $row->rc_patrolled, 'rc_new' => $row->page_is_new, # obsolete 'rc_old_len' => $row->rc_old_len, 'rc_new_len' => $row->rc_new_len, - 'rc_params' => isset($row->rc_params) ? $row->rc_params : '', - 'rc_log_type' => isset($row->rc_log_type) ? $row->rc_log_type : null, - 'rc_log_action' => isset($row->rc_log_action) ? $row->rc_log_action : null, - 'rc_log_id' => isset($row->rc_log_id) ? $row->rc_log_id: 0, + 'rc_params' => isset( $row->rc_params ) ? $row->rc_params : '', + 'rc_log_type' => isset( $row->rc_log_type ) ? $row->rc_log_type : null, + 'rc_log_action' => isset( $row->rc_log_action ) ? $row->rc_log_action : null, + 'rc_logid' => isset( $row->rc_logid ) ? $row->rc_logid : 0, 'rc_deleted' => $row->rc_deleted // MUST be set ); } @@ -643,7 +685,7 @@ class RecentChange { /** * Get an attribute value * - * @param $name String Attribute name + * @param string $name Attribute name * @return mixed */ public function getAttribute( $name ) { @@ -664,13 +706,13 @@ class RecentChange { * @return string */ public function diffLinkTrail( $forceCur ) { - if( $this->mAttribs['rc_type'] == RC_EDIT ) { - $trail = "curid=" . (int)($this->mAttribs['rc_cur_id']) . - "&oldid=" . (int)($this->mAttribs['rc_last_oldid']); - if( $forceCur ) { - $trail .= '&diff=0' ; + if ( $this->mAttribs['rc_type'] == RC_EDIT ) { + $trail = "curid=" . (int)( $this->mAttribs['rc_cur_id'] ) . + "&oldid=" . (int)( $this->mAttribs['rc_last_oldid'] ); + if ( $forceCur ) { + $trail .= '&diff=0'; } else { - $trail .= '&diff=' . (int)($this->mAttribs['rc_this_oldid']); + $trail .= '&diff=' . (int)( $this->mAttribs['rc_this_oldid'] ); } } else { $trail = ''; @@ -685,7 +727,7 @@ class RecentChange { global $wgUseRCPatrol, $wgUseNPPatrol, $wgRC2UDPInterwikiPrefix, $wgLocalInterwiki, $wgCanonicalServer, $wgScript; - if( $this->mAttribs['rc_type'] == RC_LOG ) { + if ( $this->mAttribs['rc_type'] == RC_LOG ) { // Don't use SpecialPage::getTitleFor, backwards compatibility with // IRC API which expects "Log". $titleObj = Title::newFromText( 'Log/' . $this->mAttribs['rc_log_type'], NS_SPECIAL ); @@ -695,11 +737,11 @@ class RecentChange { $title = $titleObj->getPrefixedText(); $title = self::cleanupForIRC( $title ); - if( $this->mAttribs['rc_type'] == RC_LOG ) { + if ( $this->mAttribs['rc_type'] == RC_LOG ) { $url = ''; } else { $url = $wgCanonicalServer . $wgScript; - if( $this->mAttribs['rc_type'] == RC_NEW ) { + if ( $this->mAttribs['rc_type'] == RC_NEW ) { $query = '?oldid=' . $this->mAttribs['rc_this_oldid']; } else { $query = '?diff=' . $this->mAttribs['rc_this_oldid'] . '&oldid=' . $this->mAttribs['rc_last_oldid']; @@ -712,15 +754,15 @@ class RecentChange { $url .= $query; } - if( $this->mAttribs['rc_old_len'] !== null && $this->mAttribs['rc_new_len'] !== null ) { + if ( $this->mAttribs['rc_old_len'] !== null && $this->mAttribs['rc_new_len'] !== null ) { $szdiff = $this->mAttribs['rc_new_len'] - $this->mAttribs['rc_old_len']; - if($szdiff < -500) { + if ( $szdiff < -500 ) { $szdiff = "\002$szdiff\002"; - } elseif($szdiff >= 0) { - $szdiff = '+' . $szdiff ; + } elseif ( $szdiff >= 0 ) { + $szdiff = '+' . $szdiff; } // @todo i18n with parentheses in content language? - $szdiff = '(' . $szdiff . ')' ; + $szdiff = '(' . $szdiff . ')'; } else { $szdiff = ''; } @@ -756,7 +798,7 @@ class RecentChange { # see http://www.irssi.org/documentation/formats for some colour codes. prefix is \003, # no colour (\003) switches back to the term default $fullString = "$titleString\0034 $flag\00310 " . - "\00302$url\003 \0035*\003 \00303$user\003 \0035*\003 $szdiff \00310$comment\003\n"; + "\00302$url\003 \0035*\003 \00303$user\003 \0035*\003 $szdiff \00310$comment\003\n"; return $fullString; } @@ -769,13 +811,13 @@ class RecentChange { * @return string */ public function getCharacterDifference( $old = 0, $new = 0 ) { - if( $old === 0 ) { + if ( $old === 0 ) { $old = $this->mAttribs['rc_old_len']; } - if( $new === 0 ) { + if ( $new === 0 ) { $new = $this->mAttribs['rc_new_len']; } - if( $old === null || $new === null ) { + if ( $old === null || $new === null ) { return ''; } return ChangesList::showCharacterDifference( $old, $new ); @@ -789,8 +831,9 @@ class RecentChange { } } else { $ip = $wgRequest->getIP(); - if( !$ip ) + if ( !$ip ) { $ip = ''; + } } return $ip; } |