Merge "Make PageArchive/WikiPage CDN purges use JobQueueGroup::lazyPush() in one...
[lhc/web/wiklou.git] / includes / page / WikiPage.php
index 4f0f2e2..c8566ac 100644 (file)
@@ -41,6 +41,8 @@ use Wikimedia\Rdbms\LoadBalancer;
  *
  * Some fields are public only for backwards-compatibility. Use accessors.
  * In the past, this class was part of Article.php and everything was public.
+ *
+ * @phan-file-suppress PhanAccessMethodInternal Due to the use of DerivedPageDataUpdater
  */
 class WikiPage implements Page, IDBAccessObject {
        // Constants for $mDataLoadedFrom and related
@@ -724,7 +726,7 @@ class WikiPage implements Page, IDBAccessObject {
                // Try using the replica DB first, then try the master
                $rev = $this->mTitle->getFirstRevision();
                if ( !$rev ) {
-                       $rev = $this->mTitle->getFirstRevision( Title::GAID_FOR_UPDATE );
+                       $rev = $this->mTitle->getFirstRevision( Title::READ_LATEST );
                }
                return $rev;
        }
@@ -1894,7 +1896,8 @@ class WikiPage implements Page, IDBAccessObject {
                // TODO: this check is here for backwards-compatibility with 1.31 behavior.
                // Checking the minoredit right should be done in the same place the 'bot' right is
                // checked for the EDIT_FORCE_BOT flag, which is currently in EditPage::attemptSave.
-               if ( ( $flags & EDIT_MINOR ) && !$user->isAllowed( 'minoredit' ) ) {
+               $permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
+               if ( ( $flags & EDIT_MINOR ) && !$permissionManager->userHasRight( $user, 'minoredit' ) ) {
                        $flags = ( $flags & ~EDIT_MINOR );
                }
 
@@ -1914,7 +1917,6 @@ class WikiPage implements Page, IDBAccessObject {
                // TODO: this logic should not be in the storage layer, it's here for compatibility
                // with 1.31 behavior. Applying the 'autopatrol' right should be done in the same
                // place the 'bot' right is handled, which is currently in EditPage::attemptSave.
-               $permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
 
                if ( $needsPatrol && $permissionManager->userCan(
                        'autopatrol', $user, $this->getTitle()
@@ -2839,7 +2841,7 @@ class WikiPage implements Page, IDBAccessObject {
         */
        protected function archiveRevisions( $dbw, $id, $suppress ) {
                global $wgContentHandlerUseDB, $wgMultiContentRevisionSchemaMigrationStage,
-                       $wgActorTableSchemaMigrationStage, $wgDeleteRevisionsBatchSize;
+                       $wgDeleteRevisionsBatchSize;
 
                // Given the lock above, we can be confident in the title and page ID values
                $namespace = $this->getTitle()->getNamespace();
@@ -2966,9 +2968,7 @@ class WikiPage implements Page, IDBAccessObject {
 
                        $dbw->delete( 'revision', [ 'rev_id' => $revids ], __METHOD__ );
                        $dbw->delete( 'revision_comment_temp', [ 'revcomment_rev' => $revids ], __METHOD__ );
-                       if ( $wgActorTableSchemaMigrationStage & SCHEMA_COMPAT_WRITE_NEW ) {
-                               $dbw->delete( 'revision_actor_temp', [ 'revactor_rev' => $revids ], __METHOD__ );
-                       }
+                       $dbw->delete( 'revision_actor_temp', [ 'revactor_rev' => $revids ], __METHOD__ );
 
                        // Also delete records from ip_changes as applicable.
                        if ( count( $ipRevIds ) > 0 ) {
@@ -3145,7 +3145,7 @@ class WikiPage implements Page, IDBAccessObject {
        public function commitRollback( $fromP, $summary, $bot,
                &$resultDetails, User $guser, $tags = null
        ) {
-               global $wgUseRCPatrol;
+               global $wgUseRCPatrol, $wgDisableAnonTalk;
 
                $dbw = wfGetDB( DB_MASTER );
 
@@ -3218,6 +3218,8 @@ class WikiPage implements Page, IDBAccessObject {
                if ( empty( $summary ) ) {
                        if ( !$currentEditorForPublic ) { // no public user name
                                $summary = wfMessage( 'revertpage-nouser' );
+                       } elseif ( $wgDisableAnonTalk && $current->getUser() === 0 ) {
+                               $summary = wfMessage( 'revertpage-anon' );
                        } else {
                                $summary = wfMessage( 'revertpage' );
                        }
@@ -3247,14 +3249,12 @@ class WikiPage implements Page, IDBAccessObject {
                // Save
                $flags = EDIT_UPDATE | EDIT_INTERNAL;
 
-               if ( $guser->isAllowed( 'minoredit' ) ) {
+               $permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
+               if ( $permissionManager->userHasRight( $guser, 'minoredit' ) ) {
                        $flags |= EDIT_MINOR;
                }
 
-               if ( $bot && ( MediaWikiServices::getInstance()
-                               ->getPermissionManager()
-                               ->userHasAnyRight( $guser, 'markbotedits', 'bot' ) )
-               ) {
+               if ( $bot && ( $permissionManager->userHasAnyRight( $guser, 'markbotedits', 'bot' ) ) ) {
                        $flags |= EDIT_FORCE_BOT;
                }
 
@@ -3289,7 +3289,6 @@ class WikiPage implements Page, IDBAccessObject {
                // TODO: this logic should not be in the storage layer, it's here for compatibility
                // with 1.31 behavior. Applying the 'autopatrol' right should be done in the same
                // place the 'bot' right is handled, which is currently in EditPage::attemptSave.
-               $permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
 
                if ( $wgUseRCPatrol && $permissionManager->userCan(
                        'autopatrol', $guser, $this->getTitle()
@@ -3306,7 +3305,7 @@ class WikiPage implements Page, IDBAccessObject {
                // Set patrolling and bot flag on the edits, which gets rollbacked.
                // This is done even on edit failure to have patrolling in that case (T64157).
                $set = [];
-               if ( $bot && $guser->isAllowed( 'markbotedits' ) ) {
+               if ( $bot && $permissionManager->userHasRight( $guser, 'markbotedits' ) ) {
                        // Mark all reverted edits as bot
                        $set['rc_bot'] = 1;
                }
@@ -3405,9 +3404,12 @@ class WikiPage implements Page, IDBAccessObject {
                MediaWikiServices::getInstance()->getLinkCache()->invalidateTitle( $title );
 
                // Invalidate caches of articles which include this page
-               DeferredUpdates::addUpdate(
-                       new HTMLCacheUpdate( $title, 'templatelinks', 'page-create' )
+               $job = HTMLCacheUpdateJob::newForBacklinks(
+                       $title,
+                       'templatelinks',
+                       [ 'causeAction' => 'page-create' ]
                );
+               JobQueueGroup::singleton()->lazyPush( $job );
 
                if ( $title->getNamespace() == NS_CATEGORY ) {
                        // Load the Category object, which will schedule a job to create
@@ -3449,9 +3451,12 @@ class WikiPage implements Page, IDBAccessObject {
 
                // Images
                if ( $title->getNamespace() == NS_FILE ) {
-                       DeferredUpdates::addUpdate(
-                               new HTMLCacheUpdate( $title, 'imagelinks', 'page-delete' )
+                       $job = HTMLCacheUpdateJob::newForBacklinks(
+                               $title,
+                               'imagelinks',
+                               [ 'causeAction' => 'page-delete' ]
                        );
+                       JobQueueGroup::singleton()->lazyPush( $job );
                }
 
                // User talk pages
@@ -3483,20 +3488,24 @@ class WikiPage implements Page, IDBAccessObject {
                $slotsChanged = null
        ) {
                // TODO: move this into a PageEventEmitter service
-
-               if ( $slotsChanged === null || in_array( SlotRecord::MAIN,  $slotsChanged ) ) {
+               $jobs = [];
+               if ( $slotsChanged === null || in_array( SlotRecord::MAIN, $slotsChanged ) ) {
                        // Invalidate caches of articles which include this page.
                        // Only for the main slot, because only the main slot is transcluded.
                        // TODO: MCR: not true for TemplateStyles! [SlotHandler]
-                       DeferredUpdates::addUpdate(
-                               new HTMLCacheUpdate( $title, 'templatelinks', 'page-edit' )
+                       $jobs[] = HTMLCacheUpdateJob::newForBacklinks(
+                               $title,
+                               'templatelinks',
+                               [ 'causeAction' => 'page-edit' ]
                        );
                }
-
                // Invalidate the caches of all pages which redirect here
-               DeferredUpdates::addUpdate(
-                       new HTMLCacheUpdate( $title, 'redirect', 'page-edit' )
+               $jobs[] = HTMLCacheUpdateJob::newForBacklinks(
+                       $title,
+                       'redirect',
+                       [ 'causeAction' => 'page-edit' ]
                );
+               JobQueueGroup::singleton()->lazyPush( $jobs );
 
                MediaWikiServices::getInstance()->getLinkCache()->invalidateTitle( $title );