Add small HtmlCacheUpdater service class to normalize purging code
[lhc/web/wiklou.git] / includes / page / WikiPage.php
index af1781a..33fd472 100644 (file)
@@ -813,7 +813,7 @@ class WikiPage implements Page, IDBAccessObject {
         *
         * @since 1.21
         */
-       public function getContent( $audience = Revision::FOR_PUBLIC, User $user = null ) {
+       public function getContent( $audience = RevisionRecord::FOR_PUBLIC, User $user = null ) {
                $this->loadLastEdit();
                if ( $this->mLastRevision ) {
                        return $this->mLastRevision->getContent( $audience, $user );
@@ -851,7 +851,7 @@ class WikiPage implements Page, IDBAccessObject {
         *   to the $audience parameter
         * @return int User ID for the user that made the last article revision
         */
-       public function getUser( $audience = Revision::FOR_PUBLIC, User $user = null ) {
+       public function getUser( $audience = RevisionRecord::FOR_PUBLIC, User $user = null ) {
                $this->loadLastEdit();
                if ( $this->mLastRevision ) {
                        return $this->mLastRevision->getUser( $audience, $user );
@@ -870,7 +870,7 @@ class WikiPage implements Page, IDBAccessObject {
         *   to the $audience parameter
         * @return User|null
         */
-       public function getCreator( $audience = Revision::FOR_PUBLIC, User $user = null ) {
+       public function getCreator( $audience = RevisionRecord::FOR_PUBLIC, User $user = null ) {
                $revision = $this->getOldestRevision();
                if ( $revision ) {
                        $userName = $revision->getUserText( $audience, $user );
@@ -889,7 +889,7 @@ class WikiPage implements Page, IDBAccessObject {
         *   to the $audience parameter
         * @return string Username of the user that made the last article revision
         */
-       public function getUserText( $audience = Revision::FOR_PUBLIC, User $user = null ) {
+       public function getUserText( $audience = RevisionRecord::FOR_PUBLIC, User $user = null ) {
                $this->loadLastEdit();
                if ( $this->mLastRevision ) {
                        return $this->mLastRevision->getUserText( $audience, $user );
@@ -908,7 +908,7 @@ class WikiPage implements Page, IDBAccessObject {
         * @return string|null Comment stored for the last article revision, or null if the specified
         *  audience does not have access to the comment.
         */
-       public function getComment( $audience = Revision::FOR_PUBLIC, User $user = null ) {
+       public function getComment( $audience = RevisionRecord::FOR_PUBLIC, User $user = null ) {
                $this->loadLastEdit();
                if ( $this->mLastRevision ) {
                        return $this->mLastRevision->getComment( $audience, $user );
@@ -1176,7 +1176,7 @@ class WikiPage implements Page, IDBAccessObject {
                $conds[] = 'NOT(' . $actorMigration->getWhere( $dbr, 'rev_user', $user )['conds'] . ')';
 
                // Username hidden?
-               $conds[] = "{$dbr->bitAnd( 'rev_deleted', Revision::DELETED_USER )} = 0";
+               $conds[] = "{$dbr->bitAnd( 'rev_deleted', RevisionRecord::DELETED_USER )} = 0";
 
                $jconds = [
                        'user' => [ 'LEFT JOIN', $actorQuery['fields']['rev_user'] . ' = user_id' ],
@@ -1294,13 +1294,8 @@ class WikiPage implements Page, IDBAccessObject {
 
                $this->mTitle->invalidateCache();
 
-               // Clear file cache
-               HTMLFileCache::clearFileCache( $this->getTitle() );
-               // Send purge after above page_touched update was committed
-               DeferredUpdates::addUpdate(
-                       new CdnCacheUpdate( $this->mTitle->getCdnUrls() ),
-                       DeferredUpdates::PRESEND
-               );
+               // Clear file cache and send purge after above page_touched update was committed
+               MediaWikiServices::getInstance()->getHtmlCacheUpdater()->purge( $this->mTitle );
 
                if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
                        $messageCache = MessageCache::singleton();
@@ -1588,7 +1583,7 @@ class WikiPage implements Page, IDBAccessObject {
                $baseRevId = null;
                if ( $edittime && $sectionId !== 'new' ) {
                        $lb = $this->getDBLoadBalancer();
-                       $dbr = $lb->getConnection( DB_REPLICA );
+                       $dbr = $lb->getConnectionRef( DB_REPLICA );
                        $rev = Revision::loadFromTimestamp( $dbr, $this->mTitle, $edittime );
                        // Try the master if this thread may have just added it.
                        // This could be abstracted into a Revision method, but we don't want
@@ -1597,7 +1592,7 @@ class WikiPage implements Page, IDBAccessObject {
                                && $lb->getServerCount() > 1
                                && $lb->hasOrMadeRecentMasterChanges()
                        ) {
-                               $dbw = $lb->getConnection( DB_MASTER );
+                               $dbw = $lb->getConnectionRef( DB_MASTER );
                                $rev = Revision::loadFromTimestamp( $dbw, $this->mTitle, $edittime );
                        }
                        if ( $rev ) {
@@ -2695,7 +2690,7 @@ class WikiPage implements Page, IDBAccessObject {
                // we need to remember the old content so we can use it to generate all deletion updates.
                $revision = $this->getRevision();
                try {
-                       $content = $this->getContent( Revision::RAW );
+                       $content = $this->getContent( RevisionRecord::RAW );
                } catch ( Exception $ex ) {
                        wfLogWarning( __METHOD__ . ': failed to load content during deletion! '
                                . $ex->getMessage() );
@@ -2844,7 +2839,7 @@ class WikiPage implements Page, IDBAccessObject {
 
                // Bitfields to further suppress the content
                if ( $suppress ) {
-                       $bitfield = Revision::SUPPRESSED_ALL;
+                       $bitfield = RevisionRecord::SUPPRESSED_ALL;
                        $revQuery['fields'] = array_diff( $revQuery['fields'], [ 'rev_deleted' ] );
                }
 
@@ -3384,18 +3379,20 @@ class WikiPage implements Page, IDBAccessObject {
                // Update existence markers on article/talk tabs...
                $other = $title->getOtherPage();
 
-               $other->purgeSquid();
+               MediaWikiServices::getInstance()->getHtmlCacheUpdater()->purge( [ $title, $other ] );
 
                $title->touchLinks();
-               $title->purgeSquid();
                $title->deleteTitleProtection();
 
                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
@@ -3415,19 +3412,14 @@ class WikiPage implements Page, IDBAccessObject {
                // TODO: move this into a PageEventEmitter service
 
                // Update existence markers on article/talk tabs...
-               // Clear Backlink cache first so that purge jobs use more up-to-date backlink information
-               BacklinkCache::get( $title )->clear();
                $other = $title->getOtherPage();
 
-               $other->purgeSquid();
+               MediaWikiServices::getInstance()->getHtmlCacheUpdater()->purge( [ $title, $other ] );
 
                $title->touchLinks();
-               $title->purgeSquid();
 
                MediaWikiServices::getInstance()->getLinkCache()->invalidateTitle( $title );
 
-               // File cache
-               HTMLFileCache::clearFileCache( $title );
                InfoAction::invalidateCache( $title );
 
                // Messages
@@ -3437,9 +3429,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
@@ -3472,26 +3467,28 @@ class WikiPage implements Page, IDBAccessObject {
        ) {
                // 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 );
 
-               // Purge CDN for this page only
-               $title->purgeSquid();
-               // Clear file cache for this page only
-               HTMLFileCache::clearFileCache( $title );
+               MediaWikiServices::getInstance()->getHtmlCacheUpdater()->purge( $title );
 
                // Purge ?action=info cache
                $revid = $revision ? $revision->getId() : null;
@@ -3503,7 +3500,7 @@ class WikiPage implements Page, IDBAccessObject {
                self::purgeInterwikiCheckKey( $title );
        }
 
-       /**#@-*/
+       /** #@- */
 
        /**
         * Purge the check key for cross-wiki cache entries referencing this page
@@ -3768,7 +3765,7 @@ class WikiPage implements Page, IDBAccessObject {
                        $slotContent = [ SlotRecord::MAIN => $rev ];
                } else {
                        $slotContent = array_map( function ( SlotRecord $slot ) {
-                               return $slot->getContent( Revision::RAW );
+                               return $slot->getContent( RevisionRecord::RAW );
                        }, $rev->getSlots()->getSlots() );
                }