Merge "Use {{int:}} on MediaWiki:Blockedtext and MediaWiki:Autoblockedtext"
[lhc/web/wiklou.git] / includes / page / WikiPage.php
index f45036c..cbce884 100644 (file)
@@ -2117,7 +2117,12 @@ class WikiPage implements Page, IDBAccessObject {
                                        : DB_REPLICA; // T154554
 
                                $edit->popts->setSpeculativeRevIdCallback( function () use ( $dbIndex ) {
-                                       return 1 + (int)wfGetDB( $dbIndex )->selectField(
+                                       $lb = MediaWikiServices::getInstance()->getDBLoadBalancer();
+                                       // Use a fresh connection in order to see the latest data, by avoiding
+                                       // stale data from REPEATABLE-READ snapshots.
+                                       $db = $lb->getConnectionRef( $dbIndex, [], false, $lb::CONN_TRX_AUTO );
+
+                                       return 1 + (int)$db->selectField(
                                                'revision',
                                                'MAX(rev_id)',
                                                [],
@@ -2871,13 +2876,32 @@ class WikiPage implements Page, IDBAccessObject {
                // In the future, we may keep revisions and mark them with
                // the rev_deleted field, which is reserved for this purpose.
 
+               // Lock rows in `revision` and its temp tables, but not any others.
+               // Note array_intersect() preserves keys from the first arg, and we're
+               // assuming $revQuery has `revision` primary and isn't using subtables
+               // for anything we care about.
+               $res = $dbw->select(
+                       array_intersect(
+                               $revQuery['tables'],
+                               [ 'revision', 'revision_comment_temp', 'revision_actor_temp' ]
+                       ),
+                       '1',
+                       [ 'rev_page' => $id ],
+                       __METHOD__,
+                       'FOR UPDATE',
+                       $revQuery['joins']
+               );
+               foreach ( $res as $row ) {
+                       // Fetch all rows in case the DB needs that to properly lock them.
+               }
+
                // Get all of the page revisions
                $res = $dbw->select(
                        $revQuery['tables'],
                        $revQuery['fields'],
                        [ 'rev_page' => $id ],
                        __METHOD__,
-                       'FOR UPDATE',
+                       [],
                        $revQuery['joins']
                );
 
@@ -2899,8 +2923,6 @@ class WikiPage implements Page, IDBAccessObject {
                                'ar_rev_id'     => $row->rev_id,
                                'ar_parent_id'  => $row->rev_parent_id,
                                'ar_text_id'    => $row->rev_text_id,
-                               'ar_text'       => '',
-                               'ar_flags'      => '',
                                'ar_len'        => $row->rev_len,
                                'ar_page_id'    => $id,
                                'ar_deleted'    => $suppress ? $bitfield : $row->rev_deleted,
@@ -2956,7 +2978,7 @@ class WikiPage implements Page, IDBAccessObject {
                $logid = $logEntry->insert();
 
                $dbw->onTransactionPreCommitOrIdle(
-                       function () use ( $dbw, $logEntry, $logid ) {
+                       function () use ( $logEntry, $logid ) {
                                // T58776: avoid deadlocks (especially from FileDeleteForm)
                                $logEntry->publish( $logid );
                        },
@@ -3269,7 +3291,7 @@ class WikiPage implements Page, IDBAccessObject {
 
                if ( $wgUseRCPatrol ) {
                        // Mark all reverted edits as patrolled
-                       $set['rc_patrolled'] = 1;
+                       $set['rc_patrolled'] = RecentChange::PRC_PATROLLED;
                }
 
                if ( count( $set ) ) {
@@ -3597,14 +3619,12 @@ class WikiPage implements Page, IDBAccessObject {
                        Hooks::run( 'CategoryAfterPageRemoved', [ $cat, $this, $id ] );
                }
 
-               // Refresh counts on categories that should be empty now, to
-               // trigger possible deletion. Check master for the most
-               // up-to-date cat_pages.
+               // Refresh counts on categories that should be empty now
                if ( count( $deleted ) ) {
                        $rows = $dbw->select(
                                'category',
                                [ 'cat_id', 'cat_title', 'cat_pages', 'cat_subcats', 'cat_files' ],
-                               [ 'cat_title' => $deleted, 'cat_pages <= 0' ],
+                               [ 'cat_title' => $deleted, 'cat_pages <= 100' ],
                                __METHOD__
                        );
                        foreach ( $rows as $row ) {