X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/exercices/journal.php?a=blobdiff_plain;f=includes%2Fchanges%2FRecentChange.php;h=3dacf6af0485e348ca164fce850cbfe9832d2cc5;hb=27c61fb1e94da9114314468fd00bcf129ec064b6;hp=cd110700022812b14f004cea5c0386593ce01afb;hpb=eb779496a61a51f0d2d12a8a7ff0d12d51b89204;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/changes/RecentChange.php b/includes/changes/RecentChange.php index cd11070002..3dacf6af04 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) @@ -192,7 +193,10 @@ class RecentChange { $dbType = DB_REPLICA ) { $db = wfGetDB( $dbType ); - $row = $db->selectRow( 'recentchanges', self::selectFields(), $conds, $fname ); + $rcQuery = self::getQueryInfo(); + $row = $db->selectRow( + $rcQuery['tables'], $rcQuery['fields'], $conds, $fname, [], $rcQuery['joins'] + ); if ( $row !== false ) { return self::newFromRow( $row ); } else { @@ -203,16 +207,29 @@ class RecentChange { /** * Return the list of recentchanges fields that should be selected to create * a new recentchanges object. - * @todo Deprecate this in favor of a method that returns tables and joins - * as well, and use CommentStore::getJoin(). + * @deprecated since 1.31, use self::getQueryInfo() instead. * @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', @@ -232,7 +249,48 @@ class RecentChange { 'rc_log_type', 'rc_log_action', 'rc_params', - ] + CommentStore::newKey( 'rc_comment' )->getFields(); + ] + CommentStore::getStore()->getFields( 'rc_comment' ); + } + + /** + * Return the tables, fields, and join conditions to be selected to create + * a new recentchanges object. + * @since 1.31 + * @return array With three keys: + * - tables: (string[]) to include in the `$table` to `IDatabase->select()` + * - fields: (string[]) to include in the `$vars` to `IDatabase->select()` + * - joins: (array) to include in the `$join_conds` to `IDatabase->select()` + */ + public static function getQueryInfo() { + $commentQuery = CommentStore::getStore()->getJoin( 'rc_comment' ); + $actorQuery = ActorMigration::newMigration()->getJoin( 'rc_user' ); + return [ + 'tables' => [ 'recentchanges' ] + $commentQuery['tables'] + $actorQuery['tables'], + 'fields' => [ + 'rc_id', + 'rc_timestamp', + 'rc_namespace', + 'rc_title', + 'rc_minor', + 'rc_bot', + 'rc_new', + 'rc_cur_id', + 'rc_this_oldid', + 'rc_last_oldid', + 'rc_type', + 'rc_source', + 'rc_patrolled', + 'rc_ip', + 'rc_old_len', + 'rc_new_len', + 'rc_deleted', + 'rc_logid', + 'rc_log_type', + 'rc_log_action', + 'rc_params', + ] + $commentQuery['fields'] + $actorQuery['fields'], + 'joins' => $commentQuery['joins'] + $actorQuery['joins'], + ]; } # Accessors @@ -269,10 +327,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' ); } } @@ -284,7 +346,7 @@ class RecentChange { * @param bool $noudp */ public function save( $noudp = false ) { - global $wgPutIPinRC, $wgUseEnotif, $wgShowUpdatedMarker, $wgContLang; + global $wgPutIPinRC, $wgUseEnotif, $wgShowUpdatedMarker; $dbw = wfGetDB( DB_MASTER ); if ( !is_array( $this->mExtra ) ) { @@ -315,9 +377,6 @@ class RecentChange { # 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'] ); @@ -326,11 +385,21 @@ 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::newKey( 'rc_comment' )->insert( $dbw, $comment ); + $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. @@ -364,8 +433,8 @@ class RecentChange { // Never send an RC notification email about categorization changes if ( - $this->mAttribs['rc_type'] != RC_CATEGORIZE && - Hooks::run( 'AbortEmailNotification', [ $editor, $title, $this ] ) + Hooks::run( 'AbortEmailNotification', [ $editor, $title, $this ] ) && + $this->mAttribs['rc_type'] != RC_CATEGORIZE ) { // @FIXME: This would be better as an extension hook // Send emails or email jobs once this row is safely committed @@ -600,6 +669,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, @@ -675,6 +745,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, @@ -807,6 +878,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, @@ -853,6 +925,7 @@ class RecentChange { * @param bool $bot true, if the change was made by a bot * @param string $ip IP address of the user, if the change was made anonymously * @param int $deleted Indicates whether the change has been deleted + * @param bool $added true, if the category was added, false for removed * * @return RecentChange */ @@ -867,8 +940,17 @@ class RecentChange { $lastTimestamp, $bot, $ip = '', - $deleted = 0 + $deleted = 0, + $added = null ) { + // Done in a backwards compatible way. + $params = [ + 'hidden-cat' => WikiCategoryPage::factory( $categoryTitle )->isHidden() + ]; + if ( $added !== null ) { + $params['added'] = $added; + } + $rc = new RecentChange; $rc->mTitle = $categoryTitle; $rc->mPerformer = $user; @@ -882,6 +964,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, @@ -897,9 +980,7 @@ class RecentChange { 'rc_logid' => 0, 'rc_log_type' => null, 'rc_log_action' => '', - 'rc_params' => serialize( [ - 'hidden-cat' => WikiCategoryPage::factory( $categoryTitle )->isHidden() - ] ) + 'rc_params' => serialize( $params ) ]; $rc->mExtra = [ @@ -945,12 +1026,22 @@ class RecentChange { } } - $comment = CommentStore::newKey( 'rc_comment' ) - // Legacy because $row probably came from self::selectFields() - ->getCommentLegacy( wfGetDB( DB_REPLICA ), $row, true )->text; + $comment = CommentStore::getStore() + // Legacy because $row may have come from self::selectFields() + ->getCommentLegacy( wfGetDB( DB_REPLICA ), 'rc_comment', $row, true ) + ->text; $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(); } /** @@ -961,8 +1052,27 @@ class RecentChange { */ public function getAttribute( $name ) { if ( $name === 'rc_comment' ) { - return CommentStore::newKey( 'rc_comment' )->getComment( $this->mAttribs, true )->text; + 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; } @@ -1058,9 +1168,9 @@ class RecentChange { public function parseParams() { $rcParams = $this->getAttribute( 'rc_params' ); - MediaWiki\suppressWarnings(); + Wikimedia\suppressWarnings(); $unserializedParams = unserialize( $rcParams ); - MediaWiki\restoreWarnings(); + Wikimedia\restoreWarnings(); return $unserializedParams; }