Cleanup...
authorBrion Vibber <brion@users.mediawiki.org>
Thu, 8 Dec 2005 01:36:33 +0000 (01:36 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Thu, 8 Dec 2005 01:36:33 +0000 (01:36 +0000)
* Move template / squid purging back to onArticleEdit() out of updateArticle()
* Move email notifications from showArticle() to RecentChange::save(), next to the IRC updates
* Use INSERT IGNORE instead of REPLACE for WatchedItem::watch(), avoids breaking notification timestamps for the auto-add on the user talk

includes/Article.php
includes/RecentChange.php
includes/WatchedItem.php

index 0950e61..47d091f 100644 (file)
@@ -1343,8 +1343,10 @@ class Article {
                                RecentChange::notifyEdit( $now, $this->mTitle, $isminor, $wgUser, $summary,
                                        $lastRevision, $this->getTimestamp(), $bot, '', $oldsize, $newsize,
                                        $revisionId );
-                               Article::onArticleEdit( $this->mTitle );
                                $dbw->commit();
+                               
+                               // Update caches outside the main transaction
+                               Article::onArticleEdit( $this->mTitle );
                        }
                }
 
@@ -1372,32 +1374,6 @@ class Article {
                        $this->editUpdates( $text, $summary, $minor, $now );
 
 
-                       $urls = array();
-                       # Template namespace
-                       # Purge all articles linking here
-                       if ( $this->mTitle->getNamespace() == NS_TEMPLATE) {
-                               $titles = $this->mTitle->getLinksTo();
-                               Title::touchArray( $titles );
-                               if ( $wgUseSquid ) {
-                                               foreach ( $titles as $title ) {
-                                                       $urls[] = $title->getInternalURL();
-                                               }
-                               }
-                       }
-
-                       # Squid updates
-                       if ( $wgUseSquid ) {
-                               $urls = array_merge( $urls, $this->mTitle->getSquidURLs() );
-                               $u = new SquidUpdate( $urls );
-                               array_push( $wgPostCommitUpdateList, $u );
-                       }
-
-                       # File cache
-                       if ( $wgUseFileCache ) {
-                               $cm = new CacheManager($this->mTitle);
-                               @unlink($cm->fileCacheName());
-                       }
-
                        $this->showArticle( $text, wfMsg( 'updated' ), $sectionanchor, $isminor, $now, $summary, $lastRevision, $revisionId );
                }
                wfRunHooks( 'ArticleSaveComplete',
@@ -1453,13 +1429,7 @@ class Article {
                else
                        $r = '';
                $wgOut->redirect( $this->mTitle->getFullURL( $r ).$sectionanchor );
-
-               if ( $wgUseEnotif  ) {
-                       # this would be better as an extension hook
-                       include_once( "UserMailer.php" );
-                       $enotif = new EmailNotification ();
-                       $enotif->notifyOnPageChange( $this->mTitle, $now, $summary, $me2, $oldid );
-               }
+               
                wfProfileOut( $fname );
        }
 
@@ -2436,9 +2406,38 @@ class Article {
                }
        }
 
-       function onArticleEdit($title_obj) {
-               // This would be an appropriate place to purge caches.
-               // Why's this not in here now?
+       /**
+        * Purge caches on page update etc
+        */
+       function onArticleEdit( $title ) {
+               global $wgUseSquid, $wgPostCommitUpdateList, $wgUseFileCache;
+               
+               $urls = array();
+               
+               // Template namespace? Purge all articles linking here.
+               // FIXME: When a templatelinks table arrives, use it for all includes.
+               if ( $title->getNamespace() == NS_TEMPLATE) {
+                       $titles = $title->getLinksTo();
+                       Title::touchArray( $titles );
+                       if ( $wgUseSquid ) {
+                               foreach ( $titles as $link ) {
+                                       $urls[] = $link->getInternalURL();
+                               }
+                       }
+               }
+
+               # Squid updates
+               if ( $wgUseSquid ) {
+                       $urls = array_merge( $urls, $this->mTitle->getSquidURLs() );
+                       $u = new SquidUpdate( $urls );
+                       array_push( $wgPostCommitUpdateList, $u );
+               }
+
+               # File cache
+               if ( $wgUseFileCache ) {
+                       $cm = new CacheManager( $title );
+                       @unlink( $cm->fileCacheName() );
+               }
        }
 
        /**#@-*/
index 3c5383c..8bfe10c 100644 (file)
@@ -173,6 +173,21 @@ class RecentChange
                                socket_close( $conn );
                        }
                }
+               
+               // E-mail notifications
+               global $wgUseEnotif;
+               if( $wgUseEnotif ) {
+                       # this would be better as an extension hook
+                       include_once( "UserMailer.php" );
+                       $enotif = new EmailNotification();
+                       $title = Title::makeTitle( $this->mAttribs['rc_namespace'], $this->mAttribs['rc_title'] );
+                       $enotif->notifyOnPageChange( $title,
+                               $this->mAttribs['rc_timestamp'],
+                               $this->mAttribs['rc_comment'],
+                               $this->mAttribs['rc_minor'],
+                               $this->mAttribs['rc_last_oldid'] );
+               }
+               
        }
 
        # Marks a certain row as patrolled
index a281683..a2d3414 100644 (file)
@@ -66,27 +66,27 @@ class WatchedItem {
        function addWatch() {
                $fname = 'WatchedItem::addWatch';
                wfProfileIn( $fname );
-               # REPLACE instead of INSERT because occasionally someone
-               # accidentally reloads a watch-add operation.
+               
+               // Use INSERT IGNORE to avoid overwriting the notification timestamp
+               // if there's already an entry for this page
                $dbw =& wfGetDB( DB_MASTER );
-               $dbw->replace( 'watchlist', array(array('wl_user', 'wl_namespace', 'wl_title', 'wl_notificationtimestamp')),
+               $dbw->insert( 'watchlist',
                  array(
                    'wl_user' => $this->id,
                        'wl_namespace' => ($this->ns & ~1),
                        'wl_title' => $this->ti,
                        'wl_notificationtimestamp' => NULL
-                 ), $fname );
+                 ), $fname, 'IGNORE' );
 
-               # the following code compensates the new behaviour, introduced by the enotif patch,
-               # that every single watched page needs now to be listed in watchlist
-               # namespace:page and namespace_talk:page need separate entries: create them
-               $dbw->replace( 'watchlist', array(array('wl_user', 'wl_namespace', 'wl_title', 'wl_notificationtimestamp')),
+               // Every single watched page needs now to be listed in watchlist;
+               // namespace:page and namespace_talk:page need separate entries:
+               $dbw->insert( 'watchlist',
                  array(
                        'wl_user' => $this->id,
                        'wl_namespace' => ($this->ns | 1 ),
                        'wl_title' => $this->ti,
                        'wl_notificationtimestamp' => NULL
-                 ), $fname );
+                 ), $fname, 'IGNORE' );
 
                global $wgMemc;
                $wgMemc->set( $this->watchkey(), 1 );