Merge "Enable users to watch category membership changes #2"
[lhc/web/wiklou.git] / includes / page / WikiPage.php
index 39e1ba7..cdaab1a 100644 (file)
@@ -1163,7 +1163,7 @@ class WikiPage implements Page, IDBAccessObject {
                        $title->invalidateCache();
                        if ( $wgUseSquid ) {
                                // Send purge now that page_touched update was committed above
-                               $update = SquidUpdate::newSimplePurge( $title );
+                               $update = new SquidUpdate( $title->getSquidURLs() );
                                $update->doUpdate();
                        }
                } );
@@ -2783,7 +2783,7 @@ class WikiPage implements Page, IDBAccessObject {
 
                $user = is_null( $user ) ? $wgUser : $user;
                if ( !Hooks::run( 'ArticleDelete',
-                       array( &$this, &$user, &$reason, &$error, &$status )
+                       array( &$this, &$user, &$reason, &$error, &$status, $suppress )
                ) ) {
                        if ( $status->isOK() ) {
                                // Hook aborted but didn't set a fatal status
@@ -3398,22 +3398,44 @@ class WikiPage implements Page, IDBAccessObject {
                                }
 
                                if ( count( $added ) ) {
-                                       $insertRows = array();
-                                       foreach ( $added as $cat ) {
-                                               $insertRows[] = array(
-                                                       'cat_title'   => $cat,
-                                                       'cat_pages'   => 1,
-                                                       'cat_subcats' => ( $ns == NS_CATEGORY ) ? 1 : 0,
-                                                       'cat_files'   => ( $ns == NS_FILE ) ? 1 : 0,
-                                               );
-                                       }
-                                       $dbw->upsert(
+                                       $existingAdded = $dbw->selectFieldValues(
                                                'category',
-                                               $insertRows,
-                                               array( 'cat_title' ),
-                                               $addFields,
-                                               $method
+                                               'cat_title',
+                                               array( '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,
+                                                       array( 'cat_title' => $existingAdded ),
+                                                       __METHOD__
+                                               );
+                                       }
+
+                                       $missingAdded = array_diff( $added, $existingAdded );
+                                       if ( count( $missingAdded ) ) {
+                                               $insertRows = array();
+                                               foreach ( $missingAdded as $cat ) {
+                                                       $insertRows[] = array(
+                                                               'cat_title'   => $cat,
+                                                               'cat_pages'   => 1,
+                                                               'cat_subcats' => ( $ns == NS_CATEGORY ) ? 1 : 0,
+                                                               'cat_files'   => ( $ns == NS_FILE ) ? 1 : 0,
+                                                       );
+                                               }
+                                               $dbw->upsert(
+                                                       'category',
+                                                       $insertRows,
+                                                       array( 'cat_title' ),
+                                                       $addFields,
+                                                       $method
+                                               );
+                                       }
                                }
 
                                if ( count( $deleted ) ) {
@@ -3470,11 +3492,7 @@ class WikiPage implements Page, IDBAccessObject {
                if ( $this->getLinksTimestamp() < $this->getTouched() ) {
                        $params['isOpportunistic'] = true;
                        $params['rootJobTimestamp'] = $parserOutput->getCacheTime();
-
-                       JobQueueGroup::singleton()->lazyPush( EnqueueJob::newFromLocalJobs(
-                               new JobSpecification( 'refreshLinks', $params,
-                                       array( 'removeDuplicates' => true ), $this->mTitle )
-                       ) );
+                       JobQueueGroup::singleton()->lazyPush( new RefreshLinksJob( $this->mTitle, $params ) );
                }
        }
 
@@ -3543,7 +3561,7 @@ class WikiPage implements Page, IDBAccessObject {
         *
         * @param Content|null $content Optional Content object for determining the
         *   necessary updates.
-        * @return array An array of DataUpdates objects
+        * @return DataUpdate[]
         */
        public function getDeletionUpdates( Content $content = null ) {
                if ( !$content ) {