X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;ds=sidebyside;f=includes%2Fchanges%2FRecentChange.php;h=8e8b93f1184dd020d4bef4ba95d35826740518b9;hb=922be510668b6a2bf6073a96668a7a45f6a49c4d;hp=dfaa39816ed8c761729685ec75ca3d0e1039eef5;hpb=e81a7da6c000384b97319c269ffd1e67afcb8ea8;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/changes/RecentChange.php b/includes/changes/RecentChange.php index dfaa39816e..8e8b93f118 100644 --- a/includes/changes/RecentChange.php +++ b/includes/changes/RecentChange.php @@ -34,6 +34,7 @@ * rc_cur_id page_id of associated page entry * rc_user user id who made the entry * rc_user_text user name who made the entry + * rc_actor actor id who made the entry * rc_comment edit summary * rc_this_oldid rev_id associated with this entry (or zero) * rc_last_oldid rev_id associated with the entry before this one (or zero) @@ -73,6 +74,10 @@ class RecentChange { const SRC_EXTERNAL = 'mw.external'; // obsolete const SRC_CATEGORIZE = 'mw.categorize'; + const PRC_UNPATROLLED = 0; + const PRC_PATROLLED = 1; + const PRC_AUTOPATROLLED = 2; + public $mAttribs = []; public $mExtra = []; @@ -210,12 +215,25 @@ class RecentChange { * @return array */ public static function selectFields() { + global $wgActorTableSchemaMigrationStage; + wfDeprecated( __METHOD__, '1.31' ); + if ( $wgActorTableSchemaMigrationStage > MIGRATION_WRITE_BOTH ) { + // If code is using this instead of self::getQueryInfo(), there's a + // decent chance it's going to try to directly access + // $row->rc_user or $row->rc_user_text and we can't give it + // useful values here once those aren't being written anymore. + throw new BadMethodCallException( + 'Cannot use ' . __METHOD__ . ' when $wgActorTableSchemaMigrationStage > MIGRATION_WRITE_BOTH' + ); + } + return [ 'rc_id', 'rc_timestamp', 'rc_user', 'rc_user_text', + 'rc_actor' => 'NULL', 'rc_namespace', 'rc_title', 'rc_minor', @@ -249,13 +267,12 @@ class RecentChange { */ public static function getQueryInfo() { $commentQuery = CommentStore::getStore()->getJoin( 'rc_comment' ); + $actorQuery = ActorMigration::newMigration()->getJoin( 'rc_user' ); return [ - 'tables' => [ 'recentchanges' ] + $commentQuery['tables'], + 'tables' => [ 'recentchanges' ] + $commentQuery['tables'] + $actorQuery['tables'], 'fields' => [ 'rc_id', 'rc_timestamp', - 'rc_user', - 'rc_user_text', 'rc_namespace', 'rc_title', 'rc_minor', @@ -275,8 +292,8 @@ class RecentChange { 'rc_log_type', 'rc_log_action', 'rc_params', - ] + $commentQuery['fields'], - 'joins' => $commentQuery['joins'], + ] + $commentQuery['fields'] + $actorQuery['fields'], + 'joins' => $commentQuery['joins'] + $actorQuery['joins'], ]; } @@ -314,10 +331,14 @@ class RecentChange { */ public function getPerformer() { if ( $this->mPerformer === false ) { - if ( $this->mAttribs['rc_user'] ) { + if ( !empty( $this->mAttribs['rc_actor'] ) ) { + $this->mPerformer = User::newFromActorId( $this->mAttribs['rc_actor'] ); + } elseif ( !empty( $this->mAttribs['rc_user'] ) ) { $this->mPerformer = User::newFromId( $this->mAttribs['rc_user'] ); - } else { + } elseif ( !empty( $this->mAttribs['rc_user_text'] ) ) { $this->mPerformer = User::newFromName( $this->mAttribs['rc_user_text'], false ); + } else { + throw new MWException( 'RecentChange object lacks rc_actor, rc_user, and rc_user_text' ); } } @@ -368,12 +389,22 @@ class RecentChange { unset( $this->mAttribs['rc_cur_id'] ); } - # Convert mAttribs['rc_comment'] for CommentStore $row = $this->mAttribs; + + # Convert mAttribs['rc_comment'] for CommentStore $comment = $row['rc_comment']; unset( $row['rc_comment'], $row['rc_comment_text'], $row['rc_comment_data'] ); $row += CommentStore::getStore()->insert( $dbw, 'rc_comment', $comment ); + # Convert mAttribs['rc_user'] etc for ActorMigration + $user = User::newFromAnyId( + isset( $row['rc_user'] ) ? $row['rc_user'] : null, + isset( $row['rc_user_text'] ) ? $row['rc_user_text'] : null, + isset( $row['rc_actor'] ) ? $row['rc_actor'] : null + ); + unset( $row['rc_user'], $row['rc_user_text'], $row['rc_actor'] ); + $row += ActorMigration::newMigration()->getInsertValues( $dbw, 'rc_user', $user ); + # Don't reuse an existing rc_id for the new row, if one happens to be # set for some reason. unset( $row['rc_id'] ); @@ -591,7 +622,7 @@ class RecentChange { $dbw->update( 'recentchanges', [ - 'rc_patrolled' => 1 + 'rc_patrolled' => self::PRC_PATROLLED ], [ 'rc_id' => $this->getAttribute( 'rc_id' ) @@ -642,6 +673,7 @@ class RecentChange { 'rc_cur_id' => $title->getArticleID(), 'rc_user' => $user->getId(), 'rc_user_text' => $user->getName(), + 'rc_actor' => $user->getActorId(), 'rc_comment' => &$comment, 'rc_comment_text' => &$comment, 'rc_comment_data' => null, @@ -672,9 +704,6 @@ class RecentChange { function () use ( $rc, $tags ) { $rc->addTags( $tags ); $rc->save(); - if ( $rc->mAttribs['rc_patrolled'] ) { - PatrolLog::record( $rc, true, $rc->getPerformer() ); - } }, DeferredUpdates::POSTSEND, wfGetDB( DB_MASTER ) @@ -717,6 +746,7 @@ class RecentChange { 'rc_cur_id' => $title->getArticleID(), 'rc_user' => $user->getId(), 'rc_user_text' => $user->getName(), + 'rc_actor' => $user->getActorId(), 'rc_comment' => &$comment, 'rc_comment_text' => &$comment, 'rc_comment_data' => null, @@ -747,9 +777,6 @@ class RecentChange { function () use ( $rc, $tags ) { $rc->addTags( $tags ); $rc->save(); - if ( $rc->mAttribs['rc_patrolled'] ) { - PatrolLog::record( $rc, true, $rc->getPerformer() ); - } }, DeferredUpdates::POSTSEND, wfGetDB( DB_MASTER ) @@ -849,6 +876,7 @@ class RecentChange { 'rc_cur_id' => $target->getArticleID(), 'rc_user' => $user->getId(), 'rc_user_text' => $user->getName(), + 'rc_actor' => $user->getActorId(), 'rc_comment' => &$logComment, 'rc_comment_text' => &$logComment, 'rc_comment_data' => null, @@ -856,7 +884,7 @@ class RecentChange { 'rc_last_oldid' => 0, 'rc_bot' => $user->isAllowed( 'bot' ) ? (int)$wgRequest->getBool( 'bot', true ) : 0, 'rc_ip' => self::checkIPAddress( $ip ), - 'rc_patrolled' => $markPatrolled ? 1 : 0, + 'rc_patrolled' => $markPatrolled ? self::PRC_PATROLLED : self::PRC_UNPATROLLED, 'rc_new' => 0, # obsolete 'rc_old_len' => null, 'rc_new_len' => null, @@ -934,6 +962,7 @@ class RecentChange { 'rc_cur_id' => $pageTitle->getArticleID(), 'rc_user' => $user ? $user->getId() : 0, 'rc_user_text' => $user ? $user->getName() : '', + 'rc_actor' => $user ? $user->getActorId() : null, 'rc_comment' => &$comment, 'rc_comment_text' => &$comment, 'rc_comment_data' => null, @@ -941,7 +970,7 @@ class RecentChange { 'rc_last_oldid' => $oldRevId, 'rc_bot' => $bot ? 1 : 0, 'rc_ip' => self::checkIPAddress( $ip ), - 'rc_patrolled' => 1, // Always patrolled, just like log entries + 'rc_patrolled' => self::PRC_PATROLLED, // Always patrolled, just like log entries 'rc_new' => 0, # obsolete 'rc_old_len' => null, 'rc_new_len' => null, @@ -1002,6 +1031,15 @@ class RecentChange { $this->mAttribs['rc_comment'] = &$comment; $this->mAttribs['rc_comment_text'] = &$comment; $this->mAttribs['rc_comment_data'] = null; + + $user = User::newFromAnyId( + isset( $this->mAttribs['rc_user'] ) ? $this->mAttribs['rc_user'] : null, + isset( $this->mAttribs['rc_user_text'] ) ? $this->mAttribs['rc_user_text'] : null, + isset( $this->mAttribs['rc_actor'] ) ? $this->mAttribs['rc_actor'] : null + ); + $this->mAttribs['rc_user'] = $user->getId(); + $this->mAttribs['rc_user_text'] = $user->getName(); + $this->mAttribs['rc_actor'] = $user->getActorId(); } /** @@ -1015,6 +1053,24 @@ class RecentChange { return CommentStore::getStore() ->getComment( 'rc_comment', $this->mAttribs, true )->text; } + + if ( $name === 'rc_user' || $name === 'rc_user_text' || $name === 'rc_actor' ) { + $user = User::newFromAnyId( + isset( $this->mAttribs['rc_user'] ) ? $this->mAttribs['rc_user'] : null, + isset( $this->mAttribs['rc_user_text'] ) ? $this->mAttribs['rc_user_text'] : null, + isset( $this->mAttribs['rc_actor'] ) ? $this->mAttribs['rc_actor'] : null + ); + if ( $name === 'rc_user' ) { + return $user->getId(); + } + if ( $name === 'rc_user_text' ) { + return $user->getName(); + } + if ( $name === 'rc_actor' ) { + return $user->getActorId(); + } + } + return isset( $this->mAttribs[$name] ) ? $this->mAttribs[$name] : null; }