Revert "MessageCache invalidation improvements" (temporary)
[lhc/web/wiklou.git] / includes / page / WikiPage.php
index 54bc6f6..f016494 100644 (file)
@@ -624,7 +624,7 @@ class WikiPage implements Page, IDBAccessObject {
                        // SELECT. Thus we need S1 to also gets the revision row FOR UPDATE; otherwise, it
                        // may not find it since a page row UPDATE and revision row INSERT by S2 may have
                        // happened after the first S1 SELECT.
-                       // http://dev.mysql.com/doc/refman/5.0/en/set-transaction.html#isolevel_repeatable-read
+                       // https://dev.mysql.com/doc/refman/5.0/en/set-transaction.html#isolevel_repeatable-read
                        $flags = Revision::READ_LOCKING;
                        $revision = Revision::newFromPageId( $this->getId(), $latest, $flags );
                } elseif ( $this->mDataLoadedFrom == self::READ_LATEST ) {
@@ -938,8 +938,8 @@ class WikiPage implements Page, IDBAccessObject {
                $dbw->startAtomic( __METHOD__ );
 
                if ( !$oldLatest || $oldLatest == $this->lockAndGetLatest() ) {
-                       $dbw->replace( 'redirect',
-                               [ 'rd_from' ],
+                       $dbw->upsert(
+                               'redirect',
                                [
                                        'rd_from' => $this->getId(),
                                        'rd_namespace' => $rt->getNamespace(),
@@ -947,6 +947,13 @@ class WikiPage implements Page, IDBAccessObject {
                                        'rd_fragment' => $rt->getFragment(),
                                        'rd_interwiki' => $rt->getInterwiki(),
                                ],
+                               [ 'rd_from' ],
+                               [
+                                       'rd_namespace' => $rt->getNamespace(),
+                                       'rd_title' => $rt->getDBkey(),
+                                       'rd_fragment' => $rt->getFragment(),
+                                       'rd_interwiki' => $rt->getInterwiki(),
+                               ],
                                __METHOD__
                        );
                }
@@ -2485,13 +2492,13 @@ class WikiPage implements Page, IDBAccessObject {
                }
 
                if ( !$protect ) { // No protection at all means unprotection
-                       $revCommentMsg = 'unprotectedarticle';
+                       $revCommentMsg = 'unprotectedarticle-comment';
                        $logAction = 'unprotect';
                } elseif ( $isProtected ) {
-                       $revCommentMsg = 'modifiedarticleprotection';
+                       $revCommentMsg = 'modifiedarticleprotection-comment';
                        $logAction = 'modify';
                } else {
-                       $revCommentMsg = 'protectedarticle';
+                       $revCommentMsg = 'protectedarticle-comment';
                        $logAction = 'protect';
                }
 
@@ -2675,16 +2682,14 @@ class WikiPage implements Page, IDBAccessObject {
        public function insertProtectNullRevision( $revCommentMsg, array $limit,
                array $expiry, $cascade, $reason, $user = null
        ) {
-               global $wgContLang;
                $dbw = wfGetDB( DB_MASTER );
 
                // Prepare a null revision to be added to the history
-               $editComment = $wgContLang->ucfirst(
-                       wfMessage(
-                               $revCommentMsg,
-                               $this->mTitle->getPrefixedText()
-                       )->inContentLanguage()->text()
-               );
+               $editComment = wfMessage(
+                       $revCommentMsg,
+                       $this->mTitle->getPrefixedText(),
+                       $user ? $user->getName() : ''
+               )->inContentLanguage()->text();
                if ( $reason ) {
                        $editComment .= wfMessage( 'colon-separator' )->inContentLanguage()->text() . $reason;
                }
@@ -2863,7 +2868,7 @@ class WikiPage implements Page, IDBAccessObject {
         */
        public function doDeleteArticleReal(
                $reason, $suppress = false, $u1 = null, $u2 = null, &$error = '', User $user = null,
-               $tags = []
+               $tags = [], $logsubtype = 'delete'
        ) {
                global $wgUser, $wgContentHandlerUseDB;
 
@@ -2926,17 +2931,13 @@ class WikiPage implements Page, IDBAccessObject {
                        $content = null;
                }
 
+               $fields = Revision::selectFields();
+               $bitfield = false;
+
                // Bitfields to further suppress the content
                if ( $suppress ) {
-                       $bitfield = 0;
-                       // This should be 15...
-                       $bitfield |= Revision::DELETED_TEXT;
-                       $bitfield |= Revision::DELETED_COMMENT;
-                       $bitfield |= Revision::DELETED_USER;
-                       $bitfield |= Revision::DELETED_RESTRICTED;
-                       $deletionFields = [ $dbw->addQuotes( $bitfield ) . ' AS deleted' ];
-               } else {
-                       $deletionFields = [ 'rev_deleted AS deleted' ];
+                       $bitfield = Revision::SUPPRESSED_ALL;
+                       $fields = array_diff( $fields, [ 'rev_deleted' ] );
                }
 
                // For now, shunt the revision data into the archive table.
@@ -2947,10 +2948,9 @@ class WikiPage implements Page, IDBAccessObject {
                // the rev_deleted field, which is reserved for this purpose.
 
                // Get all of the page revisions
-               $fields = array_diff( Revision::selectFields(), [ 'rev_deleted' ] );
                $res = $dbw->select(
                        'revision',
-                       array_merge( $fields, $deletionFields ),
+                       $fields,
                        [ 'rev_page' => $id ],
                        __METHOD__,
                        'FOR UPDATE'
@@ -2973,7 +2973,7 @@ class WikiPage implements Page, IDBAccessObject {
                                'ar_flags'      => '',
                                'ar_len'        => $row->rev_len,
                                'ar_page_id'    => $id,
-                               'ar_deleted'    => $row->deleted,
+                               'ar_deleted'    => $suppress ? $bitfield : $row->rev_deleted,
                                'ar_sha1'       => $row->rev_sha1,
                        ];
                        if ( $wgContentHandlerUseDB ) {
@@ -2999,7 +2999,7 @@ class WikiPage implements Page, IDBAccessObject {
                // Log the deletion, if the page was suppressed, put it in the suppression log instead
                $logtype = $suppress ? 'suppress' : 'delete';
 
-               $logEntry = new ManualLogEntry( $logtype, 'delete' );
+               $logEntry = new ManualLogEntry( $logtype, $logsubtype );
                $logEntry->setPerformer( $user );
                $logEntry->setTarget( $logTitle );
                $logEntry->setComment( $reason );
@@ -3556,107 +3556,103 @@ class WikiPage implements Page, IDBAccessObject {
         * Update all the appropriate counts in the category table, given that
         * we've added the categories $added and deleted the categories $deleted.
         *
+        * This should only be called from deferred updates or jobs to avoid contention.
+        *
         * @param array $added The names of categories that were added
         * @param array $deleted The names of categories that were deleted
         * @param integer $id Page ID (this should be the original deleted page ID)
         */
        public function updateCategoryCounts( array $added, array $deleted, $id = 0 ) {
                $id = $id ?: $this->getId();
+               $ns = $this->getTitle()->getNamespace();
+
+               $addFields = [ 'cat_pages = cat_pages + 1' ];
+               $removeFields = [ 'cat_pages = cat_pages - 1' ];
+               if ( $ns == NS_CATEGORY ) {
+                       $addFields[] = 'cat_subcats = cat_subcats + 1';
+                       $removeFields[] = 'cat_subcats = cat_subcats - 1';
+               } elseif ( $ns == NS_FILE ) {
+                       $addFields[] = 'cat_files = cat_files + 1';
+                       $removeFields[] = 'cat_files = cat_files - 1';
+               }
+
                $dbw = wfGetDB( DB_MASTER );
-               $method = __METHOD__;
-               // Do this at the end of the commit to reduce lock wait timeouts
-               $dbw->onTransactionPreCommitOrIdle(
-                       function () use ( $dbw, $added, $deleted, $id, $method ) {
-                               $ns = $this->getTitle()->getNamespace();
-
-                               $addFields = [ 'cat_pages = cat_pages + 1' ];
-                               $removeFields = [ 'cat_pages = cat_pages - 1' ];
-                               if ( $ns == NS_CATEGORY ) {
-                                       $addFields[] = 'cat_subcats = cat_subcats + 1';
-                                       $removeFields[] = 'cat_subcats = cat_subcats - 1';
-                               } elseif ( $ns == NS_FILE ) {
-                                       $addFields[] = 'cat_files = cat_files + 1';
-                                       $removeFields[] = 'cat_files = cat_files - 1';
-                               }
 
-                               if ( count( $added ) ) {
-                                       $existingAdded = $dbw->selectFieldValues(
-                                               'category',
-                                               'cat_title',
-                                               [ 'cat_title' => $added ],
-                                               $method
-                                       );
+               if ( count( $added ) ) {
+                       $existingAdded = $dbw->selectFieldValues(
+                               'category',
+                               'cat_title',
+                               [ 'cat_title' => $added ],
+                               __METHOD__
+                       );
 
-                                       // For category rows that already exist, do a plain
-                                       // UPDATE instead of INSERT...ON DUPLICATE KEY UPDATE
-                                       // to avoid creating gaps in the cat_id sequence.
-                                       if ( count( $existingAdded ) ) {
-                                               $dbw->update(
-                                                       'category',
-                                                       $addFields,
-                                                       [ 'cat_title' => $existingAdded ],
-                                                       $method
-                                               );
-                                       }
+                       // For category rows that already exist, do a plain
+                       // UPDATE instead of INSERT...ON DUPLICATE KEY UPDATE
+                       // to avoid creating gaps in the cat_id sequence.
+                       if ( count( $existingAdded ) ) {
+                               $dbw->update(
+                                       'category',
+                                       $addFields,
+                                       [ 'cat_title' => $existingAdded ],
+                                       __METHOD__
+                               );
+                       }
 
-                                       $missingAdded = array_diff( $added, $existingAdded );
-                                       if ( count( $missingAdded ) ) {
-                                               $insertRows = [];
-                                               foreach ( $missingAdded as $cat ) {
-                                                       $insertRows[] = [
-                                                               'cat_title'   => $cat,
-                                                               'cat_pages'   => 1,
-                                                               'cat_subcats' => ( $ns == NS_CATEGORY ) ? 1 : 0,
-                                                               'cat_files'   => ( $ns == NS_FILE ) ? 1 : 0,
-                                                       ];
-                                               }
-                                               $dbw->upsert(
-                                                       'category',
-                                                       $insertRows,
-                                                       [ 'cat_title' ],
-                                                       $addFields,
-                                                       $method
-                                               );
-                                       }
+                       $missingAdded = array_diff( $added, $existingAdded );
+                       if ( count( $missingAdded ) ) {
+                               $insertRows = [];
+                               foreach ( $missingAdded as $cat ) {
+                                       $insertRows[] = [
+                                               'cat_title'   => $cat,
+                                               'cat_pages'   => 1,
+                                               'cat_subcats' => ( $ns == NS_CATEGORY ) ? 1 : 0,
+                                               'cat_files'   => ( $ns == NS_FILE ) ? 1 : 0,
+                                       ];
                                }
+                               $dbw->upsert(
+                                       'category',
+                                       $insertRows,
+                                       [ 'cat_title' ],
+                                       $addFields,
+                                       __METHOD__
+                               );
+                       }
+               }
 
-                               if ( count( $deleted ) ) {
-                                       $dbw->update(
-                                               'category',
-                                               $removeFields,
-                                               [ 'cat_title' => $deleted ],
-                                               $method
-                                       );
-                               }
+               if ( count( $deleted ) ) {
+                       $dbw->update(
+                               'category',
+                               $removeFields,
+                               [ 'cat_title' => $deleted ],
+                               __METHOD__
+                       );
+               }
 
-                               foreach ( $added as $catName ) {
-                                       $cat = Category::newFromName( $catName );
-                                       Hooks::run( 'CategoryAfterPageAdded', [ $cat, $this ] );
-                               }
+               foreach ( $added as $catName ) {
+                       $cat = Category::newFromName( $catName );
+                       Hooks::run( 'CategoryAfterPageAdded', [ $cat, $this ] );
+               }
 
-                               foreach ( $deleted as $catName ) {
-                                       $cat = Category::newFromName( $catName );
-                                       Hooks::run( 'CategoryAfterPageRemoved', [ $cat, $this, $id ] );
-                               }
+               foreach ( $deleted as $catName ) {
+                       $cat = Category::newFromName( $catName );
+                       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.
-                               if ( count( $deleted ) ) {
-                                       $rows = $dbw->select(
-                                               'category',
-                                               [ 'cat_id', 'cat_title', 'cat_pages', 'cat_subcats', 'cat_files' ],
-                                               [ 'cat_title' => $deleted, 'cat_pages <= 0' ],
-                                               $method
-                                       );
-                                       foreach ( $rows as $row ) {
-                                               $cat = Category::newFromRow( $row );
-                                               $cat->refreshCounts();
-                                       }
-                               }
-                       },
-                       __METHOD__
-               );
+               // Refresh counts on categories that should be empty now, to
+               // trigger possible deletion. Check master for the most
+               // up-to-date cat_pages.
+               if ( count( $deleted ) ) {
+                       $rows = $dbw->select(
+                               'category',
+                               [ 'cat_id', 'cat_title', 'cat_pages', 'cat_subcats', 'cat_files' ],
+                               [ 'cat_title' => $deleted, 'cat_pages <= 0' ],
+                               __METHOD__
+                       );
+                       foreach ( $rows as $row ) {
+                               $cat = Category::newFromRow( $row );
+                               $cat->refreshCounts();
+                       }
+               }
        }
 
        /**