Merge "Fix sessionfailure i18n message during authentication"
[lhc/web/wiklou.git] / includes / changes / RecentChange.php
index 588f602..678e39a 100644 (file)
@@ -192,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 {
@@ -203,11 +206,11 @@ 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() {
+               wfDeprecated( __METHOD__, '1.31' );
                return [
                        'rc_id',
                        'rc_timestamp',
@@ -232,7 +235,49 @@ 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' );
+               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'],
+               ];
        }
 
        # Accessors
@@ -284,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 ) ) {
@@ -315,12 +360,8 @@ 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 ) {
@@ -331,7 +372,11 @@ class RecentChange {
                $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 );
+               $row += CommentStore::getStore()->insert( $dbw, 'rc_comment', $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', $row, __METHOD__ );
@@ -361,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
@@ -850,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
         */
@@ -864,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;
@@ -894,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 = [
@@ -942,9 +995,10 @@ 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;
@@ -958,7 +1012,8 @@ 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;
                }
                return isset( $this->mAttribs[$name] ) ? $this->mAttribs[$name] : null;
        }