X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;ds=sidebyside;f=includes%2Fchanges%2FRecentChange.php;h=a47186581a7c5d4990b507e26d9defe20a02faf1;hb=c8257fff63295f75755bb0624ceb9b600f692585;hp=f1233639fe691e0aa956d0e52dd441e3ce62baa1;hpb=5256bb8ce2da1390f84ef535d990129eebd74fd2;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/changes/RecentChange.php b/includes/changes/RecentChange.php index f1233639fe..a47186581a 100644 --- a/includes/changes/RecentChange.php +++ b/includes/changes/RecentChange.php @@ -59,6 +59,10 @@ * temporary: not stored in the database * notificationtimestamp * numberofWatchingusers + * + * @todo Deprecate access to mAttribs (direct or via getAttributes). Right now + * we're having to include both rc_comment and rc_comment_text/rc_comment_data + * so random crap works right. */ class RecentChange { // Constants for the rc_source field. Extensions may also have @@ -188,7 +192,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 { @@ -199,9 +206,11 @@ class RecentChange { /** * Return the list of recentchanges fields that should be selected to create * a new recentchanges object. + * @deprecated since 1.31, use self::getQueryInfo() instead. * @return array */ public static function selectFields() { + wfDeprecated( __METHOD__, '1.31' ); return [ 'rc_id', 'rc_timestamp', @@ -209,7 +218,6 @@ class RecentChange { 'rc_user_text', 'rc_namespace', 'rc_title', - 'rc_comment', 'rc_minor', 'rc_bot', 'rc_new', @@ -227,6 +235,48 @@ class RecentChange { 'rc_log_type', 'rc_log_action', 'rc_params', + ] + CommentStore::newKey( 'rc_comment' )->getFields(); + } + + /** + * 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::newKey( 'rc_comment' )->getJoin(); + return [ + 'tables' => [ 'recentchanges' ] + $commentQuery['tables'], + 'fields' => [ + 'rc_id', + 'rc_timestamp', + 'rc_user', + 'rc_user_text', + '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'], + 'joins' => $commentQuery['joins'], ]; } @@ -279,7 +329,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 ) ) { @@ -310,20 +360,26 @@ 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'] ); - $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 ( $this->mAttribs['rc_cur_id'] == 0 ) { unset( $this->mAttribs['rc_cur_id'] ); } + # Convert mAttribs['rc_comment'] for CommentStore + $row = $this->mAttribs; + $comment = $row['rc_comment']; + unset( $row['rc_comment'], $row['rc_comment_text'], $row['rc_comment_data'] ); + $row += CommentStore::newKey( 'rc_comment' )->insert( $dbw, $comment ); + + # Don't reuse an existing rc_id for the new row, if one happens to be + # set for some reason. + unset( $row['rc_id'] ); + # Insert new row - $dbw->insert( 'recentchanges', $this->mAttribs, __METHOD__ ); + $dbw->insert( 'recentchanges', $row, __METHOD__ ); # Set the ID $this->mAttribs['rc_id'] = $dbw->insertId(); @@ -350,8 +406,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 @@ -586,7 +642,9 @@ class RecentChange { 'rc_cur_id' => $title->getArticleID(), 'rc_user' => $user->getId(), 'rc_user_text' => $user->getName(), - 'rc_comment' => $comment, + 'rc_comment' => &$comment, + 'rc_comment_text' => &$comment, + 'rc_comment_data' => null, 'rc_this_oldid' => $newId, 'rc_last_oldid' => $oldId, 'rc_bot' => $bot ? 1 : 0, @@ -659,7 +717,9 @@ class RecentChange { 'rc_cur_id' => $title->getArticleID(), 'rc_user' => $user->getId(), 'rc_user_text' => $user->getName(), - 'rc_comment' => $comment, + 'rc_comment' => &$comment, + 'rc_comment_text' => &$comment, + 'rc_comment_data' => null, 'rc_this_oldid' => $newId, 'rc_last_oldid' => 0, 'rc_bot' => $bot ? 1 : 0, @@ -789,7 +849,9 @@ class RecentChange { 'rc_cur_id' => $target->getArticleID(), 'rc_user' => $user->getId(), 'rc_user_text' => $user->getName(), - 'rc_comment' => $logComment, + 'rc_comment' => &$logComment, + 'rc_comment_text' => &$logComment, + 'rc_comment_data' => null, 'rc_this_oldid' => $revId, 'rc_last_oldid' => 0, 'rc_bot' => $user->isAllowed( 'bot' ) ? (int)$wgRequest->getBool( 'bot', true ) : 0, @@ -833,6 +895,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 */ @@ -847,8 +910,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; @@ -862,7 +934,9 @@ class RecentChange { 'rc_cur_id' => $pageTitle->getArticleID(), 'rc_user' => $user ? $user->getId() : 0, 'rc_user_text' => $user ? $user->getName() : '', - 'rc_comment' => $comment, + 'rc_comment' => &$comment, + 'rc_comment_text' => &$comment, + 'rc_comment_data' => null, 'rc_this_oldid' => $newRevId, 'rc_last_oldid' => $oldRevId, 'rc_bot' => $bot ? 1 : 0, @@ -875,9 +949,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 = [ @@ -922,6 +994,13 @@ class RecentChange { $this->mAttribs['rc_ip'] = substr( $this->mAttribs['rc_ip'], 0, $n ); } } + + $comment = CommentStore::newKey( 'rc_comment' ) + // Legacy because $row may have come from self::selectFields() + ->getCommentLegacy( wfGetDB( DB_REPLICA ), $row, true )->text; + $this->mAttribs['rc_comment'] = &$comment; + $this->mAttribs['rc_comment_text'] = &$comment; + $this->mAttribs['rc_comment_data'] = null; } /** @@ -931,6 +1010,9 @@ class RecentChange { * @return mixed */ public function getAttribute( $name ) { + if ( $name === 'rc_comment' ) { + return CommentStore::newKey( 'rc_comment' )->getComment( $this->mAttribs, true )->text; + } return isset( $this->mAttribs[$name] ) ? $this->mAttribs[$name] : null; }