From 1c9c38d38c25a1522c4d31879602dc3da09dd239 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Thu, 8 Dec 2005 01:36:33 +0000 Subject: [PATCH] Cleanup... * 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 | 73 +++++++++++++++++++-------------------- includes/RecentChange.php | 15 ++++++++ includes/WatchedItem.php | 18 +++++----- 3 files changed, 60 insertions(+), 46 deletions(-) diff --git a/includes/Article.php b/includes/Article.php index 0950e6163c..47d091fc7d 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -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() ); + } } /**#@-*/ diff --git a/includes/RecentChange.php b/includes/RecentChange.php index 3c5383c0bc..8bfe10c724 100644 --- a/includes/RecentChange.php +++ b/includes/RecentChange.php @@ -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 diff --git a/includes/WatchedItem.php b/includes/WatchedItem.php index a281683ffc..a2d3414857 100644 --- a/includes/WatchedItem.php +++ b/includes/WatchedItem.php @@ -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 ); -- 2.20.1