From 1f3284da900157b85a5fdba1dd3362d489cd8b68 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Sat, 25 Jun 2005 13:47:18 +0000 Subject: [PATCH] recovering previous behaviour when enotif is switched off --- includes/Article.php | 45 +++++++++------ includes/Setup.php | 2 + maintenance/archives/patch-usernewtalk2.sql | 6 ++ maintenance/tables.sql | 16 +++--- maintenance/updaters.inc | 64 +++++++++------------ 5 files changed, 72 insertions(+), 61 deletions(-) create mode 100644 maintenance/archives/patch-usernewtalk2.sql diff --git a/includes/Article.php b/includes/Article.php index 038d6cf2c5..dd563ba0c6 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -1199,6 +1199,7 @@ class Article { */ function showArticle( $text, $subtitle , $sectionanchor = '', $me2, $now, $summary, $oldid ) { global $wgUseDumbLinkUpdate, $wgAntiLockFlags, $wgOut, $wgUser, $wgLinkCache, $wgEnotif; + global $wgUseEnotif; $wgLinkCache = new LinkCache(); @@ -1251,12 +1252,12 @@ class Article { $r = ''; $wgOut->redirect( $this->mTitle->getFullURL( $r ).$sectionanchor ); - # this call would better fit into RecentChange::notifyEdit and RecentChange::notifyNew . - # this will be improved later (to-do) - - include_once( "UserMailer.php" ); - $wgEnotif = new EmailNotification (); - $wgEnotif->notifyOnPageChange( $this->mTitle, $now, $summary, $me2, $oldid ); + if ( $wgUseEnotif ) { + # this would be better as an extension hook + include_once( "UserMailer.php" ); + $wgEnotif = new EmailNotification (); + $wgEnotif->notifyOnPageChange( $this->mTitle, $now, $summary, $me2, $oldid ); + } } /** @@ -1933,7 +1934,7 @@ class Article { * @private */ function viewUpdates() { - global $wgDeferredUpdateList; + global $wgDeferredUpdateList, $wgUseEnotif; if ( 0 != $this->getID() ) { global $wgDisableCounters; @@ -1951,9 +1952,14 @@ class Article { if ($this->mTitle->getNamespace() == NS_USER_TALK && $this->mTitle->getText() == $wgUser->getName()) { - require_once( 'UserTalkUpdate.php' ); - $u = new UserTalkUpdate( 0, $this->mTitle->getNamespace(), $this->mTitle->getDBkey(), false, false, false ); - } else { + if ( $wgUseEnotif ) { + require_once( 'UserTalkUpdate.php' ); + $u = new UserTalkUpdate( 0, $this->mTitle->getNamespace(), $this->mTitle->getDBkey(), false, false, false ); + } else { + $wgUser->setNewtalk(0); + $wgUser->saveNewtalk(); + } + } elseif ( $wgUseEnotif ) { $wgUser->clearNotification( $this->mTitle ); } @@ -1967,7 +1973,7 @@ class Article { */ function editUpdates( $text, $summary, $minoredit, $timestamp_of_pagechange) { global $wgDeferredUpdateList, $wgDBname, $wgMemc; - global $wgMessageCache, $wgUser; + global $wgMessageCache, $wgUser, $wgUseEnotif; wfSeedRandom(); if ( 0 == mt_rand( 0, 999 ) ) { @@ -1991,13 +1997,18 @@ class Article { $u = new SearchUpdate( $id, $title, $text ); array_push( $wgDeferredUpdateList, $u ); - # If this is another user's talk page, - # create a watchlist entry for this page + # If this is another user's talk page, update newtalk - if ($this->mTitle->getNamespace() == NS_USER_TALK && - $shortTitle != $wgUser->getName()) { - require_once( 'UserTalkUpdate.php' ); - $u = new UserTalkUpdate( 1, $this->mTitle->getNamespace(), $shortTitle, $summary, $minoredit, $timestamp_of_pagechange); + if ($this->mTitle->getNamespace() == NS_USER_TALK && $shortTitle != $wgUser->getName()) { + if ( $wgUseEnotif ) { + require_once( 'UserTalkUpdate.php' ); + $u = new UserTalkUpdate( 1, $this->mTitle->getNamespace(), $shortTitle, $summary, + $minoredit, $timestamp_of_pagechange); + } else { + $other = User::newFromName($shortTitle); + $other->setNewtalk(1); + $other->saveNewtalk(); + } } if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) { diff --git a/includes/Setup.php b/includes/Setup.php index f7753f08b4..ecbd474b5b 100644 --- a/includes/Setup.php +++ b/includes/Setup.php @@ -101,6 +101,8 @@ if ( $wgSkipSkin ) { $wgSkipSkins[] = $wgSkipSkin; } +$wgUseEnotif = $wgEnotifUserTalk || $wgEnotifWatchlist; + wfProfileOut( $fname.'-misc1' ); wfProfileIn( $fname.'-memcached' ); diff --git a/maintenance/archives/patch-usernewtalk2.sql b/maintenance/archives/patch-usernewtalk2.sql new file mode 100644 index 0000000000..477109b794 --- /dev/null +++ b/maintenance/archives/patch-usernewtalk2.sql @@ -0,0 +1,6 @@ +CREATE TABLE /*$wgDBprefix*/user_newtalk ( + user_id int(5) NOT NULL default '0', + user_ip varchar(40) NOT NULL default '', + INDEX user_id (user_id), + INDEX user_ip (user_ip) +); diff --git a/maintenance/tables.sql b/maintenance/tables.sql index 9feaae5eb8..6ce0173aa1 100644 --- a/maintenance/tables.sql +++ b/maintenance/tables.sql @@ -135,14 +135,14 @@ CREATE TABLE /*$wgDBprefix*/user_groups ( KEY (ug_group) ) TYPE=InnoDB; --- The following table is no longer needed with Enotif >= 2.00 --- Entries for newtalk on user_talk page are handled like in the watchlist table --- CREATE TABLE /*$wgDBprefix*/user_newtalk ( --- user_id int(5) NOT NULL default '0', --- user_ip varchar(40) NOT NULL default '', --- INDEX user_id (user_id), --- INDEX user_ip (user_ip) --- ); +-- Stores notifications of user talk page changes, for the display +-- of the "you have new messages" box +CREATE TABLE /*$wgDBprefix*/user_newtalk ( + user_id int(5) NOT NULL default '0', + user_ip varchar(40) NOT NULL default '', + INDEX user_id (user_id), + INDEX user_ip (user_ip) +); -- diff --git a/maintenance/updaters.inc b/maintenance/updaters.inc index 5978eede30..e5220e612a 100644 --- a/maintenance/updaters.inc +++ b/maintenance/updaters.inc @@ -23,6 +23,7 @@ $wgNewTables = array( array( 'categorylinks', 'patch-categorylinks.sql' ), array( 'logging', 'patch-logging.sql' ), array( 'validate', 'patch-validate.sql' ), + array( 'user_newtalk', 'patch-usernewtalk2.sql' ), ); $wgNewFields = array( @@ -45,7 +46,7 @@ $wgNewFields = array( array( 'image', 'img_metadata', 'patch-img_metadata.sql' ), array( 'image', 'img_media_type', 'patch-img_media_type.sql' ), array( 'validate', 'val_ip', 'patch-val_ip.sql' ), - array( 'site_stats', 'ss_total_articles', 'patch-ss_total_articles.sql' ), + array( 'site_stats', 'ss_total_pages', 'patch-ss_total_articles.sql' ), ); function rename_table( $from, $to, $patch ) { @@ -167,9 +168,9 @@ function do_image_name_unique_update() { function do_watchlist_update() { global $wgDatabase; if( $wgDatabase->fieldExists( 'watchlist', 'wl_notificationtimestamp' ) ) { - echo "ENOTIF: The watchlist table is already set up for email notification.\n"; + echo "The watchlist table is already set up for email notification.\n"; } else { - echo "ENOTIF: Adding wl_notificationtimestamp field for email notification management."; + echo "Adding wl_notificationtimestamp field for email notification management."; /* ALTER TABLE watchlist ADD (wl_notificationtimestamp varchar(14) binary NOT NULL default '0'); */ dbsource( "maintenance/archives/patch-email-notification.sql", $wgDatabase ); echo "ok\n"; @@ -180,47 +181,38 @@ function do_copy_newtalk_to_watchlist() { global $wgDatabase; global $wgCommandLineMode; # this needs to be saved while getID() and getName() are called - if ( $wgDatabase->tableExists( 'user_newtalk' ) ) { - $res = $wgDatabase->safeQuery( 'SELECT user_id, user_ip FROM !', - $wgDatabase->tableName( 'user_newtalk' ) ); - $num_newtalks=$wgDatabase->numRows($res); - echo "ENOTIF: Now converting ".$num_newtalks." user_newtalk entries to watchlist table entries ... \n"; - - $user = new User(); - for ( $i = 1; $i <= $num_newtalks; $i++ ) { - $wluser = $wgDatabase->fetchObject( $res ); - echo 'ENOTIF: <= user_newtalk: user_id='.$wluser->user_id.' user_ip='.$wluser->user_ip."\n"; - if ($wluser->user_id == 0) { # anonymous users ... have IP numbers as "names" - if ($user->isIP($wluser->user_ip)) { # do only if it really looks like an IP number (double checked) - $wgDatabase->replace( 'watchlist', - array(array('wl_user','wl_namespace', 'wl_title', 'wl_notificationtimestamp' )), - array('wl_user' => 0, - 'wl_namespace' => NS_USER_TALK, - 'wl_title' => $wluser->user_ip, - 'wl_notificationtimestamp' => '19700101000000' - ), 'updaters.inc::do_watchlist_update2' - ); - echo 'ENOTIF: ====> watchlist: user_id=0 '.$wluser->user_ip."\n"; - } - } else { # normal users ... have user_ids - $user->setID($wluser->user_id); + $res = $wgDatabase->safeQuery( 'SELECT user_id, user_ip FROM !', + $wgDatabase->tableName( 'user_newtalk' ) ); + $num_newtalks=$wgDatabase->numRows($res); + echo "Now converting ".$num_newtalks." user_newtalk entries to watchlist table entries ... \n"; + + $user = new User(); + for ( $i = 1; $i <= $num_newtalks; $i++ ) { + $wluser = $wgDatabase->fetchObject( $res ); + if ($wluser->user_id == 0) { # anonymous users ... have IP numbers as "names" + if ($user->isIP($wluser->user_ip)) { # do only if it really looks like an IP number (double checked) $wgDatabase->replace( 'watchlist', array(array('wl_user','wl_namespace', 'wl_title', 'wl_notificationtimestamp' )), - array('wl_user' => $user->getID(), + array('wl_user' => 0, 'wl_namespace' => NS_USER_TALK, - 'wl_title' => $user->getName(), + 'wl_title' => $wluser->user_ip, 'wl_notificationtimestamp' => '19700101000000' - ), 'updaters.inc::do_watchlist_update3' + ), 'updaters.inc::do_watchlist_update2' ); - echo 'ENOTIF: ====> watchlist: user_id='.$user->getID().' '.$user->getName()."\n"; } + } else { # normal users ... have user_ids + $user->setID($wluser->user_id); + $wgDatabase->replace( 'watchlist', + array(array('wl_user','wl_namespace', 'wl_title', 'wl_notificationtimestamp' )), + array('wl_user' => $user->getID(), + 'wl_namespace' => NS_USER_TALK, + 'wl_title' => $user->getName(), + 'wl_notificationtimestamp' => '19700101000000' + ), 'updaters.inc::do_watchlist_update3' + ); } - echo "ENOTIF: The watchlist table has got the former user_newtalk entries.\n"; - dbsource( "maintenance/archives/patch-drop-user_newtalk.sql", $wgDatabase ); - echo "ENOTIF: Deleting the user_newtalk table as its entries are now in the watchlist table.\n"; - } else { - echo "ENOTIF: No user_newtalk table found. Nothing to convert to watchlist table entries.\n"; } + echo "Done.\n"; } -- 2.20.1