Merge "Removed old HTMLCacheUpdateJob b/c code"
[lhc/web/wiklou.git] / includes / page / WikiPage.php
index a0a3c69..fe61f6f 100644 (file)
@@ -2154,10 +2154,12 @@ class WikiPage implements Page, IDBAccessObject {
         * - changed: boolean, whether the revision changed the content (default true)
         * - created: boolean, whether the revision created the page (default false)
         * - moved: boolean, whether the page was moved (default false)
-        * - oldcountable: boolean or null (default null):
+        * - oldcountable: boolean, null, or string 'no-change' (default null):
         *   - boolean: whether the page was counted as an article before that
         *     revision, only used in changed is true and created is false
-        *   - null: don't change the article count
+        *   - null: if created is false, don't update the article count; if created
+        *     is true, do update the article count
+        *   - 'no-change': don't update the article count, ever
         */
        public function doEditUpdates( Revision $revision, User $user, array $options = array() ) {
                global $wgEnableParserCache;
@@ -2200,11 +2202,8 @@ class WikiPage implements Page, IDBAccessObject {
                Hooks::run( 'ArticleEditUpdates', array( &$this, &$editInfo, $options['changed'] ) );
 
                if ( Hooks::run( 'ArticleEditUpdatesDeleteFromRecentchanges', array( &$this ) ) ) {
-                       if ( 0 == mt_rand( 0, 99 ) ) {
-                               // Flush old entries from the `recentchanges` table; we do this on
-                               // random requests so as to avoid an increase in writes for no good reason
-                               RecentChange::purgeExpiredChanges();
-                       }
+                       // Flush old entries from the `recentchanges` table
+                       JobQueueGroup::singleton()->push( RecentChangesUpdateJob::newPurgeJob() );
                }
 
                if ( !$this->exists() ) {
@@ -2215,7 +2214,9 @@ class WikiPage implements Page, IDBAccessObject {
                $title = $this->mTitle->getPrefixedDBkey();
                $shortTitle = $this->mTitle->getDBkey();
 
-               if ( !$options['changed'] && !$options['moved'] ) {
+               if ( $options['oldcountable'] === 'no-change' ||
+                       ( !$options['changed'] && !$options['moved'] )
+               ) {
                        $good = 0;
                } elseif ( $options['created'] ) {
                        $good = (int)$this->isCountable( $editInfo );
@@ -3377,70 +3378,35 @@ class WikiPage implements Page, IDBAccessObject {
        }
 
        /**
-        * Updates cascading protections
+        * Opportunistically enqueue link update jobs given fresh parser output if useful
         *
-        * @param ParserOutput $parserOutput ParserOutput object for the current version
+        * @param ParserOutput $parserOutput Current version page output
+        * @return bool Whether a job was pushed
+        * @since 1.25
         */
-       public function doCascadeProtectionUpdates( ParserOutput $parserOutput ) {
-               if ( wfReadOnly() || !$this->mTitle->areRestrictionsCascading() ) {
-                       return;
-               }
-
-               // templatelinks or imagelinks tables may have become out of sync,
-               // especially if using variable-based transclusions.
-               // For paranoia, check if things have changed and if
-               // so apply updates to the database. This will ensure
-               // that cascaded protections apply as soon as the changes
-               // are visible.
-
-               // Get templates from templatelinks and images from imagelinks
-               $id = $this->getId();
-
-               $dbLinks = array();
-
-               $dbr = wfGetDB( DB_SLAVE );
-               $res = $dbr->select( array( 'templatelinks' ),
-                       array( 'tl_namespace', 'tl_title' ),
-                       array( 'tl_from' => $id ),
-                       __METHOD__
-               );
-
-               foreach ( $res as $row ) {
-                       $dbLinks["{$row->tl_namespace}:{$row->tl_title}"] = true;
+       public function triggerOpportunisticLinksUpdate( ParserOutput $parserOutput ) {
+               if ( wfReadOnly() ) {
+                       return false;
                }
 
-               $dbr = wfGetDB( DB_SLAVE );
-               $res = $dbr->select( array( 'imagelinks' ),
-                       array( 'il_to' ),
-                       array( 'il_from' => $id ),
-                       __METHOD__
-               );
-
-               foreach ( $res as $row ) {
-                       $dbLinks[NS_FILE . ":{$row->il_to}"] = true;
+               if ( $this->mTitle->areRestrictionsCascading() ) {
+                       // If the page is cascade protecting, the links should really be up-to-date
+                       $params = array( 'prioritize' => true );
+               } elseif ( $parserOutput->hasDynamicContent() ) {
+                       // Assume the output contains time/random based magic words
+                       $params = array();
+               } else {
+                       // If the inclusions are deterministic, the edit-triggered link jobs are enough
+                       return false;
                }
 
-               // Get templates and images from parser output.
-               $poLinks = array();
-               foreach ( $parserOutput->getTemplates() as $ns => $templates ) {
-                       foreach ( $templates as $dbk => $id ) {
-                               $poLinks["$ns:$dbk"] = true;
-                       }
-               }
-               foreach ( $parserOutput->getImages() as $dbk => $id ) {
-                       $poLinks[NS_FILE . ":$dbk"] = true;
+               // Check if the last link refresh was before page_touched
+               if ( $this->getLinksTimestamp() < $this->getTouched() ) {
+                       JobQueueGroup::singleton()->push( new RefreshLinksJob( $this->mTitle, $params ) );
+                       return true;
                }
 
-               // Get the diff
-               $links_diff = array_diff_key( $poLinks, $dbLinks );
-
-               if ( count( $links_diff ) > 0 ) {
-                       // Whee, link updates time.
-                       // Note: we are only interested in links here. We don't need to get
-                       // other DataUpdate items from the parser output.
-                       $u = new LinksUpdate( $this->mTitle, $parserOutput, false );
-                       $u->doUpdate();
-               }
+               return false;
        }
 
        /**